public void ProcessFile(string name, string file) { ManifestEntry entry = new ManifestEntry(); entry.name = name; FileStream data = File.Open(file, FileMode.Open); long fileLength = data.Length; entry.length = fileLength.ToString(); HashAlgorithm digester = new SHA1CryptoServiceProvider(); byte[] digest = digester.ComputeHash(data); data.Close(); StringBuilder digestStr = new StringBuilder(); foreach (byte b in digest) { digestStr.Append(b.ToString("x2")); } entry.digest = digestStr.ToString(); currentManifestDict[name] = entry; }
protected static void ParseManifest(Dictionary <string, ManifestEntry> dict, StreamReader reader) { ManifestEntry entry = null; for (; ;) { string line = reader.ReadLine(); if (line == null) { if (entry != null) { RegisterEntry(dict, entry); entry = null; } break; } else if (line.Trim().Length == 0) { if (entry != null) { RegisterEntry(dict, entry); entry = null; } continue; } if (!line.Contains(":")) { Trace.TraceWarning("Invalid line: " + line); continue; } char[] delims = { ':' }; string[] tmp = line.Split(delims, 2); string attr = tmp[0]; if (tmp[1].Length <= 1 || !tmp[1].StartsWith(" ")) { Trace.TraceWarning("Invalid value string: " + tmp[1]); continue; } string val = tmp[1].Substring(1); // trim off leading space switch (attr) { case "Name": entry = new ManifestEntry(); entry.name = val; break; case "SHA-Digest": // case "MD5-Digest": if (entry == null) { Trace.TraceWarning("Got digest without name"); } else { entry.digest = val; } break; case "Content-Length": if (entry == null) { Trace.TraceWarning("Got length without name"); } else { entry.length = val; } break; case "Content-Type": break; default: Trace.TraceInformation("Unexpected attribute: " + attr); break; } } }
protected static void RegisterEntry(Dictionary <string, ManifestEntry> dict, ManifestEntry entry) { dict[entry.name] = entry; }
protected static void RegisterEntry(Dictionary<string, ManifestEntry> dict, ManifestEntry entry) { dict[entry.name] = entry; }
protected static void ParseManifest(Dictionary<string, ManifestEntry> dict, StreamReader reader) { ManifestEntry entry = null; for (; ; ) { string line = reader.ReadLine(); if (line == null) { if (entry != null) { RegisterEntry(dict, entry); entry = null; } break; } else if (line.Trim().Length == 0) { if (entry != null) { RegisterEntry(dict, entry); entry = null; } continue; } if (!line.Contains(":")) { Trace.TraceWarning("Invalid line: " + line); continue; } char[] delims = { ':' }; string[] tmp = line.Split(delims, 2); string attr = tmp[0]; if (tmp[1].Length <= 1 || !tmp[1].StartsWith(" ")) { Trace.TraceWarning("Invalid value string: " + tmp[1]); continue; } string val = tmp[1].Substring(1); // trim off leading space switch (attr) { case "Name": entry = new ManifestEntry(); entry.name = val; break; case "SHA-Digest": // case "MD5-Digest": if (entry == null) Trace.TraceWarning("Got digest without name"); else entry.digest = val; break; case "Content-Length": if (entry == null) Trace.TraceWarning("Got length without name"); else entry.length = val; break; case "Content-Type": break; default: Trace.TraceInformation("Unexpected attribute: " + attr); break; } } }
public void ProcessFile(string name, string file) { ManifestEntry entry = new ManifestEntry(); entry.name = name; FileStream data = File.Open(file, FileMode.Open); long fileLength = data.Length; entry.length = fileLength.ToString(); HashAlgorithm digester = new SHA1CryptoServiceProvider(); byte[] digest = digester.ComputeHash(data); data.Close(); StringBuilder digestStr = new StringBuilder(); foreach (byte b in digest) digestStr.Append(b.ToString("x2")); entry.digest = digestStr.ToString(); currentManifestDict[name] = entry; }