public static RoomDevice GetRoomDeviceByRoomIdAndDeviceId(int roomId, int deviceId)
 {
     using (HomeAutomationEntities context = new HomeAutomationEntities())
     {
         RoomDevice result = new RoomDevice();
         result = context.RoomDevice.FirstOrDefault(c => c.RoomID == roomId && c.DeviceID == deviceId);
         return(result);
     }
 }
 public DeviceDTO(RoomDevice register)
 {
     this.RoomDeviceID = register.RoomID;
     this.RoomID       = register.RoomID;
     this.DeviceID     = register.DeviceID;
     this.StateID      = register.StateID;
     this.Value        = register.Value;
     this.UnitID       = register.UnitID;
 }
Esempio n. 3
0
        private void CheckInput(long ticks)
        {
            if (Input.GetButton("Interact"))
            {
                _roomDevice = character.Pawn.RoomDeviceListener.RoomDevice;

                stateController.TrySetState(this);
            }
        }
 public static int UpdateRoomDevice(RoomDevice reg)
 {
     using (HomeAutomationEntities context = new HomeAutomationEntities())
     {
         context.RoomDevice.Attach(reg);
         context.Entry(reg).State = EntityState.Modified;
         int result = context.SaveChanges();
         return(result);
     }
 }
        public void Subscribe(string roomName, RoomDevice device)
        {
            if (!_subscribers.ContainsKey(roomName))
            {
                _subscribers.TryAdd(roomName, new List <RoomDevice>());
            }

            lock (_deviceListLock)
            {
                _subscribers[roomName].Add(device);
            }
        }
Esempio n. 6
0
        public async void Subscribe(string roomName, string deviceName, int deviceType)
        {
            var device = new RoomDevice
            {
                ConnectionId = Context.ConnectionId,
                Name         = deviceName,
                DeviceType   = (RoomDeviceType)deviceType
            };

            await Groups.AddToGroupAsync(Context.ConnectionId, roomName);

            _roomSubscription.Subscribe(roomName, device);
        }
 public void Unsubscribe(RoomDevice roomDevice)
 {
     foreach (var(key, value) in _subscribers)
     {
         foreach (var device in value.ToArray())
         {
             if (device.ConnectionId == roomDevice.ConnectionId)
             {
                 lock (_deviceListLock)
                 {
                     value.Remove(device);
                 }
             }
         }
     }
 }
Esempio n. 8
0
        public override IEnumerable GetEvaluationBlock()
        {
            var timer = new AutoTimer(typedInfo.duration / character.StatModifier);

            _roomDevice.IsBeingRepared = true;

            while (timer.ValueNormalized < 1)
            {
                yield return(null);
            }

            if (_roomDevice.IsBroken())
            {
                _roomDevice.SetFixed();
            }
            else
            {
                _roomDevice.Interact(character);
            }

            _roomDevice.IsBeingRepared = false;

            _roomDevice = null;
        }
Esempio n. 9
0
        // public int UpdateConfig(string result, string topic, ObservableCollection<Temp> MyTemp, string type)
        public int UpdateConfig(string result, string topic, ObservableCollection <Temp> MyTemp, string type, Dictionary <string, string> NeedLoadedRoomsAndDevices)
        {
            try
            {
                string[] parsedmessage = ParseMessage(result);

                Name = parsedmessage[0];

                if (parsedmessage[1].IndexOf("delete") == -1)// name pin/delete
                {
                    Count = parsedmessage[1];

                    if (parsedmessage.Length > 2)
                    {
                        string[] topicword = topic.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

                        for (int i = 0; i < parsedmessage.Length - 2; i++)
                        {
                            string parsedmessage2 = parsedmessage[i + 2];
                            if (parsedmessage[i + 2].IndexOf("delete") > -1)
                            {
                                string res = parsedmessage2.Remove(parsedmessage2.Length - 6, 6);//6 = delete
                                Temp   t   = (from o in MyTemp where o.Key == res select o).FirstOrDefault();
                                if (t != null)
                                {
                                    RoomDevice.Remove(t);
                                    t.isHaveRooms = false;
                                    t.MyRoom      = new Room();
                                }
                            }
                            else
                            {
                                Temp t = (from o in MyTemp where o.Key == parsedmessage[i + 2] select o).FirstOrDefault();
                                if (t != null)
                                {
                                    t.MyRoom = new Room()
                                    {
                                        Name = parsedmessage[0], Count = parsedmessage[1], Key = topicword[2], Type = type, RoomDevice = new ObservableCollection <Temp>()
                                        {
                                            t
                                        }
                                    };
                                    t.myDevice.InRoom = new Room()
                                    {
                                        Name = parsedmessage[0], Count = parsedmessage[1], Key = topicword[2], Type = type, RoomDevice = new ObservableCollection <Temp>()
                                        {
                                            t
                                        }
                                    };

                                    Temp t1 = (from o in RoomDevice where o.Key == parsedmessage[i + 2] select o).FirstOrDefault();
                                    if (t1 == null)
                                    {
                                        RoomDevice.Add(t);
                                    }

                                    if (t.MyRoom.RoomDevice.Count > 0)
                                    {
                                        t.isHaveRooms = true;
                                    }
                                }
                                else
                                {
                                    //KeyValuePair<string, string> item = (from o in NeedLoadedRoomsAndDevices where o.Key.Contains(parsedmessage[2]) select o).FirstOrDefault();
                                    ////  message = result;
                                    //try
                                    //{
                                    //    if (!String.IsNullOrEmpty(item.Key) && !String.IsNullOrEmpty(item.Value))
                                    //    {
                                    //        string topic1 = item.Key;
                                    //       string mss = item.Value + "|"+ topicword[2];
                                    //        NeedLoadedRoomsAndDevices.Remove(item.Key);
                                    //        NeedLoadedRoomsAndDevices.Add(topic1, mss);
                                    //    }
                                    //}
                                    //catch (Exception ex)
                                    //{

                                    //   // throw;
                                    //}

                                    if (!NeedLoadedRoomsAndDevices.ContainsKey(topic))
                                    {
                                        NeedLoadedRoomsAndDevices.Add(topic, result);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < RoomDevice.Count; i++)
                    {
                        //Temp t = (from o in RoomDevice where o.Key == RoomDevice[i].Key select o).FirstOrDefault();
                        if (RoomDevice[i] != null)
                        {
                            RoomDevice[i].isHaveRooms = false;
                            RoomDevice[i].MyRoom      = new Room();
                            RoomDevice.Remove(RoomDevice[i]);
                            i--;
                        }
                    }

                    return(1);
                }
                return(0);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Updates the device status.
        /// </summary>
        /// <param name="roomId">The room identifier.</param>
        /// <param name="selectedDeviceID">The selected device identifier.</param>
        /// <param name="buttonState">if set to <c>true</c> [button state].</param>
        /// <returns></returns>
        /// <Author> Daniel Molina </Author>
        /// <LastModification>  29/11/2017 - 16:20 </LastModification>
        /// <LastModificationBy> Daniel Molina </LastModificationBy>
        public static RoomDeviceResponse UpdateDeviceStatus(int roomId, int selectedDeviceID, bool buttonState)
        {
            try
            {
                //Validate the Device Status
                List <GetDeviceByRoomIdAndDeviceID_Result> lstDeviceByRoomIdAndDeviceId = DeviceController.GetDeviceByRoomIdAndDeviceId(roomId, selectedDeviceID);
                List <DevicesDTOPartial> retVal = new List <DevicesDTOPartial>();
                foreach (GetDeviceByRoomIdAndDeviceID_Result reg in lstDeviceByRoomIdAndDeviceId)
                {
                    retVal.Add(new DevicesDTOPartial(reg));
                }

                //Validate that the device State
                if (retVal[0].State == buttonState)
                {
                    Logger.Logger.Info(profileName, "Method Response: The device has the same status. Username:"******"PasswordRetriesListByUtilityID", "Endpoint not found exception", ex);
                return(new RoomDeviceResponse {
                    Code = (int)ResponseCode.Exception, Message = ResponseCode.Exception.ToString() + ": " + ex.Message
                });
            }
        }
Esempio n. 11
0
 void OnTriggerEnter(Collider other)
 {
     RoomDevice = other.gameObject.GetComponent <RoomDevice>();
 }