Exemple #1
0
 /// <summary>
 /// Add Resident to resident list. Resident search dictionary is updated as well.
 /// If resident of same name exists, the add operation will fail.
 /// If add operation succeed, return True. Return False otherwise.
 /// </summary>
 /// <param name="resident"></param>
 /// <returns></returns>
 public bool AddResident(Resident resident)
 {
     if (_residentDictionary.TryGetValue(resident.Name, out int i))
     {
         return(false);
     }
     else
     {
         Residents.Add(resident);
         _residentDictionary.Add(resident.Name, Residents.Count - 1);
         _isModified = true;
         return(true);
     }
 }
Exemple #2
0
 public void FromJsonObject(JsonObject homeObject)
 {
     Name             = homeObject.GetNamedString(nameKey);
     _pathToFloorPlan = homeObject.GetNamedString(floorPlanKey);
     _sensorList      = new List <Sensor>();
     _residentList    = new List <Resident>();
     _activityList    = new List <Activity>();
     try
     {
         JsonArray jsonSensorArray = homeObject.GetNamedArray(sensorKey);
         foreach (IJsonValue sensorValue in jsonSensorArray)
         {
             Sensor sensor = new Sensor(sensorValue.GetObject());
             _sensorList.Add(sensor);
         }
     }
     catch (Exception) { }
     try
     {
         JsonArray jsonResidentArray = homeObject.GetNamedArray(residentKey);
         foreach (IJsonValue residentValue in jsonResidentArray)
         {
             Resident resident = new Resident(residentValue.GetObject());
             _residentList.Add(resident);
         }
     }
     catch (Exception) { }
     try
     {
         JsonArray jsonActivityArray = homeObject.GetNamedArray(activityKey);
         foreach (IJsonValue activityValue in jsonActivityArray)
         {
             Activity activity = new Activity(activityValue.GetObject());
             _activityList.Add(activity);
         }
     }
     catch (Exception) { }
 }
Exemple #3
0
        public Resident GetResident(string name, bool createIfNotExist = false)
        {
            Logger   appLog   = Logger.Instance;
            Resident resident = GetResident(name);

            if (resident == null && createIfNotExist)
            {
                appLog.Warn(this.GetType().ToString(), string.Format("Resident {0} not Found. Add to dataset {1}.", name, Name));
                resident = new Resident
                {
                    Name  = name,
                    Color = "#FFFFFFFF"
                };
                if (AddResident(resident))
                {
                    return(resident);
                }
                else
                {
                    return(null);
                }
            }
            return(resident);
        }
Exemple #4
0
 public void RemoveResident(Resident resident)
 {
     _residentList.Remove(resident);
 }
Exemple #5
0
 public void AddResident(Resident resident)
 {
     _residentList.Add(resident);
 }