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

            var pvt = new Pivoter();

            var om = new ObjectManager();

            bus = new Bus();
            bus.OnMessageReceived += (se, ea) =>
            {
                logger.Debug("поступило сообщение {0}", ea.Message.head.what);
                if (ea.Message.head.what == "export-data")
                {
                    DateTime start = ea.Message.body.start;
                    DateTime end   = ea.Message.body.end;

                    string type = ea.Message.body.type;

                    var ids = (ea.Message.body.ids as IEnumerable <object>).Select(s => Guid.Parse(s.ToString())).ToArray();

                    var rcs = pvt.Pivot(ids, start, end, type);
                    //pvt.Pivot()
                    var ans = bus.MakeMessageStub("export");
                    ans.head.id   = ea.Message.head.id;
                    ans.body.data = rcs;

                    bus.SendToSession(ans);
                }
                if (ea.Message.head.what == "export-names")
                {
                    var ans = bus.MakeMessageStub("export");
                    ans.head.id   = ea.Message.head.id;
                    ans.body.data = om.GetObjects();

                    bus.SendToSession(ans);
                }
            };
            bus.Start();

            uc.RegisterInstance(pvt);
            uc.RegisterInstance(om);
            uc.RegisterInstance(bus);

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

            webHost = WebApp.Start(url, app =>
            {
                app.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(uc));
            });
            logger.Info("сервис запущен, url: {0}", url);
        }
예제 #2
0
        public ApiModule(Pivoter pvt, ObjectManager om)
        {
            Post["data"] = (_) =>
            {
                var body = Request.GetBody();

                DateTime start = body.start;
                DateTime end   = body.end;

                string type = body.type;

                var ids = (body.ids as IEnumerable <object>).Select(s => Guid.Parse(s.ToString())).ToArray();

                var rcs = pvt.Pivot(ids, start, end, type);

                return(Json(rcs));
            };

            Get["objects"] = (_) =>
            {
                var objs = om.GetObjects();
                return(Json(objs));
            };
        }