Beispiel #1
0
        public void Start()
        {
            var uc = new UnityContainer();

            var log = new LogAnalizer();

            parameterAnalizer = new ParameterAnalizer();

            bus = new Bus();
            bus.OnMessageReceived += (se, ea) =>
            {
                var records = ea.Message.body.records.ToArray();
                try
                {
                    log.Analize(records);
                }
                catch (Exception ex)
                {
                    logger.Error("не обработались логером");
                }

                try
                {
                    parameterAnalizer.Analize(records);
                }
                catch (Exception ex)
                {
                    logger.Error("не обработались параметры");
                }
            };

            bus.OnSubscribeMessageReceived += (se, ea) =>
            {
                Guid sessionId = Guid.Parse(ea.Message.body.sessionId);
                var  ids       = new List <Guid>();
                foreach (var id in ea.Message.body.ids)
                {
                    ids.Add(Guid.Parse(id));
                }
                log.Subscribe(sessionId, ids);
            };

            bus.Start();
            uc.RegisterInstance(bus);
            uc.BuildUp(log);
            uc.RegisterInstance(log);

            uc.BuildUp(parameterAnalizer);
            uc.RegisterInstance(parameterAnalizer);

            var url = ConfigurationManager.AppSettings["service-url"];

            webHost = WebApp.Start(url, app =>
            {
                app.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(uc));
            });
            logger.Info("сервис запущен, url: {0}", url);
        }
Beispiel #2
0
        public ApiModule(LogAnalizer log)
        {
            Get[""] = (_) =>
            {
                return(Response.AsFile(@"ui/index.html"));
            };

            Put["subscribe"] = (_) =>
            {
                var body = Request.GetBody();

                Guid sessionId = Guid.Parse(body.sessionId);

                var ids = new List <Guid>();
                foreach (var id in body.ids)
                {
                    Guid gid = Guid.Parse(id);
                    ids.Add(gid);
                }

                log.Subscribe(sessionId, ids);
                return("ok");
            };

            Put["unsubscribe"] = (_) =>
            {
                var body = Request.GetBody();

                Guid sessionId = Guid.Parse(body.sessionId);

                var ids = new List <Guid>();
                foreach (var id in body.ids)
                {
                    Guid gid = Guid.Parse(id);
                    ids.Add(gid);
                }

                log.Unsubscribe(sessionId, ids);
                return("ok");
            };

            Get["subscribers"] = (_) => {
                return(Json(log.Subscribers));
            };

            //Get["updateCache"] = (_) => {
            //    measure.LoadTags();
            //    return "ok";
            //};
        }