public static Device ParseDevice(JsonObject data, IStringProvider stringProvider, IContextActionProvider contextActionProvider, List <Room> rooms, List <DeviceCategory> categories) { Room room = null; if (data.ContainsKey("Room")) { string roomId = data["Room"].GetString(); if (!string.IsNullOrEmpty(roomId)) { room = rooms.FirstOrDefault((a) => a.Id == roomId); if (room == null) { throw new Exception(string.Format("Unable to locate room with id {0}", roomId)); } } } string categoryId = data["Category"].GetString(); DeviceCategory category = categories.FirstOrDefault((a) => a.Id == categoryId); if (category == null) { throw new Exception(string.Format("Unable to locate category with id {0}", categoryId)); } List <IProperty> properties = Property.ParsePropertyList(data["Properties"].GetArray(), category.SharedBitmapLists); Device retVal = new Device(stringProvider, contextActionProvider, data["Id"].GetString(), category, data["Caption"].GetString(), data["Thumbnail"].GetString(), room, properties); if (room != null) { room.AddDevice(retVal); } return(retVal); }
public static DeviceCategory ParseDeviceCategory(JsonObject data, IStringProvider stringProvider, IContextActionProvider contextActionProvider) { bool showDeviceShelf = bool.Parse(data["ShowDeviceShelf"].GetString()); Vector3 shelfOffset = data["ShelfOffset"].GetObject().GetVector3(); Vector3 deviceOffset = data["DeviceOffset"].GetObject().GetVector3(); Vector3 spotlightOffset = data["SpotlightOffset"].GetObject().GetVector3(); Vector3 spotlight1Offset = data["Spotlight1Offset"].GetObject().GetVector3(); Vector3 pointlightOffset = data["PointlightOffset"].GetObject().GetVector3(); Dictionary <string, List <PropertyBitmapPickerItem> > sharedBitmapLists = new Dictionary <string, List <PropertyBitmapPickerItem> >(); JsonArray nodes = data["SharedBitmapLists"].GetArray(); foreach (var node in nodes) { JsonObject nodeObject = node.GetObject(); string id = nodeObject["Id"].GetString(); List <PropertyBitmapPickerItem> list = PropertyBitmapPickerItem.ParsePropertyBitmapPickerItemList(nodeObject["List"].GetArray()); sharedBitmapLists.Add(id, list); } var retVal = new DeviceCategory(data["Id"].GetString(), showDeviceShelf, shelfOffset, deviceOffset, spotlightOffset, spotlight1Offset, pointlightOffset, sharedBitmapLists, null, data["Caption"].GetString(), data["Thumbnail"].GetString(), data["ThumbnailHeight"].GetNumber(), data["ThumbnailTopMargin"].GetNumber()); var defaultDevice = Device.ParseDevice(data["DefaultDevice"].GetObject(), stringProvider, contextActionProvider, null, retVal); retVal.DefaultDevice = defaultDevice; return(retVal); }
public Device(IStringProvider stringProvider, IContextActionProvider contextActionProvider, string id, DeviceCategory category, string caption, string thumbnailPath, Room room, List <IProperty> properties) { _stringProvider = stringProvider; _contextActionProvider = contextActionProvider; _id = id; _category = category; _caption = caption; _thumbnailPath = thumbnailPath; _room = room; _properties = properties; if (_properties != null) { foreach (IProperty prop in _properties) { if (prop != null) { prop.ValueChanged += Prop_ValueChanged; } } } }