public string ComputeSHA1(string json) { // SHA1 value is based on UTF8 encoded file contents using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(json))) { return(HashGenerator.ComputeSHA1(memoryStream)); } }
public static string ComputeSHA1(this IObject3D object3D) { // ******************************************************************************************************************************* // TODO: We must ensure we always compute with a stream that marks for UTF encoding with BOM, irrelevant of in-memory or on disk // ******************************************************************************************************************************* // SHA1 value is based on UTF8 encoded file contents using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(object3D.ToJson()))) { return(HashGenerator.ComputeSHA1(memoryStream)); } }
public static string GCodeFilePath(PrinterConfig printer, IObject3D object3D) { using (var memoryStream = new MemoryStream()) { // Write JSON object3D.SaveTo(memoryStream); // Reposition memoryStream.Position = 0; // Calculate string fileHashCode = HashGenerator.ComputeSHA1(memoryStream); ulong settingsHashCode = printer.Settings.GetGCodeCacheKey(); return(Path.Combine( ApplicationDataStorage.Instance.GCodeOutputPath, $"{fileHashCode}_{ settingsHashCode}.gcode")); } }
public string StoreStream(Stream stream, string extension) { // Compute SHA1 string sha1 = HashGenerator.ComputeSHA1(stream); string fileName = $"{sha1}{extension}"; string assetPath = Path.Combine(Object3D.AssetsPath, fileName); // Load cache if (!File.Exists(assetPath)) { stream.Position = 0; using (var outstream = File.OpenWrite(assetPath)) { stream.CopyTo(outstream); } } return(fileName); }
public async Task <string> StoreMcx(IObject3D object3D, bool publishAfterSave) { // TODO: Track SHA1 of persisted asset // TODO: Skip if cached sha1 exists in assets // Serialize object3D to in memory mcx/json stream using (var memoryStream = new MemoryStream()) { // Write JSON object3D.SaveTo(memoryStream); // Reposition memoryStream.Position = 0; Directory.CreateDirectory(Object3D.AssetsPath); // Calculate string sha1 = HashGenerator.ComputeSHA1(memoryStream); string sha1PlusExtension = sha1 + ".mcx"; string assetPath = Path.Combine(Object3D.AssetsPath, sha1PlusExtension); if (!File.Exists(assetPath)) { memoryStream.Position = 0; using (var outStream = File.Create(assetPath)) { memoryStream.CopyTo(outStream); } } await ConditionalPublish( sha1PlusExtension, publishAfterSave, CancellationToken.None, null); return(assetPath); } }
public async Task <string> StoreStream(Stream stream, string extension, bool publishAfterSave, CancellationToken cancellationToken, Action <double, string> progress) { // Compute SHA1 string sha1PlusExtension = $"{HashGenerator.ComputeSHA1(stream)}{extension}"; string assetPath = Path.Combine(Object3D.AssetsPath, sha1PlusExtension); // Load cache if (!File.Exists(assetPath)) { stream.Position = 0; using (var outstream = File.OpenWrite(assetPath)) { stream.CopyTo(outstream); } } if (publishAfterSave) { await Publish(sha1PlusExtension, cancellationToken, progress); } return(sha1PlusExtension); }