public void Unload()
        {
            var application = new ApplicationConfigured(new ApplicationResources
            {
                new ApplicationConfig
                {
                    Modules =
                    {
                        (IApplicationModuleBuilder)Resources.Load("Module", typeof(IApplicationModuleBuilder))
                    }
                }
            });

            application.Initialize();

            var    module = application.GetModule <IAssetModule>();
            object asset  = module.Load <Material>("7ab173a97bcf2bc44b710c33213fa557");

            Assert.NotNull(asset);
            Assert.IsInstanceOf <Material>(asset);

            module.Unload("7ab173a97bcf2bc44b710c33213fa557", asset, AssetUnloadParameters.Empty);

            Assert.Null(asset);
        }
        public void Uninitialize()
        {
            var application = new ApplicationConfigured(new ApplicationResources
            {
                new ApplicationConfig
                {
                    Modules =
                    {
                        (IApplicationModuleBuilder)Resources.Load("Module", typeof(IApplicationModuleBuilder))
                    }
                }
            });

            application.Initialize();

            var    module = application.GetModule <IAssetModule>();
            object asset1 = module.Load <Material>("7ab173a97bcf2bc44b710c33213fa557");
            object asset2 = module.Load <Material>("7ab173a97bcf2bc44b710c33213fa557");

            Assert.NotNull(asset1);
            Assert.NotNull(asset2);
            Assert.AreEqual(asset1, asset2);
            Assert.IsNotEmpty(module.Tracker.Entries);
            Assert.AreEqual(1, module.Tracker.Entries.Count);
            Assert.AreEqual(2, module.Tracker.Get("7ab173a97bcf2bc44b710c33213fa557").Count);

            application.Uninitialize();

            Assert.AreEqual(null, asset1);
            Assert.AreEqual(null, asset2);
            Assert.IsEmpty(module.Tracker.Entries);
            Assert.AreEqual(0, module.Tracker.Entries.Count);
            Assert.False(module.Tracker.TryGet("7ab173a97bcf2bc44b710c33213fa557", out _));
        }
        public IEnumerator Preload()
        {
            var application = new ApplicationConfigured(new ApplicationResources
            {
                new ApplicationConfig
                {
                    Modules =
                    {
                        (IApplicationModuleBuilder)Resources.Load("Module2", typeof(IApplicationModuleBuilder))
                    }
                }
            });

            application.Initialize();

            var module = application.GetModule <IAssetModule>();

            Assert.AreEqual(1, module.Tracker.Entries.Count);
            Assert.True(module.Tracker.Entries.ContainsKey("6ecbdf2a84bc4b94794d0ccbb7164158"));
            Assert.False(module.Tracker.Entries.ContainsKey("7532bc5c40ab10644812b87b664d33ba"));

            Task task = application.InitializeAsync();

            while (!task.IsCompleted)
            {
                yield return(null);
            }

            Assert.AreEqual(2, module.Tracker.Entries.Count);
            Assert.True(module.Tracker.Entries.ContainsKey("6ecbdf2a84bc4b94794d0ccbb7164158"));
            Assert.True(module.Tracker.Entries.ContainsKey("7532bc5c40ab10644812b87b664d33ba"));
        }
Ejemplo n.º 4
0
        public async Task InitializeSession(TLCFIClientSession session, TLCFIClientConfig config, TLCFIClientStateManager stateManager, CancellationToken token)
        {
            if (config == null)
            {
                throw new NullReferenceException("Config is null, has SetConfig been called first?");
            }
            try
            {
                var sessionId = await RegisterAsync(session, config, token);

                if (!session.State.Registered)
                {
                    throw new TLCFISessionException("Registering with TLC failed");
                }
                ApplicationRegistered?.Invoke(this, EventArgs.Empty);
                session.StartAliveTimers();
                await GetSessionDataAsync(sessionId, session, config, stateManager, token);

                if (stateManager == null)
                {
                    return;
                }
                await ReadFacilitiesMetaAsync(session, config, stateManager, token);

                Intersection inter = null;
                if (!config.UseIdsFromTLCForSubscription)
                {
                    inter = await ReadIntersectionMetaAndSubscribeAsync(session, config, stateManager, token);
                }
                var refs = CollectAllRefs(stateManager.Facilities, inter, config);

                CheckMetaData(stateManager.Facilities, inter, config);
                await ReadAllObjectsMetaAsync(refs, session, config, stateManager, token);
                await SubscribeAllObjectsAsync(refs, session, stateManager, token);

                ApplicationConfigured?.Invoke(this, EventArgs.Empty);
                await SetInitialControlState(session, stateManager);

                _logger.Info("Client configured succesfully. Now ready to request control.");
            }
            catch (TLCFISessionException e)
            {
                _logger.Fatal(e, "Error initializing session. " + (e.Fatal ? "(FATAL!): " : ": "));
                throw new TLCFISessionException("Error initializing session. " + (e.Fatal ? "(FATAL!) " : ""), e.Fatal);
            }
        }
        public void LoadReferenced()
        {
            var application = new ApplicationConfigured(new ApplicationResources
            {
                new ApplicationConfig
                {
                    Modules =
                    {
                        (IApplicationModuleBuilder)Resources.Load("Module", typeof(IApplicationModuleBuilder))
                    }
                }
            });

            application.Initialize();

            var    module = application.GetModule <IAssetModule>();
            object asset  = module.Load <Material>("d307b79fb3863804f8298a0390544dc6");

            Assert.NotNull(asset);
            Assert.IsInstanceOf <Material>(asset);
            Assert.AreEqual("AssetReferenced", ((Material)asset).name);
        }
        public void Load()
        {
            var application = new ApplicationConfigured(new ApplicationResources
            {
                new ApplicationConfig
                {
                    Modules =
                    {
                        (IApplicationModuleBuilder)Resources.Load("Module", typeof(IApplicationModuleBuilder))
                    }
                }
            });

            application.Initialize();

            var    module = application.GetModule <IAssetModule>();
            object asset  = module.Load <Material>("7ab173a97bcf2bc44b710c33213fa557");

            Assert.NotNull(asset);
            Assert.IsInstanceOf <Material>(asset);
            Assert.AreEqual("Asset", ((Material)asset).name);
        }