示例#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);
 }