private bool TryGetDefinitionVersion(ZipFile zip, string version, out RelationDefinition definition, out DateTime lastMod) { var storedVersionEntry = zip[VersionFile]; string storedVersion; using (var s = storedVersionEntry.OpenReader()) { using (var r = new StreamReader(s)) storedVersion = r.ReadToEnd(); } if (storedVersion != version) { var existingDefPath = string.Format("{0}/{1}", version, DefinitionFile); if (zip.ContainsEntry(existingDefPath)) { ZipCopy(zip, existingDefPath, DefinitionFile); UpdateVersion(zip); zip.Save(); definition = ReadDefinition(zip, DefinitionFile, out lastMod); return true; } definition = null; lastMod = DateTime.MinValue; return false; } definition = ReadDefinition(zip, DefinitionFile, out lastMod); return true; }
/// <summary> /// Attempt to get the <see cref="RelationDefinition" /> for a specific version from storage. /// </summary> /// <param name="zip"><see cref="ZipFile" /> to read from.</param> /// <param name="version">Definition version to look for.</param> /// <param name="definition"> /// When this method returns, contains the <see cref="RelationDefinition" /> for the specified /// version, if found; otherwise, <c>null</c>. /// </param> /// <returns><c>true</c> if the definition for the specified version was present; <c>false</c> otherwise.</returns> private bool TryGetDefinitionVersion(ZipFile zip, string version, out RelationDefinition definition) { DateTime mod; return TryGetDefinitionVersion(zip, version, out definition, out mod); }
private bool TryGetDefinitionFromFileSystem(FileInfo file, out RelationDefinition definition, out DateTime lastWrite) { if (file.Exists) { lastWrite = file.LastWriteTimeUtc; definition = RelationDefinition.Deserialize(file.FullName); return true; } lastWrite = DateTime.MinValue; definition = null; return false; }
private bool TryGetDefinitionFromFileSystem(out RelationDefinition definition, out DateTime lastWrite) { var file = new FileInfo(Path.Combine(StateFile.Directory.FullName, DefinitionFile)); return TryGetDefinitionFromFileSystem(file, out definition, out lastWrite); }
/// <summary> /// Serialize a <see cref="RelationDefinition" /> into a <see cref="ZipFile" />. /// </summary> /// <param name="zip"><see cref="ZipFile" /> to write to.</param> /// <param name="definition"><see cref="RelationDefinition" /> to store.</param> /// <param name="path">File name inside the storage to write to.</param> private static void StoreDefinition(ZipFile zip, RelationDefinition definition, string path) { using (var ms = new MemoryStream()) { using (var writer = new StreamWriter(ms, ZipEncoding)) { definition.Serialize(writer); writer.Flush(); zip.UpdateEntry(path, ms.ToArray()); } } }
public static RelationDefinition FromJson(string json) { JObject obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(json); return(RelationDefinition.FromJson(obj)); }