public UsageStore Load(string userId) { UsageStore result = null; string json = null; if (path.FileExists()) { try { json = path.ReadAllText(Encoding.UTF8); result = json?.FromJson <UsageStore>(lowerCase: true); } catch (Exception ex) { LogHelper.Instance.Warning(ex, "Error Loading Usage: {0}; Deleting File", path); try { path.DeleteIfExists(); } catch { } } } if (result == null) { result = new UsageStore(); } if (String.IsNullOrEmpty(result.Model.Guid)) { result.Model.Guid = userId; } return(result); }
public static DugiteReleaseManifest Load(NPath path, IEnvironment environment) { var manifest = path.ReadAllText().FromJson <DugiteReleaseManifest>(true, false); var(zipAsset, shaAsset) = manifest.GetAsset(environment); var shaAssetPath = environment.UserCachePath.Combine("downloads", shaAsset.Name); if (!shaAssetPath.FileExists()) { var downloader = new Downloader(); downloader.QueueDownload(shaAsset.Url, shaAssetPath.Parent, shaAssetPath.FileName); downloader.RunSynchronously(); } zipAsset.Hash = shaAssetPath.ReadAllText(); manifest.DugitePackage = zipAsset; return(manifest); }
private void LoadConnectionsFromDisk() { if (cachePath.FileExists()) { var json = cachePath.ReadAllText(); try { var conns = json.FromJson <Connection[]>(); UpdateConnections(conns); } catch (IOException ex) { logger.Error(ex, "Error reading connection cache: {0}", cachePath); } catch (Exception ex) { logger.Error(ex, "Error deserializing connection cache: {0}", cachePath); // try to fix the corrupted file with the data we have SaveConnectionsToDisk(raiseChangedEvent: false); } } }