Ejemplo n.º 1
0
        private void Form1Load(object sender, EventArgs e)
        {
            // create loggers
            _loggerRef = Reference <ILogger> .Create(new TextBoxLogger(txtMainLog));

            // create client factory and client
            _clientFactory = new CoreClientFactory(_loggerRef);
            _clientFactory.SetEnv(BuildConst.BuildEnv);
            _clientFactory.SetApplication(Assembly.GetExecutingAssembly());
            _client = _clientFactory.Create();
            // - form title
            WinFormHelper.SetAppFormTitle(this, EnvHelper.EnvName(BuildEnv));
            // setup the AlertRule view
            _alertRuleViewHelper = new AlertRuleViewHelper();
            _alertRuleDataHelper = new AlertRuleDataHelper();
            _alertRuleFilters    = new ComboxBoxFilterGroup(
                panelAlertRule, _alertRuleViewHelper, AlertRuleSelectionChanged);
            _alertRuleSelecter = new AlertRuleSelecter(
                _alertRuleFilters, _alertRuleViewHelper, _alertRuleDataHelper);
            _alertRuleView = new ListViewManager <AlertRule>(
                _loggerRef.Target, lvAlertRule, _alertRuleViewHelper,
                _alertRuleSelecter, _alertRuleFilters, new AlertRuleSorter(), _alertRuleDataHelper);

            ICoreCache alertRuleCache = _client.CreateCache(
                update => _alertRuleView.UpdateData(new ViewChangeNotification <AlertRule>
            {
                Change  = update.Change,
                OldData =
                    (AlertRule)update.OldItem?.Data,
                NewData =
                    (AlertRule)update.NewItem?.Data
            }), SynchronizationContext.Current);

            alertRuleCache.SubscribeNoWait <AlertRule>(Expr.ALL, null, null);
            // setup the AlertSignal view
            _alertSignalViewHelper = new AlertSignalViewHelper();
            _alertSignalDataHelper = new AlertSignalDataHelper();
            _alertSignalFilters    = new ComboxBoxFilterGroup(
                panelAlertSignal, _alertSignalViewHelper, AlertSignalSelectionChanged);
            _alertSignalSelecter = new AlertSignalSelecter(
                _alertSignalFilters, _alertSignalViewHelper, _alertSignalDataHelper);
            _alertSignalView = new ListViewManager <AlertSignal>(
                _loggerRef.Target, lvAlertSignal, _alertSignalViewHelper,
                _alertSignalSelecter, _alertSignalFilters, new AlertSignalSorter(), _alertSignalDataHelper);
            ICoreCache alertSignalCache = _client.CreateCache(
                update => _alertSignalView.UpdateData(new ViewChangeNotification <AlertSignal>
            {
                Change  = update.Change,
                OldData =
                    (AlertSignal)update.OldItem?.Data,
                NewData =
                    (AlertSignal)update.NewItem?.Data
            }), SynchronizationContext.Current);

            alertSignalCache.SubscribeNoWait <AlertSignal>(Expr.ALL, null, null);
            // setup the LogEvent view
            _logEventViewHelper = new LogEventViewHelper();
            _logEventDataHelper = new LogEventDataHelper();
            _logEventFilters    = new ComboxBoxFilterGroup(
                panelLogEvent, _logEventViewHelper, LogEventSelectionChanged);
            _logEventSelecter = new LogEventSelecter(
                _logEventFilters, _logEventViewHelper, _logEventDataHelper);
            _logEventView = new ListViewManager <DebugLogEvent>(
                _loggerRef.Target, lvLogEvent, _logEventViewHelper,
                _logEventSelecter, _logEventFilters, new LogEventSorter(), _logEventDataHelper);
            ICoreCache logEventCache = _client.CreateCache(
                update => _logEventView.UpdateData(new ViewChangeNotification <DebugLogEvent>
            {
                Change  = update.Change,
                OldData =
                    (DebugLogEvent)update.OldItem?.Data,
                NewData =
                    (DebugLogEvent)update.NewItem?.Data
            }), SynchronizationContext.Current);

            logEventCache.SubscribeNoWait <DebugLogEvent>(Expr.ALL, null, null);
            // init controls
            // server 0
            _serverAddress[0] = txtServer0Address;
            _ping[0]          = chkServer0Ping;
            _lastChecked[0]   = txtServer0LastChecked;
            _lastReplied[0]   = txtServer0LastReplied;
            _serverStatus[0]  = txtServer0Status;
            _serverReason[0]  = txtServer0OtherInfo;
            // server 1
            _serverAddress[1] = txtServer1Address;
            _ping[1]          = chkServer1Ping;
            _lastChecked[1]   = txtServer1LastChecked;
            _lastReplied[1]   = txtServer1LastReplied;
            _serverStatus[1]  = txtServer1Status;
            _serverReason[1]  = txtServer1OtherInfo;
            // server 2
            _serverAddress[2] = txtServer2Address;
            _ping[2]          = chkServer2Ping;
            _lastChecked[2]   = txtServer2LastChecked;
            _lastReplied[2]   = txtServer2LastReplied;
            _serverStatus[2]  = txtServer2Status;
            _serverReason[2]  = txtServer2OtherInfo;
            // server 3
            _serverAddress[3] = txtServer3Address;
            _ping[3]          = chkServer3Ping;
            _lastChecked[3]   = txtServer3LastChecked;
            _lastReplied[3]   = txtServer3LastReplied;
            _serverStatus[3]  = txtServer3Status;
            _serverReason[3]  = txtServer3OtherInfo;
            // server 4
            _serverAddress[4] = txtServer4Address;
            _ping[4]          = chkServer4Ping;
            _lastChecked[4]   = txtServer4LastChecked;
            _lastReplied[4]   = txtServer4LastReplied;
            _serverStatus[4]  = txtServer4Status;
            _serverReason[4]  = txtServer4OtherInfo;
            // server 5
            _serverAddress[5] = txtServer5Address;
            _ping[5]          = chkServer5Ping;
            _lastChecked[5]   = txtServer5LastChecked;
            _lastReplied[5]   = txtServer5LastReplied;
            _serverStatus[5]  = txtServer5Status;
            _serverReason[5]  = txtServer5OtherInfo;
            for (int i = 0; i < NServers; i++)
            {
                _lastChecked[i].BackColor  = Color.FromKnownColor(KnownColor.Window);
                _lastReplied[i].BackColor  = Color.FromKnownColor(KnownColor.Window);
                _serverStatus[i].BackColor = Color.FromKnownColor(KnownColor.Window);
                _serverReason[i].BackColor = Color.FromKnownColor(KnownColor.Window);
            }
        }
Ejemplo n.º 2
0
        public void TestServerBridge()
        {
            // required environment:
            // - local env (eg. DEV) server
            // - lower env (eg. UTT) server
            // creates the bridge, and check all messages published
            //   in local env are re-published correctly in lower env
            EnvId  localEnvId   = EnvId.Dev_Development;
            string localEnvName = EnvHelper.EnvName(localEnvId);
            EnvId  lowerEnvId   = (localEnvId - 1);
            string lowerEnvName = EnvHelper.EnvName(lowerEnvId);
            int    localPort    = 9214;
            int    lowerPort    = 9114;

            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                CoreClientFactory clientfactory = new CoreClientFactory(loggerRef);
                using (CoreServer localServer =
                           new CoreServer(loggerRef, localEnvName, NodeType.Router, localPort))
                    using (CoreServer lowerServer =
                               new CoreServer(loggerRef, lowerEnvName, NodeType.Router, lowerPort))
                    {
                        // start servers
                        localServer.Start();
                        lowerServer.Start();
                        // create clients
                        using (Reference <ICoreClient> localClientRef = Reference <ICoreClient> .Create(clientfactory.SetEnv(localEnvName).SetServers("localhost:" + localPort).Create()))
                            using (ICoreClient lowerClient = clientfactory.SetEnv(lowerEnvName).SetServers("localhost:" + lowerPort).Create())
                            {
                                using (ServerBridge bridge = new ServerBridge())
                                {
                                    bridge.LoggerRef    = loggerRef;
                                    bridge.Client       = localClientRef;
                                    bridge.TargetClient = lowerClient;
                                    // test begins here
                                    // - start the bridge
                                    bridge.Start();
                                    const int sendCount      = 500;
                                    const int maxWaitSeconds = 5;
                                    long      excpCount      = 0;
                                    long      recdCount      = 0;
                                    // subscribe to objects on downstream server
                                    ISubscription subs = lowerClient.Subscribe <TestData>(Expr.ALL,
                                                                                          delegate(ISubscription subscription, ICoreItem item)
                                    {
                                        // receiver
                                        long count = Interlocked.Increment(ref recdCount);
                                        try
                                        {
                                            TestData data = (TestData)item.Data;
                                            //loggerRef.Target.LogDebug("Recd[{0}]", data.field2);
                                            Assert.AreEqual <long>(count, data.field2);
                                        }
                                        catch (Exception)
                                        {
                                            Interlocked.Increment(ref excpCount);
                                        }
                                    }, null);

                                    long sentCount = 0;
                                    // publish n Server events
                                    for (int i = 1; i <= sendCount; i++)
                                    {
                                        Interlocked.Increment(ref sentCount);
                                        localClientRef.Target.SaveObject <TestData>(new TestData("Test", i), "Test", null, TimeSpan.MaxValue);
                                    }
                                    // wait for a short period
                                    DateTimeOffset waitStart  = DateTimeOffset.Now;
                                    DateTimeOffset waitExpiry = waitStart.AddSeconds(maxWaitSeconds);
                                    while ((Interlocked.Add(ref recdCount, 0) < Interlocked.Add(ref sentCount, 0)) &&
                                           (DateTimeOffset.Now < waitExpiry) &&
                                           (Interlocked.Add(ref excpCount, 0) == 0))
                                    {
                                        Thread.Sleep(TimeSpan.FromSeconds(1.0));
                                        loggerRef.Target.LogDebug("Recd/Sent: {0}/{1} items...", Interlocked.Add(ref recdCount, 0), Interlocked.Add(ref sentCount, 0));
                                    }
                                    loggerRef.Target.LogDebug("Duration: {0}", (DateTimeOffset.Now - waitStart));
                                    Assert.AreEqual <long>(0, excpCount);
                                    Assert.AreEqual <long>(sendCount, recdCount);
                                    // done
                                    Assert.IsTrue(true);
                                }
                            }
                    }
            }
        }
Ejemplo n.º 3
0
        private void BtnPingAllClick(object sender, EventArgs e)
        {
            var sw = new Stopwatch();

            sw.Start();
            long t0 = sw.ElapsedMilliseconds;

            _loggerRef.Target.LogInfo("Ping: Starting...");
            for (int serverN = 0; serverN < NServers; serverN++)
            {
                if (_ping[serverN].Checked)
                {
                    _lastChecked[serverN].Text  = DateTime.Now.ToString(CultureInfo.InvariantCulture);
                    _lastReplied[serverN].Text  = "Connecting...";
                    _serverStatus[serverN].Text = "Connecting...";
                    _serverReason[serverN].Text = "Connecting...";
                    string clientResult = "Undefined!";
                    string clientReason = "";
                    Color  clientColour;
                    string activity = "Initialising";
                    long   clientT0 = sw.ElapsedMilliseconds;
                    try
                    {
                        activity = "Resolving address";
                        string[] addrParts = _serverAddress[serverN].Text.Split(';');
                        if (addrParts.Length != 2)
                        {
                            throw new ApplicationException("Address not in format 'env;host[:port]'");
                        }
                        string env           = addrParts[0];
                        string serverAddress = addrParts[1];
                        activity = "Connecting";
                        using (_clientFactory.SetEnv(env).SetServers(serverAddress).Create())
                        {
                            // connect done
                            activity = "Loading";
                        }
                        long     clientTZ    = sw.ElapsedMilliseconds;
                        TimeSpan clientTotal = TimeSpan.FromMilliseconds(clientTZ - clientT0);
                        _lastReplied[serverN].Text = DateTime.Now.ToString(CultureInfo.InvariantCulture);
                        clientResult = $"{clientTotal.TotalMilliseconds}ms";
                        clientColour = clientTotal.TotalMilliseconds <= 1000.0 ? Color.LightGreen : Color.Orange;
                        activity     = "Disposing";
                    }
                    catch (Exception excp)
                    {
                        _loggerRef.Target.LogDebug("{0}: FAILED while {1}: {2} {3}",
                                                   _serverAddress[serverN].Text, activity, excp.GetType().Name, excp.Message);
                        clientResult = "FAILED";
                        clientReason = excp.Message;
                        clientColour = Color.OrangeRed;
                        _loggerRef.Target.Log(excp);
                    }
                    //clientTZ = sw.ElapsedMilliseconds;
                    //TimeSpan durationClient = TimeSpan.FromMilliseconds(clientTZ - clientT0);
                    _serverStatus[serverN].Text      = clientResult;
                    _serverStatus[serverN].BackColor = clientColour;
                    _serverReason[serverN].Text      = clientReason;
                }
            }
            long tZ = sw.ElapsedMilliseconds;

            sw.Stop();
            TimeSpan duration = TimeSpan.FromMilliseconds(tZ - t0);

            _loggerRef.Target.LogInfo("Ping: Completed ({0}s)", duration.TotalSeconds);
        }