예제 #1
0
        public static JObject GetThing(long referenceId)
        {
            Thing thing;

            if (!XmlSaveLoad.Referencables.TryGetValue(referenceId, out thing))
            {
                return(null);
            }
            return(JsonTranslator.ObjectToJson(thing));
        }
예제 #2
0
        public static JObject GetDevice(long referenceId)
        {
            var device = Device.AllDevices.Find(x => x.ReferenceId == referenceId);

            if (device == null)
            {
                return(null);
            }
            return(JsonTranslator.ObjectToJson(device));
        }
예제 #3
0
        public static IList <JObject> GetItems()
        {
            // AllDevices has duplicates, so filtering this to be safe.
            var set = new HashSet <Item>();

            foreach (var item in Item.AllItems)
            {
                set.Add(item);
            }
            return(set.Select(x => JsonTranslator.ObjectToJson(x)).ToList());
        }
예제 #4
0
        public static IList <JObject> GetDevices()
        {
            // Devices can have duplicates in this list.
            var set = new HashSet <Device>();

            foreach (var device in Device.AllDevices)
            {
                set.Add(device);
            }
            return(set.Select(x => JsonTranslator.ObjectToJson(x)).ToList());
        }
예제 #5
0
 public static IList <JObject> GetThings()
 {
     // This seems to have prefabs in it.  Not sure how to filter those out apart from checking ReferenceId 0
     return(OcclusionManager.AllThings.Keys.Where(x => x.ReferenceId != 0).Select(thing =>
     {
         try
         {
             return JsonTranslator.ObjectToJson(thing);
         }
         catch (Exception ex)
         {
             Logging.Log("GetThings: Exception deserializing thing id {0}: {1}\n{2}", thing.ReferenceId, ex.Message, ex.StackTrace);
             return null;
         }
     }).Where(x => x != null).ToList());
 }
예제 #6
0
        public static JObject UpdateThing(long referenceId, JObject updates)
        {
            Thing thing;

            if (!XmlSaveLoad.Referencables.TryGetValue(referenceId, out thing))
            {
                return(null);
            }

            try
            {
                JsonTranslator.UpdateObjectFromJson(updates, thing);
            }
            catch (JsonTranslationException e)
            {
                throw new BadRequestException(e.Message);
            }
            return(JsonTranslator.ObjectToJson(thing));
        }
예제 #7
0
        public static JObject UpdateDevice(long referenceId, JObject updates)
        {
            var device = Device.AllDevices.Find(x => x.ReferenceId == referenceId);

            if (device == null)
            {
                return(null);
            }

            try
            {
                JsonTranslator.UpdateObjectFromJson(updates, device);
            }
            catch (JsonTranslationException e)
            {
                throw new BadRequestException(e.Message);
            }
            return(JsonTranslator.ObjectToJson(device));
        }