示例#1
0
        public static async Task <IUnityContainer> RegisterConfiguration()
        {
            var emitter = new MonithorEmitter("https://monithor.azurewebsites.net/thorhub", "Pokora Console");

            bool connectionEstablished = false;

            emitter.ConnectionStatusChanged += async(status) =>
            {
                if (status == ConnectionStatus.Healthy)
                {
                    connectionEstablished = true;
                    await emitter.Trace(MessageLevel.Informational, MessageType.Fonctional,
                                        "", "Pokora monithor connected",
                                        "");
                }
            };

            emitter.Connect();

            //TODO remove azure slow
            //while (!connectionEstablished)
            //{
            //    Console.WriteLine("trying to connect to monithor");
            //    await Task.Delay(1000);
            //}


            var container = new UnityContainer();
            var logger    = new Logger(emitter);

            container.RegisterInstance(logger, new ContainerControlledLifetimeManager());

            var eventManager = new EventManager();

            container.RegisterInstance(eventManager, new ContainerControlledLifetimeManager());

            var displayer = new PokoraDisplayer();

            container.RegisterInstance(displayer, new ContainerControlledLifetimeManager());

            return(container);
        }
示例#2
0
        static async Task MainAsync()
        {
            var displayer = new Displayer();

            var monithorEmitter = new MonithorEmitter("https://monithor.azurewebsites.net/thorhub", "ConsoleEmitter");

            monithorEmitter.Connected               += () => { displayer.LogTrace("Connected !"); };
            monithorEmitter.Disconnected            += () => { displayer.LogTrace("Disconnected =( "); };
            monithorEmitter.ConnectionStatusChanged += (status) => { displayer.LogTrace($"Connection status changed to {status}"); };

            try
            {
                monithorEmitter.Connect();
            }
            catch (MonithorClientException e)
            {
                displayer.LogException("monithor emitter error occured =(", e);
            }
            Random random = new Random();
            int    i      = 0;

            do
            {
                await Task.Delay(200);

                try
                {
                    await monithorEmitter.UpdateMetric(MessageLevel.Verbose, MessageType.Communication, "posX",
                                                       i.ToString());

                    displayer.LogTrace($"sent metric posX {i}");
                    await monithorEmitter.UpdateMetric(MessageLevel.Verbose, MessageType.Communication, "posY",
                                                       i.ToString());

                    displayer.LogTrace($"sent metric posY {i}");
                    await monithorEmitter.UpdateMetric(MessageLevel.Verbose, MessageType.Communication, "posZ",
                                                       i.ToString());

                    displayer.LogTrace($"sent metric posZ {i}");


                    if (i % 7 == 0)
                    {
                        var          criticity = random.Next(10);
                        MessageLevel level;
                        string       message;

                        if (criticity <= 1)
                        {
                            level   = MessageLevel.Error;
                            message = "An engine just crashed.";
                        }
                        else if (criticity <= 4)
                        {
                            level   = MessageLevel.Informational;
                            message = "Target position reached.";
                        }
                        else
                        {
                            level   = MessageLevel.Verbose;
                            message = "Nothing detected in radar";
                        }

                        await monithorEmitter.Trace(level, MessageType.Communication, "trace", message, "");

                        displayer.LogTrace($"sent trace {i}");
                    }

                    i++;
                }
                catch (MonithorClientException e)
                {
                    displayer.LogException("send trace failed", e);
                }
            } while (true);
        }