Skip to content

Commit

Permalink
Not all SWIS implementations support access control, so test for supp…
Browse files Browse the repository at this point in the history
…ort before querying it. Fixes #6.
  • Loading branch information
tdanner committed Jul 30, 2015
1 parent d5c6af8 commit 40fd96f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Src/SwqlStudio/ObjectExplorer/SwisMetaDataProvider.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using SwqlStudio.Metadata;

Expand All @@ -19,11 +20,14 @@ public SwisMetaDataProvider(ConnectionInfo info)

public void Refresh()
{
const string query =
const string queryTemplate =
@"SELECT Entity.FullName, Entity.Namespace, Entity.BaseType, (Entity.Type ISA 'System.Indication') AS IsIndication,
Entity.Properties.Name, Entity.Properties.Type, Entity.Properties.IsNavigable, Entity.Properties.IsInherited, Entity.Properties.IsKey,
Entity.Verbs.EntityName, Entity.Verbs.Name, Entity.IsAbstract, Entity.CanCreate, Entity.CanDelete, Entity.CanInvoke, Entity.CanRead, Entity.CanUpdate
Entity.Verbs.EntityName, Entity.Verbs.Name, Entity.IsAbstract{0}
FROM Metadata.Entity";
const string crudFragment = ", Entity.CanCreate, Entity.CanDelete, Entity.CanInvoke, Entity.CanRead, Entity.CanUpdate";

string query = string.Format(queryTemplate, SupportsAccessControl() ? crudFragment : string.Empty);

entities = info.Query<Entity>(query).ToDictionary(entity => entity.FullName);

Expand All @@ -35,6 +39,16 @@ public void Refresh()
}
}

public bool SupportsAccessControl()
{
const string query = @"SELECT Name
FROM Metadata.Property
WHERE EntityName='Metadata.Entity' AND Name='CanCreate'";

DataTable dt = info.Query(query);
return dt != null && dt.Rows.Count == 1;
}

public IEnumerable<VerbArgument> GetVerbArguments(Verb verb)
{
return info.Query<VerbArgument>(
Expand Down

0 comments on commit 40fd96f

Please sign in to comment.