/// <summary> /// Saves an lines of data coresponding to a url /// </summary> /// <param name="url"></param> /// <param name="data"></param> public static void Save(string url, string[] data) { TextFile tf = CacheIndex; string dataFile = FileUtility.GetTempFileName(".tmp"); tf.Add(dataFile); tf.Add(url); tf.SaveAs(tf.FileName); TextFile df = new TextFile(data); df.SaveAs(dataFile); Logger.WriteLine("Caching " + url); Logger.WriteLine("\"" + dataFile + "\""); }
public void Save(string server, string password) { int idx = tf.IndexOf(server); if (idx < 0) { tf.Add(server); tf.Add(Protect(password)); } else { tf.FileData[idx + 1] = Protect(password); } tf.SaveAs(tf.FileName); }
public void Save(string server, string password) { int idx = tf.IndexOf(server); if (idx < 0) { tf.Add(server); //tf.Add( Protect(password)); tf.Add(StringCipher.Encrypt(password, "")); } else { tf.FileData[idx + 1] = StringCipher.Encrypt(password, ""); } tf.SaveAs(tf.FileName); }
/// <summary> /// This method generates the HJ and Q tables /// </summary> /// <param name="station"></param> private void CreateShiftAndFlowTables(TextFile rdbFile) { var tempFile = Path.GetTempFileName(); rdbFile.SaveAs(tempFile); rdbFile = new TextFile(tempFile); var rdbFileString = rdbFile.FileContents; var rdbItems = rdbFileString.Split('\t', '\n', '\r', ' ').ToList();//[JR] these separate the rdb file into chunks, make sure that new line characters are specified in this line var skelPtIdx = Enumerable.Range(0, rdbItems.Count).Where(i => rdbItems[i] == "*").ToList();//get skeletal points idx var breakptIdx = Enumerable.Range(0, rdbItems.Count).Where(i => rdbItems[i].Contains("BREAKPOINT")).ToList();//get breakpoint idx var offsetIdx = Enumerable.Range(0, rdbItems.Count).Where(i => rdbItems[i].Contains("OFFSET")).ToList();//get offset idx // Generate HJ Table by defining stage-shift pairs within a C# DataTable var hjTable = CreateHJTable(rdbFileString); // Define Logarithmic coefficient pairs in a C# DataTable var coeffTable = new DataTable(); coeffTable.Columns.Add(new DataColumn("breakpoint", typeof(double))); coeffTable.Columns.Add(new DataColumn("offset", typeof(double))); if (offsetIdx.Count == 0) // no breakpoint and coefficient data { var coeffRow = coeffTable.NewRow(); coeffRow["breakpoint"] = -999999999.99; coeffRow["offset"] = 0.0; coeffTable.Rows.Add(coeffRow); } else if (offsetIdx.Count == 1) { var coeffRow = coeffTable.NewRow(); coeffRow["breakpoint"] = -999999999.99; coeffRow["offset"] = Convert.ToDouble(rdbItems[offsetIdx[0]].Split('=')[1].ToString().Replace("\"", "")); coeffTable.Rows.Add(coeffRow); } else { for (int i = 0; i < offsetIdx.Count; i++) { var coeffRow = coeffTable.NewRow(); if (i == 0) { coeffRow["breakpoint"] = -999999999.99; } else { coeffRow["breakpoint"] = Convert.ToDouble(rdbItems[breakptIdx[i - 1]].Split('=')[1].ToString().Replace("\"", "")); } coeffRow["offset"] = Convert.ToDouble(rdbItems[offsetIdx[i]].Split('=')[1].ToString().Replace("\"", "")); coeffTable.Rows.Add(coeffRow); } } // Generate Q DataTable var qTable = new DataTable(); qTable.Columns.Add(new DataColumn("Stage", typeof(double))); qTable.Columns.Add(new DataColumn("Flow", typeof(double))); qTable.Columns.Add(new DataColumn("A-Coeff", typeof(double))); qTable.Columns.Add(new DataColumn("B-Coeff", typeof(double))); foreach (var item in skelPtIdx) { var qRow = qTable.NewRow(); double ghVal = Convert.ToDouble(rdbItems[item - 3]); double shiftVal = Convert.ToDouble(rdbItems[item - 2]); double stageVal = ghVal + shiftVal; qRow["Stage"] = stageVal; qRow["Flow"] = Convert.ToDouble(rdbItems[item - 1]); DataRow[] coeffMatch = coeffTable.Select("[breakpoint] <= '" + stageVal + "'"); qRow["A-Coeff"] = coeffMatch[coeffMatch.Count() - 1][1]; qRow["B-Coeff"] = 0.0; qTable.Rows.Add(qRow); } if (qTable.Rows.Count < 1) { throw new Exception("No skeletal points found for station: " + this.stationName); } this.hjTable = hjTable; this.qTable = qTable; }
/// <summary> /// This method generates the full table from the RDB file /// </summary> /// <param name="rdbFile"></param> private void CreateFullRatingTable(TextFile rdbFile) { // Build container DataTable DataTable ratingTable = new DataTable(); ratingTable.Columns.Add(new DataColumn("Stage", typeof(double))); ratingTable.Columns.Add(new DataColumn("Shift", typeof(double))); ratingTable.Columns.Add(new DataColumn("Flow", typeof(double))); // Save RDB file var tempFile = Path.GetTempFileName(); rdbFile.SaveAs(tempFile); rdbFile = new TextFile(tempFile); // Loop through each RDB file row to find the data int headerRow = rdbFile.IndexOf("INDEP SHIFT DEP STOR") + 2; for (int i = headerRow; i < rdbFile.Length; i++) { var row = rdbFile[i]; var newRow = ratingTable.NewRow(); var rowVals = rdbFile[i].Split('\t'); newRow["Stage"] = Convert.ToDouble(rowVals[0]); newRow["Shift"] = Convert.ToDouble(rowVals[1]); newRow["Flow"] = Convert.ToDouble(rowVals[2]); ratingTable.Rows.Add(newRow); } this.fullRatingTable = ratingTable; }