public static void DrawContentPlatformSupport(VRC.Core.ApiModel m) { if (m.supportedPlatforms == VRC.Core.ApiModel.SupportedPlatforms.StandaloneWindows || m.supportedPlatforms == VRC.Core.ApiModel.SupportedPlatforms.All) { EditorGUILayout.LabelField("Windows Support: YES"); } else { EditorGUILayout.LabelField("Windows Support: NO"); } if (m.supportedPlatforms == VRC.Core.ApiModel.SupportedPlatforms.Android || m.supportedPlatforms == VRC.Core.ApiModel.SupportedPlatforms.All) { EditorGUILayout.LabelField("Android Support: YES"); } else { EditorGUILayout.LabelField("Android Support: NO"); } }
public virtual ApiModel Clone(Type targetType = null, string newID = null) { try { if (targetType == null) { targetType = GetType(); } else if (!typeof(ApiModel).IsAssignableFrom(targetType)) { Logger.LogErrorFormat(DebugLevel.API, "Expected an ApiModel type."); return(null); } ApiModel apiModel = Activator.CreateInstance(targetType) as ApiModel; string Error = null; Dictionary <string, object> fields = ExtractApiFields(); if (!apiModel.SetApiFieldsFromJson(fields, ref Error)) { Logger.LogErrorFormat(DebugLevel.API, "Unable to clone {0}: {1}", targetType.Name, Error); } if (newID != null) { apiModel.id = newID; } apiModel.Endpoint = Endpoint; return(apiModel); IL_00a3: ApiModel result; return(result); } catch (Exception ex) { Debug.LogException(ex); return(null); IL_00b7: ApiModel result; return(result); } }
protected virtual void PostOrPut(Action <ApiContainer> onSuccess, Action <ApiContainer> onFailure, PostOrPutSelect select, Dictionary <string, object> requestParams = null) { if (string.IsNullOrEmpty(Endpoint)) { Logger.LogErrorFormat(DebugLevel.API, "Cannot save to null endpoint"); } else { if (requestParams == null) { requestParams = ExtractApiFields(); } if (APIUser.CurrentUser == null || !APIUser.CurrentUser.hasSuperPowers) { List <KeyValuePair <string, object> > list = (from kvp in requestParams where IsAdminWritableOnly(FindProperty(kvp.Key)) select kvp).ToList(); foreach (KeyValuePair <string, object> item in list) { requestParams.Remove(item.Key); } } List <KeyValuePair <string, object> > list2 = (from kvp in requestParams where IsApiWritableOnly(FindProperty(kvp.Key)) select kvp).ToList(); foreach (KeyValuePair <string, object> item2 in list2) { requestParams.Remove(item2.Key); } Action <ApiContainer> onSuccess2 = delegate(ApiContainer c) { ApiCache.Save(c.Model.id, c.Model, andClone: true); if (onSuccess != null) { onSuccess(c); } }; switch (select) { case PostOrPutSelect.Auto: if (!string.IsNullOrEmpty(id)) { SendPutRequest(new ApiContainer { OnSuccess = onSuccess2, OnError = onFailure, Model = this }, requestParams); } else { API.SendPostRequest(Endpoint, MakeModelContainer(onSuccess2, onFailure), requestParams); } break; case PostOrPutSelect.Post: API.SendPostRequest(Endpoint, MakeModelContainer(onSuccess2, onFailure), requestParams); break; case PostOrPutSelect.Put: { ApiModel target = null; if (ApiCache.Fetch(GetType(), id + "_copy", ref target, 3.40282347E+38f)) { foreach (KeyValuePair <string, object> item3 in target.ExtractApiFields()) { if (requestParams.ContainsKey(item3.Key)) { if (typeof(IList).IsAssignableFrom(item3.Value.GetType()) && typeof(IList).IsAssignableFrom(requestParams[item3.Key].GetType())) { IList a = item3.Value as IList; IList b = requestParams[item3.Key] as IList; if (!b.Cast <object>().Any((object bo) => !a.Contains(bo)) && !a.Cast <object>().Any((object ao) => !b.Contains(ao))) { requestParams.Remove(item3.Key); } } else if (item3.Value.Equals(requestParams[item3.Key])) { requestParams.Remove(item3.Key); } } } } SendPutRequest(new ApiContainer { OnSuccess = onSuccess2, OnError = onFailure, Model = this }, requestParams); break; } } } }
public static void Post(ApiModel model, Action <ApiContainer> onSuccess = null, Action <ApiContainer> onFailure = null) { model.Post(onSuccess, onFailure); }
public static T Clone <T>(ApiModel model) where T : ApiModel, ApiCacheObject, new() { return(model.Clone(typeof(T)) as T); }