public static bool ToFile(HistSimIndex hsi, string path, DebugDelegate debug) { try { // get checksum of data string md5 = MD5(indextoc(hsi)); // see if it's complete if (!hsi.isComplete) { if (debug != null) { debug("Index not completed " + md5); } return(false); } // get index directory string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // get filepath string filepath = dir + "\\" + md5 + ".txt"; // pack contents so serializable hsi.packTOC(); XmlSerializer xs = new XmlSerializer(typeof(HistSimIndex)); Stream fs = new FileStream(filepath, FileMode.Create); System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Compress); xs.Serialize(gs, hsi); gs.Close(); fs.Close(); } catch (Exception ex) { if (debug != null) { debug(ex.Message + ex.StackTrace); } return(false); } return(true); }
public static string Serialize(HistSimIndex hsi, DebugDelegate debug) { try { hsi.packTOC(); XmlSerializer xs = new XmlSerializer(typeof(HistSimIndex)); StringWriter fs = new StringWriter(); xs.Serialize(fs, hsi); fs.Close(); string msg = fs.GetStringBuilder().ToString(); return GZip.Compress(msg); } catch (Exception ex) { if (debug != null) debug(ex.Message + ex.StackTrace); } return string.Empty; }
public static string Serialize(HistSimIndex hsi, DebugDelegate debug) { try { hsi.packTOC(); XmlSerializer xs = new XmlSerializer(typeof(HistSimIndex)); StringWriter fs = new StringWriter(); xs.Serialize(fs, hsi); fs.Close(); string msg = fs.GetStringBuilder().ToString(); return(GZip.Compress(msg)); } catch (Exception ex) { if (debug != null) { debug(ex.Message + ex.StackTrace); } } return(string.Empty); }
public static bool ToFile(HistSimIndex hsi, string path,DebugDelegate debug) { try { // get checksum of data string md5 = MD5(indextoc(hsi)); // see if it's complete if (!hsi.isComplete) { if (debug!=null) debug("Index not completed "+md5); return false; } // get index directory string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); // get filepath string filepath = dir + "\\" + md5 + ".txt"; // pack contents so serializable hsi.packTOC(); XmlSerializer xs = new XmlSerializer(typeof(HistSimIndex)); Stream fs = new FileStream(filepath, FileMode.Create); System.IO.Compression.GZipStream gs = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Compress); xs.Serialize(gs, hsi); gs.Close(); fs.Close(); } catch (Exception ex) { if (debug != null) debug(ex.Message + ex.StackTrace); return false; } return true; }