/// ------------------------------------------------------------------------------------------- /// <summary> /// This function parsing the CSS file and creates a TreeNode nodeTemp. /// </summary> /// <param name="path">Its gets the file path of the CSS File</param> /// ------------------------------------------------------------------------------------------- private void ParseCSS(string path) { var ctp = new CssTreeParser(); try { ctp.Parse(path); ErrorText = ctp.ErrorText(); } catch (Exception) { ErrorText = ctp.ErrorText(); throw; } CommonTree r = ctp.Root; _nodeTemp.Nodes.Clear(); if (r.Text != "nil" && r.Text != null) { _nodeTemp.Text = "nil"; AddSubTree(_nodeTemp, r, ctp); } else { string rootNode = r.Text ?? "nil"; _nodeTemp.Text = rootNode; foreach (CommonTree child in ctp.Children(r)) { AddSubTree(_nodeTemp, child, ctp); } } // To validate the nodes in nodeTemp has copied to nodeFine if (_isReCycle == false) { _nodeFinal.Nodes.Clear(); MakeTreeNode(_nodeTemp, _nodeFinal, false); // To traverse the node second time. if (_isReCycle) { MakeTreeNode(_nodeFinal, _nodeFinal, true); } } }
/// <summary> /// Do a single test. /// </summary> /// <param name="testName">Test name is also the folder containing the test.</param> /// <param name="msg">Message to display if failure occurs.</param> protected void OneTest(string testName, string msg) { // Create input file name for test var inpFileName = Common.PathCombine(_inpPath, testName + ".css"); var ctp = new CssTreeParser(); ctp.Parse(inpFileName); var strResult = ctp.StringTree(); // Output result to disk var outFileName = Common.PathCombine(_outPath, testName + ".txt"); var sw = new StreamWriter(outFileName); sw.Write(strResult); sw.Close(); // Compare result to expected result var expFileName = Common.PathCombine(_expPath, testName + ".txt"); var sr = new StreamReader(expFileName); var strExpect = sr.ReadToEnd(); sr.Close(); Assert.AreEqual(strResult, strExpect, msg); if (ctp.Errors.Count != 0) { var strError = ctp.ErrorText(); var outErrorName = Common.PathCombine(_outPath, testName + "Err.txt"); var swe = new StreamWriter(outErrorName); swe.Write(strError); swe.Close(); var expErrorName = Common.PathCombine(_expPath, testName + "Err.txt"); var sre = new StreamReader(expErrorName); var strExpError = sre.ReadToEnd(); sre.Close(); var msgErr = msg + " in Error text"; Assert.AreEqual(strError, strExpError, msgErr); } else { Assert.AreEqual(File.Exists(testName + "Err.txt"), false, msg + " error not generated"); } }
private void btnBrowse_Click(object sender, EventArgs e) { TreeNode _nodeTemp = new TreeNode(); OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = "CSS"; dlg.Filter = "Cascading Style Sheet (*.css)|*.css"; if (dlg.ShowDialog() == DialogResult.OK) { string path = dlg.FileName; var ctp = new CssTreeParser(); try { ctp.Parse(path); } catch (Exception) { throw; } CommonTree r = ctp.Root; _nodeTemp.Nodes.Clear(); if (r.Text != "nil" && r.Text != null) { _nodeTemp.Text = "nil"; AddSubTree(_nodeTemp, r, ctp); } else { string rootNode = r.Text ?? "nil"; _nodeTemp.Text = rootNode; foreach (CommonTree child in ctp.Children(r)) { AddSubTree(_nodeTemp, child, ctp); } } } treeView1.Nodes.Clear(); treeView1.Nodes.Add((TreeNode)_nodeTemp.Clone()); treeView1.ExpandAll(); }
/// <summary> /// To list the errors found in CSS inout file and error's are added into ErrorList. /// </summary> /// <param name="path">Input CSS Filepath</param> public void GetErrorReport(string path) { if (!File.Exists(path)) { return; } var ctp = new CssTreeParser(); try { ctp.Parse(path); ctp.ValidateError(); if (ctp.Errors.Count > 0) { ErrorText += ctp.ErrorText() + "\r\n"; string fileName = Path.GetFileName(path); if (ErrorList.ContainsKey(fileName)) { ErrorList[fileName].Add(ctp.Errors); } else { var err = new ArrayList(); err.AddRange(ctp.Errors); ErrorList[fileName] = err; } } } catch (Exception) { ErrorText += ctp.Errors; throw; } finally { } }
/// <summary> /// To list the errors found in CSS inout file and error's are added into ErrorList. /// </summary> /// <param name="path">Input CSS Filepath</param> public void GetErrorReport(string path) { if(!File.Exists(path)) return; var ctp = new CssTreeParser(); try { ctp.Parse(path); ctp.ValidateError(); if (ctp.Errors.Count > 0) { ErrorText += ctp.ErrorText() + "\r\n"; string fileName = Path.GetFileName(path); if (ErrorList.ContainsKey(fileName)) { ErrorList[fileName].Add(ctp.Errors); } else { var err = new ArrayList(); err.AddRange(ctp.Errors); ErrorList[fileName] = err; } } } catch (Exception) { ErrorText += ctp.Errors; throw; } finally { } }