コード例 #1
0
        public static IdentityServerServiceFactory Configure(this IdentityServerServiceFactory factory,
                                                             string connectionString)
        {
            var serviceOptions = new EntityFrameworkServiceOptions {
                ConnectionString = connectionString, Schema = "AuthServer".ToUpper()
            };

            SetupScopes(InMemoryManager.GetScopes(), serviceOptions);
            SetupUsers(InMemoryManager.GetUsers(), serviceOptions);
            SetupClients(InMemoryManager.GetClients(), serviceOptions);
            factory.RegisterOperationalServices(serviceOptions);
            factory.RegisterConfigurationServices(serviceOptions);
            //factory.Register(new Registration<OperationsDbContext>(resolver=>new OperationsDbContext(serviceOptions.ConnectionString,serviceOptions.Schema)));
            factory.Register(new Registration <Context>(resolver => new Context(connectionString)));
            factory.Register(new Registration <UserStore>());
            factory.Register(new Registration <UserManager>());
            new TokenCleanup(serviceOptions, 1).Start();
            var context = new Context(serviceOptions.ConnectionString);

            var userService =
                new AspNetIdentityUserService <IdentityUser, string>(new UserManager(new UserStore(context)));

            factory.UserService = new Registration <IUserService>(userService);
            return(factory);
        }
コード例 #2
0
        private void InitializeManagers()
        {
            FilepathManagerInstance = new FilepathManager(GetFileManagerPath());

            DatabaseManagerInstance = new SQLiteDatabaseManager(FilepathManagerInstance);

            InMemoryManagerInstance = new InMemoryManager(DatabaseManagerInstance);

            ApiManagerInstance = new ApiManager
                                     (Properties.Settings.Default.ConsumerKey, Properties.Settings.Default.ConsumerSecret,
                                     Properties.Settings.Default.AccessKey, Properties.Settings.Default.AccessSecret,
                                     Properties.Settings.Default.RequestKey, Properties.Settings.Default.RequestSecret);

            ServerQueriesManagerInstance = new ServerQueriesManager(ApiManagerInstance, InMemoryManagerInstance);

            ImageCacheInstance = new ImageCache(
                Properties.Settings.Default.ImageCacheSizeInMB,
                new TimeSpan(0, 0, Properties.Settings.Default.ImageCacheSlidingExpirationInSeconds));

            ImageRetrieverInstance = new ImageRetriever(FilepathManagerInstance, ImageCacheInstance);

            ImageDownloaderInstance = new ImageDownloader(FilepathManagerInstance, InMemoryManagerInstance);

            GlobalManagerInstance = new GlobalManager
                                        (ApiManagerInstance, DatabaseManagerInstance, ImageDownloaderInstance, InMemoryManagerInstance, ServerQueriesManagerInstance);

            PortraitConverter portraitConv = (PortraitConverter)Application.Current.FindResource("PortraitConv");

            portraitConv.ImageRetriever = ImageRetrieverInstance;
        }
コード例 #3
0
ファイル: AclService.cs プロジェクト: DaveSenn/Zuehlke.Hades
 /// <summary>
 /// Initializes a new instance of the <see cref="AclService"/>
 /// </summary>
 /// <param name="manager">A <see cref="IAclManager"/> for the policies (default: in memory)</param>
 public AclService(IAclManager manager = null)
 {
     if (manager == null)
     {
         manager = new InMemoryManager();
     }
     Manager = manager;
 }
コード例 #4
0
        public void SparqlGroupByWithEmptyResultSet()
        {
            //var query = "SELECT ?s  (COUNT(?o) AS ?c) WHERE {?s a ?o} GROUP BY ?s";
            var query  = "SELECT ?s  (COUNT(?o) AS ?c) WHERE {?s a ?o} GROUP BY ?s";
            var m      = new InMemoryManager();
            var result = (SparqlResultSet)m.Query(query);

            Assert.Empty(result.Results);
        }
コード例 #5
0
        private IEnumerable <CardBase> Search(string partialName)
        {
            if (InMemoryManager == null || partialName.Length < MinimumSearchChars)
            {
                yield break;
            }

            foreach (string name in InMemoryManager.LookForCardNames(partialName))
            {
                yield return(InMemoryManager.GetCardBase(name));
            }
        }
コード例 #6
0
        private static readonly bool UseStorage = true; // option from config file

        public static IEventManager CreateManager()
        {
            if (UseStorage)
            {
                var stg     = new FileEventManager("events.txt");
                var primary = new InMemoryManager();
                return(new CombinedManager(primary, stg));
            }
            else
            {
                return(new InMemoryManager());
            }
        }
コード例 #7
0
        public void Configuration(IAppBuilder app)
        {
            var factory = new IdentityServerServiceFactory()
                          .UseInMemoryUsers(InMemoryManager.GetUsers())
                          .UseInMemoryScopes(InMemoryManager.GetScopes())
                          .UseInMemoryClients(InMemoryManager.GetClients());

            var options = new IdentityServerOptions
            {
                SigningCertificate = Certificate.Load(),
                RequireSsl         = false,
                Factory            = factory
            };

            app.UseIdentityServer(options);
        }
コード例 #8
0
        public void Configuration(IAppBuilder app)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.RollingFile("C:\\logs\\oauth.log", retainedFileCountLimit: 7,
                                              outputTemplate: "{Timestamp} [{Level}] {Message}{NewLine}{Exception}")
                         .CreateLogger();

            var inMemoryManager = new InMemoryManager();

            var users = inMemoryManager.GetUsers();

            var factory = new IdentityServerServiceFactory()
                          .UseInMemoryUsers(inMemoryManager.GetUsers())
                          .UseInMemoryClients(inMemoryManager.GetClients())
                          .UseInMemoryScopes(inMemoryManager.GetScopes());

            factory.SecretValidators.Clear();
            factory.SecretValidators.Add(new Registration <ISecretValidator>(resolver => new SecretValidator()));

            factory.SecretParsers.Clear();
            factory.SecretParsers.Add(new Registration <ISecretParser>(resolver => new SecretParser()));

            factory.CustomTokenResponseGenerator = new Registration <ICustomTokenResponseGenerator, SofTokenResponseGenerator>();

            /*var viewOptions = new DefaultViewServiceOptions();
             * viewOptions.Stylesheets.Add("TBD...");
             * factory.ConfigureDefaultViewService(viewOptions);*/

            var options = new IdentityServerOptions
            {
                SiteName           = "NextGen Healthcare",
                SigningCertificate = Certificate.Load(),
                Factory            = factory,
                RequireSsl         = false,
                LoggingOptions     = new LoggingOptions
                {
                    EnableHttpLogging          = true,
                    EnableKatanaLogging        = true,
                    EnableWebApiDiagnostics    = true,
                    WebApiDiagnosticsIsVerbose = true
                }
            };

            app.Map("", idsrvApp => { idsrvApp.UseIdentityServer(options); });
        }
コード例 #9
0
        private IGraph ExecuteDiff(IGraph older, IGraph newer, Uri graphUri = null)
        {
            var diff   = new GraphDiff().Difference(older, newer);
            var update = diff.AsUpdate(graphUri);
            var sparql = update.ToString();

            output.WriteLine(sparql);

            older = older ?? new Graph();

            var ts = new TripleStore();

            ts.Add(older);

            var store = new InMemoryManager(ts) as IUpdateableStorage;

            store.Update(sparql);

            return(older);
        }
コード例 #10
0
        private static void Test(string query, bool isNamedGraph, int expectedCount)
        {
            IGraph graph = new Graph();

            if (isNamedGraph)
            {
                graph.BaseUri = new Uri("http://g");
            }
            new TurtleParser().Load(graph, new StringReader(TestData));

            IInMemoryQueryableStore store = new TripleStore();

            store.Add(graph);
            IQueryableStorage storage = new InMemoryManager(store);

            using (SparqlResultSet resultSet = (SparqlResultSet)storage.Query(query))
            {
                Assert.Equal(expectedCount, resultSet.Count);
            }
        }
コード例 #11
0
        private static void Test(string query, string literal)

        {
            IGraph graph = new Graph();

            graph.LoadFromString(TestData);

            IInMemoryQueryableStore store = new TripleStore();

            store.Add(graph);
            IQueryableStorage storage = new InMemoryManager(store);

            using (SparqlResultSet resultSet = (SparqlResultSet)storage.Query(query))
            {
                TestTools.ShowResults(resultSet);
                Assert.Equal(1, resultSet.Count);

                SparqlResult result = resultSet[0];
                Assert.True(result.HasBoundValue("oo"));
                Assert.Equal(graph.CreateLiteralNode(literal), result["oo"]);
            }
        }
コード例 #12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var dir = Path.GetDirectoryName(typeof(Startup).GetTypeInfo().Assembly.Location);

            var xmlConfig     = File.OpenRead(Path.Combine(dir, "xml/ZWave_custom_cmd_classes.xml"));
            var xmlParser     = new ZWaveClassesXmlParser();
            var loggerFactory = new LoggerFactory()
                                .AddConsole();
            var zwaveController = new ZWaveSerialController("/dev/tty.usbmodem411", xmlParser.Parse(xmlConfig), loggerFactory);

            zwaveController.Connect();

            var store = new InMemoryManager();

            services.AddSingleton <IUpdateableStorage>(store);
            services.AddSingleton(zwaveController);

            Task.Run(async() =>
            {
                var tcs = new CancellationTokenSource(20000);
                await zwaveController.DiscoverNodes(tcs.Token);
                await zwaveController.FetchNodeInfo(tcs.Token);

                var zwaveTripleCollector = new ZWaveTripleCollector(zwaveController, store);
                zwaveTripleCollector.SaveNodesToStore();
            }).Wait();

            // Add framework services.
            services.AddMvcCore()
            .AddRdfFormatters()
            .AddMvcOptions(opt =>
            {
                opt.Filters.Add(new ApiDocumentationFilter());
            });
            services.AddCors();
        }
コード例 #13
0
        public void ParsingWriteToStoreHandlerBNodesAcrossBatchesInMemory()
        {
            InMemoryManager manager = new InMemoryManager();

            this.TestWriteToStoreHandlerWithBNodes(manager);
        }
コード例 #14
0
        public void ParsingWriteToStoreHandlerDatasetsInMemory()
        {
            InMemoryManager manager = new InMemoryManager();

            this.TestWriteToStoreDatasetsHandler(manager);
        }
コード例 #15
0
        public void ParsingWriteToStoreHandlerInMemory()
        {
            InMemoryManager mem = new InMemoryManager();

            this.TestWriteToStoreHandler(mem);
        }
コード例 #16
0
        /// <summary>
        /// Tries to load a Generic IO Manager based on information from the Configuration Graph.
        /// </summary>
        /// <param name="g">Configuration Graph.</param>
        /// <param name="objNode">Object Node.</param>
        /// <param name="targetType">Target Type.</param>
        /// <param name="obj">Output Object.</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            IStorageProvider          storageProvider = null;
            IStorageServer            storageServer   = null;
            SparqlConnectorLoadMethod loadMode;

            obj = null;

            String server, user, pwd, store, catalog, loadModeRaw;

            Object temp;
            INode  storeObj;

            // Create the URI Nodes we're going to use to search for things
            INode propServer          = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyServer)),
                  propDb              = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDatabase)),
                  propStore           = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStore)),
                  propAsync           = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyAsync)),
                  propStorageProvider = g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyStorageProvider));

            switch (targetType.FullName)
            {
            case AllegroGraph:
                // Get the Server, Catalog and Store
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                catalog = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyCatalog)));
                store   = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }

                // Get User Credentials
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                if (user != null && pwd != null)
                {
                    storageProvider = new AllegroGraphConnector(server, catalog, store, user, pwd);
                }
                else
                {
                    storageProvider = new AllegroGraphConnector(server, catalog, store);
                }
                break;

            case AllegroGraphServer:
                // Get the Server, Catalog and User Credentials
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                catalog = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyCatalog)));
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                if (user != null && pwd != null)
                {
                    storageServer = new AllegroGraphServer(server, catalog, user, pwd);
                }
                else
                {
                    storageServer = new AllegroGraphServer(server, catalog);
                }
                break;

            case DatasetFile:
                // Get the Filename and whether the loading should be done asynchronously
                String file = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyFromFile)));
                if (file == null)
                {
                    return(false);
                }
                file = ConfigurationLoader.ResolvePath(file);
                bool isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false);
                storageProvider = new DatasetFileManager(file, isAsync);
                break;

            case Dydra:
                throw new DotNetRdfConfigurationException("DydraConnector is no longer supported by dotNetRDF and is considered obsolete");

            case FourStore:
                // Get the Server and whether Updates are enabled
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEnableUpdates)), true);
                storageProvider = new FourStoreConnector(server, enableUpdates);
                break;

            case Fuseki:
                // Get the Server URI
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                storageProvider = new FusekiConnector(server);
                break;

            case InMemory:
                // Get the Dataset/Store
                INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingDataset)));
                if (datasetObj != null)
                {
                    temp = ConfigurationLoader.LoadObject(g, datasetObj);
                    if (temp is ISparqlDataset)
                    {
                        storageProvider = new InMemoryManager((ISparqlDataset)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface");
                    }
                }
                else
                {
                    // If no dnr:usingDataset try dnr:usingStore instead
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUsingStore)));
                    if (storeObj != null)
                    {
                        temp = ConfigurationLoader.LoadObject(g, storeObj);
                        if (temp is IInMemoryQueryableStore)
                        {
                            storageProvider = new InMemoryManager((IInMemoryQueryableStore)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface");
                        }
                    }
                    else
                    {
                        // If no dnr:usingStore either then create a new empty store
                        storageProvider = new InMemoryManager();
                    }
                }
                break;

            case ReadOnly:
                // Get the actual Manager we are wrapping
                storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider);
                temp     = ConfigurationLoader.LoadObject(g, storeObj);
                if (temp is IStorageProvider)
                {
                    storageProvider = new ReadOnlyConnector((IStorageProvider)temp);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IStorageProvider interface");
                }
                break;

            case ReadOnlyQueryable:
                // Get the actual Manager we are wrapping
                storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, propStorageProvider);
                temp     = ConfigurationLoader.LoadObject(g, storeObj);
                if (temp is IQueryableStorage)
                {
                    storageProvider = new QueryableReadOnlyConnector((IQueryableStorage)temp);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableStorage interface");
                }
                break;

            case Sesame:
            case SesameV5:
            case SesameV6:
                // Get the Server and Store ID
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                if (user != null && pwd != null)
                {
                    storageProvider = (IStorageProvider)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd });
                }
                else
                {
                    storageProvider = (IStorageProvider)Activator.CreateInstance(targetType, new Object[] { server, store });
                }
                break;

            case SesameServer:
                // Get the Server and User Credentials
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                if (user != null && pwd != null)
                {
                    storageServer = new SesameServer(server, user, pwd);
                }
                else
                {
                    storageServer = new SesameServer(server);
                }
                break;

            case Sparql:
                // Get the Endpoint URI or the Endpoint
                server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) });

                // What's the load mode?
                loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode)));
                loadMode    = SparqlConnectorLoadMethod.Construct;
                if (loadModeRaw != null)
                {
                    try
                    {
                        loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw);
                    }
                    catch
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid");
                    }
                }

                if (server == null)
                {
                    INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) });
                    if (endpointObj == null)
                    {
                        return(false);
                    }
                    temp = ConfigurationLoader.LoadObject(g, endpointObj);
                    if (temp is SparqlRemoteEndpoint)
                    {
                        storageProvider = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint");
                    }
                }
                else
                {
                    // Are there any Named/Default Graph URIs
                    IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri)))
                                                  where def.NodeType == NodeType.Uri
                                                  select((IUriNode)def).Uri;

                    IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri)))
                                                    where named.NodeType == NodeType.Uri
                                                    select((IUriNode)named).Uri;

                    if (defGraphs.Any() || namedGraphs.Any())
                    {
                        storageProvider = new SparqlConnector(new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs), loadMode);
                    }
                    else
                    {
                        storageProvider = new SparqlConnector(UriFactory.Create(server), loadMode);
                    }
                }
                break;

            case ReadWriteSparql:
                SparqlRemoteEndpoint       queryEndpoint;
                SparqlRemoteUpdateEndpoint updateEndpoint;

                // Get the Query Endpoint URI or the Endpoint
                server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) });

                // What's the load mode?
                loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode)));
                loadMode    = SparqlConnectorLoadMethod.Construct;
                if (loadModeRaw != null)
                {
                    try
                    {
                        loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw);
                    }
                    catch
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid");
                    }
                }

                if (server == null)
                {
                    INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyQueryEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) });
                    if (endpointObj == null)
                    {
                        return(false);
                    }
                    temp = ConfigurationLoader.LoadObject(g, endpointObj);
                    if (temp is SparqlRemoteEndpoint)
                    {
                        queryEndpoint = (SparqlRemoteEndpoint)temp;
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:queryEndpoint/dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint");
                    }
                }
                else
                {
                    // Are there any Named/Default Graph URIs
                    IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyDefaultGraphUri)))
                                                  where def.NodeType == NodeType.Uri
                                                  select((IUriNode)def).Uri;

                    IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyNamedGraphUri)))
                                                    where named.NodeType == NodeType.Uri
                                                    select((IUriNode)named).Uri;

                    if (defGraphs.Any() || namedGraphs.Any())
                    {
                        queryEndpoint = new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs);
                        ;
                    }
                    else
                    {
                        queryEndpoint = new SparqlRemoteEndpoint(UriFactory.Create(server));
                    }
                }

                // Find the Update Endpoint or Endpoint URI
                server = ConfigurationLoader.GetConfigurationString(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpointUri)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpointUri)) });

                if (server == null)
                {
                    INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, new INode[] { g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyUpdateEndpoint)), g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyEndpoint)) });
                    if (endpointObj == null)
                    {
                        return(false);
                    }
                    temp = ConfigurationLoader.LoadObject(g, endpointObj);
                    if (temp is SparqlRemoteUpdateEndpoint)
                    {
                        updateEndpoint = (SparqlRemoteUpdateEndpoint)temp;
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the ReadWriteSparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:updateEndpoint/dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteUpdateEndpoint");
                    }
                }
                else
                {
                    updateEndpoint = new SparqlRemoteUpdateEndpoint(UriFactory.Create(server));
                }
                storageProvider = new ReadWriteSparqlConnector(queryEndpoint, updateEndpoint, loadMode);
                break;

            case SparqlHttpProtocol:
                // Get the Service URI
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                storageProvider = new SparqlHttpProtocolConnector(UriFactory.Create(server));
                break;

            case Stardog:
            case StardogV1:
            case StardogV2:
            case StardogV3:
                // Get the Server and Store
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }

                // Get User Credentials
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                // Get Reasoning Mode
                StardogReasoningMode reasoning = StardogReasoningMode.None;
                String mode = ConfigurationLoader.GetConfigurationString(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyLoadMode)));
                if (mode != null)
                {
                    try
                    {
                        reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode, true);
                    }
                    catch
                    {
                        reasoning = StardogReasoningMode.None;
                    }
                }

                if (user != null && pwd != null)
                {
                    switch (targetType.FullName)
                    {
                    case StardogV1:
                        storageProvider = new StardogV1Connector(server, store, reasoning, user, pwd);
                        break;

                    case StardogV2:
                        storageProvider = new StardogV2Connector(server, store, reasoning, user, pwd);
                        break;

                    case StardogV3:
                        storageProvider = new StardogV3Connector(server, store, user, pwd);
                        break;

                    case Stardog:
                    default:
                        storageProvider = new StardogConnector(server, store, user, pwd);
                        break;
                    }
                }
                else
                {
                    switch (targetType.FullName)
                    {
                    case StardogV1:
                        storageProvider = new StardogV1Connector(server, store, reasoning);
                        break;

                    case StardogV2:
                        storageProvider = new StardogV2Connector(server, store, reasoning);
                        break;

                    case StardogV3:
                        storageProvider = new StardogV3Connector(server, store);
                        break;

                    case Stardog:
                    default:
                        storageProvider = new StardogConnector(server, store);
                        break;
                    }
                }
                break;

            case StardogServer:
            case StardogServerV1:
            case StardogServerV2:
            case StardogServerV3:
                // Get the Server and User Credentials
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                if (user != null && pwd != null)
                {
                    switch (targetType.FullName)
                    {
                    case StardogServerV1:
                        storageServer = new StardogV1Server(server, user, pwd);
                        break;

                    case StardogServerV2:
                        storageServer = new StardogV2Server(server, user, pwd);
                        break;

                    case StardogServerV3:
                        storageServer = new StardogV3Server(server, user, pwd);
                        break;

                    case StardogServer:
                    default:
                        storageServer = new StardogServer(server, user, pwd);
                        break;
                    }
                }
                else
                {
                    switch (targetType.FullName)
                    {
                    case StardogServerV1:
                        storageServer = new StardogV1Server(server);
                        break;

                    case StardogServerV2:
                        storageServer = new StardogV2Server(server);
                        break;

                    case StardogServerV3:
                        storageServer = new StardogV3Server(server);
                        break;

                    case StardogServer:
                    default:
                        storageServer = new StardogServer(server);
                        break;
                    }
                }
                break;
            }

            // Set the return object if one has been loaded
            if (storageProvider != null)
            {
                obj = storageProvider;
            }
            else if (storageServer != null)
            {
                obj = storageServer;
            }

            // Check whether this is a standard HTTP manager and if so load standard configuration
            if (obj is BaseHttpConnector)
            {
                BaseHttpConnector connector = (BaseHttpConnector)obj;

                int timeout = ConfigurationLoader.GetConfigurationInt32(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyTimeout)), 0);
                if (timeout > 0)
                {
                    connector.Timeout = timeout;
                }
                INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, g.CreateUriNode(UriFactory.Create(ConfigurationLoader.PropertyProxy)));
                if (proxyNode != null)
                {
                    temp = ConfigurationLoader.LoadObject(g, proxyNode);
                    if (temp is IWebProxy)
                    {
                        connector.Proxy = (IWebProxy)temp;
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load storage provider/server identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:proxy property pointed to an Object which could not be loaded as an object of the required type WebProxy");
                    }
                }
            }

            return(obj != null);
        }
コード例 #17
0
        /// <summary>
        /// Tries to load a Generic IO Manager based on information from the Configuration Graph
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Output Object</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            IGenericIOManager manager = null;

            obj = null;

            String server, user, pwd, store;
            bool   isAsync;

            Object temp;
            INode  storeObj;

            //Create the URI Nodes we're going to use to search for things
            INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer),
                  propDb     = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase),
                  propStore  = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore),
                  propAsync  = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAsync);

            switch (targetType.FullName)
            {
#if !NO_SYNC_HTTP
            case AllegroGraph:
                //Get the Server, Catalog and Store
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                String catalog = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog));
                store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }

                //Get User Credentials
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                if (user != null && pwd != null)
                {
                    manager = new AllegroGraphConnector(server, catalog, store, user, pwd);
                }
                else
                {
                    manager = new AllegroGraphConnector(server, catalog, store);
                }
                break;
#endif

            case DatasetFile:
                //Get the Filename and whether the loading should be done asynchronously
                String file = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile));
                if (file == null)
                {
                    return(false);
                }
                file    = ConfigurationLoader.ResolvePath(file);
                isAsync = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false);
                manager = new DatasetFileManager(file, isAsync);
                break;

#if !NO_SYNC_HTTP
            case Dydra:
                //Get the Account Name and Store
                String account = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog));
                if (account == null)
                {
                    return(false);
                }
                store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }

                //Get User Credentials
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                if (user != null)
                {
                    manager = new DydraConnector(account, store, user);
                }
                else
                {
                    manager = new DydraConnector(account, store);
                }
                break;

            case FourStore:
                //Get the Server and whether Updates are enabled
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableUpdates), true);
                manager = new FourStoreConnector(server, enableUpdates);
                break;

            case Fuseki:
                //Get the Server URI
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                manager = new FusekiConnector(server);
                break;
#endif

            case InMemory:
                //Get the Dataset/Store
                INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset));
                if (datasetObj != null)
                {
                    temp = ConfigurationLoader.LoadObject(g, datasetObj);
                    if (temp is ISparqlDataset)
                    {
                        manager = new InMemoryManager((ISparqlDataset)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface");
                    }
                }
                else
                {
                    //If no dnr:usingDataset try dnr:usingStore instead
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore));
                    if (storeObj != null)
                    {
                        temp = ConfigurationLoader.LoadObject(g, storeObj);
                        if (temp is IInMemoryQueryableStore)
                        {
                            manager = new InMemoryManager((IInMemoryQueryableStore)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface");
                        }
                    }
                    else
                    {
                        //If no dnr:usingStore either then create a new empty store
                        manager = new InMemoryManager();
                    }
                }
                break;

#if !NO_SYNC_HTTP
            case Joseki:
                //Get the Query and Update URIs
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                String queryService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryPath));
                if (queryService == null)
                {
                    return(false);
                }
                String updateService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdatePath));
                if (updateService == null)
                {
                    manager = new JosekiConnector(server, queryService);
                }
                else
                {
                    manager = new JosekiConnector(server, queryService, updateService);
                }
                break;
#endif

            case ReadOnly:
                //Get the actual Manager we are wrapping
                storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                temp     = ConfigurationLoader.LoadObject(g, storeObj);
                if (temp is IGenericIOManager)
                {
                    manager = new ReadOnlyConnector((IGenericIOManager)temp);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IGenericIOManager interface");
                }
                break;

            case ReadOnlyQueryable:
                //Get the actual Manager we are wrapping
                storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                temp     = ConfigurationLoader.LoadObject(g, storeObj);
                if (temp is IQueryableGenericIOManager)
                {
                    manager = new QueryableReadOnlyConnector((IQueryableGenericIOManager)temp);
                }
                else
                {
                    throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableGenericIOManager interface");
                }
                break;

#if !NO_SYNC_HTTP
            case Sesame:
            case SesameV5:
            case SesameV6:
                //Get the Server and Store ID
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                if (user != null && pwd != null)
                {
                    manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store, user, pwd });
                }
                else
                {
                    manager = (IGenericIOManager)Activator.CreateInstance(targetType, new Object[] { server, store });
                }
                break;

            case Sparql:
                //Get the Endpoint URI or the Endpoint
                server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpointUri));

                //What's the load mode?
                String loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode));
                SparqlConnectorLoadMethod loadMode = SparqlConnectorLoadMethod.Construct;
                if (loadModeRaw != null)
                {
                    try
                    {
#if SILVERLIGHT
                        loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw, false);
#else
                        loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw);
#endif
                    }
                    catch
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid");
                    }
                }

                if (server == null)
                {
                    INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint));
                    if (endpointObj == null)
                    {
                        return(false);
                    }
                    temp = ConfigurationLoader.LoadObject(g, endpointObj);
                    if (temp is SparqlRemoteEndpoint)
                    {
                        manager = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint");
                    }
                }
                else
                {
                    //Are there any Named/Default Graph URIs
                    IEnumerable <Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri))
                                                  where def.NodeType == NodeType.Uri
                                                  select((IUriNode)def).Uri;

                    IEnumerable <Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyNamedGraphUri))
                                                    where named.NodeType == NodeType.Uri
                                                    select((IUriNode)named).Uri;

                    if (defGraphs.Any() || namedGraphs.Any())
                    {
                        manager = new SparqlConnector(new SparqlRemoteEndpoint(UriFactory.Create(server), defGraphs, namedGraphs), loadMode);
                    }
                    else
                    {
                        manager = new SparqlConnector(UriFactory.Create(server), loadMode);
                    }
                }
                break;

            case SparqlHttpProtocol:
                //Get the Service URI
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                manager = new SparqlHttpProtocolConnector(UriFactory.Create(server));
                break;

            case Stardog:
                //Get the Server and Store
                server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                if (server == null)
                {
                    return(false);
                }
                store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }

                //Get User Credentials
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                //Get Reasoning Mode
                StardogReasoningMode reasoning = StardogReasoningMode.None;
                String mode = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode));
                if (mode != null)
                {
                    try
                    {
                        reasoning = (StardogReasoningMode)Enum.Parse(typeof(StardogReasoningMode), mode);
                    }
                    catch
                    {
                        reasoning = StardogReasoningMode.None;
                    }
                }

                if (user != null && pwd != null)
                {
                    manager = new StardogConnector(server, store, reasoning, user, pwd);
                }
                else
                {
                    manager = new StardogConnector(server, store, reasoning);
                }
                break;

            case Talis:
                //Get the Store Name and User credentials
                store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                if (store == null)
                {
                    return(false);
                }
                ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                if (user != null && pwd != null)
                {
                    manager = new TalisPlatformConnector(store, user, pwd);
                }
                else
                {
                    manager = new TalisPlatformConnector(store);
                }
                break;
#endif
            }

#if !NO_PROXY
            //Check whether this is a proxyable manager and if we need to load proxy settings
            if (manager is BaseHttpConnector)
            {
                INode proxyNode = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyProxy));
                if (proxyNode != null)
                {
                    temp = ConfigurationLoader.LoadObject(g, proxyNode);
                    if (temp is WebProxy)
                    {
                        ((BaseHttpConnector)manager).Proxy = (WebProxy)temp;
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load Generic Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:proxy property pointed to an Object which could not be loaded as an object of the required type WebProxy");
                    }
                }
            }
#endif

            obj = manager;
            return(manager != null);
        }
コード例 #18
0
        private void CreateCombatExecute()
        {
            Combat       combat   = null;
            RandomFactor isRandom = (IsRandom) ? RandomFactor.Random : RandomFactor.NonRandom;

            List <CardDrawed> leftCards = new List <CardDrawed>();

            for (int i = 0; i < 4; i++)
            {
                CardInstance instance = InMemoryManager.GetFakeCardInstance(CreationLeftCards[i].CardBaseId, CreationLeftLevels[i].Value);
                //CardInstance instance = new CardInstance(CreationLeftCards[i], 0, CreationLeftLevels[i].Value);
                leftCards.Add(new CardDrawed(instance));
            }
            Hand leftHand = new Hand(leftCards);

            List <CardDrawed> rightCards = new List <CardDrawed>();

            for (int i = 0; i < 4; i++)
            {
                CardInstance instance = InMemoryManager.GetFakeCardInstance(CreationRightCards[i].CardBaseId, CreationRightLevels[i].Value);
                //CardInstance instance = new CardInstance(CreationRightCards[i], 0, CreationRightLevels[i].Value);
                rightCards.Add(new CardDrawed(instance));
            }
            Hand rightHand = new Hand(rightCards);

            switch (GameMode)
            {
            case GameMode.Tourney:
                combat = CombatFactory.GetTourneyCombat(leftHand, rightHand, HasInitiative, isRandom);
                break;

            case GameMode.Classic:
                combat = CombatFactory.GetClassicCombat(leftHand, rightHand, HasInitiative, isRandom);
                break;

            case GameMode.Solo:
                combat = CombatFactory.GetSoloCombat(leftHand, rightHand, HasInitiative, isRandom);
                break;

            case GameMode.LeaderWars:
                throw new NotImplementedException();

            //break;
            case GameMode.ELO:
                combat = CombatFactory.GetEloCombat(leftHand, rightHand, HasInitiative);
                break;

            case GameMode.Survivor:
                throw new NotImplementedException();

            //break;
            case GameMode.Duel:
                combat = CombatFactory.GetDuelCombat(leftHand, rightHand, HasInitiative, isRandom);
                break;

            case GameMode.Custom:
                throw new NotImplementedException();
                //break;
            }

            ((CombatCalculatorCombatModeViewModel)ViewModelLocator.Locator["CombatCalculatorCombatMode"]).Combat = combat;
        }