Ejemplo n.º 1
0
        public object UnInstall(HttpRequestParams request)
        {
            string packageId = request.GetRequiredString("packageId");

            Context.PackageManager.UnInstall(packageId);
            return null;
        }
Ejemplo n.º 2
0
        private object apiSaveScript(HttpRequestParams request)
        {
            Guid? id = request.GetGuid("id");
            string name = request.GetRequiredString("name");
            string body = request.GetString("body");

            using (var session = Context.OpenSession())
            {
                var script = id.HasValue ? session.Get<UserScript>(id.Value) : new UserScript { Id = Guid.NewGuid() };
                script.Name = name;
                script.Body = body;

                session.SaveOrUpdate(script);
                session.Flush();
            }

            return null;
        }
        private object apiSetControllerConfiguration(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var conf = request.GetRequiredString("config");

            foreach (ControllerBase controller in controllers)
                if (controller.ID == id)
                {
                    controller.SetConfiguration(conf);
                    break;
                }

            //NotifyForSignalR(new { MsgId = "ControllerIsVisibleChanged", Data = BuildControllerWebModel(ctrl) });

            return null;
        }
        private object apiSetControllerName(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var name = request.GetRequiredString("name");

            foreach (ControllerBase controller in controllers)
                if (controller.ID == id)
                {
                    controller.Name = name;
                    break;
                }

            //NotifyForSignalR(new { MsgId = "ControllerNameChanged", Data = BuildControllerWebModel(ctrl) });

            return null;
        }
        private object apiAddController(HttpRequestParams request)
        {
            var name = request.GetRequiredString("name");
            var type = (ControllerType)request.GetRequiredInt32("type");

            var ctrl = new Controller()
            {
                Id = Guid.NewGuid(),
                Name = name,
                Type = type,
                IsAutoMode = false
            };

            ControllerBase controller = CastController(ctrl);
            if (controller != null)
            {
                controller.Init(Context);
                controller.SaveToDB();
                controllers.Add(controller);

                NotifyForSignalR(new { MsgId = "ControllerAdded", Data = BuildControllerWebModel(ctrl) });
            }

            return null;
        }
Ejemplo n.º 6
0
        private object apiSetMonitorConfiguration(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var configuration = request.GetRequiredString("config");

            using (var session = Context.OpenSession())
            {
                var monitor = session.Load<Monitor>(id);
                monitor.Configuration = configuration;
                session.Flush();
            }

            //NotifyForSignalR(new { MsgId = "ControllerIsVisibleChanged", Data = BuildControllerWebModel(ctrl) });

            return null;
        }
Ejemplo n.º 7
0
 private object apiDeleteSensorValues(HttpRequestParams request)
 {
     var dateTo = DateTime.Parse(request.GetRequiredString("dateTo")).Date.AddDays(1);
     return DeleteSensorValues(dateTo);
 }
Ejemplo n.º 8
0
        private object apiSetZoneName(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var name = request.GetRequiredString("name");

            using (var session = Context.OpenSession())
            {
                var zone = session.Load<Zone>(id);
                zone.Name = name;
                session.Flush();
            }

            //NotifyForSignalR(new
            //{
            //    MsgId = "SensorNameChanged",
            //    Data = new
            //    {
            //        Id = id,
            //        Name = name
            //    }
            //});

            return null;
        }
Ejemplo n.º 9
0
        private object apiAddCommand(HttpRequestParams request)
        {
            var text = request.GetRequiredString("text");
            var scriptId = request.GetRequiredGuid("scriptId");

            using (var session = Context.OpenSession())
            {
                VoiceCommand cmd = new VoiceCommand()
                {
                    Id = Guid.NewGuid(),
                    CommandText = text,
                    UserScript = Context.GetPlugin<ScriptsPlugin>().GetScript(scriptId)
                };

                session.Save(cmd);
                session.Flush();
            }

            //NotifyForSignalR(new
            //{
            //    MsgId = "SensorNameChanged",
            //    Data = new
            //    {
            //        Id = id,
            //        Name = name
            //    }
            //});

            return null;
        }
Ejemplo n.º 10
0
        private object apiSetInformerConfiguration(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var monitorsIds = request.GetRequiredString("monitorsIds");

            using (var session = Context.OpenSession())
            {
                var informer = session.Load<Informer>(id);
                informer.MonitorsIds = monitorsIds;
                session.Flush();
            }

            return null;
        }
Ejemplo n.º 11
0
        private object apiSetInformerName(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var name = request.GetRequiredString("name");

            using (var session = Context.OpenSession())
            {
                var informer = session.Load<Informer>(id);
                informer.Name = name;
                session.Flush();
            }

            return null;
        }
Ejemplo n.º 12
0
        private object apiAddInformer(HttpRequestParams request)
        {
            var name = request.GetRequiredString("name");
            var sensorDisplayId = request.GetRequiredGuid("sensorDisplayId");

            using (var session = Context.OpenSession())
            {
                Informer informer = new Informer()
                {
                    Id = Guid.NewGuid(),
                    Name = name,
                    SensorDisplayId = sensorDisplayId,
                    MonitorsIds = "[]"
                };

                session.Save(informer);
                session.Flush();
            }

            return null;
        }
        public object apiSetConfiguration(HttpRequestParams request)
        {
            var conf = request.GetRequiredString("conf");

            configuration = (Configuration)Extensions.FromJson(typeof(Configuration), conf);
            configurationSetting.SetValue(configuration);
            SaveOrUpdate(configurationSetting);

            RequestSensorsValues();

            return null;
        }
Ejemplo n.º 14
0
        public object AddLocation(HttpRequestParams request)
        {
            var displayName = request.GetRequiredString("displayName");
            var query = request.GetRequiredString("query");

            using (var session = Context.OpenSession())
            {
                var location = new Location
                {
                    Id = Guid.NewGuid(),
                    DisplayName = displayName,
                    Query = query
                };

                session.Save(location);
                session.Flush();
            }

            return null;
        }
Ejemplo n.º 15
0
        public object AddSubscription(HttpRequestParams request)
        {
            string eventAlias = request.GetRequiredString("eventAlias");
            Guid scriptId = request.GetRequiredGuid("scriptId");

            using (var session = Context.OpenSession())
            {
                var guid = Guid.NewGuid();

                var script = session.Load<UserScript>(scriptId);

                var subscription = new ScriptEventHandler
                {
                    Id = guid,
                    EventAlias = eventAlias,
                    UserScript = script
                };

                session.Save(subscription);
                session.Flush();

                return guid;
            }
        }
Ejemplo n.º 16
0
        private object apiSetCommandName(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var text = request.GetRequiredString("text");

            using (var session = Context.OpenSession())
            {
                var cmd = session.Load<VoiceCommand>(id);
                cmd.CommandText = text;
                session.Flush();
            }

            CloseRecognitionEngine();
            InitRecognitionEngine();

            //NotifyForSignalR(new
            //{
            //    MsgId = "SensorNameChanged",
            //    Data = new
            //    {
            //        Id = id,
            //        Name = name
            //    }
            //});

            return null;
        }
Ejemplo n.º 17
0
        private object apiAddZone(HttpRequestParams request)
        {
            var name = request.GetRequiredString("name");

            using (var session = Context.OpenSession())
            {
                Zone zone = new Zone()
                {
                    Id = Guid.NewGuid(),
                    Name = name,
                    MonitorsList = "[]",
                    ControllersList = "[]",
                    ScriptsList = "[]",

                    GraphsList = "[]"
                };

                session.Save(zone);
                session.Flush();
            }

            //NotifyForSignalR(new { MsgId = "SensorNameChanged", Data = new { Id = id, Name = name } });

            return null;
        }
Ejemplo n.º 18
0
        private object apiAddMonitor(HttpRequestParams request)
        {
            var name = request.GetRequiredString("name");
            var sensorId = request.GetRequiredGuid("sensorId");
            var configuration = request.GetRequiredString("config");

            using (var session = Context.OpenSession())
            {
                Monitor monitor = new Monitor()
                {
                    Id = Guid.NewGuid(),
                    Name = name,
                    SensorId = sensorId,
                    Configuration = configuration
                };

                session.Save(monitor);
                session.Flush();
            }

            //NotifyForSignalR(new { MsgId = "MonitorAdded", Data = BuildMonitorWebModel(ctrl) });

            return null;
        }
Ejemplo n.º 19
0
        private object apiSetZoneConfiguration(HttpRequestParams request)
        {
            var id = request.GetRequiredGuid("id");
            var monitorsIds = request.GetRequiredString("monitorsIds");
            var controllersIds = request.GetRequiredString("controllersIds");
            var scriptsIds = request.GetRequiredString("scriptsIds");
            //var graphsIds = request.GetRequiredString("graphsIds");

            using (var session = Context.OpenSession())
            {
                var zone = session.Load<Zone>(id);
                zone.MonitorsList = monitorsIds;
                zone.ControllersList = controllersIds;
                zone.ScriptsList = scriptsIds;
                //zone.GraphsList = graphsIds;

                session.Flush();
            }

            //NotifyForSignalR(new { MsgId = "ControllerIsVisibleChanged", Data = BuildControllerWebModel(ctrl) });

            return null;
        }
Ejemplo n.º 20
0
        private object apiSetUnitSystem(HttpRequestParams request)
        {
            var value = request.GetRequiredString("Value");

            using (var session = Context.OpenSession())
            {
                var setting = session.Query<MySensorsSetting>().FirstOrDefault(s => s.Name == "UnitSystem");
                setting.Value = value;
                session.Flush();
            }

            //var setting = GetSetting("UnitSystem");
            //setting.Value = value;
            //SaveOrUpdate(setting);

            NotifyForSignalR(new { MsgId = "UnitSystemChanged", Data = value });

            return null;
        }