Пример #1
0
 protected void UpdateLampDb(LampNode record)
 {
     using (var db = new DatabaseClient())
     {
         db.AddOrUpdate(record);             // Update the record to the database
     }
 }
Пример #2
0
        public void AddOrUpdate(LampNode node)
        {
            lock (SyncRoot)
            {
                var table = GetTable();

                // Try to insert record. If that fails with a duplicate key, then try update
                // Old code checked for existence first and then decided, but this was
                // race condition sensitive.
                try
                {
                    InsertRecord(table, node);
                }
                catch (LiteException lE)
                {
                    if (lE.ErrorCode == LiteException.INDEX_DUPLICATE_KEY)
                    {
                        UpdateRecord(table, node);
                    }
                    else
                    {
                        throw lE;       // Some other error
                    }
                }
            }
        }
Пример #3
0
        public LampClient(LampNode data)
        {
            _node    = data;
            StateSet = true;

            Url  = data.Url;
            Name = data.Name;
        }
Пример #4
0
        public LampClient(string url, string name)
        {
            Url  = url;
            Name = name;

            _node    = new LampNode();
            StateSet = false;
        }
Пример #5
0
        public LampNode SetLampStateExtended(string id, SetLampDataExtended data)
        {
            LampNode record = null;

            RuntimeMonitor.Monitor.RegisterCall("LampSet");

            record = GetLamp(id);
            record.ProcessStateChanges(data);

            RequestSequencer.Sequencer.Schedule(new LampRequest(id, data));

            return(record);
        }
Пример #6
0
        private async Task UpdateSingleLamp(DatabaseClient db, LampNode lamp)
        {
            RuntimeMonitor.Monitor.RegisterCall("UpdateSingleLamp");

            var lampClient = new LampClient(lamp);

            try
            {
                await lampClient.GetState();

                db.AddOrUpdate(lampClient.Node);
            }
            catch
            {
                // Error is ok; if the lamp is not seen, it will be removed
            }
        }
Пример #7
0
        private void UpdateRecord(ILiteCollection <LampNode> table, LampNode node)
        {
            var currentLamp = table.FindOne(rec => rec.Name.ToLower() == node.Name.ToLower());

            if (currentLamp != null)
            {
                // Update
                currentLamp.Url      = node.Url;
                currentLamp.On       = node.On;
                currentLamp.Online   = node.Online;
                currentLamp.LastSeen = node.LastSeen;
                currentLamp.Red      = node.Red;
                currentLamp.Green    = node.Green;
                currentLamp.Blue     = node.Blue;
                currentLamp.NodeType = node.NodeType;

                table.Update(currentLamp);
            }
        }
Пример #8
0
 private void InsertRecord(ILiteCollection <LampNode> table, LampNode node)
 {
     table.Insert(node);
 }