Esempio n. 1
0
        public ActionResult SetId(string blindName, int id)
        {
            RemoteController remote = null;

            using (var db = new LiteDatabase(@"remotes.db"))
            {
                var remotes = db.GetCollection <RemoteController>("remotes");
                remote = remotes.FindOne(x => x.Name == blindName);
                if (remote == null)
                {
                    remote = new RemoteController()
                    {
                        CurrentCounter = 0, Id = id, Name = blindName
                    };
                    remotes.Insert(remote);
                }
                try
                {
                    remote.Id = id;
                    remotes.Update(remote);
                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(StatusCode(500));
                }
            }
        }
Esempio n. 2
0
        public ActionResult DeleteByName(string blindName)
        {
            RemoteController remote = null;

            using (var db = new LiteDatabase(@"remotes.db"))
            {
                var remotes = db.GetCollection <RemoteController>("remotes");
                remote = remotes.FindOne(x => x.Name == blindName);
                if (remote == null)
                {
                    return(NotFound());
                }
                remotes.Delete(remote.Id);
            }
            return(Ok());
        }
Esempio n. 3
0
        public string Post(string blindName, [FromQuery] string action)
        {
            SendAction _action = SendAction.Down;

            if (action == "up")
            {
                _action = SendAction.Up;
            }
            else if (action == "stop")
            {
                _action = SendAction.Stop;
            }
            else if (action == "prog")
            {
                _action = SendAction.Prog;
            }

            RemoteController remote = null;

            using (var db = new LiteDatabase(@"remotes.db"))
            {
                var remotes = db.GetCollection <RemoteController>("remotes");
                remote = remotes.FindOne(x => x.Name == blindName);
                if (remote == null)
                {
                    remote = new RemoteController()
                    {
                        CurrentCounter = 0, Id = remotes.FindAll().ToArray().Count() > 0 ? remotes.FindAll().ToArray().Max(x => x.Id) + 1 : 0, Name = blindName
                    };
                    remotes.Insert(remote);
                }
                try
                {
                    var remoteId = Convert.ToInt32(remote.Id.ToString(), 16);
                    new Commands().Send(remoteId, remote.CurrentCounter + 1, _action);
                    remote.CurrentCounter++;
                    remotes.Update(remote);
                    return("done");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }
        }
Esempio n. 4
0
        public ActionResult SetCounter(string blindName, int counter)
        {
            RemoteController remote = null;

            using (var db = new LiteDatabase(@"remotes.db"))
            {
                var remotes = db.GetCollection <RemoteController>("remotes");
                remote = remotes.FindOne(x => x.Name == blindName);
                if (remote == null)
                {
                    return(NotFound());
                }
                try
                {
                    remote.CurrentCounter = counter;
                    remotes.Update(remote);
                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(StatusCode(500));
                }
            }
        }