Ejemplo n.º 1
0
            internal static void Dispose(T @this)
            {
                var type = @this.GetType();
                var func = type == typeof(T) ? Func : DynamicCache.GetOrAdd(type, ClassDisposerCache <Object> .GetClassDisposeFunc);

                func(@this);
            }
Ejemplo n.º 2
0
 static CacheProvider()
 {
     Student = new DynamicCache();
     Class = new DynamicCache();
     Teacher = new DynamicCache();
     Course = new DynamicCache();
 }
Ejemplo n.º 3
0
        public ConnectionHelper(string uid)
        {
            DynamicCache dc = Program.GlobalSchoolCache;

            TargetDSNS = dc[uid].DSNS;
            UID        = uid;
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            DSAServices.AutoDisplayLoadingMessageOnMotherForm();

            if (DSAServices.AccessPoint.ToLower() != "dsaserverman.ischool.com.tw")
            {
                throw new ApplicationStartupException("不支援,請登入 dsaserverman.ischool.com.tw!");
            }

            GlobalSchoolCache = new DynamicCache(); //建立一個空的快取。

            InitAsposeLicense();
            InitStartMenu();
            InitConfigurationStorage();
            InitMainPanel();

            new Fields.FieldManager();
            new DetailItems();
            new RibbonButtons();
            //new ImportExport();//匯入學校資料

            RefreshFilteredSource();

            FISCA.Presentation.MotherForm.Form.Text = GetTitleText();
        }
Ejemplo n.º 5
0
        public async Task ShouldSubscribeToSpecificSubject()
        {
            using (var publisherSocket = new PublisherSocket())
            {
                publisherSocket.Bind(ToSubscribersEndpoint);

                var createEvent = new Func <string, string, Task>(async(streamId, market) =>
                {
                    var @event  = new ChangeCcyPairPrice(streamId, market, 0.0, 0.0, 0.0, 0.0);
                    var message = _eventSerializer.ToProducerMessage(@event);

                    var eventId = new EventId(streamId, 0, string.IsNullOrEmpty(market) ? streamId : $"{streamId}.{market}", DateTime.Now.Ticks);

                    publisherSocket.SendMoreFrame(message.Subject)
                    .SendMoreFrame(_serializer.Serialize(eventId))
                    .SendFrame(_serializer.Serialize(message));

                    await Task.Delay(500);
                });

                var subscribedToStreamId = "EUR/USD";
                var subscribedToMarket   = "Harmony";

                var NOTsubscribedToStreamId = "EUR/GBP";
                var NOTsubscribedToMarket   = "FxConnect";

                var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
                {
                    Subject          = $"{subscribedToStreamId}.{subscribedToMarket}",
                    HeartbeatDelay   = TimeSpan.FromSeconds(1),
                    HeartbeatTimeout = TimeSpan.FromSeconds(1),
                };

                var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

                await cache.Run();

                await Task.Delay(1000);

                await createEvent(NOTsubscribedToStreamId, NOTsubscribedToMarket);

                Assert.AreEqual(0, cache.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(NOTsubscribedToStreamId, subscribedToMarket);

                Assert.AreEqual(0, cache.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(subscribedToStreamId, NOTsubscribedToMarket);

                Assert.AreEqual(0, cache.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(subscribedToStreamId, subscribedToMarket);

                Assert.AreEqual(1, cache.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(subscribedToStreamId, string.Empty);

                Assert.AreEqual(1, cache.Items.SelectMany(ccy => ccy.AppliedEvents).Count());
            }
        }
        public DynamicCache <string, CurrencyPair> GetCache(IDynamicCacheConfiguration configuration)
        {
            var cache = new DynamicCache <string, CurrencyPair>(configuration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

            _actors.Add(cache);

            return(cache);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructs a new instance of the <see cref="Container"/> class.
        /// </summary>
        /// <param name="targets">Optional.  The target container whose registrations will be used for dependency lookup
        /// when <see cref="Resolve(ResolveContext)"/> (and other operations) is called.  If not provided, a new
        /// <see cref="TargetContainer"/> instance is constructed.  This will ultimately be available to inherited types,
        /// after construction, through the <see cref="Targets"/> property.</param>
        protected Container(IRootTargetContainer targets = null)
        {
            _scope  = new NonTrackingContainerScope(this);
            Targets = targets ?? new TargetContainer();
#if !ENABLE_IL_EMIT
            _cache = new ConcurrentCache(GetWorker);
#else
            _dynCache = DynamicCache.CreateCache(this);
#endif
        }
Ejemplo n.º 8
0
        public async Task ShouldCheckMinimumPerformance()
        {
            var eventIdProvider = new InMemoryEventIdProvider();
            var serializer      = new JsonNetSerializer();
            var eventSerializer = new EventSerializer(serializer);

            var eventCache = new InMemoryEventCache(eventIdProvider, eventSerializer);

            var brokerConfiguration = new BrokerageServiceConfiguration()
            {
                HeartbeatEndpoint       = HeartbeatEndpoint,
                StateOftheWorldEndpoint = StateOfTheWorldEndpoint,
                ToSubscribersEndpoint   = ToSubscribersEndpoint,
                ToPublisherEndpoint     = ToPublishersEndpoint
            };

            var router = new BrokerageService(brokerConfiguration, eventCache, serializer);

            var marketConfiguration = new ProducerConfiguration()
            {
                RouterEndpoint   = ToPublishersEndpoint,
                HearbeatEndpoint = HeartbeatEndpoint
            };

            var market = new Market("FxConnect", marketConfiguration, eventSerializer, TimeSpan.FromMilliseconds(10));

            await router.Run();

            await market.Run();

            var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
            {
                Subject          = string.Empty,
                HeartbeatDelay   = TimeSpan.FromSeconds(10),
                HeartbeatTimeout = TimeSpan.FromSeconds(2)
            };

            var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, eventSerializer);

            await cache.Run();

            //fire a little less than 300 events
            await Task.Delay(3000);

            await Task.WhenAll(new[] { router.Destroy(), market.Destroy(), cache.Destroy() });

            var cacheItems       = cache.GetItems().ToList();
            var cacheItemsEvents = cacheItems.SelectMany(items => items.AppliedEvents).ToList();

            //At least 3/4 events should be processed
            Assert.Greater((double)cacheItemsEvents.Count / (double)market.Prices.Count, 0.75);
        }
Ejemplo n.º 9
0
        public async Task ShouldApplyMultipleEvents()
        {
            using (var publisherSocket = new PublisherSocket())
            {
                publisherSocket.Bind(ToSubscribersEndpoint);

                var streamId = "EUR/USD";

                var createEvent = new Func <IEvent <String, CurrencyPair>, Task>(async(@event) =>
                {
                    var message = _eventSerializer.ToProducerMessage(@event);

                    var eventId = new EventId(@event.EventStreamId, 0, @event.Subject, DateTime.Now.Ticks);

                    publisherSocket.SendMoreFrame(message.Subject)
                    .SendMoreFrame(_serializer.Serialize(eventId))
                    .SendFrame(_serializer.Serialize(message));

                    await Task.Delay(200);
                });

                var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
                {
                    Subject          = string.Empty,
                    HeartbeatDelay   = TimeSpan.FromSeconds(1),
                    HeartbeatTimeout = TimeSpan.FromSeconds(1),
                };

                var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

                await cache.Run();

                await Task.Delay(2000);

                var priceEvent = new ChangeCcyPairPrice(streamId, "FxConnect", 0.0, 0.0, 0.0, 0.0);

                await createEvent(priceEvent);

                var changeStateClose = new ChangeCcyPairState(streamId, "FxConnect", CcyPairState.Passive);

                await createEvent(changeStateClose);

                Assert.AreEqual(1, cache.Items.Count());
                Assert.AreEqual(CcyPairState.Passive, cache.Items.First().State);
                Assert.AreEqual(2, cache.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await cache.Destroy();
            }
        }
Ejemplo n.º 10
0
        public async Task ShouldSwitchToStaledState()
        {
            using (var publisherSocket = new PublisherSocket())
            {
                publisherSocket.Bind(ToSubscribersEndpoint);

                var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
                {
                    Subject          = string.Empty,
                    HeartbeatDelay   = TimeSpan.FromSeconds(5),
                    HeartbeatTimeout = TimeSpan.FromSeconds(1),
                    IsStaleTimeout   = TimeSpan.FromSeconds(2)
                };

                var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

                await cache.Run();

                await WaitForCachesToCaughtUp(cache);

                Assert.AreEqual(DynamicCacheState.Connected, cache.CacheState);
                Assert.AreEqual(true, cache.IsStaled);

                var @event  = new ChangeCcyPairPrice("TEST", "TEST-Market", 0.0, 0.0, 0.0, 0.0);
                var message = _eventSerializer.ToProducerMessage(@event);

                var eventId = new EventId("TEST", 0, "TEST", DateTime.Now.Ticks);

                publisherSocket.SendMoreFrame(message.Subject)
                .SendMoreFrame(_serializer.Serialize(eventId))
                .SendFrame(_serializer.Serialize(message));

                await Task.Delay(200);

                Assert.AreEqual(DynamicCacheState.Connected, cache.CacheState);
                Assert.AreEqual(false, cache.IsStaled);

                await Task.Delay(3500);

                Assert.AreEqual(DynamicCacheState.Connected, cache.CacheState);
                Assert.AreEqual(true, cache.IsStaled);

                await Task.Delay(2000);

                Assert.AreEqual(true, cache.IsStaled);

                await cache.Destroy();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="title">要顯示的標題文字。</param>
        /// <param name="fieldName">對應資料庫或是 Value Object 的欄位名稱。</param>
        public ListPaneFieldImproved(string title, string fieldName)
        {
            FieldName = fieldName;
            CacheProvider = null;
            CurrentCache = null;

            if (Backend == null)
                Backend = new QueryHelper();

            Field = new ListPaneField(title);
            Field.CompareValue += (CompareValue);
            Field.PreloadVariable += (Field_PreloadVariable);
            Field.GetVariable += (Field_GetVariable);

            UISyncContext = TaskScheduler.FromCurrentSynchronizationContext();
        }
Ejemplo n.º 12
0
        public Context(LuaContext luaContext)
        {
            LuaContext = luaContext;

            DynamicCache = new DynamicCache(this);

            SetupLibraries();

            Metatables =
                new Dictionary<Type, LuaTable>
                    {
                        {typeof(bool), new LuaTable()},
                        {typeof(double), new LuaTable()},
                        {typeof(string), new LuaTable()},
                        {typeof(Delegate), new LuaTable()},
                    };
        }
Ejemplo n.º 13
0
        public async Task ShouldRetrieveStateOfTheWorld()
        {
            var topic = "EUR/USD";


            for (var i = 0; i < 49; i++)
            {
                var next    = Next(topic);
                var message = _eventSerializer.ToProducerMessage(next);
                await _eventCache.AppendToStream(Encoding.UTF8.GetBytes(next.Subject), _serializer.Serialize(message));
            }

            var lastPriceEvent = Next(topic);
            var lastMessage    = _eventSerializer.ToProducerMessage(lastPriceEvent);
            await _eventCache.AppendToStream(Encoding.UTF8.GetBytes(lastPriceEvent.Subject), _serializer.Serialize(lastMessage));

            var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
            {
                Subject          = string.Empty,
                HeartbeatDelay   = TimeSpan.FromSeconds(1),
                HeartbeatTimeout = TimeSpan.FromSeconds(1)
            };

            var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

            await cache.Run();

            await WaitForCachesToCaughtUp(cache);

            var ccyPairs = cache.Items
                           .ToList();

            Assert.AreEqual(1, ccyPairs.Count);

            var euroDol = ccyPairs.First();

            Assert.AreEqual(50, euroDol.AppliedEvents.Count());

            Assert.AreEqual(lastPriceEvent.Ask, euroDol.Ask);
            Assert.AreEqual(lastPriceEvent.Bid, euroDol.Bid);
            Assert.AreEqual(lastPriceEvent.Mid, euroDol.Mid);
            Assert.AreEqual(lastPriceEvent.Spread, euroDol.Spread);

            await cache.Destroy();
        }
Ejemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="title">要顯示的標題文字。</param>
        /// <param name="fieldName">對應資料庫或是 Value Object 的欄位名稱。</param>
        public ListPaneFieldImproved(string title, string fieldName)
        {
            FieldName     = fieldName;
            CacheProvider = null;
            CurrentCache  = null;

            if (Backend == null)
            {
                Backend = new QueryHelper();
            }

            Field = new ListPaneField(title);
            Field.CompareValue    += (CompareValue);
            Field.PreloadVariable += (Field_PreloadVariable);
            Field.GetVariable     += (Field_GetVariable);

            UISyncContext = TaskScheduler.FromCurrentSynchronizationContext();
        }
Ejemplo n.º 15
0
        public async Task ShouldPerformHeartbeat()
        {
            var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
            {
                Subject          = string.Empty,
                HeartbeatDelay   = TimeSpan.FromSeconds(1),
                HeartbeatTimeout = TimeSpan.FromSeconds(1)
            };

            var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

            await cache.Run();

            await WaitForCachesToCaughtUp(cache);

            Assert.AreEqual(DynamicCacheState.Connected, cache.CacheState);

            await cache.Destroy();
        }
Ejemplo n.º 16
0
        public async Task ShouldHandleConnectivityErrors()
        {
            var cacheConfiguration = new DynamicCacheConfiguration("tcp://localhost:9090", "tcp://localhost:9090", HeartbeatEndpoint)
            {
                Subject             = string.Empty,
                HeartbeatDelay      = TimeSpan.FromMilliseconds(500),
                HeartbeatTimeout    = TimeSpan.FromMilliseconds(500),
                StateCatchupTimeout = TimeSpan.FromMilliseconds(500)
            };

            var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

            await cache.Run();

            await Task.Delay(2000);

            Assert.Greater(cache.Errors.Count, 0);

            var error = cache.Errors.First();

            Assert.AreEqual(ActorErrorType.DynamicCacheGetStateOfTheWorldFailure, error.CacheErrorStatus);
            Assert.AreEqual(typeof(UnreachableBrokerException), error.Exception.GetType());
        }
Ejemplo n.º 17
0
        public static void Main()
        {
            #region 模組啟用先同步Schmea
            //K12.Data.Configuration.ConfigData cd = K12.Data.School.Configuration["調代課UDT載入設定"];

            //bool checkClubUDT = false;
            //string name = "調代課UDT_20131008";

            ////如果尚無設定值,預設為
            //if (string.IsNullOrEmpty(cd[name]))
            //{
            //    cd[name] = "false";
            //}
            ////檢查是否為布林
            //bool.TryParse(cd[name], out checkClubUDT);

            //if (!checkClubUDT)
            //{

            //ServerModule.AutoManaged("http://module.ischool.com.tw/module/89/KHCentralOffice/udm.xml");

            SchemaManager Manager = new SchemaManager(FISCA.Authentication.DSAServices.DefaultConnection);

            Manager.SyncSchema(new School());
            Manager.SyncSchema(new ApproachStatistics());
            Manager.SyncSchema(new VagrantStatistics());
            Manager.SyncSchema(new SchoolLog());

                //cd[name] = "true";
                //cd.Save();
            //}
            #endregion

            FISCA.Presentation.MotherForm.StartMenu["安全性"]["權限管理"].Click += (sender, e) => new FISCA.Permission.UI.RoleManager().ShowDialog();

            DSAServices.AutoDisplayLoadingMessageOnMotherForm();

            GlobalSchoolCache = new DynamicCache(); //建立一個空的快取。

            InitAsposeLicense();
            InitStartMenu();
            InitConfigurationStorage();
            InitMainPanel();

            //MainPanel.ListPaneContexMenu["執行 SQL 並匯出"].Click += delegate
            //{
            //    new ExportQueryData().Export();
            //};

            new FieldManager();
            new DetailItems();
            //new RibbonButtons();
            //new ImportExport();//匯入學校資料

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Image = Properties.Resources.school_events_config_128;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Size = RibbonBarButton.MenuButtonSize.Medium;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Click += (sender, e) => new OpenTime().ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Enable = Permissions.開放時間權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"].Image = Properties.Resources.paste_64;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"].Size = RibbonBarButton.MenuButtonSize.Medium;

            #region 匯出畢業學生進路統計分析資料
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["匯出"].Image = Properties.Resources.Export_Image;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["匯出"].Size = RibbonBarButton.MenuButtonSize.Medium;
            Catalog button_Approach_Export = RoleAclSource.Instance["學校"]["功能按鈕"];
            button_Approach_Export.Add(new RibbonFeature("button_Approach_Export", "匯出畢業學生進路統計分析資料"));
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["匯出"]["畢業學生進路統計分析資料"].Enable = UserAcl.Current["button_Approach_Export"].Executable;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["匯出"]["畢業學生進路統計分析資料"].Click += delegate
            {
                (new Approach_Export()).ShowDialog();
            };
            #endregion

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路統計表"].Click += (sender, e) => new Approach_Report("國中畢業學生進路調查填報表格", Accessor.ApproachReportTemplate.ReportType.統計表).ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路統計表"].Enable = Permissions.畢業學生進路統計表權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路複核表"].Click += (sender, e) => new Approach_Report("國中畢業學生進路調查填報複核表", Accessor.ApproachReportTemplate.ReportType.複核表).ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路複核表"].Enable = Permissions.畢業學生進路複核表權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業未升學未就業學生動向"].Click += (sender, e) => new UnApproach_Report("國中畢業未升學未就業學生動向", Properties.Resources.國中畢業未升學未就業學生動向).ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業未升學未就業學生動向"].Enable = Permissions.畢業未升學未就業學生動向權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Size = RibbonBarButton.MenuButtonSize.Medium;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Image = Properties.Resources.school_search_128;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Click += (sender, e) => new UnApproach_Check().ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Enable = Permissions.未上傳學校權限;

            FISCA.Permission.Catalog AdminCatalog = FISCA.Permission.RoleAclSource.Instance["畢業學生進路調查"]["功能按鈕"];
            AdminCatalog.Add(new RibbonFeature(Permissions.未上傳學校, "未上傳學校"));
            AdminCatalog.Add(new RibbonFeature(Permissions.畢業未升學未就業學生動向, "畢業未升學未就業學生動向"));
            AdminCatalog.Add(new RibbonFeature(Permissions.畢業學生進路統計表, "畢業學生進路統計表"));
            AdminCatalog.Add(new RibbonFeature(Permissions.畢業學生進路複核表, "畢業學生進路複核表"));
            AdminCatalog.Add(new RibbonFeature(Permissions.開放時間, "開放時間"));

            FISCA.Permission.Catalog DetailCatalog = FISCA.Permission.RoleAclSource.Instance["畢業學生進路調查"]["資料項目"];
            DetailCatalog.Add(new DetailItemFeature(Permissions.學校基本資料, "學校基本資料"));
            DetailCatalog.Add(new DetailItemFeature(Permissions.學校進路統計, "學校進路統計"));

            RefreshFilteredSource();

            FISCA.Presentation.MotherForm.Form.Text = GetTitleText();
        }
Ejemplo n.º 18
0
        public async Task ShouldSubscribeToAllSubjects()
        {
            using (var publisherSocket = new PublisherSocket())
            {
                publisherSocket.Bind(ToSubscribersEndpoint);

                await Task.Delay(200);

                var createEvent = new Func <string, string, Task>(async(streamId, market) =>
                {
                    var @event  = new ChangeCcyPairPrice(streamId, market, 0.0, 0.0, 0.0, 0.0);
                    var message = _eventSerializer.ToProducerMessage(@event);

                    var eventId = new EventId(streamId, 0, string.IsNullOrEmpty(market) ? streamId : $"{streamId}.{market}", DateTime.Now.Ticks);

                    publisherSocket.SendMoreFrame(message.Subject)
                    .SendMoreFrame(_serializer.Serialize(eventId))
                    .SendFrame(_serializer.Serialize(message));

                    await Task.Delay(200);
                });

                var euroDol = "EUR/USD";
                var harmony = "Harmony";

                var euroGbp   = "EUR/GBP";
                var fxconnect = "FxConnect";

                var cacheConfigurationEuroDol = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
                {
                    Subject          = $"{euroDol}",
                    HeartbeatDelay   = TimeSpan.FromSeconds(1),
                    HeartbeatTimeout = TimeSpan.FromSeconds(1),
                };

                var cacheConfigurationAll = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
                {
                    Subject          = string.Empty,
                    HeartbeatDelay   = TimeSpan.FromSeconds(1),
                    HeartbeatTimeout = TimeSpan.FromSeconds(1),
                };

                var cacheEuroDol = new DynamicCache <string, CurrencyPair>(cacheConfigurationEuroDol, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);
                var cacheAll     = new DynamicCache <string, CurrencyPair>(cacheConfigurationAll, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

                await cacheEuroDol.Run();

                await cacheAll.Run();

                await WaitForCachesToCaughtUp(cacheEuroDol, cacheAll);

                Assert.AreEqual(DynamicCacheState.Connected, cacheEuroDol.CacheState);
                Assert.AreEqual(DynamicCacheState.Connected, cacheAll.CacheState);

                await createEvent(euroDol, harmony);

                Assert.AreEqual(1, cacheEuroDol.Items.SelectMany(ccy => ccy.AppliedEvents).Count());
                Assert.AreEqual(1, cacheAll.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(euroDol, fxconnect);

                await Task.Delay(500);

                Assert.AreEqual(2, cacheEuroDol.Items.SelectMany(ccy => ccy.AppliedEvents).Count());
                Assert.AreEqual(2, cacheAll.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(euroDol, string.Empty);

                Assert.AreEqual(3, cacheEuroDol.Items.SelectMany(ccy => ccy.AppliedEvents).Count());
                Assert.AreEqual(3, cacheAll.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(euroGbp, string.Empty);

                Assert.AreEqual(3, cacheEuroDol.Items.SelectMany(ccy => ccy.AppliedEvents).Count());
                Assert.AreEqual(4, cacheAll.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(euroGbp, harmony);

                Assert.AreEqual(3, cacheEuroDol.Items.SelectMany(ccy => ccy.AppliedEvents).Count());
                Assert.AreEqual(5, cacheAll.Items.SelectMany(ccy => ccy.AppliedEvents).Count());

                await createEvent(euroGbp, fxconnect);

                Assert.AreEqual(3, cacheEuroDol.Items.SelectMany(ccy => ccy.AppliedEvents).Count());
                Assert.AreEqual(6, cacheAll.Items.SelectMany(ccy => ccy.AppliedEvents).Count());


                await cacheEuroDol.Destroy();

                await cacheAll.Destroy();
            }
        }
Ejemplo n.º 19
0
        public async Task ShouldHandleDisconnectAndCacheRebuild()
        {
            var eventIdProvider = new InMemoryEventIdProvider();
            var serializer      = new JsonNetSerializer();
            var eventSerializer = new EventSerializer(serializer);

            var eventCache = new InMemoryEventCache(eventIdProvider, eventSerializer);

            var brokerConfiguration = new BrokerageServiceConfiguration()
            {
                HeartbeatEndpoint       = HeartbeatEndpoint,
                StateOftheWorldEndpoint = StateOfTheWorldEndpoint,
                ToSubscribersEndpoint   = ToSubscribersEndpoint,
                ToPublisherEndpoint     = ToPublishersEndpoint
            };

            var router = new BrokerageService(brokerConfiguration, eventCache, serializer);

            var marketConfiguration = new ProducerConfiguration()
            {
                RouterEndpoint   = ToPublishersEndpoint,
                HearbeatEndpoint = HeartbeatEndpoint
            };

            var market1 = new Market("FxConnect", marketConfiguration, eventSerializer, TimeSpan.FromMilliseconds(100));
            var market2 = new Market("Harmony", marketConfiguration, eventSerializer, TimeSpan.FromMilliseconds(100));

            await router.Run();


            await Task.Delay(1000);

            await market1.Run();

            await market2.Run();

            var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
            {
                Subject          = string.Empty,
                HeartbeatDelay   = TimeSpan.FromMilliseconds(500),
                HeartbeatTimeout = TimeSpan.FromSeconds(1)
            };

            var cache      = new DynamicCache <string, CurrencyPair>(cacheConfiguration, eventSerializer);
            var cacheProof = new DynamicCache <string, CurrencyPair>(cacheConfiguration, eventSerializer);

            await cacheProof.Run();

            await cache.Run();

            Assert.AreEqual(DynamicCacheState.NotConnected, cache.CacheState);
            Assert.AreEqual(DynamicCacheState.NotConnected, cacheProof.CacheState);

            await Task.Delay(2000);

            Assert.AreEqual(DynamicCacheState.Connected, cache.CacheState);
            Assert.AreEqual(DynamicCacheState.Connected, cacheProof.CacheState);

            await Task.Delay(3000);

            Assert.AreEqual(cache.GetItems()
                            .SelectMany(item => item.AppliedEvents)
                            .Count(),
                            cacheProof.GetItems()
                            .SelectMany(item => item.AppliedEvents)
                            .Count());

            await router.Destroy();

            await Task.Delay(cacheConfiguration.HeartbeatDelay);

            Assert.AreEqual(DynamicCacheState.Disconnected, cache.CacheState);
            Assert.AreEqual(DynamicCacheState.Disconnected, cacheProof.CacheState);

            router = new BrokerageService(brokerConfiguration, eventCache, serializer);

            await router.Run();

            await Task.Delay(TimeSpan.FromSeconds(3));

            Assert.AreEqual(DynamicCacheState.Connected, cache.CacheState);
            Assert.AreEqual(DynamicCacheState.Connected, cacheProof.CacheState);

            await router.Destroy();

            var cacheCCyPair      = cache.GetItems().ToList();
            var cacheProofCcyPair = cacheProof.GetItems().ToList();

            Assert.AreEqual(cacheCCyPair.Count(), cacheProofCcyPair.Count());
            Assert.AreEqual(cacheCCyPair.Count(), cacheProofCcyPair.Count());

            foreach (var ccyPair in cacheCCyPair)
            {
                var proof = cacheProofCcyPair.First(ccy => ccy.Id == ccyPair.Id);

                Assert.AreEqual(ccyPair.Ask, proof.Ask);
                Assert.AreEqual(ccyPair.Bid, proof.Bid);
                Assert.AreEqual(ccyPair.Mid, proof.Mid);
                Assert.AreEqual(ccyPair.Spread, proof.Spread);
            }

            var brokerCacheEvents = (await eventCache.GetStreamBySubject(cacheConfiguration.Subject)).ToList();
            var cacheEvents       = cacheCCyPair.SelectMany(item => item.AppliedEvents).ToList();
            var cacheProofEvents  = cacheProofCcyPair.SelectMany(item => item.AppliedEvents).ToList();


            Assert.AreEqual(cacheEvents.Count(), cacheProofEvents.Count());
            Assert.AreEqual(cacheEvents.Count(), cacheProofEvents.Count());
            Assert.AreEqual(cacheEvents.Count(), cacheProofEvents.Count());

            await Task.WhenAll(new[] { market1.Destroy(), market2.Destroy(), cache.Destroy() });
        }
Ejemplo n.º 20
0
        public async Task ShouldHandleNewEventsWhileRebuildingTheCache()
        {
            using (var stateUpdatePublish = new PublisherSocket())
            {
                stateUpdatePublish.Bind(ToSubscribersEndpoint);

                var topic = "EUR/USD";
                var stateOfTheWorldEventCount      = 10000;
                var initialEventCache              = 50;
                var raisedEventDuringCacheBuilding = new List <EventId>();

                for (var i = 0; i < stateOfTheWorldEventCount; i++)
                {
                    var next    = Next(topic);
                    var message = _eventSerializer.ToProducerMessage(next);
                    await _eventCache.AppendToStream(Encoding.UTF8.GetBytes(next.Subject), _serializer.Serialize(message));
                }

                var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
                {
                    Subject          = string.Empty,
                    HeartbeatDelay   = TimeSpan.FromSeconds(1),
                    HeartbeatTimeout = TimeSpan.FromSeconds(1)
                };

                var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, LoggerForTests <DynamicCache <string, CurrencyPair> > .Default(), _eventSerializer);

                await cache.Run();

                for (var i = 0; i < initialEventCache; i++)
                {
                    var next    = Next(topic);
                    var message = _eventSerializer.ToProducerMessage(next);
                    var payload = _serializer.Serialize(message);
                    var eventId = _eventCache.AppendToStream(Encoding.UTF8.GetBytes(next.Subject), payload).Result;

                    raisedEventDuringCacheBuilding.Add(eventId);

                    stateUpdatePublish.SendMoreFrame(next.Subject)
                    .SendMoreFrame(_serializer.Serialize(eventId))
                    .SendFrame(payload);

                    await Task.Delay(100);
                }

                await WaitForCachesToCaughtUp(cache);

                Assert.IsFalse(cache.IsCaughtingUp);

                var ccyPairs = cache.Items
                               .ToList();

                Assert.AreEqual(1, ccyPairs.Count);



                var euroDol = ccyPairs.First();

                Assert.AreEqual(stateOfTheWorldEventCount + initialEventCache, euroDol.AppliedEvents.Count());

                await cache.Destroy();
            }
        }
Ejemplo n.º 21
0
        public void SetUp()
        {
            _eventIdProvider = new InMemoryEventIdProvider();
            _serializer      = new JsonNetSerializer();
            _eventSerializer = new EventSerializer(_serializer);
            _eventCache      = new InMemoryEventCache(_eventIdProvider, _eventSerializer);

            JsonConvert.DefaultSettings = () =>
            {
                var settings = new JsonSerializerSettings
                {
                    Formatting       = Formatting.Indented,
                    TypeNameHandling = TypeNameHandling.Objects,
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                };

                return(settings);
            };

            var brokerConfiguration = new BrokerageServiceConfiguration()
            {
                HeartbeatEndpoint       = HeartbeatEndpoint,
                StateOfTheWorldEndpoint = StateOfTheWorldEndpoint,
                ToSubscribersEndpoint   = ToSubscribersEndpoint,
                ToPublisherEndpoint     = ToPublishersEndpoint
            };

            var router = GetBrokerageService(brokerConfiguration);

            var marketConfigurationFxConnect = new MarketConfiguration("FxConnect")
            {
                IsAutoGen         = false,
                BrokerEndpoint    = ToPublishersEndpoint,
                HeartbeatEndpoint = HeartbeatEndpoint,
                HeartbeatDelay    = TimeSpan.FromSeconds(5),
                HeartbeatTimeout  = TimeSpan.FromSeconds(5)
            };

            _market1 = GetMarket(marketConfigurationFxConnect);

            router.Run().Wait();

            Task.Delay(1000).Wait();

            _market1.Run().Wait();

            var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
            {
                Subject          = string.Empty,
                HeartbeatDelay   = TimeSpan.FromSeconds(5),
                HeartbeatTimeout = TimeSpan.FromSeconds(5),
                ZmqHighWatermark = 1000,
                UseEventBatching = UseEventBatch,
                DoStoreEvents    = false
            };

            _cache = GetCache(cacheConfiguration);

            _cache.Run().Wait();

            WaitForCachesToCaughtUp(_cache).Wait();
        }
Ejemplo n.º 22
0
        public async Task ShouldSubscribeToEventFeed()
        {
            var eventIdProvider = new InMemoryEventIdProvider();
            var serializer      = new JsonNetSerializer();
            var eventSerializer = new EventSerializer(serializer);
            var eventCache      = new InMemoryEventCache(eventIdProvider, eventSerializer);

            var brokerConfiguration = new BrokerageServiceConfiguration()
            {
                HeartbeatEndpoint       = HeartbeatEndpoint,
                StateOftheWorldEndpoint = StateOfTheWorldEndpoint,
                ToSubscribersEndpoint   = ToSubscribersEndpoint,
                ToPublisherEndpoint     = ToPublishersEndpoint
            };

            var router = new BrokerageService(brokerConfiguration, eventCache, serializer);

            var marketConfiguration = new ProducerConfiguration()
            {
                RouterEndpoint   = ToPublishersEndpoint,
                HearbeatEndpoint = HeartbeatEndpoint
            };

            var market1 = new Market("FxConnect", marketConfiguration, eventSerializer, TimeSpan.FromMilliseconds(750));
            var market2 = new Market("Harmony", marketConfiguration, eventSerializer, TimeSpan.FromMilliseconds(750));

            await router.Run();

            await market1.Run();

            await market2.Run();

            //create an event cache
            await Task.Delay(2000);

            //Assert.Greater(router.Cache.Count(), 0);

            var cacheConfiguration = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint);

            var cache = new DynamicCache <string, CurrencyPair>(cacheConfiguration, eventSerializer);

            var counter = 0;

            var cleanup = cache.OnItemChanged()
                          .Connect()
                          .Subscribe(_ =>
            {
                counter++;
            });

            await cache.Run();

            await Task.Delay(2000);

            // Assert.AreEqual(router.Cache.Count(), counter);
            Assert.AreEqual(cache.GetItems().SelectMany(item => item.AppliedEvents).Count(), counter);

            //fxconnext & harmony
            Assert.AreEqual(2, cache.GetItems()
                            .SelectMany(item => item.AppliedEvents)
                            .Cast <ChangeCcyPairPrice>()
                            .Select(ev => ev.Market)
                            .Distinct()
                            .Count());


            cleanup.Dispose();

            await Task.WhenAll(new[] { router.Destroy(), market1.Destroy(), market2.Destroy(), cache.Destroy() });
        }
Ejemplo n.º 23
0
        private void Field_PreloadVariable(object sender, PreloadVariableEventArgs e)
        {
            if (IsDataLoading)
            {
                IsPaddingTask = true;
                return;
            }

            if (IsReloading)
            {
                return;
            }

            if (CacheProvider != null)
            {
                CurrentCache = CacheProvider;
            }
            else
            {
                CurrentCache = new DynamicCache();
            }

            IsDataLoading = true;
            Task task = Task.Factory.StartNew(() =>
            {
                if (CurrentCache.GetOutOfDate(e.Keys, FieldName))
                {//如果不是在最新狀態就呼叫 GetDataAsync 讀取資料,並更新到 Cache 中。
                    if (e.Keys.Count() <= 0)
                    {
                        return;                      //如果沒有資料就不執行。
                    }
                    IEnumerable <Value> values = GetDataAsync(e.Keys);
                    HashSet <string> resultSet = new HashSet <string>();
                    foreach (Value v in values)
                    {
                        CurrentCache.FillProperty(v.Id, FieldName, v.Val);
                        resultSet.Add(v.Id);
                    }

                    HashSet <string> clearSet = new HashSet <string>(e.Keys);
                    clearSet.ExceptWith(resultSet);

                    //將沒有回傳的 Id 值清空。
                    foreach (string id in clearSet)
                    {
                        CurrentCache.FillProperty(id, FieldName, string.Empty);
                    }
                }
            }, new CancellationToken(), TaskCreationOptions.PreferFairness, TaskScheduler.Default);

            task.ContinueWith((x) =>
            {
                IsDataLoading = false;

                if (IsPaddingTask)
                {
                    IsPaddingTask = false;
                    Field.Reload();
                    return;
                }

                if (x.Exception != null)
                {
                    RTOut.WriteError(x.Exception);
                }
                else
                {
                    IsReloading = true;
                    Field.Reload();
                    IsReloading = false;
                }
                CurrentCache = null;
            }, UISyncContext);
        }
        private void Field_PreloadVariable(object sender, PreloadVariableEventArgs e)
        {
            if (IsDataLoading)
            {
                IsPaddingTask = true;
                return;
            }

            if (IsReloading) return;

            if (CacheProvider != null)
                CurrentCache = CacheProvider;
            else
                CurrentCache = new DynamicCache();

            IsDataLoading = true;
            Task task = Task.Factory.StartNew(() =>
            {
                if (CurrentCache.GetOutOfDate(e.Keys, FieldName))
                {//如果不是在最新狀態就呼叫 GetDataAsync 讀取資料,並更新到 Cache 中。

                    if (e.Keys.Count() <= 0) return; //如果沒有資料就不執行。

                    IEnumerable<Value> values = GetDataAsync(e.Keys);
                    HashSet<string> resultSet = new HashSet<string>();
                    foreach (Value v in values)
                    {
                        CurrentCache.FillProperty(v.Id, FieldName, v.Val);
                        resultSet.Add(v.Id);
                    }

                    HashSet<string> clearSet = new HashSet<string>(e.Keys);
                    clearSet.ExceptWith(resultSet);

                    //將沒有回傳的 Id 值清空。
                    foreach (string id in clearSet)
                        CurrentCache.FillProperty(id, FieldName, string.Empty);
                }
            }, new CancellationToken(), TaskCreationOptions.PreferFairness, TaskScheduler.Default);

            task.ContinueWith((x) =>
            {
                IsDataLoading = false;

                if (IsPaddingTask)
                {
                    IsPaddingTask = false;
                    Field.Reload();
                    return;
                }

                if (x.Exception != null)
                    RTOut.WriteError(x.Exception);
                else
                {
                    IsReloading = true;
                    Field.Reload();
                    IsReloading = false;
                }
                CurrentCache = null;
            }, UISyncContext);
        }
Ejemplo n.º 25
0
        public static void Main()
        {
            DSAServices.AutoDisplayLoadingMessageOnMotherForm();

            if (DSAServices.AccessPoint.ToLower() != "campusman.ischool.com.tw")
            {
                throw new ApplicationStartupException("不支援,請登入 campusman.ischool.com.tw!");
            }

            GlobalSchoolCache = new DynamicCache(); //建立一個空的快取。

            InitAsposeLicense();
            InitStartMenu();
            InitConfigurationStorage();
            InitMainPanel();


            MainPanel.ListPaneContexMenu["執行 SQL 並匯出"].Enable = false;
            MainPanel.ListPaneContexMenu["執行 SQL 並匯出"].Click += delegate
            {
                new ExportQueryData().Export();
            };



            new FieldManager();
            new DetailItems();
            new RibbonButtons();
            new ImportExport();//匯入學校資料

            Program.MainPanel.RibbonBarItems["批次作業"]["發送最新消息"].Enable = false;
            Program.MainPanel.RibbonBarItems["批次作業"]["發送最新消息"].Image  = Properties.Resources.speech_balloon_64;
            Program.MainPanel.RibbonBarItems["批次作業"]["發送最新消息"].Size   = FISCA.Presentation.RibbonBarButton.MenuButtonSize.Large;
            Program.MainPanel.RibbonBarItems["批次作業"]["發送最新消息"].Click += delegate
            {
                SendNews send = new SendNews(Program.MainPanel.SelectedSource);
                send.ShowDialog();
            };

            Program.MainPanel.RibbonBarItems["批次作業"]["SQL大神"].Enable = false;
            Program.MainPanel.RibbonBarItems["批次作業"]["SQL大神"].Image  = Properties.Resources.technology_64;
            Program.MainPanel.RibbonBarItems["批次作業"]["SQL大神"].Size   = FISCA.Presentation.RibbonBarButton.MenuButtonSize.Large;
            Program.MainPanel.RibbonBarItems["批次作業"]["SQL大神"].Click += delegate
            {
                RunSQL RUN = new RunSQL();
                RUN.ShowDialog();
            };

            Program.MainPanel.SelectedSourceChanged += delegate
            {
                if (Program.MainPanel.SelectedSource.Count == 0)
                {
                    SetEnable(false);
                }
                else
                {
                    SetEnable(true);
                }
            };


            RefreshFilteredSource();

            FISCA.Presentation.MotherForm.Form.Text = GetTitleText();
        }
Ejemplo n.º 26
0
        public static void Main()
        {
            #region 模組啟用先同步Schmea
            //K12.Data.Configuration.ConfigData cd = K12.Data.School.Configuration["調代課UDT載入設定"];

            //bool checkClubUDT = false;
            //string name = "調代課UDT_20131008";

            ////如果尚無設定值,預設為
            //if (string.IsNullOrEmpty(cd[name]))
            //{
            //    cd[name] = "false";
            //}
            ////檢查是否為布林
            //bool.TryParse(cd[name], out checkClubUDT);

            //if (!checkClubUDT)
            //{

            ServerModule.AutoManaged("http://module.ischool.com.tw/module/89/KHCentralOffice/udm.xml");

            SchemaManager Manager = new SchemaManager(FISCA.Authentication.DSAServices.DefaultConnection);

            Manager.SyncSchema(new School());
            Manager.SyncSchema(new ApproachStatistics());
            Manager.SyncSchema(new VagrantStatistics());
            Manager.SyncSchema(new SchoolLog());

            //cd[name] = "true";
            //cd.Save();
            //}
            #endregion

            FISCA.Presentation.MotherForm.StartMenu["安全性"]["權限管理"].Click += (sender, e) => new FISCA.Permission.UI.RoleManager().ShowDialog();

            DSAServices.AutoDisplayLoadingMessageOnMotherForm();

            GlobalSchoolCache = new DynamicCache(); //建立一個空的快取。

            InitAsposeLicense();
            InitStartMenu();
            InitConfigurationStorage();
            InitMainPanel();

            //MainPanel.ListPaneContexMenu["執行 SQL 並匯出"].Click += delegate
            //{
            //    new ExportQueryData().Export();
            //};

            new FieldManager();
            new DetailItems();
            //new RibbonButtons();
            //new ImportExport();//匯入學校資料

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Image  = Properties.Resources.school_events_config_128;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Size   = RibbonBarButton.MenuButtonSize.Medium;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Click += (sender, e) => new OpenTime().ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["開放時間"].Enable = Permissions.開放時間權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"].Image = Properties.Resources.paste_64;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"].Size  = RibbonBarButton.MenuButtonSize.Medium;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路統計表"].Click += (sender, e) => new Approach_Report("國中畢業學生進路調查填報表格", Properties.Resources._102學年度國中畢業學生進路調查填報表格).ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路統計表"].Enable = Permissions.畢業學生進路統計表權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路複核表"].Click += (sender, e) => new Approach_Report("國中畢業學生進路調查填報複核表", Properties.Resources._102學年度國中畢業學生進路調查填報複核表).ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業學生進路複核表"].Enable = Permissions.畢業學生進路複核表權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業未升學未就業學生動向"].Click += (sender, e) => new UnApproach_Report("國中畢業未升學未就業學生動向", Properties.Resources.中畢業未升學未就業學生動向).ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["報表"]["畢業未升學未就業學生動向"].Enable = Permissions.畢業未升學未就業學生動向權限;

            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Size   = RibbonBarButton.MenuButtonSize.Medium;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Image  = Properties.Resources.school_search_128;
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Click += (sender, e) => new UnApproach_Check().ShowDialog();
            Program.MainPanel.RibbonBarItems["畢業學生進路調查"]["未上傳學校"].Enable = Permissions.未上傳學校權限;

            FISCA.Permission.Catalog AdminCatalog = FISCA.Permission.RoleAclSource.Instance["畢業學生進路調查"]["功能按鈕"];
            AdminCatalog.Add(new RibbonFeature(Permissions.未上傳學校, "未上傳學校"));
            AdminCatalog.Add(new RibbonFeature(Permissions.畢業未升學未就業學生動向, "畢業未升學未就業學生動向"));
            AdminCatalog.Add(new RibbonFeature(Permissions.畢業學生進路統計表, "畢業學生進路統計表"));
            AdminCatalog.Add(new RibbonFeature(Permissions.畢業學生進路複核表, "畢業學生進路複核表"));
            AdminCatalog.Add(new RibbonFeature(Permissions.開放時間, "開放時間"));

            FISCA.Permission.Catalog DetailCatalog = FISCA.Permission.RoleAclSource.Instance["畢業學生進路調查"]["資料項目"];
            DetailCatalog.Add(new DetailItemFeature(Permissions.學校基本資料, "學校基本資料"));
            DetailCatalog.Add(new DetailItemFeature(Permissions.學校進路統計, "學校進路統計"));

            RefreshFilteredSource();

            FISCA.Presentation.MotherForm.Form.Text = GetTitleText();
        }
Ejemplo n.º 27
0
        public async Task ShouldSubscribeToSubject()
        {
            //todo .NET COre MVC implem
            var eventIdProvider = new InMemoryEventIdProvider();
            var serializer      = new JsonNetSerializer();
            var eventSerializer = new EventSerializer(serializer);

            var eventCache = new InMemoryEventCache(eventIdProvider, eventSerializer);

            var brokerConfiguration = new BrokerageServiceConfiguration()
            {
                HeartbeatEndpoint       = HeartbeatEndpoint,
                StateOftheWorldEndpoint = StateOfTheWorldEndpoint,
                ToSubscribersEndpoint   = ToSubscribersEndpoint,
                ToPublisherEndpoint     = ToPublishersEndpoint
            };

            var router = new BrokerageService(brokerConfiguration, eventCache, serializer);

            var marketConfiguration = new ProducerConfiguration()
            {
                RouterEndpoint   = ToPublishersEndpoint,
                HearbeatEndpoint = HeartbeatEndpoint
            };

            var market1 = new Market("FxConnect", marketConfiguration, eventSerializer, TimeSpan.FromMilliseconds(750));
            var market2 = new Market("Harmony", marketConfiguration, eventSerializer, TimeSpan.FromMilliseconds(750));

            await router.Run();

            await market1.Run();

            await market2.Run();


            var cacheConfigurationEuroDol = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
            {
                Subject = "EUR/USD"
            };

            var cacheConfigurationEuroDolFxConnect = new DynamicCacheConfiguration(ToSubscribersEndpoint, StateOfTheWorldEndpoint, HeartbeatEndpoint)
            {
                Subject = "EUR/USD.FxConnect"
            };

            var cacheEuroDol          = new DynamicCache <string, CurrencyPair>(cacheConfigurationEuroDol, eventSerializer);
            var cacheEuroDolFxConnect = new DynamicCache <string, CurrencyPair>(cacheConfigurationEuroDolFxConnect, eventSerializer);

            await cacheEuroDol.Run();

            await cacheEuroDolFxConnect.Run();

            //wait for a substential event stream
            await Task.Delay(5000);

            // Assert.Greater(router.Cache.Count(), 1);

            var ccyPairsCacheEuroDol = cacheEuroDol.GetItems()
                                       .SelectMany(item => item.AppliedEvents)
                                       .Select(item => item.Subject)
                                       .Distinct();

            // EUR/USD.FxConnect & EUR/USD.Harmony
            Assert.AreEqual(2, ccyPairsCacheEuroDol.Count());
            Assert.IsTrue(ccyPairsCacheEuroDol.All(subject => subject.EndsWith("FxConnect") || subject.EndsWith("Harmony")));
            Assert.IsTrue(ccyPairsCacheEuroDol.All(subject => subject.StartsWith(cacheConfigurationEuroDol.Subject)));

            var ccyPairsCacheEuroDolFxConnect = cacheEuroDolFxConnect.GetItems()
                                                .SelectMany(item => item.AppliedEvents)
                                                .Select(item => item.Subject)
                                                .Distinct();

            // EUR/USD.FxConnect
            Assert.AreEqual(1, ccyPairsCacheEuroDolFxConnect.Count());
            Assert.AreEqual(cacheConfigurationEuroDolFxConnect.Subject, ccyPairsCacheEuroDolFxConnect.First());


            await Task.WhenAll(new[] { router.Destroy(), market1.Destroy(), market2.Destroy(), cacheEuroDol.Destroy(), cacheEuroDolFxConnect.Destroy() });
        }