private void GetSpaceInfoResponse(bool error, RestGetSpaceResponseData spaceData) { if (error) { ProcessError(Process.Fetching); } else { try { ProcessEnd(Process.Fetching); // NOTE: TinyJSON does not serialize System.DateTime values correctly, so this will always return true. if (this.modified < JSONTools.ParseDateTimeFromString(spaceData.modified_at)) { CopyFromGetResponseData(spaceData); SaveToCache(); } //RegisterAssets(); } catch (Exception ex) { Debug.LogException(ex); ProcessError(Process.Fetching); } } }
private void CopyFromGetResponseData(RestGetSpaceResponseData responseData) { this.id = responseData.id; this.creatorID = responseData.creator_id; this.ownerID = responseData.owner_id; this.name = responseData.name; this.basePath = responseData.base_path; this.lastAccessed = JSONTools.ParseDateTimeFromString(responseData.last_accessed_at); this.created = JSONTools.ParseDateTimeFromString(responseData.created_at); this.modified = JSONTools.ParseDateTimeFromString(responseData.modified_at); this.assetIDs = new List <string>(responseData.asset_ids); }
public static void LoadFromCache() { string spacePath = string.Format(@"{0}/SpaceList.json", Constants.SPACES_CACHE); if (System.IO.File.Exists(spacePath)) { foreach (var space in JSONTools.Load <Space[]>(spacePath)) { if (!s_spaces.Contains(space)) { s_spaces.Add(space); } } } }
public static void SaveToCache() { string spacePath = string.Format(@"{0}/SpaceList", Constants.SPACES_CACHE); string spaceJSON = JSONTools.LoadToString(s_spaces); if (!System.IO.Directory.Exists(Constants.SPACES_CACHE)) { System.IO.Directory.CreateDirectory(Constants.SPACES_CACHE); } using (var writer = new System.IO.StreamWriter(spacePath + ".json")) { writer.Write(spaceJSON); } }
private bool TryFetchFromCache(string spaceID) { bool success = false; string spacePath = string.Format("{0}/{1}.json", Constants.SPACES_CACHE, spaceID); if (System.IO.File.Exists(spacePath)) { try { var cachedSpace = JSONTools.Load <Space>(spacePath); Copy(cachedSpace); success = true; } catch (Exception ex) { Debug.LogError(name + " (" + id + ") [Error Loading Space from Cache] " + ex); } } return(success); }