/// <summary> /// Deep copies aTest to us. /// </summary> /// <param name="aTest"></param> public void Assign(ATest aTest) { if (aTest == null) { aTest = new ATest(); } this.Image = aTest.Image; this.Name = aTest.Name; this.ToolTip = aTest.ToolTip; this.listOfSubSections.Clear(); foreach (string str in aTest.listOfSubSections) { this.listOfSubSections.Add(str); } this.dictionaryOfDefVals.Clear(); foreach (string topTey in aTest.dictionaryOfDefVals.Keys) { Dictionary <string, string> dct = new Dictionary <string, string>(); foreach (string subKey in aTest.dictionaryOfDefVals[topTey].Keys) { dct.Add(subKey, aTest.dictionaryOfDefVals[topTey][subKey]); } this.dictionaryOfDefVals.Add(topTey, dct); } } // end assign
/// <summary> /// Returns a deep copy of this. /// </summary> /// <returns></returns> public ATest Clone() { ATest aClone = new ATest(); try { aClone.Image = this.Image; aClone.Name = this.Name; aClone.ToolTip = this.ToolTip; for (int i = 0; i < this.listOfSubSections.Count; i++) { aClone.listOfSubSections.Add(this.listOfSubSections[i]); } foreach (string topTey in this.dictionaryOfDefVals.Keys) { Dictionary <string, string> dct = new Dictionary <string, string>(); foreach (string subKey in this.dictionaryOfDefVals[topTey].Keys) { dct.Add(subKey, this.dictionaryOfDefVals[topTey][subKey]); } aClone.dictionaryOfDefVals.Add(topTey, dct); } } catch { } return(aClone); }
/// <summary> /// Calculate CRC32 for data portion of file. /// </summary> /// <returns>CRC32 string.</returns> public string AddUpVersion() { MemoryStream seqStream = new MemoryStream(); byte[] data = Encoding.Unicode.GetBytes("hello"); // Salt seqStream.Write(data, 0, data.Length); for (int i = 0; i < ArrayListTests.Count; i++) { ATest aTest = (ATest)ArrayListTests[i]; byte[] data1 = Encoding.Unicode.GetBytes( this.ArrayListCols[0].ToString().Trim() + aTest.Name.Trim() + this.ArrayListCols[1].ToString().Trim() + aTest.Image.Trim() + this.ArrayListCols[2].ToString().Trim() + aTest.ToolTip.Trim() ); seqStream.Write(data1, 0, data1.Length); // loop for each subsection for (int j = 0; j < aTest.listOfSubSections.Count; j++) { string TmpKey = aTest.listOfSubSections[j]; // loop for each item in subsection foreach (KeyValuePair <string, string> Entry in aTest.dictionaryOfDefVals[TmpKey]) { byte[] data2 = Encoding.Unicode.GetBytes( Entry.Key.Trim() + Entry.Value.Trim() ); seqStream.Write(data2, 0, data2.Length); } } } seqStream.Seek(0, SeekOrigin.Begin); StreamCrcClass streamCrcClass = new StreamCrcClass(); string theCRC = streamCrcClass.GetCrcString(seqStream); seqStream.Close(); seqStream.Dispose(); return(theCRC); }
private void ReadAndParseFile(Stream fs) { try { //dictionaryTestImages.Clear(); // dictionaryToolTips.Clear(); ; dictionaryHeader.Clear(); ArrayListCols.Clear(); ArrayListTests.Clear(); // we parse all of the xml stuff with this XmlDocument xmlTestDoc = new XmlDocument(); // load tmp file xmlTestDoc.Load(fs); // get Header stuff (name, version) for (int i = 0; i < xmlTestDoc.ChildNodes[1].Attributes.Count; i++) { dictionaryHeader.Add( xmlTestDoc.ChildNodes[1].Attributes[i].Name, xmlTestDoc.ChildNodes[1].Attributes[i].Value ); } // get date dictionaryHeader.Add( xmlTestDoc.ChildNodes[1].ChildNodes[0].Name, xmlTestDoc.ChildNodes[1].ChildNodes[0].InnerText ); // fill image and Tests structures // local test struct ATest aTest; // loop once for each test (we start at one because the first element is the date) for (int i = 1; i < xmlTestDoc.ChildNodes[1].ChildNodes.Count; i++) { // one test struct aTest = new ATest(); // get the test name aTest.Name = xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[0].Value; // get the test image aTest.Image = xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[1].Value; // get the toolTip aTest.ToolTip = xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[2].Value; // loop once for each subtype (testState, testFlags, ...) for (int j = 0; j < xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes.Count; j++) { aTest.listOfSubSections.Add(xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes[j].Name); Dictionary <string, string> tmpDir = new Dictionary <string, string>(); // loop once for each item is the subtypes (these are the ListView cols) for (int k = 0; k < xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes[j].ChildNodes.Count; k++) { tmpDir.Add(xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes[j].ChildNodes[k].Name, xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes[j].ChildNodes[k].InnerText); int l; for (l = 0; l < ArrayListCols.Count; l++) { // see if this one already is there if ((string)(ArrayListCols[l]) == xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes[j].ChildNodes[k].Name) { break; } } // end for l (each item in the global list) if (l >= ArrayListCols.Count) // then the for did not find it { // so we add it ArrayListCols.Add(xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes[j].ChildNodes[k].Name); } } // end for k (each item in each subtype) // add to the Columns dir for this test [i] aTest.dictionaryOfDefVals.Add( xmlTestDoc.ChildNodes[1].ChildNodes[i].ChildNodes[j].Name, tmpDir ); } // end for j (each subitem) // put this test in the list ArrayListTests.Add(aTest); //// put this image in the list //if(!dictionaryTestImages.ContainsKey(xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[0].Value)) //{ // dictionaryTestImages.Add( // xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[0].Value, // xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[1].Value // ); //} //// put this tool tip in the list //if (!dictionaryToolTips.ContainsKey(xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[0].Value)) //{ // dictionaryToolTips.Add( // xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[0].Value, // xmlTestDoc.ChildNodes[1].ChildNodes[i].Attributes[2].Value // ); //} } // end for i (each test) } catch (Exception e) { throw e; } } // end read and parse
/// <summary> /// Write this test sequence to the passed in stream. /// </summary> /// <param name="XmlStream"></param> /// <param name="Today"></param> public void WriteTests(Stream XmlStream, bool Today) { dictionaryHeader["Version"] = this.AddUpVersion(); StreamWriter sw = null; try { using (sw = new StreamWriter(XmlStream, System.Text.Encoding.Unicode)) { // Add beginning stuff. sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-16\" ?>"); sw.WriteLine("<testSequence Name=\"" + dictionaryHeader["Name"] + "\" Version=\"" + dictionaryHeader["Version"] + "\">"); string dateStr; StringBuilder dateStrBuilder = new StringBuilder(); if (Today) { dateStrBuilder.Append(DateTime.Today.Year.ToString() + "-"); if (DateTime.Today.Month.ToString().Length == 1) { dateStrBuilder.Append("0"); } dateStrBuilder.Append(DateTime.Today.Month.ToString() + "-"); if (DateTime.Today.Day.ToString().Length == 1) { dateStrBuilder.Append("0"); } dateStrBuilder.Append(DateTime.Today.Day.ToString()); dateStr = dictionaryHeader["date"] = dateStrBuilder.ToString(); } else { dateStr = dictionaryHeader["date"]; } sw.WriteLine(" <date type=\"date\">" + dateStr + "</date>"); // loop for each test for (int i = 0; i < ArrayListTests.Count; i++) { ATest aTest = (ATest)ArrayListTests[i]; sw.WriteLine(" <test Name=\"" + aTest.Name + "\" Image=\"" + aTest.Image + "\" ToolTip=\"" + aTest.ToolTip + "\">"); // loop for each subsection for (int j = 0; j < aTest.listOfSubSections.Count; j++) { string TmpKey = aTest.listOfSubSections[j]; sw.WriteLine(" <" + TmpKey + ">"); // loop for each item in subsection foreach (KeyValuePair <string, string> Entry in aTest.dictionaryOfDefVals[TmpKey]) { sw.WriteLine(" <" + Entry.Key + ">" + Entry.Value + "</" + Entry.Key + ">"); } sw.WriteLine(" </" + TmpKey + ">"); } // end for j subsections sw.WriteLine(" </test>"); } // end for i each test sw.WriteLine("</testSequence>"); sw.Flush(); sw.Close(); sw.Dispose(); sw = null; } // end using Modified = false; NewFile = false; } catch { } finally { if (sw != null) { sw.Flush(); sw.Close(); sw.Dispose(); } } }