3378 lines
		
	
	
		
			115 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			3378 lines
		
	
	
		
			115 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.ComponentModel;
 | |
| using System.Data;
 | |
| using System.Drawing;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Threading.Tasks;
 | |
| using System.Windows.Forms;
 | |
| using System.Xml;
 | |
| using System.Text.RegularExpressions;
 | |
| using VEPROMS.CSLA.Library;
 | |
| using log4net;
 | |
| using System.IO;
 | |
| using Volian.Controls.Library;
 | |
| using C1.Win.C1FlexGrid;
 | |
| 
 | |
| 
 | |
| namespace XMLConvert
 | |
| {
 | |
| 	public partial class frmConvertXML : Form
 | |
| 	{
 | |
| 		public frmConvertXML()
 | |
| 		{
 | |
| 			InitializeComponent();
 | |
| 			Database.VEPROMS_Connection =
 | |
| 				"Data Source=.\\SQL2008EXPRESS;Initial Catalog=VEPROMS_Barakah;Integrated Security=True";
 | |
| 		}
 | |
| 		private XmlDocument _MyXMLDoc = new XmlDocument();
 | |
| 		public XmlDocument MyXMLDoc
 | |
| 		{
 | |
| 			get { return _MyXMLDoc; }
 | |
| 			set { _MyXMLDoc = value; }
 | |
| 		}
 | |
| 		private void btnLoad_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			LoadXml(tbFile.Text, "Document Loaded");
 | |
| 		}
 | |
| 		private void LoadXml(string fileName, string status)
 | |
| 		{
 | |
| 			FileInfo fi = new FileInfo(fileName);
 | |
| 			//Console.WriteLine(fi.FullName);
 | |
| 			StreamReader sr = fi.OpenText();
 | |
| 			string buf = sr.ReadToEnd();
 | |
| 			sr.Close();
 | |
| 			buf = buf.Replace(" \x8", "");
 | |
| 			buf = buf.Replace(" \x7", "");
 | |
| 			MyXMLDoc.LoadXml(buf);
 | |
| 			if (status != null) tbResults.Text = status;
 | |
| 		}
 | |
| 		private void btnFindNodeTypes_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			LoadXml(tbFile.Text, "Document Loaded");
 | |
| 			tbResults.Text = "Finding Nodes\r\n";
 | |
| 			SortedList<string, XmlElement> AllNodeTypes = new SortedList<string, XmlElement>();
 | |
| 			FindAllNodeTypes(AllNodeTypes, MyXMLDoc.DocumentElement);
 | |
| 			foreach (string key in AllNodeTypes.Keys)
 | |
| 				tbResults.AppendText(string.Format("[{0}]{1}\r\n", key, Attributes(AllNodeTypes[key])));
 | |
| 		}
 | |
| 		private string Attributes(XmlElement xe)
 | |
| 		{
 | |
| 			StringBuilder sb = new StringBuilder();
 | |
| 			string sep = "\r\n\t";
 | |
| 			foreach (XmlAttribute xa in xe.Attributes)
 | |
| 			{
 | |
| 				sb.Append(string.Format("{0}[{1}]", sep, xa.Name));
 | |
| 				//if (xa.Name == "content")
 | |
| 				//	sb.Append(string.Format ("\r\n\t\t{0}",xa.Value));
 | |
| 			}
 | |
| 			return sb.ToString();
 | |
| 		}
 | |
| 		private void FindAllNodeTypes(SortedList<string, XmlElement> AllNodeTypes, XmlElement xmlElement)
 | |
| 		{
 | |
| 			if (!AllNodeTypes.ContainsKey(xmlElement.Name))
 | |
| 				AllNodeTypes.Add(xmlElement.Name, xmlElement);
 | |
| 			foreach (XmlNode xe in xmlElement.ChildNodes)
 | |
| 			{
 | |
| 				if (xe is XmlElement)
 | |
| 					FindAllNodeTypes(AllNodeTypes, xe as XmlElement);
 | |
| 			}
 | |
| 		}
 | |
| 		private void btnStructure_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			tbResults.Clear();
 | |
| 			Node.Reset();
 | |
| 			LoadStructure(tbFile.Text);
 | |
| 			ShowStructure();
 | |
| 		}
 | |
| 		private void LoadStructure(string fileName)
 | |
| 		{
 | |
| 			LoadXml(fileName, null);
 | |
| 			Node.Add(MyXMLDoc.DocumentElement);
 | |
| 		}
 | |
| 		private void ShowStructure()
 | |
| 		{
 | |
| 			foreach (string key in Node.AllNodes.Keys)
 | |
| 			{
 | |
| 				Node nd = Node.AllNodes[key];
 | |
| 				tbResults.AppendText(string.Format("[{0}]{1}\r\n", key, (nd.HasText ? "\tText" : "")));
 | |
| 				if (nd.Children.Count > 0)
 | |
| 				{
 | |
| 					tbResults.AppendText(string.Format("\tChildren:\r\n"));
 | |
| 					foreach (string child in nd.Children)
 | |
| 						tbResults.AppendText(string.Format("\t\t{0}\r\n", child));
 | |
| 				}
 | |
| 				if (nd.Attributes.Count > 0)
 | |
| 				{
 | |
| 					tbResults.AppendText(string.Format("\tAttributes:\r\n"));
 | |
| 					foreach (string key1 in nd.Attributes.Keys)
 | |
| 					{
 | |
| 						Attribute attr = nd.Attributes[key1];
 | |
| 						if (key1 == "content")
 | |
| 							tbResults.AppendText(string.Format("\t\t{0} Count={1}\r\n", attr.Name, attr.Count));
 | |
| 						else if (attr.MinValue == attr.MaxValue)
 | |
| 							tbResults.AppendText(string.Format("\t\t{0} Count={1} All={2}\r\n", attr.Name, attr.Count, attr.MinValue));
 | |
| 						else
 | |
| 							tbResults.AppendText(string.Format("\t\t{0} Count={1} Min={2} Max={3}\r\n", attr.Name, attr.Count, attr.MinValue, attr.MaxValue));
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private void ShowStructure2()
 | |
| 		{
 | |
| 			foreach (string key in Node.AllNodes.Keys)
 | |
| 			{
 | |
| 				Node nd = Node.AllNodes[key];
 | |
| 				bool hasContent = false;
 | |
| 				tbResults.AppendText(string.Format("case \"{0}\":~", key));
 | |
| 				string prefix = "\tformat=\"";
 | |
| 				foreach (string key1 in nd.Attributes.Keys)
 | |
| 				{
 | |
| 					if (key1 == "content")
 | |
| 						hasContent = true;
 | |
| 					else
 | |
| 					{
 | |
| 						tbResults.AppendText(string.Format("{0}{1}={{{1}}}\";", prefix, key1));
 | |
| 						prefix = " ";
 | |
| 					}
 | |
| 					if (hasContent)
 | |
| 						tbResults.AppendText(string.Format(" {{content}}"));
 | |
| 				}
 | |
| 				tbResults.AppendText("\";~\tbreak;\r\n");
 | |
| 			}
 | |
| 		}
 | |
| 		private void btnLoadContent_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			LoadXml(tbFile.Text, "Document Loaded");
 | |
| 			tbResults.Clear();
 | |
| 			ShowAllContent(MyXMLDoc.DocumentElement, 0);
 | |
| 		}
 | |
| 		private void ShowAllContent(XmlElement xe, int level)
 | |
| 		{
 | |
| 			ShowContent(xe, level);
 | |
| 			foreach (XmlNode ch in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (ch is XmlElement)
 | |
| 					ShowAllContent(ch as XmlElement, level + 1);
 | |
| 			}
 | |
| 		}
 | |
| 		Regex regFixAttributes = new Regex("(\\{[A-Za-z]+?\\})", RegexOptions.Compiled);
 | |
| 		private void ShowContent(XmlElement xe, int level)
 | |
| 		{
 | |
| 			string format = "Not Defined";
 | |
| 			string prefix = "  ";
 | |
| 			switch (xe.Name)
 | |
| 			{
 | |
| 				case "ident":
 | |
| 					format = "Procedure (LabelType-number)={labelType}-{number} fullName={fullName} PNSNo={PNSNo}";
 | |
| 					break;
 | |
| 				case "type":
 | |
| 					format = "Procedure Type: {procedureType}";
 | |
| 					break;
 | |
| 				case "GrossStep":
 | |
| 					format = "number={number} name={name}";
 | |
| 					break;
 | |
| 				case "Step":
 | |
| 					format = "{number} {name}";
 | |
| 					prefix = "S ";
 | |
| 					break;
 | |
| 				case "Contingency":
 | |
| 					format = "{number} {name}";
 | |
| 					prefix = "C ";
 | |
| 					break;
 | |
| 				case "attrib":
 | |
| 				case "procedure":
 | |
| 				case "controllers":
 | |
| 				case "row":
 | |
| 					format = "";// No Content
 | |
| 					break;
 | |
| 				case "CautionInstruction":
 | |
| 				case "NoteInstruction":
 | |
| 					format = "number={number} {content}";
 | |
| 					break;
 | |
| 				case "UnitaryInstruction":
 | |
| 				case "BinaryInstruction":
 | |
| 					format = "number={number} Left Target: {leftTarget} Link Target: {linkTarget} {content}";
 | |
| 					break;
 | |
| 				case "JoinInstruction":
 | |
| 					format = "Link Target: {linkTarget} JoinType: {joinType}";
 | |
| 					break;
 | |
| 				case "UnitaryContingencyCallInstruction":
 | |
| 					format = "number={number} Link Target: {linkTarget} Evaluation Type: {evaluationType} {content}";
 | |
| 					prefix = "U ";
 | |
| 					break;
 | |
| 				case "taskGroup":
 | |
| 					format = "name={name} borderVisible={borderVisible}";
 | |
| 					break;
 | |
| 				case "BoolVarInputItem":
 | |
| 					format = "varInputLabel={varInputLabel} Data Point: {varInputDataPoint}";
 | |
| 					break;
 | |
| 				case "TextVarInputItem":
 | |
| 					format = "varInputLabel={varInputLabel} Data Point: {varInputDataPoint}";
 | |
| 					break;
 | |
| 				case "ovationGraphic":
 | |
| 					format = "title={title} Diagram Number: {diagramNumber}";
 | |
| 					break;
 | |
| 				case "ovationGroupTrend":
 | |
| 					format = "name={name} description={description}";
 | |
| 					break;
 | |
| 				case "controller":
 | |
| 					format = "controller - Unknown";
 | |
| 					break;
 | |
| 				case "and":
 | |
| 					format = "and id={id}";
 | |
| 					break;
 | |
| 				case "BigOverview":
 | |
| 					format = "BigOverview grossStep={grossStep} number={number} id={id}";
 | |
| 					break;
 | |
| 				case "BovActionStep":
 | |
| 					format = "column={column}	number={number} linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovCheckBox":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovIfStep":
 | |
| 					format = "column={column}	number={number} linkTarget={linkTarget} group={group} id={id} name={name} label={label} rightTarget={rightTarget} {content}";
 | |
| 					break;
 | |
| 				case "BovMessageBox":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovProcedureLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovStepInLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovStepOutLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "descr":
 | |
| 				case "esinfo":
 | |
| 				case "esproj":
 | |
| 				case "esprop":
 | |
| 				case "private":
 | |
| 				case "pwg":
 | |
| 				case "pwt":
 | |
| 				case "revbase":
 | |
| 				case "systemtest":
 | |
| 					format = "";
 | |
| 					break;
 | |
| 				case "eq":
 | |
| 				case "gt":
 | |
| 				case "gte":
 | |
| 				case "lt":
 | |
| 				case "lte":
 | |
| 				case "not":
 | |
| 				case "or":
 | |
| 					format = "id={id}";
 | |
| 					break;
 | |
| 				case "fcase":
 | |
| 				case "tcase":
 | |
| 					format = "rst={rst}";
 | |
| 					break;
 | |
| 				case "logic":
 | |
| 					format = "id={id} number={number}";
 | |
| 					break;
 | |
| 				case "ovationSingleTrend":
 | |
| 					format = "description={description} number={number} id={id} name={name}";
 | |
| 					break;
 | |
| 				case "prop":
 | |
| 					format = "type={type} value={value} name={name}";
 | |
| 					break;
 | |
| 				case "TextVarInputInstruction":
 | |
| 					format = "taskDescription={taskDescription} varInputLabel={varinputLabel} number={number} {content}";
 | |
| 					break;
 | |
| 				case "utest":
 | |
| 					format = "tested={tested}";
 | |
| 					break;
 | |
| 				case "var":
 | |
| 					format = "var_type={var_type} id={id} name={name} number={number}";
 | |
| 					break;
 | |
| 				case "const":
 | |
| 					format = "var_type={var_type} id={id} value={value}";
 | |
| 					break;
 | |
| 			}
 | |
| 			tbResults.AppendText(string.Format("\r\n{0}{1}{2} ", prefix, "".PadRight(level, ' ').Replace(" ", "| "), xe.Name));
 | |
| 			tbResults.AppendText(ReplaceAllAttributes(format, xe, level, prefix));
 | |
| 		}
 | |
| 		private string ReplaceAllAttributes(string format, XmlElement xe, int level, string prefix)
 | |
| 		{
 | |
| 			MatchCollection m;
 | |
| 			while ((m = regFixAttributes.Matches(format)).Count > 0)
 | |
| 			{
 | |
| 				string part1 = format.Substring(0, m[0].Groups[1].Index);
 | |
| 				string part3 = format.Substring(m[0].Groups[1].Index + m[0].Groups[1].Length);
 | |
| 				string att = m[0].Groups[1].Value.Replace("{", "").Replace("}", "");
 | |
| 				XmlAttribute xa = xe.Attributes[att];
 | |
| 				//if (xa == null)
 | |
| 				//	Console.WriteLine(xe.OuterXml);
 | |
| 				string part2;
 | |
| 				if (xa != null)
 | |
| 					part2 = xe.Attributes[att].Value; //GetAttribute(xe, att);
 | |
| 				else
 | |
| 					part2 = "null";
 | |
| 				if (part2 == string.Empty) part2 = "empty";
 | |
| 				if (att == "content")
 | |
| 				{
 | |
| 					string imageSrc = null;
 | |
| 					if (part2.Contains(" src="))
 | |
| 					{
 | |
| 						imageSrc = RegFindImage.Replace(part2, "$1");
 | |
| 						//Console.WriteLine(imageSrc);
 | |
| 					}
 | |
| 					part2 = FixHTML(part2, level);
 | |
| 					if (imageSrc != null) part2 += "\n" + imageSrc;
 | |
| 					part2 = part2.Replace("<br />", "<br />\n   ");
 | |
| 					part2 = part2.Replace("\n", string.Format("\r\n  {0}  ", "".PadRight(level).Replace(" ", "| ")));
 | |
| 				}
 | |
| 				format = part1 + part2 + part3;
 | |
| 			}
 | |
| 			return format;
 | |
| 		}
 | |
| 		private static Regex RegFixHTMLMulti = new Regex("<(p|li) [^>]*?>([^<>]*)</(p|li)>", RegexOptions.Compiled | RegexOptions.Singleline);
 | |
| 		private static Regex RegFixHTML = new Regex(".*<(p|li).*?>(.*)</(p|li)>.*", RegexOptions.Compiled | RegexOptions.Singleline);
 | |
| 		private static Regex RegFixHTMLbody = new Regex(".*<body.*?>(.*)</body>.*", RegexOptions.Compiled | RegexOptions.Singleline);
 | |
| 		private static Regex RegFindImage = new Regex(".*<img src=\"([^\"]*)\".*/>.*", RegexOptions.Compiled | RegexOptions.Singleline);
 | |
| 		private string FixHTML(string html, int level)
 | |
| 		{
 | |
| 			html = cleanupHTML(html, level);
 | |
| 			return html;
 | |
| 			//Console.WriteLine(html);
 | |
| 			MatchCollection mc = RegFixHTMLMulti.Matches(html);
 | |
| 			if (mc.Count > 1)
 | |
| 			{
 | |
| 				StringBuilder sb = new StringBuilder();
 | |
| 				string sep = "";
 | |
| 				foreach (Match m in mc)
 | |
| 				{
 | |
| 					string str = RegFixHTML.Replace(m.Value, "$2");
 | |
| 					if (str != "")
 | |
| 						sb.Append(sep + str);
 | |
| 					sep = "\r\n";
 | |
| 				}
 | |
| 				return StripSpan(sb.ToString());
 | |
| 			}
 | |
| 			string newHTML = RegFixHTML.Replace(html, "$2");
 | |
| 			if (html != newHTML) return StripSpan(newHTML);
 | |
| 			newHTML = RegFixHTMLbody.Replace(html, "$1");
 | |
| 			if (html != newHTML) return StripSpan(newHTML);
 | |
| 			return StripSpan(html);
 | |
| 		}
 | |
| 		private static Regex RegStripSpan1 = new Regex("<span.*?>", RegexOptions.Compiled | RegexOptions.Singleline);
 | |
| 		private static Regex RegStripSpan2 = new Regex("</span>", RegexOptions.Compiled | RegexOptions.Singleline);
 | |
| 		private string StripSpan(string html)
 | |
| 		{
 | |
| 			return RegStripSpan2.Replace(RegStripSpan1.Replace(html, ""), "");
 | |
| 
 | |
| 		}
 | |
| 		private static Regex[] Cleanup = 
 | |
| 		{
 | |
| 			new Regex("<![^>]*>", RegexOptions.Compiled ),
 | |
| 			new Regex(" margin-top: ?[0-9]+px;", RegexOptions.Compiled ),
 | |
| 			new Regex(" margin-bottom: ?[0-9]+px;", RegexOptions.Compiled ),
 | |
| 			new Regex(" margin-right: ?[0-9]+px;", RegexOptions.Compiled ),
 | |
| 			new Regex(" margin-left: ?[0-9]+px;", RegexOptions.Compiled ),
 | |
| 			new Regex(" padding-top:0;", RegexOptions.Compiled ),
 | |
| 			new Regex(" padding-bottom:0;", RegexOptions.Compiled ),
 | |
| 			new Regex(" padding-right:0;", RegexOptions.Compiled ),
 | |
| 			new Regex(" padding-left:0;", RegexOptions.Compiled ),
 | |
| 			new Regex(" color:#000000;", RegexOptions.Compiled ),
 | |
| 			new Regex("-qt-paragraph-type:empty;", RegexOptions.Compiled ),
 | |
| 			new Regex(" text-indent: ?0px", RegexOptions.Compiled ),
 | |
| 			new Regex(" -qt-block-indent: ?0;", RegexOptions.Compiled ),
 | |
| 			new Regex(" font-family:'Arial';", RegexOptions.Compiled ),
 | |
| 			new Regex(" font-family:'Gulim';", RegexOptions.Compiled ),
 | |
| 			new Regex(" font-family:'A';", RegexOptions.Compiled ),
 | |
| 			new Regex(" font-size:[0-9]+pt;", RegexOptions.Compiled ),
 | |
| 			new Regex("style=\"(| |;)*\"", RegexOptions.Compiled ),
 | |
| 			new Regex("</?span[^>]*>", RegexOptions.Compiled ),
 | |
| 			new Regex("<style[^>]*>[^<]*</style>", RegexOptions.Compiled ),
 | |
| 			new Regex("</?meta[^>]*>", RegexOptions.Compiled ),
 | |
| 			//new Regex("</?html[^>]*>", RegexOptions.Compiled ),
 | |
| 			new Regex("</?body[^>]*>", RegexOptions.Compiled ),
 | |
| 			new Regex("<p ></p>", RegexOptions.Compiled ),
 | |
| 			new Regex("</?head[^>]*>", RegexOptions.Compiled),
 | |
| 			//new Regex("<p[^>]*>NOTE</p>", RegexOptions.Compiled),
 | |
| 			//new Regex("<p[^>]*>CAUTION</p>", RegexOptions.Compiled),
 | |
| 			new Regex("<p[^>]*></p>", RegexOptions.Compiled),
 | |
| 		};
 | |
| 		private static Regex regexFixPFrontPadding = new Regex("<p[^>]*> +", RegexOptions.Compiled);
 | |
| 		private static Regex regexFixPRearPadding = new Regex(" +</p>", RegexOptions.Compiled);
 | |
| 		private static Regex regexFixLiFrontPadding = new Regex("<li[^>]*> +", RegexOptions.Compiled);
 | |
| 		private static Regex regexFixLiRearPadding = new Regex(" +</li>", RegexOptions.Compiled);
 | |
| 		private static Regex removeExtraReturns = new Regex("\r?\n(\r?\n)+", RegexOptions.Compiled);
 | |
| 		private static Regex RegFixMultipleULs = new Regex("</ul>[\r\n]*<ul[^<>]+>", RegexOptions.Compiled | RegexOptions.Multiline);
 | |
| 		private static Regex RegFixMultipleOLs = new Regex("</ol>[\r\n]*<ol[^<>]+>", RegexOptions.Compiled | RegexOptions.Multiline);
 | |
| 		private static RegexReplace[] MyRegExReplaceSpecialChars = {
 | |
| 																			 new RegexReplace("oF","\\'b0F"),// Degree
 | |
| 																			 new RegexReplace("oC","\\'b0C"),// Degree
 | |
| 																			 new RegexReplace("\xB0","\\'b0"),// Degree
 | |
| 																			 new RegexReplace("\xBA","\\'b0"),// Degree
 | |
| 																			 new RegexReplace("\u02DA","\\'b0"),// Degree
 | |
| 																			 new RegexReplace("\xB1","\\'b1"),//
 | |
| 																			 new RegexReplace("\xB2","\\up3 2\\up0 "),// Square
 | |
| 																			 new RegexReplace("\xD7","x"),// Times
 | |
| 																			 new RegexReplace("\u2013","\\u8209?"),
 | |
| 																			 new RegexReplace("\xB1","\\'B1"),
 | |
| 																			 new RegexReplace("\xB7","\\u9679?"),
 | |
| 																			 new RegexReplace("\u2022","\\u9679?"),
 | |
| 																			 new RegexReplace("\u2022","*"),
 | |
| 																			 new RegexReplace("\u25AA","\\u9679?"),
 | |
| 																			 new RegexReplace("\xA0","\\u160?"),
 | |
| 																			 new RegexReplace("\u2019","'"),
 | |
| 																			 new RegexReplace("\u2018","'"),
 | |
| 																			 new RegexReplace("\u201C","\""),
 | |
| 																			 new RegexReplace("\u201D","\""),
 | |
| 																			 new RegexReplace("\u0394","\\u916?"),
 | |
| 																			 new RegexReplace("\uFF06","&"),
 | |
| 																			 new RegexReplace("\u2265","\\u8805?"),
 | |
| 																			 new RegexReplace("\u25CF","\\u9679?"),
 | |
| 																			 new RegexReplace("\u33A0","cm\\up3 2\\up0 "),
 | |
| 																			 new RegexReplace("\u2192","\\u8594?"),
 | |
| 																			 new RegexReplace("\uF07F","\\u9633?"),
 | |
| 																			 new RegexReplace("\\u2264","\\u8804?"),
 | |
| /*
 | |
| 																			 new RegexReplace("",""),
 | |
| */
 | |
| 																			 new RegexReplace(@">NOTE\\line<",">NOTE<"),// Note - line break
 | |
| 																			 new RegexReplace(@">NOTES\\line<",">NOTES<"),// Note - line break
 | |
| 																			 new RegexReplace(@">NOTE CONTINUED\\line<",">NOTE CONTINUED<"),// Note - line break
 | |
| 																			 new RegexReplace(@"</p>[\r\n]*<p ?>THEN"," THEN")// Break - THEN
 | |
| 																															 };
 | |
| 		private static string cleanupHTML(string html, int level)
 | |
| 		{
 | |
| 			//Console.WriteLine(html);
 | |
| 			//Console.WriteLine("END {0}",level);
 | |
| 			html = html.Replace("<br />", "\\line ");
 | |
| 			//if (html.Contains("All Safety Function Status Check"))
 | |
| 			//	Console.WriteLine(html.Substring(html.IndexOf("All Safety Function Status Check") - 10, 20));
 | |
| 
 | |
| 			foreach (Regex clean in Cleanup)
 | |
| 			{
 | |
| 				html = clean.Replace(html, "");
 | |
| 			}
 | |
| 			//if (html.Contains("All Safety Function Status Check"))
 | |
| 			//	Console.WriteLine(html.Substring(html.IndexOf("All Safety Function Status Check") - 10, 20));
 | |
| 			// TODO Remove Padding from Front
 | |
| 			//html = regexFixPFrontPadding.Replace(html, "<p>");
 | |
| 			//if (html.Contains("All Safety Function Status Check"))
 | |
| 			//	Console.WriteLine(html.Substring(html.IndexOf("All Safety Function Status Check") - 10, 20));
 | |
| 			html = regexFixPRearPadding.Replace(html, "</p>");
 | |
| 			html = regexFixLiFrontPadding.Replace(html, "<li>");
 | |
| 			html = regexFixLiRearPadding.Replace(html, "</li>");
 | |
| 			html = removeExtraReturns.Replace(html, "\n");
 | |
| 			if (html.StartsWith("\r\n"))
 | |
| 				html = html.Substring(2);
 | |
| 			if (html.StartsWith("\n"))
 | |
| 				html = html.Substring(1);
 | |
| 			//if (html.Contains("IF the RCS has experienced cooldown rate greater than"))
 | |
| 			//	Console.WriteLine("Here");
 | |
| 			html = RegFixMultipleULs.Replace(html, "");
 | |
| 			html = RegFixMultipleOLs.Replace(html, "");
 | |
| 			//if( html.Contains("NOTE\\"))
 | |
| 			//	Console.WriteLine("Here");
 | |
| 			foreach (RegexReplace rr in MyRegExReplaceSpecialChars)
 | |
| 				html = rr.DoReplace(html);
 | |
| 			return html;
 | |
| 		}
 | |
| 		private void tbResults_KeyDown(object sender, KeyEventArgs e)
 | |
| 		{
 | |
| 			if (e.KeyCode == Keys.A && e.Control)
 | |
| 			{
 | |
| 				tbResults.SelectAll();
 | |
| 				e.Handled = true;
 | |
| 			}
 | |
| 		}
 | |
| 		private void btnLoadProcedure_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			if (_MyFlexGrid == null)
 | |
| 			{
 | |
| 				_MyFlexGrid = new VlnFlexGrid();
 | |
| 				this.Controls.Add(_MyFlexGrid);
 | |
| 				_MyFlexGrid.Location = tbResults.Location;
 | |
| 				_MyFlexGrid.Size = tbResults.Size;
 | |
| 				_MyFlexGrid.BringToFront();
 | |
| 				_NodeProcessed = new List<XmlNode>();
 | |
| 			}
 | |
| 			XML2PROMSDB(tbFile.Text);
 | |
| 		}
 | |
| 		private static string _MyTablePrefix;
 | |
| 		private static XmlNamespaceManager _NSMGR;
 | |
| 		private void XML2PROMSDB(string filename)
 | |
| 		{
 | |
| 			try
 | |
| 			{
 | |
| 				LoadXml(filename, null);
 | |
| 				FileInfo fi = new FileInfo(filename);
 | |
| 				fi.Directory.CreateSubdirectory("TableHTMLs");
 | |
| 				_MyTablePrefix = fi.DirectoryName + "\\TableHTMLs";
 | |
| 				XmlNamespaceManager nsmgr = new XmlNamespaceManager(MyXMLDoc.NameTable);
 | |
| 				nsmgr.AddNamespace("x", MyXMLDoc.DocumentElement.NamespaceURI);
 | |
| 				_NSMGR = nsmgr;
 | |
| 				XmlNode xn = GetProcedureIdentifier(nsmgr);
 | |
| 				string procType = GetProcedureType(xn);
 | |
| 				if (procType == "FRP") procType = "EOP";
 | |
| 				// Walk through structure Adding Items as you go
 | |
| 				DocVersionInfoList dvil = DocVersionInfoList.Get();
 | |
| 				DocVersionInfo dvi = null;
 | |
| 				foreach (DocVersionInfo dviC in dvil)
 | |
| 					if (dviC.MyFolder.Name == procType)
 | |
| 						dvi = dviC;
 | |
| 				ProcedureInfo lastProc = GetLastProcedure(dvi);
 | |
| 				//string ProcNum = GetProcedureNumber(lastProc, xn);
 | |
| 				string ProcNum = GetProcedureNumber(lastProc, filename);
 | |
| 				lblProcedure.Text = ProcNum;
 | |
| 				Application.DoEvents();
 | |
| 				using (Procedure proc = Procedure.MakeProcedure(dvi, lastProc, ProcNum, xn.Attributes["fullName"].Value, 0))
 | |
| 				{
 | |
| 					proc.Save();
 | |
| 					lastProc = ProcedureInfo.Get(proc.ItemID);
 | |
| 				}
 | |
| 				try
 | |
| 				{
 | |
| 					AddGrossStep(lastProc, nsmgr);
 | |
| 				}
 | |
| 				catch (Exception ex)
 | |
| 				{
 | |
| 					Console.WriteLine(lastProc.DisplayNumber + "\r\n\r\n" + ex.GetType().Name + "\r\n\r\n" + ex.Message + "\r\n\r\n" + ex.StackTrace);
 | |
| 					MessageBox.Show(lastProc.DisplayNumber + "\r\n\r\n" + ex.Message + "\r\n\r\n" + ex.StackTrace, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
 | |
| 				}
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				tbResults.AppendText(string.Format("\r\n{0}\r\n{1} - {2}\r\n", filename, ex.GetType().Name, ex.Message));
 | |
| 			}
 | |
| 		}
 | |
| 		private static string GetProcedureType(XmlNode xn)
 | |
| 		{
 | |
| 			foreach (XmlNode xnc in xn.ParentNode.ChildNodes)
 | |
| 				if (xnc.Name == "type")
 | |
| 					return xnc.Attributes["procedureType"].Value;
 | |
| 			return null;
 | |
| 		}
 | |
| 		private static string GetProcedureNumber(string filename)
 | |
| 		{
 | |
| 			FileInfo fi = new FileInfo(filename);
 | |
| 			string fn = Regex.Replace(fi.Name.Replace(fi.Extension, ""), @"1N2-OP-([-0-9A-Z]+).+", "$1");
 | |
| 			return fn;
 | |
| 		}
 | |
| 		private static string GetProcedureNumber(ProcedureInfo lastProc, string filename)
 | |
| 		{
 | |
| 			string ProcNum = GetProcedureNumber(filename);
 | |
| 			if (lastProc == null)
 | |
| 				;// ProcNum is correct
 | |
| 			else if (lastProc.DisplayNumber == ProcNum)
 | |
| 				ProcNum += " Rev 1";
 | |
| 			else if (lastProc.DisplayNumber.StartsWith(ProcNum))
 | |
| 			{
 | |
| 				ProcNum = ProcNum + " Rev " + (1 + int.Parse(lastProc.DisplayNumber.Substring(ProcNum.Length + 5))).ToString();
 | |
| 			}
 | |
| 			return ProcNum;
 | |
| 		}
 | |
| 		private static string GetProcedureNumber(ProcedureInfo lastProc, XmlNode xn)
 | |
| 		{
 | |
| 			string ProcNum = string.Format("{0}-{1}", GetProcedureType(xn), xn.Attributes["shortName"].Value);
 | |
| 			if (lastProc == null)
 | |
| 				;// ProcNum is correct
 | |
| 			else if (lastProc.DisplayNumber == ProcNum)
 | |
| 				ProcNum += " Rev 1";
 | |
| 			else if (lastProc.DisplayNumber.StartsWith(ProcNum))
 | |
| 			{
 | |
| 				ProcNum = ProcNum + " Rev " + (1 + int.Parse(lastProc.DisplayNumber.Substring(ProcNum.Length + 5))).ToString();
 | |
| 			}
 | |
| 			return ProcNum;
 | |
| 		}
 | |
| 		private XmlNode GetProcedureIdentifier(XmlNamespaceManager nsmgr)
 | |
| 		{
 | |
| 			XmlNodeList xl = MyXMLDoc.DocumentElement.SelectNodes("//x:ident", nsmgr);
 | |
| 			if (xl.Count != 1)
 | |
| 				throw (new Exception("XML File Does not contain a Single Ident Node"));
 | |
| 			XmlNode xn = xl[0];
 | |
| 			return xn;
 | |
| 		}
 | |
| 		private static ProcedureInfo GetLastProcedure(DocVersionInfo dvi)
 | |
| 		{
 | |
| 			ProcedureInfo lastProc = null;
 | |
| 			if (dvi.Procedures != null)
 | |
| 				foreach (ProcedureInfo oldProc in dvi.Procedures)
 | |
| 					lastProc = oldProc;
 | |
| 			return lastProc;
 | |
| 		}
 | |
| 		private void AddGrossStep(ProcedureInfo lastProc, XmlNamespaceManager nsmgr)
 | |
| 		{
 | |
| 			XmlNodeList xl = MyXMLDoc.SelectNodes("//x:GrossStep", nsmgr);
 | |
| 			SectionInfo prevSection = null;
 | |
| 			pbSection.Maximum = xl.Count;
 | |
| 			pbSection.Value = 0;
 | |
| 			foreach (XmlNode xn in xl)
 | |
| 			{
 | |
| 				lblSection.Text = "Sect " + xn.Attributes["number"].Value;
 | |
| 				pbSection.Value++;
 | |
| 				Application.DoEvents();
 | |
| 				string config = null;
 | |
| 				int type = 10000;
 | |
| 				string sectName = xn.Attributes["name"].Value;
 | |
| 				switch (sectName)
 | |
| 				{
 | |
| 					case "Purpose":
 | |
| 					case "Entry Conditions":
 | |
| 					case "Exit Conditions":
 | |
| 						type = 10001;// Purpose Symptoms and Entry Conditions
 | |
| 						config = "<Config><Section ColumnMode=\"1\" /></Config>";
 | |
| 						break;
 | |
| 					default:
 | |
| 						if (sectName.ToUpper().Contains("ACTION"))
 | |
| 							type = 10000;// Procedure Steps
 | |
| 						else
 | |
| 							if (sectName.ToUpper().StartsWith("ATTACHMENT"))
 | |
| 							{
 | |
| 								type = 10008;
 | |
| 							}
 | |
| 							else if(HasContingency(xn))
 | |
| 							{
 | |
| 								type = 10002;// Attachment with Column Header
 | |
| 								// Two Column
 | |
| 							}
 | |
| 							else
 | |
| 							{
 | |
| 								type = 10008;// Attachment without Column Header
 | |
| 								config = "<Config><Section ColumnMode=\"1\" /></Config>";
 | |
| 							}
 | |
| 						break;
 | |
| 				}
 | |
| 				using (Section sect = Section.MakeSection(lastProc, prevSection, FixSectionNumber(xn.Attributes["number"].Value), xn.Attributes["name"].Value, type))
 | |
| 				{
 | |
| 					if (config != null)
 | |
| 						sect.MyContent.Config = config;
 | |
| 					sect.Save();
 | |
| 					prevSection = SectionInfo.Get(sect.ItemID);
 | |
| 					AddStepChildren(nsmgr, prevSection, xn.SelectNodes("x:Step", nsmgr));
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private bool HasContingency(XmlNode xn)
 | |
| 		{
 | |
| 			XmlNodeList xl = xn.SelectNodes(".//x:Contingency", _NSMGR);
 | |
| 			if (xl.Count == 0) xl = xn.SelectNodes(".//x:BinaryInstruction", _NSMGR);
 | |
| 			//if (xl.Count > 0) 
 | |
| 			//	Console.WriteLine("Found Contingency {0} {1} {2} {3}", _ProcNum,xn.Name ,GetAttribute( xn,"number"),GetAttribute( xn,"name"));
 | |
| 			return xl.Count > 0;
 | |
| 		}
 | |
| 		private string FixSectionNumber(string num)
 | |
| 		{
 | |
| 			if (Regex.IsMatch(num, "[IVX]+"))
 | |
| 				return num + ".";
 | |
| 			return num;
 | |
| 		}
 | |
| 		private void AddStepChildren(XmlNamespaceManager nsmgr, SectionInfo prevSection, XmlNodeList xl)
 | |
| 		{
 | |
| 			if (xl.Count > 0)
 | |
| 			{
 | |
| 				if (prevSection.DisplayText.StartsWith("Attachment"))
 | |
| 					AddAttachments(prevSection, xl, nsmgr);
 | |
| 				else
 | |
| 					switch (prevSection.DisplayText.ToUpper())
 | |
| 					{
 | |
| 						case "PURPOSE":
 | |
| 						case "ENTRY CONDITIONS":
 | |
| 						case "EXIT CONDITIONS":
 | |
| 							AddPSEC(prevSection, xl[0].ChildNodes);
 | |
| 							break;
 | |
| 						default:
 | |
| 							if (AllSiblingsAreCautionsOrNotes(xl))
 | |
| 								AddPSEC(prevSection, xl[0].ChildNodes);
 | |
| 							else
 | |
| 								AddStep(prevSection, xl);
 | |
| 							break;
 | |
| 					}
 | |
| 			}
 | |
| 		}
 | |
| 		private bool AllSiblingsAreCautionsOrNotes(XmlNodeList xl)
 | |
| 		{
 | |
| 			if (xl.Count > 1) return false;
 | |
| 			return AllSiblingsAreCautionsOrNotes((xl[0] as XmlElement).ChildNodes[0] as XmlElement);
 | |
| 		}
 | |
| 		private void AddPSEC(SectionInfo prevSection, XmlNodeList xl)
 | |
| 		{
 | |
| 			SectionInfo keepPrevSection = prevSection;
 | |
| 			//xl = (xl)[0].ChildNodes;
 | |
| 			if (xl.Count == 0) return;
 | |
| 			//TODO Need to add logic to save the first note as a step and the rest off of the first note
 | |
| 			//TODO ChildNodes Can include xmlText as well as xmlElement nodes
 | |
| 			//TODO Create list of children
 | |
| 			XmlElement FirstNote = null;
 | |
| 			XmlElement FirstCaution = null;
 | |
| 			XmlElement FirstUnitary = null;
 | |
| 			XmlElement FirstContingency = null;
 | |
| 			int UnitaryCount = 0;
 | |
| 			//			List<XmlElement> xl1 = new List<XmlElement>();
 | |
| 			foreach (XmlNode xn in xl)
 | |
| 			{
 | |
| 				if (xn is XmlElement)
 | |
| 				{
 | |
| 					//Find First Child that is a Note
 | |
| 					if (FirstNote == null || (xn.Name == "NoteInstruction" && FirstNote.Name != "NoteInstruction"))
 | |
| 						FirstNote = xn as XmlElement;
 | |
| 					if (FirstCaution == null || (xn.Name == "CautionInstruction" && FirstCaution.Name != "CautionInstruction"))
 | |
| 						FirstCaution = xn as XmlElement;
 | |
| 					if(FirstUnitary == null && (xn.Name == "UnitaryInstruction" || xn.Name == "UnitaryContingencyCallInstruction"
 | |
| 						|| xn.Name == "BinaryInstruction" || xn.Name == "Contingency")) 
 | |
| 						FirstUnitary = xn as XmlElement;
 | |
| 					if (xn.Name == "UnitaryInstruction" || xn.Name == "UnitaryContingencyCallInstruction"
 | |
| 						|| xn.Name == "BinaryInstruction" || xn.Name == "Contingency")
 | |
| 						UnitaryCount++;
 | |
| 					if (FirstContingency == null && xn.Name == "Contingency")
 | |
| 						FirstContingency = xn as XmlElement;
 | |
| 					////if (xn.OuterXml.Contains("ALL AAC"))
 | |
| 					//	Console.WriteLine("XN ALL AAC");
 | |
| 				}
 | |
| 			}
 | |
| 			FirstNote = FirstNote ?? FirstCaution;
 | |
| 			if (FirstNote != null && FirstNote.Name == "UnitaryInstruction")
 | |
| 				if (FirstCaution != null && FirstCaution.Name == "NoteInstruction")
 | |
| 					Console.WriteLine("oopsie!");
 | |
| 			//Remove First Note from List
 | |
| 			//xl1.Remove(FirstNote);
 | |
| 			//TODO Add Remaining Children
 | |
| 			StepLookup mySteps = new StepLookup();
 | |
| 			int level = -1;
 | |
| 			if (FirstUnitary != null)
 | |
| 			{
 | |
| 				_LastStepText.Clear();
 | |
| 				while (FirstUnitary != null)
 | |
| 				{
 | |
| 					//XmlElement lastNote = FirstUnitary;
 | |
| 					// Add Other Notes if they exist
 | |
| 					prevSection = keepPrevSection;
 | |
| 					level = -1;
 | |
| 					if (FirstUnitary.Attributes["content"] != null)
 | |
| 					{
 | |
| 						AddContent(prevSection, mySteps, level, FirstUnitary, true, UnitaryCount);
 | |
| 						//if (FirstUnitary.ChildNodes.Count > 0 && FirstUnitary.Name == "UnitaryInstruction")
 | |
| 						if (FirstUnitary.Name == "UnitaryContingencyCallInstruction")
 | |
| 							MyContingencies.Add((1 + MyContingencies.Count).ToString(), mySteps[mySteps.Count - 1].ItemID);
 | |
| 						if (FirstUnitary.ChildNodes.Count > 0)
 | |
| 							AddStepStucture(mySteps, mySteps.Count - 1, FirstUnitary, false);
 | |
| 						//Console.WriteLine("\"Unitary\"\t\"{0}\"\t\"{1}\"", prevSection, mySteps[mySteps.Count - 1]);
 | |
| 						if (FirstContingency != null)
 | |
| 						{
 | |
| 							ContingencyStep = mySteps[mySteps.Count -1];
 | |
| 							int lev1 = 1 + Math.Min(level + 1, mySteps.Count);
 | |
| 							int inc = 1;
 | |
| 							FirstContingency = FirstContingency.ChildNodes[0] as XmlElement;
 | |
| 							while (FirstContingency != null)
 | |
| 							{
 | |
| 								AddStepStucture(mySteps, lev1, FirstContingency, true);
 | |
| 								lev1 += inc;
 | |
| 								mySteps[lev1 - 1] = mySteps[lev1 - 1];
 | |
| 								inc = 0;
 | |
| 								FirstContingency = FirstContingency.NextSibling as XmlElement;
 | |
| 							}
 | |
| 							mySteps[lev1 - 2] = mySteps[lev1 - 2];
 | |
| 						}
 | |
| 						if (mySteps.Count > 0)
 | |
| 						{
 | |
| 							level = 1;
 | |
| 							prevSection = null;
 | |
| 						}
 | |
| 						else
 | |
| 						{
 | |
| 							//Console.WriteLine("No Steps");
 | |
| 						}
 | |
| 					}
 | |
| 					if (FirstNote != null && FirstNote.Name == "UnitaryInstruction")
 | |
| 						Console.WriteLine("Should not be Unitary Instruction 1 \"{0}\" {1}", _StepLocation, _StepID);
 | |
| 					AddNotesAndCautions(ref prevSection, FirstNote, mySteps, ref level);
 | |
| 					FirstNote = null;
 | |
| 					FirstUnitary = FirstUnitary.NextSibling as XmlElement;
 | |
| 					if (FirstUnitary != null && FirstUnitary == FirstContingency) FirstUnitary = FirstUnitary.NextSibling as XmlElement;
 | |
| 					while (FirstUnitary != null && (FirstUnitary.Name == "NoteInstruction" || FirstUnitary.Name == "CautionInstruction"))
 | |
| 					{
 | |
| 						if (FirstNote == null) FirstNote = FirstUnitary;
 | |
| 						FirstUnitary = FirstUnitary.NextSibling as XmlElement;
 | |
| 						if (FirstUnitary != null && FirstUnitary == FirstContingency) FirstUnitary = FirstUnitary.NextSibling as XmlElement;
 | |
| 						break;
 | |
| 					}
 | |
| 					// if (FirstUnitary != null && FirstUnitary.Name == "Contingency") Console.WriteLine("Contingency");
 | |
| 					//if (FirstUnitary != null && FirstUnitary.Name == "BinaryInstruction") Console.WriteLine("Contingency");
 | |
| 					//if(FirstUnitary != null) 
 | |
| 					//	Console.Write("{0}", mySteps[0]);
 | |
| 					//				if (FirstNote != null) Console.WriteLine("next");
 | |
| 				}
 | |
| 			}
 | |
| 			else
 | |
| 				AddNotesAndCautions(ref prevSection, FirstNote, mySteps, ref level);
 | |
| 			//TODO Add Cautions
 | |
| 		}
 | |
| 
 | |
| 		private static void AddNotesAndCautions(ref SectionInfo prevSection, XmlElement FirstNote, StepLookup mySteps, ref int level)
 | |
| 		{
 | |
| 			_LastStepText.Clear();
 | |
| 			while (FirstNote != null)
 | |
| 			{
 | |
| 				//XmlElement lastNote = FirstNote;
 | |
| 				// Add Other Notes if they exist
 | |
| 				if (FirstNote.Attributes["content"] != null)
 | |
| 				{
 | |
| 					XmlElement nextNote = FirstNote.NextSibling as XmlElement;
 | |
| 					AddContent(prevSection, mySteps, level, FirstNote, true);
 | |
| 					if (FirstNote.ChildNodes.Count > 0 && FirstNote.Name != "NoteInstruction" && FirstNote.Name != "CautionInstruction")
 | |
| 						AddStepStucture(mySteps, level, FirstNote);
 | |
| 					if (mySteps.Count > 0 && (nextNote == null || nextNote.Name != FirstNote.Name))
 | |
| 					{
 | |
| 						level = 1;
 | |
| 						prevSection = null;
 | |
| 					}
 | |
| 					else
 | |
| 					{
 | |
| 						//Console.WriteLine("No Steps");
 | |
| 					}
 | |
| 				}
 | |
| 				FirstNote = FirstNote.NextSibling as XmlElement;
 | |
| 				if (FirstNote != null && FirstNote.Name != "NoteInstruction" && FirstNote.Name != "CautionInstruction")
 | |
| 					break;
 | |
| 				//				if (FirstNote != null) Console.WriteLine("next");
 | |
| 				if (FirstNote != null &&  FirstNote.Name == "UnitaryInstruction")
 | |
| 					Console.WriteLine("Should not be Unitary Instruction 2 \"{0}\" {1}",_StepLocation,_StepID);
 | |
| 
 | |
| 			}
 | |
| 		}
 | |
| 		private static StepInfo _ContingencyStep = null;
 | |
| 		public static StepInfo ContingencyStep
 | |
| 		{
 | |
| 			get { return _ContingencyStep; }
 | |
| 			set { _ContingencyStep = value; }
 | |
| 		}
 | |
| 		private static string _LastName = "";
 | |
| 		private static List<XmlNode> _NodeProcessed = null;
 | |
| 		private static void AddContent(SectionInfo prevSection, StepLookup mySteps, int level, XmlNode xn, bool ignoreNote)
 | |
| 		{
 | |
| 			AddContent(prevSection, mySteps, level, xn, ignoreNote, 0);
 | |
| 		}
 | |
| 		private static string _StepLocation;
 | |
| 		private static int _StepID;
 | |
| 		private static	Dictionary<int, StepText> _LastStepText = new Dictionary<int, StepText>();
 | |
| 		private static string _MyRawData = null;
 | |
| 		private static string _MyRawType = null;
 | |
| 		private static bool _MyRawCheck = true;
 | |
| 		private static void AddContent(SectionInfo prevSection, StepLookup mySteps, int level, XmlNode xn, bool ignoreNote, int steps)
 | |
| 		{
 | |
| 			//if (!_NodeProcessed.Contains(xn))
 | |
| 			//	_NodeProcessed.Add(xn);
 | |
| 			//else
 | |
| 			//	Console.WriteLine("node Being Processed again");
 | |
| 			int nextLevel = 0;
 | |
| 			int adjustLevel = 0;
 | |
| 			//if (level >= mySteps.Count - 1)
 | |
| 			//{
 | |
| 			//	adjustLevel = level - mySteps.Count;
 | |
| 			//	Console.WriteLine("Level beyond Range");
 | |
| 			//}
 | |
| 			string RNOGoTo = xn.Attributes["linkTarget"] == null ? "" : xn.Attributes["linkTarget"].Value;
 | |
| 			int type = 20001;
 | |
| 			if (prevSection != null && prevSection.IsSection ) type = 20002;
 | |
| 			E_FromType frType = E_FromType.Step;
 | |
| 			string xmlbase = xn.Attributes["content"].Value;
 | |
| 			//if (xmlbase.Contains("qt-block-indent"))
 | |
| 			//	Console.WriteLine("Here Indent");
 | |
| 			//if (xmlbase.Contains("the affected SG has been isolated and the cooldown"))
 | |
| 			//	Console.WriteLine("Here 6");
 | |
| 			//if (xmlbase.Contains("unless misoperation"))
 | |
| 			//	Console.WriteLine("Here 1");
 | |
| 			//if (xmlbase.Contains("5. Natural"))
 | |
| 			//	Console.WriteLine("Here 5");
 | |
| 
 | |
| 			string xml = cleanupHTML(xmlbase, 0);
 | |
| 			_MyRawData = xml;
 | |
| 			_MyRawType = xn.Name;
 | |
| 			if (xn.Name == "NoteInstruction" && xml != null && xml.Contains("NOTE"))
 | |
| 				Console.WriteLine(xml);
 | |
| 			//if (xml.Contains("SET CV-PIK-201, Letdown Backpressure Controller"))
 | |
| 			//	Console.WriteLine("Found it");
 | |
| 			//if (xml.Contains("<img")) Console.WriteLine("here");
 | |
| 			//if (xn.Name.StartsWith("Unitary")) Console.WriteLine("here");
 | |
| 			//if ((xml.Contains("<table") || xml.Contains("<img")) && _MyTableFileName != null)
 | |
| 			if (GetSectionStyle(xn.ParentNode) == "Free Form" && _MyTableFileName != null)
 | |
| 			{
 | |
| 				xmlbase = BuildHTMLLibDoc(xn, xmlbase);
 | |
| 				return;
 | |
| 			}
 | |
| 			//if(xml.Contains(@"\u916?") && !xmlbase.Contains(@"\u916?"))
 | |
| 			//	Console.WriteLine("here");
 | |
| 			if (!xml.Contains("<"))
 | |
| 			{
 | |
| 				Console.WriteLine("not XML - '{0}'");
 | |
| 				xml = "<html><p>" + xml + "</p></html>";
 | |
| 			}
 | |
| 			//if (xml.Contains("SPADES") || xml.Contains("CONFIRM the diagnosis of a SGTR by performing the following"))
 | |
| 			//	Console.WriteLine("HERE");
 | |
| 			if (prevSection == null)
 | |
| 			{
 | |
| 				if (xn.Name == "CautionInstruction")
 | |
| 				{
 | |
| 					type = 20006;
 | |
| 					frType = E_FromType.Caution;
 | |
| 				}
 | |
| 				else if (xn.Name == "NoteInstruction" && (xml.Contains(">NOTE<") || xml.Contains(">NOTES<") || xml.Contains(">NOTE CONTINUED<")))
 | |
| 				{
 | |
| 					type = 20007;
 | |
| 					frType = E_FromType.Note;
 | |
| 				}
 | |
| 				else
 | |
| 				{
 | |
| 					if (ContingencyStep != null)
 | |
| 					{
 | |
| 						type = 20040;
 | |
| 						frType = E_FromType.RNO;
 | |
| 					}
 | |
| 					else
 | |
| 					{
 | |
| 						type = 20001;
 | |
| 						frType = E_FromType.Step;
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 			XmlDocument xd = new XmlDocument();
 | |
| 			xd.LoadXml(xml);
 | |
| 			//bool resetUL = true;
 | |
| 			string lastNodeName = "";
 | |
| 			//_LastStepText.Clear();
 | |
| 			foreach (XmlNode xn2 in xd.DocumentElement.ChildNodes)
 | |
| 			{
 | |
| 				if (xn2.InnerText != "" && xn2.InnerText != "NOTE" && xn2.InnerText != "NOTES" && xn2.InnerText != "NOTE CONTINUED" && xn2.InnerText != "CAUTION" && xn2.InnerText != "WARNING")
 | |
| 				{
 | |
| 
 | |
| 					//if (xn2.InnerText.StartsWith("VERIFY the most affected SG 1"))
 | |
| 					//	Console.WriteLine("{0},{1}",mySteps,level);
 | |
| 					StepText xn2Text = FixText(xn2);
 | |
| 					//if (xn2Text.Text.Contains("indications should be used to aid in evaluating plant"))
 | |
| 					//	Console.WriteLine("Here");
 | |
| 					//if (xn2Text.Text.Contains("unless misoperation"))
 | |
| 					//	Console.WriteLine("Here 1");
 | |
| 					//if (xn2Text.Text.Contains("temperatures. SG water level is calibrated for normal"))
 | |
| 					//	Console.WriteLine("Here 4.5");
 | |
| 					//if (xn2Text.Text.StartsWith("Natural"))
 | |
| 					//	Console.WriteLine("Here 5.0");
 | |
| 					//if (xn2Text.Text.Contains("the affected SG has been isolated and the cooldown"))
 | |
| 					//	Console.WriteLine("Here 6.0");
 | |
| 					//if (xn2Text.Text.Contains("During all phases of the cooldown"))
 | |
| 					//	Console.WriteLine("Here 7.0");
 | |
| 					//if (xn2Text.Text.Contains("Minimize the number of cycles of pressurizer auxiliary spray"))
 | |
| 					//	Console.WriteLine("Here 8.0");
 | |
| 					//if (xn2Text.Text.Contains("Operators should be aware of the status of CCW supply to the"))
 | |
| 					//	Console.WriteLine("Here 18.0");
 | |
| 					//if (xn2Text.Text.Contains("To minimize the unmonitored release of radioactivity"))
 | |
| 					//	Console.WriteLine("Here 10.0");
 | |
| 					//if (xn2Text.Text.Contains("When indicated SG water level is excessively high"))
 | |
| 					//	Console.WriteLine("Here 11.0");
 | |
| 					//if (xn2Text.Text.Contains("When restarting RCPs, it is preferable to first start an RCP"))
 | |
| 					//	Console.WriteLine("Here 22.0");
 | |
| 					//if (xn2Text.Text.Contains("Allowing the secondary system to backflow to the primary system"))
 | |
| 					//	Console.WriteLine("Here 27.0");
 | |
| 					//if (xn2Text.Text.Contains("SG backflow for level control Backflow is a permissible operational"))
 | |
| 					//	Console.WriteLine("Here 27.a");
 | |
| 					//if (xn2Text.Text.Contains("SG backflow for depressurization and cooldown Back flow is"))
 | |
| 					//	Console.WriteLine("Here 27.b");
 | |
| 					//if (xn2Text.Text.Contains("At least one RCP must be operating before attempting"))
 | |
| 					//	Console.WriteLine("Here 27.b.*");
 | |
| 					//if (xn2Text.Text.Contains("Once the entire RCS has been successfully cooled to SDC entry"))
 | |
| 					//	Console.WriteLine("Here 28.0");
 | |
| 					//if (xn2Text.Text.Contains("Operation of the Containment Spray System "))
 | |
| 					//	Console.WriteLine("Here 20.0");
 | |
| 					//if (xn2Text.Text.StartsWith("10."))
 | |
| 					//	Console.WriteLine("Numbered Step");
 | |
| 					//if (xn2Text.Text.Contains("Cooling System Entry Conditions are satisfied") ||
 | |
| 					//	xn2Text.Text.Contains("Recovery Guideline may be exited when ANY of the following") ||
 | |
| 					//	xn2Text.Text.Contains("has accomplished its purpose by satisfying"))
 | |
| 					//	Console.WriteLine("Here");
 | |
| 					// Check against last
 | |
| 					int lastLevel = level;
 | |
| 					level = getMatchingLevel(_LastStepText, xn2Text,lastLevel);
 | |
| 					if (level > 0 && type == 20002)
 | |
| 					{
 | |
| 						if (xn2Text.Tab == "") type = 20024;
 | |
| 						else type = 20001;
 | |
| 					}
 | |
| 					//if (xn2Text.Tab == "*")
 | |
| 					//	type = 20004;
 | |
| 					//else if (xn2Text.Tab == "" && level > 0)
 | |
| 					//	type = 20024;
 | |
| 					//else
 | |
| 						//type = 20001;
 | |
| 					if (xn2Text.Text != "")
 | |
| 					{
 | |
| 						if (xn2.Name == "p")
 | |
| 						{
 | |
| 							//resetUL = true;
 | |
| 							XmlNode pxn = PreviousNode(xn2, "p");
 | |
| 							StepText pxnText = FixText(pxn);
 | |
| 							XmlNode nxn = NextNode(xn2, "p");
 | |
| 							StepText nxnText = FixText(nxn);
 | |
| 							//ListMySteps("AddContent", mySteps);
 | |
| 							bool levelIsOK = true;// level < 0 || level < mySteps.Count - 1;
 | |
| 							if (xn2Text.Text != "AND" && xn2Text.Text != "OR")
 | |
| 							{
 | |
| 								if (pxnText != null && pxnText.Text == "OR")
 | |
| 									using (Step step = MakeCSLAStep(mySteps, level, null, xn2Text.Text, 20005, E_FromType.Step)) { ;}
 | |
| 								else if (pxnText != null && pxnText.Text == "AND")
 | |
| 									using (Step step = MakeCSLAStep(mySteps, level, null, xn2Text.Text, 20019, E_FromType.Step)) { ;}
 | |
| 								else if (nxnText != null && nxnText.Text == "OR" && NextNode(nxn, "p") != null && nxn.ParentNode.Name != "ul" && levelIsOK)
 | |
| 									using (Step step = MakeCSLAStep(mySteps, level, null, xn2Text.Text, 20005, E_FromType.Step)) { ;}
 | |
| 								else if (nxnText != null && nxnText.Text == "AND")
 | |
| 									using (Step step = MakeCSLAStep(mySteps, level, null, xn2Text.Text, 20019, E_FromType.Step)) { ;}
 | |
| 								else
 | |
| 								{
 | |
| 									if (level < 1 && prevSection != null)
 | |
| 									{
 | |
| 										if (type == 20007 || frType == E_FromType.Note)
 | |
| 											Console.WriteLine("Here");
 | |
| 										int myType = 20002;
 | |
| 										if (prevSection.MyContent.Type == 10001 && steps == 0)
 | |
| 											myType = 20041;
 | |
| 										if(level < 0)level++;
 | |
| 										//Console.WriteLine("\"prevSection1\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}", prevSection, mySteps[level], level, myType);
 | |
| 										using (Step step = MakeNewStep(prevSection, mySteps[level], null, xn2Text.Text, myType, E_FromType.Step))
 | |
| 										{
 | |
| 											//if (step.ItemID == 9408)
 | |
| 											//	Console.WriteLine("Here");
 | |
| 											step.Save();
 | |
| 											StepInfo si = mySteps[level] = StepInfo.Get(step.ItemID);
 | |
| 											CheckHLS(si, "Case 1");
 | |
| 											_StepLocation = si.ShortPath;
 | |
| 											_StepID = si.ItemID;
 | |
| 											//if (step.ItemID >= 10079 && step.ItemID <= 10089)
 | |
| 											//	Console.WriteLine("{0} - {1} - {2}", si.ItemID, si.DisplayText, si.ShortPath);
 | |
| 											if ((nxnText == null || nxnText.Tab == "" || xn2Text.Tab == "") && (pxnText == null || pxnText.Tab == "" || xn2Text.Tab == ""))
 | |
| 											{
 | |
| 												prevSection = null;
 | |
| 												nextLevel = level + 1;
 | |
| 											}
 | |
| 										}
 | |
| 									}
 | |
| 									else
 | |
| 									{
 | |
| 										switch (frType)
 | |
| 										{
 | |
| 											case E_FromType.Caution:
 | |
| 												if (mySteps[0].Cautions != null && mySteps[0].Cautions.Count > 0)
 | |
| 													mySteps[1] = StepInfo.Get(mySteps[0].Cautions[0].LastSibling.ItemID);
 | |
| 												break;
 | |
| 											case E_FromType.Note:
 | |
| 												if (mySteps[0].Notes != null && mySteps[0].Notes.Count > 0)
 | |
| 													mySteps[1] = StepInfo.Get(mySteps[0].Notes[0].LastSibling.ItemID);
 | |
| 												break;
 | |
| 											case E_FromType.RNO:
 | |
| 												if (ContingencyStep != null)
 | |
| 												{
 | |
| 													//Console.WriteLine("BuildMySteps {0} type {1} frtype {2}", ContingencyStep,type,frType);
 | |
| 													BuildMySteps(ContingencyStep, mySteps);
 | |
| 													ContingencyStep = null;
 | |
| 												}
 | |
| 												else
 | |
| 												{
 | |
| 													type = 20024;
 | |
| 													frType = E_FromType.Step;
 | |
| 												}
 | |
| 												level = mySteps.Count;
 | |
| 												break;
 | |
| 											case E_FromType.Step:
 | |
| 												if (level > mySteps.Count) level = mySteps.Count;
 | |
| 												if (level > 0 && mySteps[level - 1].Steps != null && mySteps[level - 1].Steps.Count > 0)
 | |
| 													mySteps[level] = StepInfo.Get(mySteps[level - 1].Steps[0].LastSibling.ItemID);
 | |
| 												break;
 | |
| 											case E_FromType.SupInfo:
 | |
| 												if (mySteps[level - 1].SupInfos != null && mySteps[level - 1].SupInfos.Count > 0)
 | |
| 													mySteps[level] = StepInfo.Get(mySteps[level - 1].SupInfos[0].LastSibling.ItemID);
 | |
| 												break;
 | |
| 											case E_FromType.Table:
 | |
| 												if (mySteps[level - 1].Tables != null && mySteps[level - 1].Tables.Count > 0)
 | |
| 													mySteps[level] = StepInfo.Get(mySteps[level - 1].Tables[0].LastSibling.ItemID);
 | |
| 												break;
 | |
| 											default:
 | |
| 												break;
 | |
| 										}
 | |
| 										switch (frType)
 | |
| 										{
 | |
| 											case E_FromType.Caution:
 | |
| 												using (Step step = MakeNewStep(mySteps[0].MyHLS, GetFirstCaution(mySteps[0].MyHLS), null, xn2Text.Text, type, frType))
 | |
| 												{
 | |
| 													step.Save();
 | |
| 													level = 1;
 | |
| 													StepInfo si = mySteps[level] = StepInfo.Get(step.ItemID);
 | |
| 													CheckHLS(si, "Case 2");
 | |
| 													_StepLocation = si.ShortPath;
 | |
| 													_StepID = si.ItemID;
 | |
| 													//if (step.ItemID >= 10079 && step.ItemID <= 10089)
 | |
| 													//	Console.WriteLine("{0} - {1} - {2}", si.ItemID, si.DisplayText, si.ShortPath);
 | |
| 												}
 | |
| 												type = 20001;
 | |
| 												break;
 | |
| 											case E_FromType.Note:
 | |
| 												using (Step step = MakeNewStep(mySteps[0].MyHLS, GetFirstNote(mySteps[0].MyHLS), null, xn2Text.Text, type, frType))
 | |
| 												{
 | |
| 													step.Save();
 | |
| 													level = 1;
 | |
| 													StepInfo si = mySteps[level] = StepInfo.Get(step.ItemID);
 | |
| 													CheckHLS(si, "Case 3");
 | |
| 													_StepLocation = si.ShortPath;
 | |
| 													_StepID = si.ItemID;
 | |
| 													//if (step.ItemID >= 10079 && step.ItemID <= 10089)
 | |
| 													//	Console.WriteLine("{0} - {1} - {2}", si.ItemID, si.DisplayText, si.ShortPath);
 | |
| 												}
 | |
| 												type = 20001;
 | |
| 												break;
 | |
| 											default:
 | |
| 												//if (frType == E_FromType.RNO)
 | |
| 												//	Console.WriteLine("{0} {1} {2} {3}", mySteps[level - 1], mySteps[level], frType, xn2.InnerText.Trim(" ".ToCharArray()));
 | |
| 												string originalText = null;
 | |
| 												if (RNOGoTo != string.Empty && xn.Name != "UnitaryContingencyCallInstruction")
 | |
| 												{
 | |
| 													string xn2TextAfter = StripQuestion(xn2Text.Text);
 | |
| 													if (xn2Text.Text != xn2TextAfter)
 | |
| 													{
 | |
| 														string removeWord = xn2Text.Text.Replace(xn2TextAfter, "").Replace("?", "");
 | |
| 														originalText = xn2Text.Text;
 | |
| 														xn2Text.Text = xn2TextAfter;
 | |
| 													}
 | |
| 												}
 | |
| 												if (originalText != null)
 | |
| 													_MyRawCheck = false;
 | |
| 												using (Step step = MakeCSLAStep(mySteps, level, null, xn2Text.Text, type, frType))
 | |
| 												{
 | |
| 													if (frType == E_FromType.RNO) level++;
 | |
| 													if (originalText != null)
 | |
| 														Annotation.MakeAnnotation(step, AnnotationType.GetByNameOrCreate("Barakah Conversion1"), null,
 | |
| 															string.Format("Original Text:\r\n\r\n{0}\r\n\r\nThis step may need edited.", originalText), null);
 | |
| 												}
 | |
| 												break;
 | |
| 										}
 | |
| 									}
 | |
| 												if (RNOGoTo != string.Empty && xn.Name != "UnitaryContingencyCallInstruction")
 | |
| 												{
 | |
| 													//TODO Add Transitions
 | |
| 													using (Step stepr = MakeCSLAStep(mySteps, level + 1, null, "Go to step " + RNOGoTo, 20040, E_FromType.RNO)) { ;}
 | |
| 													if(level < 0) level = mySteps.Count - 1;
 | |
| 													mySteps[level] = mySteps[level];
 | |
| 												}
 | |
| 												_MyRawCheck = true;
 | |
| 								}
 | |
| 							}
 | |
| 						}
 | |
| 						else if (xn2.Name == "ul" || xn2.Name == "ol")
 | |
| 						{
 | |
| 							int lev = mySteps.Count - 1;
 | |
| 							//if (resetUL)
 | |
| 							//		mySteps.Remove(lev + 1);
 | |
| 							if (lastNodeName == "ul" || lastNodeName == "ol")
 | |
| 								lev--;
 | |
| 							//resetUL = false;
 | |
| 							XmlNodeList xl1 = xn2.SelectNodes("li");
 | |
| 							foreach (XmlNode xn3 in xl1)
 | |
| 							{
 | |
| 								if (prevSection == null)
 | |
| 								{
 | |
| 									try
 | |
| 									{
 | |
| 										if(frType == E_FromType.Note && type == 20007)
 | |
| 											using (Step step = MakeCSLAStep(mySteps, lev + 1, null, FixText(xn3).Text, type, frType)) { ;}
 | |
| 
 | |
| 										else
 | |
| 										using (Step step = MakeCSLAStep(mySteps, lev + 1, null, FixText(xn3).Text, mySteps[lev].DisplayText.ToUpper().StartsWith("ONE ") ? 20005 : 20004, E_FromType.Step)) { ;}
 | |
| 									}
 | |
| 									catch (Exception ex)
 | |
| 									{
 | |
| 										ListMySteps(string.Format("makeCSLAStep Crash Level= {0}\r\n\r\n", lev), mySteps);
 | |
| 										throw ex;
 | |
| 									}
 | |
| 								}
 | |
| 								else
 | |
| 								{
 | |
| 									int myType = 20002;
 | |
| 									if (mySteps.Count > level)
 | |
| 									{
 | |
| 										level++;
 | |
| 									}
 | |
| 									else
 | |
| 										Console.WriteLine("Change in Conversion");
 | |
| 									StepText xn3txt = FixText(xn3);
 | |
| 									//if(xn3txt.Contains("The following actions are"))
 | |
| 									//Console.WriteLine("\"prevSection2\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}", prevSection, mySteps[level], level, myType);
 | |
| 									using (Step step = MakeNewStep(prevSection, mySteps[level], null, xn3txt.Text, myType, E_FromType.Step))
 | |
| 									{
 | |
| 										step.Save();
 | |
| 										StepInfo si = mySteps[level] = StepInfo.Get(step.ItemID);
 | |
| 										CheckHLS(si, "Case 4");
 | |
| 										_StepLocation = si.ShortPath;
 | |
| 										_StepID = si.ItemID;
 | |
| 										//if (step.ItemID >= 10079 && step.ItemID <= 10089)
 | |
| 										//	Console.WriteLine("{0} - {1} - {2}", si.ItemID, si.DisplayText, si.ShortPath);
 | |
| 										prevSection = null;
 | |
| 										lev = level;
 | |
| 									}
 | |
| 								}
 | |
| 							}
 | |
| 						}
 | |
| 						else
 | |
| 						{
 | |
| 							if (xn2.Name == "table")
 | |
| 							{
 | |
| 								//Console.WriteLine("======================> Unprocessed table {0}", GetPath(xn));
 | |
| 								//if (xn2.OuterXml.Contains(@"\u916?") )
 | |
| 								//	Console.WriteLine("Here");
 | |
| 								if (mySteps.Count == 0)
 | |
| 									using (Step step = MakeNewStep(prevSection, mySteps[level], null, "\xA0 Empty High Level Step", 2, E_FromType.Step))
 | |
| 									{
 | |
| 										step.Save();
 | |
| 										level = Math.Max(level, 0);
 | |
| 										StepInfo si = mySteps[level] = StepInfo.Get(step.ItemID);
 | |
| 										CheckHLS(si, "Case 5");
 | |
| 										_StepLocation = si.ShortPath;
 | |
| 										_StepID = si.ItemID;
 | |
| 										//if (step.ItemID >= 10079 && step.ItemID <= 10089)
 | |
| 										//	Console.WriteLine("{0} - {1} - {2}", si.ItemID, si.DisplayText, si.ShortPath);
 | |
| 										prevSection = null;
 | |
| 									}
 | |
| 								if (_MyTableFileName == null)
 | |
| 								{
 | |
| 									Console.WriteLine("xml='{0}'",xn2.OuterXml);
 | |
| 									LoadTable2(xn2, mySteps, level);
 | |
| 								}
 | |
| 							}
 | |
| 						}
 | |
| 					}
 | |
| 					lastNodeName = xn2.Name;
 | |
| 					if(xn2Text.Text != "AND" && xn2Text.Text != "OR")
 | |
| 						_LastStepText[level] = xn2Text;
 | |
| 					level = Math.Max(level, nextLevel);
 | |
| 				}
 | |
| 			}
 | |
| 			RemoveStepsAbove(mySteps, level);
 | |
| 		}
 | |
| 		private static Step MakeNewStep(ItemInfo parentInfo, ItemInfo previousInfo, string stepNumber, string stepTitle, int stepType, E_FromType fromType)
 | |
| 		{
 | |
| 			Step step = Step.MakeStep(parentInfo, previousInfo, stepNumber, stepTitle, stepType, fromType);
 | |
| 			if (_MyRawData != null)
 | |
| 			{
 | |
| 				if (_MyRawCheck && (FixRawData(_MyRawData) != stepTitle))
 | |
| 				{
 | |
| 				if (stepType != 20007 && _MyRawData.Contains(">NOTE"))
 | |
| 					//Console.WriteLine("Here");
 | |
| 					Annotation.MakeAnnotation(step, AnnotationType.GetByNameOrCreate("Barakah Raw Data"), null, _MyRawType + ":\r\n" + FixRawData(_MyRawData), null);
 | |
| 				}
 | |
| 				if (_MyRawCheck && _MyRawData != null && _MyRawType == "BinaryInstruction" && _MyRawType == "Contingency")
 | |
| 					Annotation.MakeAnnotation(step, AnnotationType.GetByNameOrCreate("Barakah Raw Data2"), null, _MyRawType + ":\r\n" + FixRawData(_MyRawData), null);
 | |
| 				_MyRawData = null;
 | |
| 			}
 | |
| 			return step;
 | |
| 		}
 | |
| 		private static string FixRawData(string str)
 | |
| 		{
 | |
| 			str = str.Replace("<p >", "").Replace("</p>", "").Replace("<li >", "\u25CF ").Replace("</li>", "\r\n").Replace("<html>", "")
 | |
| 				.Replace("</html>", "").Replace(@"\line", "").Replace("</ul>","").TrimStart(" \r\n\t".ToCharArray())
 | |
| 				.Replace(@"\u8209?", "\u2011").Replace(@"\u9679?", "\u25CF").Replace("<li  >", "\u25CF ").Replace("<li>", "\u25CF ");
 | |
| 			str = Regex.Replace(str, "<ul[^>]+>", "");
 | |
| 			str = Regex.Replace(str, "<p[^>]+>", "");
 | |
| 			str = Regex.Replace(str, "[\r\n]+", "\r\n");
 | |
| 			return str;
 | |
| 		}
 | |
| 		private static void CheckHLS(StepInfo si, string str)
 | |
| 		{
 | |
| 			if (si.MyContent.Type == 20002 && si.ActiveParent is ItemInfo && (si.ActiveParent as ItemInfo).MyContent.Type == 20002)
 | |
| 					Console.WriteLine("HLS Parent of HLS {0}",str);
 | |
| 		}
 | |
| 		private static Regex _regalpha = new Regex(@"[a-z][\.\)]");
 | |
| 		private static Regex _regALPHA = new Regex(@"[A-Z][\.\)]");
 | |
| 		private static Regex _regNumeric = new Regex(@"([0-9]+)[\.\)]");
 | |
| 		private static string NextTab(string tab)
 | |
| 		{
 | |
| 			Match m = _regalpha.Match(tab);
 | |
| 			if (m.Success)
 | |
| 			{
 | |
| 				string retval = ((char)(tab[0] + 1)) + tab.Substring(1);
 | |
| 				return retval;
 | |
| 			}
 | |
| 			m = _regALPHA.Match(tab);
 | |
| 			if (m.Success)
 | |
| 			{
 | |
| 				string retval = ((char)(tab[0] + 1)) + tab.Substring(1);
 | |
| 				return retval;
 | |
| 			}
 | |
| 			m = _regNumeric.Match(tab);
 | |
| 			if (m.Success)
 | |
| 				return ((int.Parse(m.Groups[1].Value)+1).ToString() + tab.Substring(m.Groups[1].Length));
 | |
| 			return tab;
 | |
| 		}
 | |
| 		private static Regex _RegFirst = new Regex(@"[1Aa][\.\)]", RegexOptions.Compiled);
 | |
| 		private static bool IsFirstTab(string tab)
 | |
| 		{
 | |
| 			if (tab == "" || tab == "*") return true;
 | |
| 			bool retval = _RegFirst.IsMatch(tab);
 | |
| 			if(retval) return true;
 | |
| 			return false;
 | |
| 		}
 | |
| 		private static int getMatchingLevel(Dictionary<int, StepText> lastStepText, StepText xn2Text, int level)
 | |
| 		{
 | |
| 			//if (xn2Text.Text.Contains("All Safety Function Status Check"))
 | |
| 			//	Console.WriteLine("here");
 | |
| 
 | |
| 			if (lastStepText.Count == 0) return level;
 | |
| 			int maxkey = 0;
 | |
| 			int i = 0;
 | |
| 			foreach (int key in lastStepText.Keys) // Look at exact match first
 | |
| 			{
 | |
| 				StepText st = lastStepText[key];
 | |
| 				if (NextTab(st.Tab) == xn2Text.Tab)
 | |
| 				{
 | |
| 					//if (st.Tab != "*" && st.Tab != "")
 | |
| 					//	Console.WriteLine("Here");
 | |
| 					if (st.Indent == xn2Text.Indent)
 | |
| 					{
 | |
| 						return key;
 | |
| 					}
 | |
| 					if(xn2Text.Tab != "" && Math.Abs(st.Indent - xn2Text.Indent) > 1)
 | |
| 						Console.WriteLine("\"Wrong Indent\"\t\"{0}\"\t{1}\t{2}\t{3}\t\"{4}\"\t\"{5}\"\t\"{6}\"",_StepLocation,_StepID, st.Indent, xn2Text.Indent, st.Tab, xn2Text.Tab, xn2Text.Text);
 | |
| 				}
 | |
| 				if (key > maxkey) maxkey = key;
 | |
| 				i++;
 | |
| 			}
 | |
| 			i = 0; 
 | |
| 			foreach (int key in lastStepText.Keys) //Look for an indent match
 | |
| 			{
 | |
| 				StepText st = lastStepText[key];
 | |
| 				if (st.Indent == xn2Text.Indent)
 | |
| 				{
 | |
| 					//Console.WriteLine("\"=\"\t{0}\t{1}\t{2}\t\"{3}\"\t\"{4}\"", i, st.Indent, xn2Text.Indent, st.Tab, xn2Text.Tab);
 | |
| 					//Console.WriteLine("{0}\t\"{1}\"\t\"{2}\"", i, st.Tab, xn2Text.Tab);
 | |
| 					if (NextTab(st.Tab) == xn2Text.Tab)
 | |
| 					{
 | |
| 						//if (st.Tab != "*" && st.Tab != "")
 | |
| 						//	Console.WriteLine("Here");
 | |
| 						return key;
 | |
| 					}
 | |
| 					if (IsFirstTab(xn2Text.Tab))
 | |
| 						return key + 1;
 | |
| 					// Partial Indent Match 
 | |
| 					Console.WriteLine("\"Wrong Tab\"\t\"{0}\"\t{1}\t{2}\t{3}\t\"{4}\"\t\"{5}\"\t\"{6}\"", _StepLocation, _StepID, st.Indent, xn2Text.Indent, st.Tab, xn2Text.Tab, xn2Text.Text);
 | |
| 					return key;
 | |
| 				}
 | |
| 				if (key > maxkey) maxkey = key;
 | |
| 				i++;
 | |
| 			}
 | |
| 			i = 0;
 | |
| 			foreach (int key in lastStepText.Keys) // Close Indent Match
 | |
| 			{
 | |
| 				StepText st = lastStepText[key];
 | |
| 				if (st.Indent + 1 == xn2Text.Indent)
 | |
| 				{
 | |
| 					//Console.WriteLine("\">\"\t{0}\t{1}\t{2}\t\"{3}\"\t\"{4}\"", i, st.Indent, xn2Text.Indent, st.Tab, xn2Text.Tab);
 | |
| 					if (xn2Text.Tab == "") return i+1;
 | |
| 					return key;
 | |
| 				}
 | |
| 
 | |
| 				if (st.Indent - 1 == xn2Text.Indent)
 | |
| 				{
 | |
| 					//Console.WriteLine("\"<\"\t{0}\t{1}\t{2}\t\"{3}\"\t\"{4}\"", i, st.Indent, xn2Text.Indent, st.Tab, xn2Text.Tab);
 | |
| 					if (xn2Text.Tab == "") return i+1;
 | |
| 					return key;
 | |
| 				}
 | |
| 				i++;
 | |
| 			}
 | |
| 			if (IsFirstTab(xn2Text.Tab))
 | |
| 				return maxkey+1;
 | |
| 			Console.WriteLine("\"First Not First\"\t\"{0}\"\t{1}\t{2}\t{3}\t\"{4}\"\t\"{5}\"\t\"{6}\"", _StepLocation, _StepID, "", xn2Text.Indent, "", xn2Text.Tab, xn2Text.Text);
 | |
| 			return maxkey + 1;
 | |
| 		}
 | |
| 
 | |
| 		private static string BuildHTMLLibDoc(XmlNode xn, string xmlbase)
 | |
| 		{
 | |
| 			XmlDocument xd1 = new XmlDocument();
 | |
| 			xmlbase = Regex.Replace(xmlbase, "<![^>]+>[\r\n]*", "");
 | |
| 			xmlbase = Regex.Replace(xmlbase, " style=\"\" style=\"", " style=\"");
 | |
| 			string pat = " style=\\\"([^\"]+)\\\" style=\\\"";
 | |
| 			xmlbase = Regex.Replace(xmlbase, pat, " style=\"$1");
 | |
| 			xmlbase = xmlbase.Replace(" src=\".", " src=\"..");
 | |
| 			if (_MyTableFileName == _LastTableFileName)
 | |
| 			{
 | |
| 				FileInfo fi = new FileInfo(_LastName);
 | |
| 				using (StreamReader tr = fi.OpenText())
 | |
| 				{
 | |
| 					string lastContents = tr.ReadToEnd();
 | |
| 					// Merge two HTML documents
 | |
| 					int endLocation = lastContents.IndexOf("</body>");
 | |
| 					int startLocation = xmlbase.IndexOf(">", xmlbase.IndexOf("<body "));
 | |
| 					xmlbase = lastContents.Substring(0, endLocation) + xmlbase.Substring(startLocation + 1);
 | |
| 				}
 | |
| 				fi.Delete();
 | |
| 				_TableNumber++;
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				_TableNumber = 1;
 | |
| 			}
 | |
| 			_LastTableFileName = _MyTableFileName;
 | |
| 			xd1.LoadXml(xmlbase);
 | |
| 			string filename = MakeFileName(xn);
 | |
| 			_LastName = filename;
 | |
| 			xd1.Save(filename);
 | |
| 			return xmlbase;
 | |
| 		}
 | |
| 		private static string MakeFileName(XmlNode xn)
 | |
| 		{
 | |
| 			string filename = _MyTablePrefix + "\\" + GetLibDocName(xn).Replace(".", "").Replace("/", "").Replace("\\.", "") + "_" + _MyTableFileName + "_Table" + string.Format("{0:000}.HTML", _TableNumber);
 | |
| 			return filename;
 | |
| 		}
 | |
| 		private static string GetLibDocName(XmlNode xn)
 | |
| 		{
 | |
| 			while (xn.Name != "Step")
 | |
| 				xn = xn.ParentNode;
 | |
| 			return xn.Attributes["name"].Value;
 | |
| 		}
 | |
| 		private static string _LastTableFileName=null;
 | |
| 		private static int _TableNumber = 0;
 | |
| 		//private static void LoadTable1(XmlNode xn)
 | |
| 		//{
 | |
| 		//	XmlNode xn2 = xn.SelectSingleNode("tr/td/table");
 | |
| 		//	if (xn2 != null) xn = xn2;
 | |
| 		//	//xn.OwnerDocument.Save(filename);
 | |
| 		//	//if (xn.OuterXml.Contains("colspan") || xn.OuterXml.Contains("colspan"))
 | |
| 		//	//	Console.WriteLine("Span");
 | |
| 		//	//XmlNodeList xlr = xn.SelectNodes("tr");
 | |
| 		//	//XmlNodeList xlc = xn.SelectNodes("tr/td");
 | |
| 		//	//XmlNodeList xlrs = xn.SelectNodes("tr/td/@colspan");
 | |
| 		//	//XmlNodeList xlcs = xn.SelectNodes("tr/td/@rowspan");
 | |
| 		//	//Console.WriteLine("{0}\t{1}\t{2}\t{3}", xlr.Count, xlc.Count, sum(xlcs,"colspan"),sum( xlrs,"rowspan"));			
 | |
| 		//	//LoadTable(xn, 0,0,0);
 | |
| 		//}
 | |
| 
 | |
| private static int sum(XmlNodeList xls,string attname)
 | |
| {
 | |
|  	int result = 0;
 | |
| 	if(xls != null && xls.Count > 0)
 | |
| 	foreach(XmlNode xc in xls)
 | |
| 		if(xc is XmlAttribute)
 | |
| 			result += int.Parse(xc.Value);
 | |
| 	return result;
 | |
| }
 | |
| 		//private static void LoadTable(XmlNode xn, int level, int row, int col)
 | |
| 		//{
 | |
| 		//	//if(xn is XmlText)
 | |
| 		//		//Console.WriteLine("T {0}{1}", "".PadLeft(2*level), xn.InnerText);
 | |
| 		//	//else 
 | |
| 		//	if(xn is XmlElement)
 | |
| 		//		foreach(XmlNode xc in xn.ChildNodes)
 | |
| 		//		{
 | |
| 		//			if (xc is XmlElement && xc.Name == "td")
 | |
| 		//			{
 | |
| 		//				col++;
 | |
| 		//				//Console.WriteLine("X {0}{1} CS {2} RS {3}", "".PadLeft(2 * level), xc.Name, GetAttribute(xc, "colspan"), GetAttribute(xc, "rowspan"));
 | |
| 		//			}
 | |
| 		//			else if (xc is XmlElement && xc.Name == "tr")
 | |
| 		//			{
 | |
| 		//				row++;
 | |
| 		//				//Console.WriteLine("X {0}{1}", "".PadLeft(2 * level), xc.Name);
 | |
| 		//			}
 | |
| 		//			else
 | |
| 		//				//Console.WriteLine("X {0}{1}({2},{3})", "".PadLeft(2 * level), xc.Name,row,col);
 | |
| 		//			if (xc is XmlElement && xc.Name == "table")
 | |
| 		//				LoadTable(xc, level + 1, 0, 0);
 | |
| 		//			else
 | |
| 		//				LoadTable(xc, level + 1, row, col);
 | |
| 		//		}
 | |
| 		//}
 | |
| 		private static string GetAttribute(XmlNode xc, string attName)
 | |
| 		{
 | |
| 			string retval = null;
 | |
| 			XmlAttribute xa = xc.Attributes[attName];
 | |
| 			if (xa != null)
 | |
| 				retval = xa.Value;
 | |
| 			return retval;
 | |
| 		}
 | |
| 		private static string StripQuestion(string str)
 | |
| 		{
 | |
| 			string tmp = Regex.Replace(str, @"^(Is|Are|Has|Does|Did|Can|Do|Was|Were) (.+)\?$", "VERIFY $2");
 | |
| 			//if (tmp != str)
 | |
| 			//	tmp = tmp.Substring(0, 1).ToUpper() + tmp.Substring(1);
 | |
| 			return tmp;
 | |
| 		}
 | |
| 		private static Regex _RegRemoveLineBreaks = new Regex(@"\\line +", RegexOptions.Compiled);
 | |
| 		private static StepText FixText(XmlNode xn)
 | |
| 		{
 | |
| 			if (xn == null) return null;
 | |
| 			string str = xn.InnerText;
 | |
| 			//if (str.Contains("may be exited when ANY of the following conditions"))
 | |
| 			//	Console.WriteLine("here");
 | |
| 			// TODO Remove Tab Numbers
 | |
| 			//str = Regex.Replace(xn.InnerText, "[A-Z0-9]+[.)] +", "");
 | |
| 			//str = str.Trim(" \t".ToCharArray());
 | |
| 			//str = Regex.Replace(str, " +", " ");
 | |
| 			str = _RegRemoveLineBreaks.Replace(str, " ");
 | |
| 			//if (str.Contains("The diagnosis of a SGTR is NOT confirmed"))
 | |
| 			//	Console.WriteLine("here");
 | |
| 			return new StepText(str);
 | |
| 			//RHM return Regex.Replace(str, "^(NOTE|NOTE CONTINUED|CAUTION|WARNING)$", "");
 | |
| 		}
 | |
| 		private static ItemInfo GetFirstNote(ItemInfo myItemInfo)
 | |
| 		{
 | |
| 			if (myItemInfo.Notes != null && myItemInfo.Notes.Count > 0)
 | |
| 				return StepInfo.Get(myItemInfo.Notes[0].LastSibling.ItemID);
 | |
| 			return null;
 | |
| 		}
 | |
| 		private static ItemInfo GetFirstCaution(ItemInfo myItemInfo)
 | |
| 		{
 | |
| 			if (myItemInfo.Cautions != null && myItemInfo.Cautions.Count > 0)
 | |
| 				return StepInfo.Get(myItemInfo.Cautions[0].LastSibling.ItemID);
 | |
| 			return null;
 | |
| 		}
 | |
| 		private static void BuildMySteps(StepInfo step, StepLookup mySteps)
 | |
| 		{
 | |
| 			if ((step.ActiveParent as ItemInfo).IsStep)
 | |
| 			{
 | |
| 				BuildMySteps(step.ActiveParent as StepInfo, mySteps);
 | |
| 				mySteps.AddOne(step);
 | |
| 			}
 | |
| 			else
 | |
| 				mySteps[0] = step;
 | |
| 		}
 | |
| 		private static void ListMySteps(string str, StepLookup mySteps)
 | |
| 		{
 | |
| 			int i = 0;
 | |
| 			foreach (string key in mySteps.Keys)
 | |
| 			{
 | |
| 				//if (key != i.ToString())
 | |
| 				Console.WriteLine("{0} {1} {2} {3}", str, i, key, mySteps[key].ToString());
 | |
| 				i++;
 | |
| 			}
 | |
| 		}
 | |
| 		public static Step MakeCSLAStep(StepLookup mySteps, int level, string stepNumber, string stepText, int stepType, E_FromType fromType)
 | |
| 		{
 | |
| 			if (mySteps.Count < level)
 | |
| 			{
 | |
| 				//Console.WriteLine("StepText + '{0}", stepText);
 | |
| 				level = mySteps.Count;
 | |
| 				//throw (new Exception("Error Making Step - null parent and previous"));
 | |
| 			}
 | |
| 			try
 | |
| 			{
 | |
| 				//if (mySteps.Count > 1 && mySteps[0].Ordinal == 5 && mySteps[level - 1].IsCautionOrNotePart)
 | |
| 				//	Console.WriteLine("Here");
 | |
| 				if (level < 1) level = 1;
 | |
| 				if (stepType == 20002)
 | |
| 				{
 | |
| 					if (mySteps[level - 1] != null && mySteps[level - 1].MyContent.Type == 20002)
 | |
| 						stepType = 20001;
 | |
| 					else if (mySteps[level] != null && mySteps[level].MyContent.Type == 20002)
 | |
| 						Console.WriteLine("Oops");
 | |
| 				}
 | |
| 				else if (stepType == 20001)
 | |
| 				{
 | |
| 					if (mySteps[level] != null && mySteps[level].MyContent.Type == 20002)
 | |
| 						stepType = 20002;
 | |
| 				}
 | |
| 				using (Step stp = MakeNewStep(mySteps[level - 1], mySteps[level], stepNumber, stepText, stepType, fromType))
 | |
| 				{
 | |
| 					stp.Save();
 | |
| 					StepInfo si = mySteps[level] = StepInfo.Get(stp.ItemID);
 | |
| 					CheckHLS(si, "Case 6");
 | |
| 					_StepLocation = si.ShortPath;
 | |
| 					_StepID = si.ItemID;
 | |
| 					//if (stp.ItemID >= 10079 && stp.ItemID <= 10089)
 | |
| 					//	Console.WriteLine("{0} - {1} - {2}", si.ItemID, si.DisplayText, si.ShortPath);
 | |
| 					return stp;
 | |
| 				}
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				throw (new Exception("Error Making Step"));
 | |
| 			}
 | |
| 		}
 | |
| 		private static void RemoveStepsAbove(StepLookup mySteps, int level)
 | |
| 		{
 | |
| 			List<string> removeList = new List<string>();
 | |
| 			foreach (string key in mySteps.Keys)
 | |
| 				if (int.Parse(key) > level)
 | |
| 					removeList.Add(key);
 | |
| 			foreach (string k in removeList)
 | |
| 				mySteps.Remove(k);
 | |
| 			//ListMySteps("RemoveStepsAbove", mySteps);
 | |
| 		}
 | |
| 		private static XmlNode NextNode(XmlNode xn2, string nodeName)
 | |
| 		{
 | |
| 			while (xn2 != null)
 | |
| 			{
 | |
| 				xn2 = xn2.NextSibling;
 | |
| 				if (xn2 == null) return null;
 | |
| 				if (xn2.Name == nodeName) return xn2;
 | |
| 			}
 | |
| 			return null;
 | |
| 		}
 | |
| 		private static XmlNode PreviousNode(XmlNode xn2, string nodeName)
 | |
| 		{
 | |
| 			while (xn2 != null)
 | |
| 			{
 | |
| 				xn2 = xn2.PreviousSibling;
 | |
| 				if (xn2 == null) return null;
 | |
| 				if (xn2.Name == nodeName) return xn2;
 | |
| 			}
 | |
| 			return null;
 | |
| 		}
 | |
| 		private void AddStep(SectionInfo prevSection, XmlNodeList xl)
 | |
| 		{
 | |
| 			StepLookup mySteps = new StepLookup();
 | |
| 			pbStep.Value = 0;
 | |
| 			pbStep.Maximum = xl.Count;
 | |
| 			foreach (XmlNode xn in xl)
 | |
| 			{
 | |
| 				pbStep.Value++;
 | |
| 				Application.DoEvents();
 | |
| 				using (Step step = MakeNewStep(prevSection, mySteps[0], null, xn.Attributes["name"].Value, 20002, E_FromType.Step))
 | |
| 				{
 | |
| 					//if (step.ItemID == 9408)
 | |
| 					//	Console.WriteLine("Here");
 | |
| 					//if (xn.Name == "UnitaryContingencyCallInstruction")
 | |
| 					//{
 | |
| 					//	string key = xn.Attributes["number"].Value;
 | |
| 					//	MyContingencies.Add((1 + MyContingencies.Count).ToString(), step.ItemID);
 | |
| 					//}
 | |
| 					MyContingencies.Clear();
 | |
| 					step.Save();
 | |
| 					mySteps[0] = StepInfo.Get(step.ItemID);
 | |
| 					CheckHLS(mySteps[0], "Case 7");
 | |
| 					_StepLocation = mySteps[0].ShortPath;
 | |
| 					_StepID = mySteps[0].ItemID;
 | |
| 					lblStep.Text = "Step " + mySteps[0].Ordinal.ToString();
 | |
| 					Application.DoEvents();
 | |
| 					AddStepStucture(mySteps, 0, xn);
 | |
| 					if (MyContingencies.Count > 0) Console.WriteLine("{0} Contingencies not processed", MyContingencies.Count);
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private static Dictionary<string, int> _MyContingencies = new Dictionary<string, int>();
 | |
| 		public static Dictionary<string, int> MyContingencies
 | |
| 		{
 | |
| 			get { return frmConvertXML._MyContingencies; }
 | |
| 			set { frmConvertXML._MyContingencies = value; }
 | |
| 		}
 | |
| 		private static void AddStepStucture(StepLookup mySteps, int level, XmlNode xn)
 | |
| 		{
 | |
| 			AddStepStucture(mySteps, level, xn, true);
 | |
| 		}
 | |
| 		private static void AddStepStucture(StepLookup mySteps, int level, XmlNode xn, bool addContent)
 | |
| 		{
 | |
| 			//if (mySteps.Count > 0 && mySteps[0].ToString().StartsWith("5"))
 | |
| 			//ListMySteps("AddStepStructure", mySteps);
 | |
| 			if (xn.Name != "JoinInstruction" && xn.Attributes["content"] != null && xn.Attributes["content"].Value != "")
 | |
| 			{
 | |
| 				//if (xn.Attributes["content"].InnerText.Contains("the time of this procedure entry"))
 | |
| 				//	Console.WriteLine("here");
 | |
| 				if (level == -1 && xn.Name != "NoteInstruction" && xn.Name != "CautionInstruction")
 | |
| 					level = 0;
 | |
| 				if(addContent)
 | |
| 				{
 | |
| 					_LastStepText.Clear();
 | |
| 					AddContent(null, mySteps, level, xn, false);
 | |
| 				}
 | |
| 				if (level != mySteps.Count && xn.ParentNode.Name == "Contingency")
 | |
| 					level = mySteps.Count;
 | |
| 				if (xn.Name == "UnitaryContingencyCallInstruction")
 | |
| 				{
 | |
| 					if (level == 1)
 | |
| 					{
 | |
| 						string key = xn.Attributes["number"].Value;
 | |
| 						MyContingencies.Add((1 + MyContingencies.Count).ToString(), mySteps[mySteps.Count - 1].ItemID);
 | |
| 						//ListMyContingencies(string.Format("Parent Count={0} number={1} linkTarget={2}", MyContingencies.Count, key, xn.Attributes["linkTarget"].Value));
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 			string lastNodeName = "";
 | |
| 			foreach (XmlNode xn1 in xn.ChildNodes)
 | |
| 			{
 | |
| 				// ChildNodes can contain XmlText as well as XmlElement nodes
 | |
| 				if (xn1 is XmlElement)
 | |
| 				{
 | |
| 					//if (mySteps.Count > 0 && mySteps[0].Ordinal==5)
 | |
| 					//	ListMySteps(string.Format("AddStepStructure {0}",xn1.Name), mySteps);
 | |
| 					if (xn1.Name == "BoolVarInputItem" || xn1.Name == "TextVarInputItem")
 | |
| 						level = mySteps.Count - 1;
 | |
| 					//else 
 | |
| 					if (lastNodeName != xn1.Name && xn1.ParentNode.Name != "Contingency")// RHM 20181018
 | |
| 						RemoveStepsAbove(mySteps, level);
 | |
| 					lastNodeName = xn1.Name;
 | |
| 					if (xn1.Name == "JoinInstruction")
 | |
| 					{
 | |
| 						AddStepStucture(mySteps, level, xn1);
 | |
| 					}
 | |
| 					else if (xn1.Name == "UnitaryContingencyCallInstruction")
 | |
| 					{
 | |
| 						AddStepStucture(mySteps, level + 1, xn1);
 | |
| 						string key = xn1.Attributes["number"].Value;
 | |
| 						if (level != 0)
 | |
| 						{
 | |
| 							MyContingencies.Add((1 + MyContingencies.Count).ToString(), mySteps[level + 1].ItemID);
 | |
| 							//ListMyContingencies(string.Format("Child count={0} number={1} linkTarget={2}", MyContingencies.Count, key, xn1.Attributes["linkTarget"].Value));
 | |
| 						}
 | |
| 					}
 | |
| 					else if (xn1.Name == "taskGroup")
 | |
| 					{
 | |
| 						XmlNodeList xl = xn1.SelectNodes(".//x:ovationGraphic",_NSMGR);
 | |
| 						if (xl.Count > 0)
 | |
| 						{
 | |
| 							//Add CPSData annotation for Display
 | |
| 							StringBuilder sb = new StringBuilder();
 | |
| 							sb.AppendFormat                         ("<CPSData>");
 | |
| 							int i = 0;
 | |
| 							foreach (XmlNode xnog in xl)
 | |
| 							{
 | |
| 								sb.AppendFormat("<display number='{0}'>", ++i);
 | |
| 								sb.AppendFormat("<identifier>{0}</identifier>", GetAttribute(xnog, "diagramNumber"));
 | |
| 								sb.AppendFormat("<description>{0}</description>", GetAttribute(xnog, "title"));
 | |
| 								sb.AppendFormat("</display>");
 | |
| 							}
 | |
| 							sb.AppendLine("</CPSData>");
 | |
| 							if (mySteps.Count > 0)
 | |
| 							{
 | |
| 								using (Item itm = mySteps[mySteps.Count - 1].Get())
 | |
| 									Annotation.MakeAnnotation(itm, AnnotationType.GetByNameOrCreate("CPS Data"), null, sb.ToString(), sb.ToString());
 | |
| 							}
 | |
| 						}
 | |
| 						if (xn1.Attributes["name"].Value != "") AddTaskGroup(mySteps, level + 1, xn1);
 | |
| 						else AddStepStucture(mySteps, level, xn1);
 | |
| 					}
 | |
| 					else if (xn1.Name == "row")
 | |
| 					{
 | |
| 						AddStepStucture(mySteps, level, xn1);
 | |
| 					}
 | |
| 					else if (xn1.Name == "BoolVarInputItem")
 | |
| 					{
 | |
| 						AddBoolVar(mySteps, level, xn1);
 | |
| 					}
 | |
| 					else if (xn1.Name == "TextVarInputItem")
 | |
| 					{
 | |
| 						AddTextVar(mySteps, level+1, xn1);
 | |
| 					}
 | |
| 					else if (xn1.Name == "Contingency")
 | |
| 					{
 | |
| 						string key = xn1.Attributes["number"].Value;
 | |
| 						//Console.WriteLine("Try to use contingency {0}", key);
 | |
| 						if (_MyContingencies.Count > 0)
 | |
| 						{
 | |
| 							if (ContingencyStep != null)
 | |
| 								Console.WriteLine("Not Processed");
 | |
| 							ContingencyStep = StepInfo.Get(MyContingencies[key]);
 | |
| 							if (ContingencyStep == null)
 | |
| 							{
 | |
| 								Console.WriteLine("Could not find contingency");
 | |
| 							}
 | |
| 							else
 | |
| 							{
 | |
| 								//Console.WriteLine("Contingency + {0}", ContingencyStep);
 | |
| 							}
 | |
| 							MyContingencies.Remove(key);
 | |
| 							//ListMyContingencies(string.Format("Remove number {0}", key));
 | |
| 							AddStepStucture(mySteps, Math.Min(level + 1, mySteps.Count), xn1);
 | |
| 						}
 | |
| 						else
 | |
| 						{
 | |
| 							Console.WriteLine("No Contingencies left");
 | |
| 						}
 | |
| 					}
 | |
| 					else
 | |
| 					{
 | |
| 						if (xn1.Name == "NoteInstruction" || xn1.Name == "CautionInstruction")
 | |
| 						{
 | |
| 							StepLookup stack = CloneSteps(mySteps);
 | |
| 							//if (mySteps.Count > 0 && mySteps[0].ToString().StartsWith("5"))
 | |
| 							//	ListMySteps("AddStepStructure Before ", mySteps);
 | |
| 							mySteps[0] = mySteps[0];
 | |
| 							AddStepStucture(mySteps, 1, xn1);
 | |
| 							foreach (string key in stack.Keys)
 | |
| 								mySteps[key] = stack[key];
 | |
| 							//if (mySteps.Count > 0 && mySteps[0].ToString().StartsWith("5"))
 | |
| 							//	ListMySteps("AddStepStructure After", mySteps);
 | |
| 						}
 | |
| 						else
 | |
| 							AddStepStucture(mySteps, Math.Min(level + 1, mySteps.Count), xn1);
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 			//if (mySteps.Count > 0 && mySteps[0].ToString().StartsWith("5"))
 | |
| 			//	ListMySteps("AddStepStructure", mySteps);
 | |
| 		}
 | |
| 		private static StepLookup CloneSteps(StepLookup mySteps)
 | |
| 		{
 | |
| 			StepLookup sl = new StepLookup();
 | |
| 			foreach (string key in mySteps.Keys)
 | |
| 				sl.Add(key, mySteps[key]);
 | |
| 			return sl;
 | |
| 		}
 | |
| 		private static void ListMyContingencies(string name)
 | |
| 		{
 | |
| 			Console.WriteLine("contingencies - {0}", name);
 | |
| 			foreach (string key in MyContingencies.Keys)
 | |
| 				Console.WriteLine("{0}\t{1}", key, MyContingencies[key]);
 | |
| 		}
 | |
| 		private static void AddBoolVar(StepLookup mySteps, int level, XmlNode xn1)
 | |
| 		{
 | |
| 			if(xn1.Attributes["varInputReadOnly"].Value == "false")
 | |
| 				using (Step step = MakeCSLAStep(mySteps, level, null, xn1.Attributes["varInputLabel"].Value + "  True __ / False __", 20011, E_FromType.Step)) { ;}
 | |
| 			else
 | |
| 				using (Step step = MakeCSLAStep(mySteps, level, null, xn1.Attributes["varInputLabel"].Value, 20011, E_FromType.Step)) { ;}
 | |
| 		}
 | |
| 		private static void AddTextVar(StepLookup mySteps, int level, XmlNode xn1)
 | |
| 		{
 | |
| 			using (Step step = MakeCSLAStep(mySteps, level, null, xn1.Attributes["varInputLabel"].Value +"  ____________", 20011, E_FromType.Step)) { ;}
 | |
| 		}
 | |
| 		private static void AddTaskGroup(StepLookup mySteps, int level, XmlNode xn1)
 | |
| 		{
 | |
| 			if (level > mySteps.Count) level = mySteps.Count;
 | |
| 			using (Step step = MakeCSLAStep(mySteps, level, null, xn1.Attributes["name"].Value, 20024, E_FromType.Step)) { ;}
 | |
| 			AddStepStucture(mySteps, level, xn1);
 | |
| 		}
 | |
| 		private void AddAttachments(SectionInfo parentSection, XmlNodeList xl, XmlNamespaceManager nsmgr)
 | |
| 		{
 | |
| 			SectionInfo prevSection = null;
 | |
| 			foreach (XmlNode xn in xl)
 | |
| 			{
 | |
| 				string config = null;
 | |
| 				int type ;
 | |
| 				if(HasContingency(xn))
 | |
| 				{
 | |
| 					type=10002;
 | |
| 				}
 | |
| 				else
 | |
| 				{
 | |
| 					type = 10008;
 | |
| 					config ="<Config><Section ColumnMode=\"1\" /></Config>";
 | |
| 				}
 | |
| 				using (Section sect = Section.MakeSection(parentSection, prevSection, "Attachment " + xn.Attributes["number"].Value, xn.Attributes["name"].Value,  type))
 | |
| 				{
 | |
| 					if(config != null)
 | |
| 					{
 | |
| 						sect.MyContent.Config = config;
 | |
| 						sect.Save();
 | |
| 					}
 | |
| 					prevSection = SectionInfo.Get(sect.ItemID);
 | |
| 					//AddStepChildren(nsmgr, prevSection, xn.ChildNodes);
 | |
| 					//Console.WriteLine("{0} - {1}", prevSection.ShortPath, xn.OuterXml);
 | |
| 					_MyTableFileName = parentSection.MyProcedure.DisplayNumber + "_"
 | |
| 						+ parentSection.DisplayNumber + prevSection.DisplayNumber;
 | |
| 					//if (GetSectionStyle(xn) == "Free Form")
 | |
| 						AddPSEC(prevSection, xn.ChildNodes);
 | |
| 					//else
 | |
| 					//	AddStep(prevSection, xn.ChildNodes);
 | |
| 					_MyTableFileName = null;
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private static string _MyTableFileName;
 | |
| 		private void btnBrowse_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			ofd.FileName = tbFile.Text;
 | |
| 			if (ofd.ShowDialog() == DialogResult.OK)
 | |
| 				tbFile.Text = ofd.FileName;
 | |
| 		}
 | |
| 		private void btnAll_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			if (_MyFlexGrid == null)
 | |
| 			{
 | |
| 				_MyFlexGrid = new VlnFlexGrid();
 | |
| 				this.Controls.Add(_MyFlexGrid);
 | |
| 				_MyFlexGrid.Location = tbResults.Location;
 | |
| 				_MyFlexGrid.Size = tbResults.Size;
 | |
| 				_MyFlexGrid.BringToFront();
 | |
| 
 | |
| 			}
 | |
| 
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				_ProcNum = GetProcedureNumber(chld.FullName);
 | |
| 				XML2PROMSDB(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			lblStep.Text = "Step";
 | |
| 			lblSection.Text = "Section";
 | |
| 			lblProcedure.Text = "Procedure";
 | |
| 			tbResults.AppendText("\r\n\r\n Done\r\n");
 | |
| 		}
 | |
| 		private void btnAllStructure_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			tbResults.Clear();
 | |
| 			Node.Reset();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				LoadStructure(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			tbResults.Clear();
 | |
| 			ShowStructure2();
 | |
| 		}
 | |
| 
 | |
| 		private void btnAllStructure2_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			tbResults.Clear();
 | |
| 			Node.Reset();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				LoadStructure(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			tbResults.Clear();
 | |
| 			ShowStructure();
 | |
| 		}
 | |
| 
 | |
| 		private void btnAllContent_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			tbResults.Text = "";
 | |
| 			Node.Reset();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			FileInfo [] children = fi.Directory.GetFiles("*.xml");
 | |
| 			pbProcs.Maximum = children.Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in children)
 | |
| 			{
 | |
| 				if (!chld.Name.StartsWith("._"))
 | |
| 				{
 | |
| 					tbResults.AppendText("\r\n" + chld.FullName);
 | |
| 					GetAllContents(chld.FullName);
 | |
| 					pbProcs.Value++;
 | |
| 					Application.DoEvents();
 | |
| 				}
 | |
| 			}
 | |
| 			tbResults.AppendText("\r\nDone");
 | |
| 		}
 | |
| 
 | |
| 		private void GetAllContents(string fileName)
 | |
| 		{
 | |
| 			FileInfo fi = new FileInfo(fileName);
 | |
| 			FileInfo fo = new FileInfo(fi.DirectoryName + "\\" + GetProcedureNumber(fileName) + ".txt");
 | |
| 			GetAllContents(fi, fo);
 | |
| 		}
 | |
| 
 | |
| 		private void GetAllContents(FileInfo fi, FileInfo fo)
 | |
| 		{
 | |
| 			StreamWriter sw = fo.CreateText();
 | |
| 			LoadXml(fi.FullName, "Document Loaded");
 | |
| 			ShowAllContent(MyXMLDoc.DocumentElement, 0, sw);
 | |
| 			sw.Close();
 | |
| 		}
 | |
| 
 | |
| 		private void ShowAllContent(XmlElement xe, int level, StreamWriter sw)
 | |
| 		{
 | |
| 			ShowContent(xe, level, sw);
 | |
| 			foreach (XmlNode ch in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (ch is XmlElement)
 | |
| 					ShowAllContent(ch as XmlElement, level + 1, sw);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void ShowContent(XmlElement xe, int level, StreamWriter sw)
 | |
| 		{
 | |
| 			string format = "Not Defined";
 | |
| 			string prefix = "  ";
 | |
| 			switch (xe.Name)
 | |
| 			{
 | |
| 				case "ident":
 | |
| 					format = "Procedure (LabelType-number)={labelType}-{number} fullName={fullName} PNSNo={PNSNo}";
 | |
| 					break;
 | |
| 				case "type":
 | |
| 					format = "Procedure Type: {procedureType}";
 | |
| 					break;
 | |
| 				case "GrossStep":
 | |
| 					format = "number={number} name={name}";
 | |
| 					break;
 | |
| 				case "Step":
 | |
| 					format = "{number} {name}";
 | |
| 					prefix = "S ";
 | |
| 					break;
 | |
| 				case "Contingency":
 | |
| 					format = "{number} {name}";
 | |
| 					prefix = "C ";
 | |
| 					break;
 | |
| 				case "attrib":
 | |
| 				case "procedure":
 | |
| 				case "controllers":
 | |
| 				case "row":
 | |
| 					format = "";// No Content
 | |
| 					break;
 | |
| 				case "CautionInstruction":
 | |
| 				case "NoteInstruction":
 | |
| 					format = "number={number} {content}";
 | |
| 					break;
 | |
| 				case "UnitaryInstruction":
 | |
| 				case "BinaryInstruction":
 | |
| 					format = "number={number} Left Target: {leftTarget} Link Target: {linkTarget} {content}";
 | |
| 					break;
 | |
| 				case "JoinInstruction":
 | |
| 					format = "Link Target: {linkTarget} JoinType: {joinType}";
 | |
| 					break;
 | |
| 				case "UnitaryContingencyCallInstruction":
 | |
| 					format = "number={number} Link Target: {linkTarget} Evaluation Type: {evaluationType} {content}";
 | |
| 					prefix = "U ";
 | |
| 					break;
 | |
| 				case "taskGroup":
 | |
| 					format = "name={name} borderVisible={borderVisible}";
 | |
| 					break;
 | |
| 				case "BoolVarInputItem":
 | |
| 					format = "varInputLabel={varInputLabel} Data Point: {varInputDataPoint}";
 | |
| 					break;
 | |
| 				case "TextVarInputItem":
 | |
| 					format = "varInputLabel={varInputLabel} Data Point: {varInputDataPoint}";
 | |
| 					break;
 | |
| 				case "ovationGraphic":
 | |
| 					format = "title={title} Diagram Number: {diagramNumber}";
 | |
| 					break;
 | |
| 				case "ovationGroupTrend":
 | |
| 					format = "name={name} description={description}";
 | |
| 					break;
 | |
| 				case "controller":
 | |
| 					format = "controller - Unknown";
 | |
| 					break;
 | |
| 				case "and":
 | |
| 					format = "and id={id}";
 | |
| 					break;
 | |
| 				case "BigOverview":
 | |
| 					format = "BigOverview grossStep={grossStep} number={number} id={id}";
 | |
| 					break;
 | |
| 				case "BovActionStep":
 | |
| 					format = "column={column}	number={number} linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovCheckBox":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovIfStep":
 | |
| 					format = "column={column}	number={number} linkTarget={linkTarget} group={group} id={id} name={name} label={label} rightTarget={rightTarget} {content}";
 | |
| 					break;
 | |
| 				case "BovMessageBox":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovProcedureLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovStepInLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovStepOutLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "descr":
 | |
| 				case "esinfo":
 | |
| 				case "esproj":
 | |
| 				case "esprop":
 | |
| 				case "private":
 | |
| 				case "pwg":
 | |
| 				case "pwt":
 | |
| 				case "revbase":
 | |
| 				case "systemtest":
 | |
| 					format = "";
 | |
| 					break;
 | |
| 				case "eq":
 | |
| 				case "gt":
 | |
| 				case "gte":
 | |
| 				case "lt":
 | |
| 				case "lte":
 | |
| 				case "not":
 | |
| 				case "or":
 | |
| 					format = "id={id}";
 | |
| 					break;
 | |
| 				case "fcase":
 | |
| 				case "tcase":
 | |
| 					format = "rst={rst}";
 | |
| 					break;
 | |
| 				case "logic":
 | |
| 					format = "id={id} number={number}";
 | |
| 					break;
 | |
| 				case "ovationSingleTrend":
 | |
| 					format = "description={description} number={number} id={id} name={name}";
 | |
| 					break;
 | |
| 				case "prop":
 | |
| 					format = "type={type} value={value} name={name}";
 | |
| 					break;
 | |
| 				case "TextVarInputInstruction":
 | |
| 					format = "taskDescription={taskDescription} varInputLabel={varinputLabel} number={number} {content}";
 | |
| 					break;
 | |
| 				case "utest":
 | |
| 					format = "tested={tested}";
 | |
| 					break;
 | |
| 				case "var":
 | |
| 					format = "var_type={var_type} id={id} name={name} number={number}";
 | |
| 					break;
 | |
| 				case "const":
 | |
| 					format = "var_type={var_type} id={id} value={value}";
 | |
| 					break;
 | |
| 			}
 | |
| 			sw.Write(string.Format("\r\n{0}{1}{2} ", prefix, "".PadRight(level, ' ').Replace(" ", "| "), xe.Name));
 | |
| 			sw.Write(ReplaceAllAttributes(format, xe, level, prefix));
 | |
| 		}
 | |
| 
 | |
| 		private void btnHTML_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			tbResults.Clear();
 | |
| 			Node.Reset();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				LoadStructure3(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			tbResults.Clear();
 | |
| 			ShowStructure();
 | |
| 		}
 | |
| 
 | |
| 		private void LoadStructure3(string fileName)
 | |
| 		{
 | |
| 			LoadXml(fileName, null);
 | |
| 			//Find Content Attributes
 | |
| 			LoadStructure3(MyXMLDoc.DocumentElement);
 | |
| 		}
 | |
| 		private void LoadStructure3(XmlElement xe)
 | |
| 		{
 | |
| 			LoadStructure3Content(xe);
 | |
| 			foreach (XmlNode xn in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (xn is XmlElement)
 | |
| 					LoadStructure3(xn as XmlElement);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void LoadStructure3Content(XmlElement xn)
 | |
| 		{
 | |
| 			if (xn.Attributes["content"] != null)
 | |
| 			{
 | |
| 				string xml = cleanupHTML(xn.Attributes["content"].Value, 0);
 | |
| 				if (xml == string.Empty) return;
 | |
| 				if (xml.Replace(" ", "") == xn.Name) return;
 | |
| 
 | |
| 				if (!xml.Contains("<"))
 | |
| 				{
 | |
| 					Console.WriteLine("not XML '{0}'", xml);
 | |
| 					xml = "<html><p>" + xml + "</p></html>";
 | |
| 				}
 | |
| 				XmlDocument xd = new XmlDocument();
 | |
| 				xd.LoadXml(xml);
 | |
| 				//xml = xml.Replace("<html>", "<html xmlns='http://www.w3.org/2000/html'>");
 | |
| 				//vlnhtml myHTML = HtmlSerializer<vlnhtml>.StringDeserialize(xml);
 | |
| 				Node.Add(xd.DocumentElement);
 | |
| 			}
 | |
| 		}
 | |
| 		private Dictionary<string, int> _DicHTMLStruct;
 | |
| 
 | |
| 		public Dictionary<string, int> DicHTMLStruct
 | |
| 		{
 | |
| 			get { return _DicHTMLStruct; }
 | |
| 			set { _DicHTMLStruct = value; }
 | |
| 		}
 | |
| 
 | |
| 		private void btnHTML2_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			DicHTMLStruct = new Dictionary<string, int>();
 | |
| 			tbResults.Clear();
 | |
| 			Node.Reset();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				LoadStructure4(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			tbResults.Clear();
 | |
| 			ShowHtmlStructure();
 | |
| 		}
 | |
| 		/// <summary>
 | |
| 		/// Show Count for each structure
 | |
| 		/// </summary>
 | |
| 		private void ShowHtmlStructure()
 | |
| 		{
 | |
| 			tbResults.Text = "";
 | |
| 			foreach (string key in DicHTMLStruct.Keys)
 | |
| 				tbResults.AppendText(string.Format("{0}\t\"{1}\"\r\n", DicHTMLStruct[key], key));
 | |
| 		}
 | |
| 		private void LoadStructure4(string fileName)
 | |
| 		{
 | |
| 			LoadXml(fileName, null);
 | |
| 			//Find Content Attributes
 | |
| 			LoadStructure4(MyXMLDoc.DocumentElement);
 | |
| 		}
 | |
| 		private void LoadStructure4(XmlElement xe)
 | |
| 		{
 | |
| 			LoadStructure4Content(xe);
 | |
| 			foreach (XmlNode xn in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (xn is XmlElement)
 | |
| 					LoadStructure4(xn as XmlElement);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void LoadStructure4Content(XmlElement xn)
 | |
| 		{
 | |
| 			if (xn.Attributes["content"] != null)
 | |
| 			{
 | |
| 				string xml = cleanupHTML(xn.Attributes["content"].Value, 0);
 | |
| 				if (xml == string.Empty) return;
 | |
| 				if (xml.Replace(" ", "") == xn.Name) return;
 | |
| 
 | |
| 				if (!xml.Contains("<"))
 | |
| 				{
 | |
| 					//Console.WriteLine("not XML '{0}'", xml);
 | |
| 					xml = "<html><p>" + xml + "</p></html>";
 | |
| 				}
 | |
| 				XmlDocument xd = new XmlDocument();
 | |
| 				xd.LoadXml(xml);
 | |
| 				XmlAttribute xa = xd.CreateAttribute("type");
 | |
| 				xa.Value = xn.Name;
 | |
| 				xd.DocumentElement.Attributes.Append(xa);
 | |
| 				if (xn.Attributes["number"] != null && xn.Attributes["number"].Value != string.Empty)
 | |
| 				{
 | |
| 					XmlAttribute xa1 = xd.CreateAttribute("number");
 | |
| 					xa1.Value = xn.Attributes["number"].Value;
 | |
| 					if (Regex.IsMatch(xa1.Value, "[0-9]+")) xa1.Value = "#";
 | |
| 					xd.DocumentElement.Attributes.Append(xa1);
 | |
| 				}
 | |
| 
 | |
| 				//AddStructure(GetStructurePath(xd.DocumentElement).Replace("[br]-T",""));
 | |
| 				AddStructure(GetStructurePath(xd.DocumentElement,true));
 | |
| 			}
 | |
| 		}
 | |
| 		private void AddStructure(string mystruct)
 | |
| 		{
 | |
| 			if (!DicHTMLStruct.ContainsKey(mystruct))
 | |
| 				DicHTMLStruct.Add(mystruct, 1);
 | |
| 			else
 | |
| 				DicHTMLStruct[mystruct]++;
 | |
| 		}
 | |
| 		private string GetStructurePath(XmlElement xe, bool removeDuplicates)
 | |
| 		{
 | |
| 			StringBuilder sb = new StringBuilder();
 | |
| 			sb.Append("[" + xe.Name);
 | |
| 			if (xe.Name == "ul")
 | |
| 				sb.Append(GetUlDetail(xe));
 | |
| 			//if (xe.Name == "html")
 | |
| 			//{
 | |
| 			//	sb.Append(" " + xe.Attributes["type"].Value);
 | |
| 			//	if (xe.Attributes["number"] != null && xe.Attributes["number"].Value != string.Empty)
 | |
| 			//		sb.Append(" " + xe.Attributes["number"].Value);
 | |
| 			//}
 | |
| 			if (xe.ChildNodes != null && xe.ChildNodes.Count > 0)
 | |
| 			{
 | |
| 				if (xe.Name != "table")
 | |
| 				{
 | |
| 					foreach (XmlNode xc in xe.ChildNodes)
 | |
| 					{
 | |
| 						if (xc is XmlElement)
 | |
| 							sb.Append(GetStructurePath(xc as XmlElement, removeDuplicates));
 | |
| 						else if (xc is XmlText)
 | |
| 						{
 | |
| 							//Console.WriteLine(xc.Value);
 | |
| 							Match ma = Regex.Match(xc.Value, "^ *(and|or|AND|OR) *$");
 | |
| 							Match mcn = Regex.Match(xc.Value, "^ *(CAUTION|NOTE|WARNING|CAUTIONS|NOTES|WARNINGS|NOTE CONTINUED) *$");
 | |
| 							Match m1 = Regex.Match(xc.Value, "^[0-9]+[\\.\\)] ");
 | |
| 							Match m2 = Regex.Match(xc.Value, "^[A-Z][\\.\\)] ");
 | |
| 							Match m3 = Regex.Match(xc.Value, "^[a-z][\\.\\)] ");
 | |
| 							Match m4 = Regex.Match(xc.Value, "^[-\u2022\u25AA\u25CF]");// Bullets and Dashes
 | |
| 							Match m5 = Regex.Match(xc.Value, "^[^#0-9\\t*(A-Za-z \u00A0\"<>\u2264\\[\uD558\u00B7\u0025\u002F\uF07F\uFF1C\uFF1E\u02C2\u02C3\u203B\u2265\u2267\u2460\u2461\u25AA\u25B2\u25BC\u25CF] ");
 | |
| 							if (mcn.Value != string.Empty)
 | |
| 								sb.Append("-T " + mcn.Value);
 | |
| 							else if (ma.Value != string.Empty)
 | |
| 								sb.Append("-T " + ma.Value);
 | |
| 							else if (m1.Value != string.Empty)
 | |
| 								sb.Append("-T " + m1.Value.Trim());
 | |
| 							else if (m2.Value != string.Empty)
 | |
| 								sb.Append("-T " + m2.Value.Trim());
 | |
| 							else if (m3.Value != string.Empty)
 | |
| 								sb.Append("-T " + m3.Value.Trim());
 | |
| 							else if (m4.Value != string.Empty)
 | |
| 								sb.Append("-T {" + "Bullet " + ((int)(m4.Value[0])).ToString() + "}");
 | |
| 							else if (m5.Value != string.Empty)
 | |
| 								sb.Append("-T {{" + ((int)(m5.Value[0])).ToString() + "}}");
 | |
| 							else sb.Append("-T");
 | |
| 						}
 | |
| 					}
 | |
| 				}
 | |
| 				//else
 | |
| 					//Console.WriteLine("here");
 | |
| 			}
 | |
| 			sb.Append("]");
 | |
| 			RemoveRepeats(sb.ToString(),removeDuplicates);
 | |
| 			return sb.ToString();
 | |
| 		}
 | |
| 		private string GetUlDetail(XmlElement xe)
 | |
| 		{
 | |
| 			XmlAttribute xaType = xe.Attributes["type"];
 | |
| 			XmlAttribute xaStyle = xe.Attributes["style"];
 | |
| 			string type = string.Empty;
 | |
| 			if (xaType != null)
 | |
| 				type = " t" + xaType.Value;
 | |
| 			string indent = string.Empty;
 | |
| 			if (xaStyle != null)
 | |
| 				indent = " i" + Regex.Replace(xaStyle.Value, "^.*-qt-list-indent: ([0-9]+).*$", "$1");
 | |
| 			return type + indent;
 | |
| 		}
 | |
| 		RegexReplace[] MyRegExReplaces = {
 | |
| 																			 new RegexReplace("\\[p-T\\]","[Para]"),
 | |
| 																			 new RegexReplace("\\[p-T OR\\]","[OR]"),
 | |
| 																			 new RegexReplace("\\[p-T AND\\]","[AND]"),
 | |
| 																			 new RegexReplace("\\[p-T NOTE\\]","[NOTE]"),
 | |
| 																			 new RegexReplace("\\[p-T CAUTION\\]","[CAUTION]"),
 | |
| 																			 new RegexReplace("\\[p-T WARNING\\]","[WARNING]"),
 | |
| 																				new RegexReplace("\\[p-T [0-9]+\\.\\]","[Seq1.]"),
 | |
| 																				new RegexReplace("\\[p-T [0-9]+\\)\\]","[Seq1)]"),
 | |
| 																				new RegexReplace("\\[p-T [A-Z]\\.\\]","[SeqA.]"),
 | |
| 																				new RegexReplace("\\[p-T [a-z]\\.\\]","[Seqa.]"),
 | |
| 																				new RegexReplace("\\[li-T\\]","[Li]"),
 | |
| 																				new RegexReplace(" tsquare i1","1"),
 | |
| 																				new RegexReplace(" tsquare i2","2"),
 | |
| 																				new RegexReplace(" tsquare i3","3"),
 | |
| 																				new RegexReplace(" tsquare i4","4"),
 | |
| 																				new RegexReplace("(\\[p\\])+","")
 | |
| 																		 };
 | |
| 		RegexReplace[] MyRegExRepeats = {
 | |
| 																				 new RegexReplace("(\\[Para\\])+","[Para]"),
 | |
| 																			 new RegexReplace("(\\[OR\\])+","[OR]"),
 | |
| 																			 new RegexReplace("(\\[AND\\])+","[AND]"),
 | |
| 																			 new RegexReplace("(\\[NOTE\\])+","[NOTE]"),
 | |
| 																			 new RegexReplace("(\\[CAUTION\\])+","[CAUTION]"),
 | |
| 																			 new RegexReplace("(\\[WARNING\\])+","[WARNING]"),																				new RegexReplace("\\[p-T \\{\u2022\\}\\]","[Bullet]"),	
 | |
| 																			 new RegexReplace("(\\[Bullet\\])+","[Bullet]"),
 | |
| 																			 new RegexReplace("(\\[Seq1\\.\\])+","[Seq1.]"),
 | |
| 																			 new RegexReplace("(\\[Seq1\\)\\])+","[Seq1)]"),
 | |
| 																			 new RegexReplace("(\\[SeqA\\.\\])+","[SeqA.]"),
 | |
| 																			 new RegexReplace("(\\[Seqa\\.\\])+","[Seqa.]"),
 | |
| 																			 new RegexReplace("(\\[Li\\])+","[Li]")
 | |
| };
 | |
| 		private string RemoveRepeats(string str, bool removeDuplicates)
 | |
| 		{
 | |
| 			foreach (RegexReplace rr in MyRegExReplaces)
 | |
| 				str = rr.DoReplace(str);
 | |
| 			if (removeDuplicates)
 | |
| 				foreach (RegexReplace rr in MyRegExRepeats)
 | |
| 					str = rr.DoReplace(str);
 | |
| 			return str;
 | |
| 		}
 | |
| 		private void btnCandN_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			LoadXml(tbFile.Text, "Document Loaded");
 | |
| 			tbResults.Clear();
 | |
| 			FindCandN(MyXMLDoc.DocumentElement);
 | |
| 		}
 | |
| 
 | |
| 		private void FindCandN(XmlElement xe)
 | |
| 		{
 | |
| 			if ((xe.Name == "CautionInstruction" || xe.Name == "NoteInstruction")
 | |
| 				&& (xe.ParentNode as XmlElement).Name == "Step" && AllSiblingsAreCautionsOrNotes(xe))
 | |
| 				tbResults.AppendText(xe.Name
 | |
| 					+ "\t" + (xe.ParentNode as XmlElement).Attributes["name"].Value
 | |
| 					+ "\t" + (xe.ParentNode as XmlElement).Attributes["name"].Value
 | |
| 					+ "\t" + (xe.ParentNode.ParentNode as XmlElement).Attributes["name"].Value
 | |
| 					+ "\r\n");
 | |
| 			foreach (XmlNode xc in xe.ChildNodes)
 | |
| 				if (xc is XmlElement)
 | |
| 					FindCandN(xc as XmlElement);
 | |
| 		}
 | |
| 		private bool AllSiblingsAreCautionsOrNotes(XmlElement xe)
 | |
| 		{
 | |
| 			XmlElement xep = xe.ParentNode as XmlElement;
 | |
| 			if (xep == null) return false;
 | |
| 			foreach (XmlNode xc in xep.ChildNodes)
 | |
| 				if (xc.Name != "CautionInstruction" && xc.Name != "NoteInstruction")
 | |
| 					return false;
 | |
| 			return true;
 | |
| 		}
 | |
| 		private void btnHTLM3_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			MessageBox.Show("Not Implemented", "NA", MessageBoxButtons.OK, MessageBoxIcon.Hand);
 | |
| 		}
 | |
| 		private void btnAllContent2_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			tbResults.Text = "";
 | |
| 			Node.Reset();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				tbResults.AppendText("\r\n" + chld.FullName);
 | |
| 				GetAllContents2(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			tbResults.AppendText("\r\nDone");
 | |
| 		}
 | |
| 		private void GetAllContents2(string fileName)
 | |
| 		{
 | |
| 			FileInfo fi = new FileInfo(fileName);
 | |
| 			FileInfo fo = new FileInfo(fi.DirectoryName + "\\" + GetProcedureNumber(fileName) + ".txt");
 | |
| 			GetAllContents2(fi, fo);
 | |
| 		}
 | |
| 		private void GetAllContents2(FileInfo fi, FileInfo fo)
 | |
| 		{
 | |
| 			StreamWriter sw = fo.CreateText();
 | |
| 			LoadXml(fi.FullName, "Document Loaded");
 | |
| 			ShowAllContent2(MyXMLDoc.DocumentElement, 0, sw);
 | |
| 			sw.Close();
 | |
| 		}
 | |
| 		private void ShowAllContent2(XmlElement xe, int level, StreamWriter sw)
 | |
| 		{
 | |
| 			ShowContent2(xe, level, sw);
 | |
| 			foreach (XmlNode ch in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (ch is XmlElement)
 | |
| 					ShowAllContent2(ch as XmlElement, level + 1, sw);
 | |
| 			}
 | |
| 		}
 | |
| 		private void ShowContent2(XmlElement xe, int level, StreamWriter sw)
 | |
| 		{
 | |
| 			string format = "Not Defined";
 | |
| 			string prefix = "  ";
 | |
| 			switch (xe.Name)
 | |
| 			{
 | |
| 				case "ident":
 | |
| 					format = "Procedure (LabelType-number)={labelType}-{number} fullName={fullName} PNSNo={PNSNo}";
 | |
| 					break;
 | |
| 				case "type":
 | |
| 					format = "Procedure Type: {procedureType}";
 | |
| 					break;
 | |
| 				case "GrossStep":
 | |
| 					format = "number={number} name={name}";
 | |
| 					break;
 | |
| 				case "Step":
 | |
| 					format = "{number} {name}";
 | |
| 					prefix = "S ";
 | |
| 					break;
 | |
| 				case "Contingency":
 | |
| 					format = "{number} {name}";
 | |
| 					prefix = "C ";
 | |
| 					break;
 | |
| 				case "attrib":
 | |
| 				case "procedure":
 | |
| 				case "controllers":
 | |
| 				case "row":
 | |
| 					format = "";// No Content
 | |
| 					break;
 | |
| 				case "CautionInstruction":
 | |
| 				case "NoteInstruction":
 | |
| 					format = "number={number} {content}";
 | |
| 					break;
 | |
| 				case "UnitaryInstruction":
 | |
| 				case "BinaryInstruction":
 | |
| 					format = "number={number} Left Target: {leftTarget} Link Target: {linkTarget} {content}";
 | |
| 					break;
 | |
| 				case "JoinInstruction":
 | |
| 					format = "Link Target: {linkTarget} JoinType: {joinType}";
 | |
| 					break;
 | |
| 				case "UnitaryContingencyCallInstruction":
 | |
| 					format = "number={number} Link Target: {linkTarget} Evaluation Type: {evaluationType} {content}";
 | |
| 					prefix = "U ";
 | |
| 					break;
 | |
| 				case "taskGroup":
 | |
| 					format = "name={name} borderVisible={borderVisible}";
 | |
| 					break;
 | |
| 				case "BoolVarInputItem":
 | |
| 					format = "varInputLabel={varInputLabel} Data Point: {varInputDataPoint}";
 | |
| 					break;
 | |
| 				case "TextVarInputItem":
 | |
| 					format = "varInputLabel={varInputLabel} Data Point: {varInputDataPoint}";
 | |
| 					break;
 | |
| 				case "ovationGraphic":
 | |
| 					format = "title={title} Diagram Number: {diagramNumber}";
 | |
| 					break;
 | |
| 				case "ovationGroupTrend":
 | |
| 					format = "name={name} description={description}";
 | |
| 					break;
 | |
| 				case "controller":
 | |
| 					format = "controller - Unknown";
 | |
| 					break;
 | |
| 				case "and":
 | |
| 					format = "and id={id}";
 | |
| 					break;
 | |
| 				case "BigOverview":
 | |
| 					format = "BigOverview grossStep={grossStep} number={number} id={id}";
 | |
| 					break;
 | |
| 				case "BovActionStep":
 | |
| 					format = "column={column}	number={number} linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovCheckBox":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovIfStep":
 | |
| 					format = "column={column}	number={number} linkTarget={linkTarget} group={group} id={id} name={name} label={label} rightTarget={rightTarget} {content}";
 | |
| 					break;
 | |
| 				case "BovMessageBox":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovProcedureLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovStepInLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "BovStepOutLink":
 | |
| 					format = "column={column}	linkTarget={linkTarget} group={group} id={id} name={name} label={label} {content}";
 | |
| 					break;
 | |
| 				case "descr":
 | |
| 				case "esinfo":
 | |
| 				case "esproj":
 | |
| 				case "esprop":
 | |
| 				case "private":
 | |
| 				case "pwg":
 | |
| 				case "pwt":
 | |
| 				case "revbase":
 | |
| 				case "systemtest":
 | |
| 					format = "";
 | |
| 					break;
 | |
| 				case "eq":
 | |
| 				case "gt":
 | |
| 				case "gte":
 | |
| 				case "lt":
 | |
| 				case "lte":
 | |
| 				case "not":
 | |
| 				case "or":
 | |
| 					format = "id={id}";
 | |
| 					break;
 | |
| 				case "fcase":
 | |
| 				case "tcase":
 | |
| 					format = "rst={rst}";
 | |
| 					break;
 | |
| 				case "logic":
 | |
| 					format = "id={id} number={number}";
 | |
| 					break;
 | |
| 				case "ovationSingleTrend":
 | |
| 					format = "description={description} number={number} id={id} name={name}";
 | |
| 					break;
 | |
| 				case "prop":
 | |
| 					format = "type={type} value={value} name={name}";
 | |
| 					break;
 | |
| 				case "TextVarInputInstruction":
 | |
| 					format = "taskDescription={taskDescription} varInputLabel={varinputLabel} number={number} {content}";
 | |
| 					break;
 | |
| 				case "utest":
 | |
| 					format = "tested={tested}";
 | |
| 					break;
 | |
| 				case "var":
 | |
| 					format = "var_type={var_type} id={id} name={name} number={number}";
 | |
| 					break;
 | |
| 				case "const":
 | |
| 					format = "var_type={var_type} id={id} value={value}";
 | |
| 					break;
 | |
| 			}
 | |
| 			sw.Write(string.Format("\r\n{0}{1}{2} ", prefix, "".PadRight(level, ' ').Replace(" ", "| "), xe.Name));
 | |
| 			sw.Write(ReplaceAllAttributes2(format, xe, level, prefix));
 | |
| 		}
 | |
| 		private string ReplaceAllAttributes2(string format, XmlElement xe, int level, string prefix)
 | |
| 		{
 | |
| 			MatchCollection m;
 | |
| 			while ((m = regFixAttributes.Matches(format)).Count > 0)
 | |
| 			{
 | |
| 				string part1 = format.Substring(0, m[0].Groups[1].Index);
 | |
| 				string part3 = format.Substring(m[0].Groups[1].Index + m[0].Groups[1].Length);
 | |
| 				string att = m[0].Groups[1].Value.Replace("{", "").Replace("}", "");
 | |
| 				XmlAttribute xa = xe.Attributes[att];
 | |
| 				//if (xa == null)
 | |
| 				//	Console.WriteLine(xe.OuterXml);
 | |
| 				string part2;
 | |
| 				if (xa != null)
 | |
| 					part2 = xe.Attributes[att].Value; //GetAttribute(xe, att);
 | |
| 				else
 | |
| 					part2 = "null";
 | |
| 				if (part2 == string.Empty) part2 = "empty";
 | |
| 				if (att == "content")
 | |
| 				{
 | |
| 					if (!part2.Contains("<"))
 | |
| 					{
 | |
| 						part2 = "<html><p>" + part2 + "</p></html>";
 | |
| 					}
 | |
| 					XmlDocument xd = new XmlDocument();
 | |
| 					xd.LoadXml(cleanupHTML(part2,1));
 | |
| 					part2 = GetStructurePath(xd.DocumentElement,false);
 | |
| 					part2 = part2.Replace("\n", string.Format("\r\n  {0}  ", "".PadRight(level).Replace(" ", "| ")));
 | |
| 				}
 | |
| 				format = part1 + part2 + part3;
 | |
| 			}
 | |
| 			return format;
 | |
| 		}
 | |
| 		Dictionary<string, int> _VerbList;
 | |
| 		private void btnVerbs_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			_VerbList = new Dictionary<string, int>();
 | |
| 			tbResults.Clear();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				FindVerbs(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			tbResults.Clear();
 | |
| 			ShowVerbs();
 | |
| 		}
 | |
| 
 | |
| 		private void ShowVerbs()
 | |
| 		{
 | |
| 			foreach (string key in _VerbList.Keys)
 | |
| 				tbResults.AppendText(string.Format("{0}\t\"{1}\"\r\n",_VerbList[key], key));
 | |
| 		}
 | |
| 
 | |
| 		private void FindVerbs(string fileName)
 | |
| 		{
 | |
| 			LoadXml(fileName, null);
 | |
| 			//Find Content Attributes
 | |
| 			FindVerbs(MyXMLDoc.DocumentElement);
 | |
| 		}
 | |
| 
 | |
| 		private void FindVerbs(XmlElement xe)
 | |
| 		{
 | |
| 			FindVerbContent(xe);
 | |
| 			foreach (XmlNode xn in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (xn is XmlElement)
 | |
| 					FindVerbs(xn as XmlElement);
 | |
| 			}
 | |
| 		}
 | |
| 		Regex _regFindSpan = new Regex("<span style=\" font-weight:600;\">([A-Z]+)</span>", RegexOptions.Compiled);
 | |
| 		private void FindVerbContent(XmlElement xn)
 | |
| 		{
 | |
| 			if (xn.Attributes["content"] != null)
 | |
| 			{
 | |
| 				string xml = xn.Attributes["content"].Value;
 | |
| 				if (xml == string.Empty) return;
 | |
| 				if (xml.Replace(" ", "") == xn.Name) return;
 | |
| 				//if (xml.Contains("font-weight:600")) Console.WriteLine("here");
 | |
| 				MatchCollection mc = _regFindSpan.Matches(xml);
 | |
| 				if (mc.Count == 0) return;
 | |
| 				foreach (Match m in mc)
 | |
| 					if (_VerbList.ContainsKey(m.Groups[1].Value))
 | |
| 						_VerbList[m.Groups[1].Value]++;
 | |
| 					else
 | |
| 						_VerbList.Add(m.Groups[1].Value,1);
 | |
| 			}
 | |
| 		}
 | |
| 		private SortedDictionary<string, int> _DicFigureUsage;
 | |
| 		private void btnFigures_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			_DicFigureUsage = new SortedDictionary<string, int>();
 | |
| 			tbResults.Clear();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			// Loop through XML Files
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				FindImages(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			ShowFigures();
 | |
| 		}
 | |
| 
 | |
| 		private void ShowFigures()
 | |
| 		{
 | |
| 			tbResults.AppendText("\r\n\r\n**** MultipleOccurences ****\r\n\r\n");
 | |
| 			foreach (string key in _DicFigureUsage.Keys)
 | |
| 				if(_DicFigureUsage[key]>1)
 | |
| 					tbResults.AppendText(string.Format("{0}\t{1}\r\n", _DicFigureUsage[key], key));
 | |
| 		}
 | |
| 		private void FindImages(string fileName)
 | |
| 		{
 | |
| 
 | |
| 			LoadXml(fileName, null);
 | |
| 			//Find Content Attributes
 | |
| 			FindImages(MyXMLDoc.DocumentElement, GetProcedureNumber(fileName));
 | |
| 		}
 | |
| 
 | |
| 		private void FindImages(XmlElement xe, string procname)
 | |
| 		{
 | |
| 			FindImageContent(xe, procname);
 | |
| 			foreach (XmlNode xn in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (xn is XmlElement)
 | |
| 					FindImages(xn as XmlElement, procname);
 | |
| 			}
 | |
| 		}
 | |
| 		//Regex _regFindImage = new Regex("<img src=([A-Z]+)</span>", RegexOptions.Compiled);
 | |
| 		private void FindImageContent(XmlElement xn, string procname)
 | |
| 		{
 | |
| 			if (xn.Attributes["content"] != null)
 | |
| 			{
 | |
| 				string xml = cleanupHTML(xn.Attributes["content"].Value, 0);
 | |
| 				if (xml == string.Empty) return;
 | |
| 				if (xml.Replace(" ", "") == xn.Name) return;
 | |
| 				if (!xml.Contains("<img")) return;
 | |
| 				XmlDocument xd = new XmlDocument();
 | |
| 				xd.LoadXml(xml);
 | |
| 				XmlNodeList xl = xd.SelectNodes("//img");
 | |
| 				foreach (XmlNode xnn in xl)
 | |
| 				{
 | |
| 					Console.WriteLine("\"{0}\"\t\"{1}\"\t\"{2}\"", procname, xnn.Attributes["src"].Value,GetPath(xn));
 | |
| 					string key = string.Format("\"{0}\"\t\"{1}\"", procname, GetPath(xn));
 | |
| 					//if (_DicFigureUsage.ContainsKey(key))
 | |
| 					//	_DicFigureUsage[key]++;
 | |
| 					//else
 | |
| 					//	_DicFigureUsage.Add(key, 1);
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private static string GetPath(XmlNode xn)
 | |
| 		{
 | |
| 			switch (xn.Name)
 | |
| 			{
 | |
| 				case "GrossStep":
 | |
| 					return xn.Attributes["number"].Value + " " + xn.Attributes["name"].Value;
 | |
| 				case "Step":
 | |
| 					return GetPath(xn.ParentNode) + ":Step " + xn.Attributes["number"].Value + " " + xn.Attributes["name"].Value + ":";
 | |
| 				default:
 | |
| 					{
 | |
| 						string siblings = GetSiblings(xn);
 | |
| 						return GetPath(xn.ParentNode) + ":" + xn.Name + (siblings == null? "" : "(" + siblings + ")" );
 | |
| 					}
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private static string GetSiblings(XmlNode xn)
 | |
| 		{
 | |
| 			SortedDictionary<string,string> siblings = new SortedDictionary<string,string>();
 | |
| 			XmlNode xp = xn.PreviousSibling;
 | |
| 			while (xp != null)
 | |
| 			{
 | |
| 				string key = xp.Name;
 | |
| 				if (!siblings.ContainsKey(key))
 | |
| 					siblings.Add(key, ShortVersion(key));
 | |
| 				xp = xp.PreviousSibling;
 | |
| 			}
 | |
| 			XmlNode xx = xn.NextSibling;
 | |
| 			while (xx != null)
 | |
| 			{
 | |
| 				string key = xx.Name;
 | |
| 				if (!siblings.ContainsKey(key))
 | |
| 					siblings.Add(key, ShortVersion(key));
 | |
| 				xx = xx.NextSibling;
 | |
| 			}
 | |
| 			string results = "";
 | |
| 			foreach (string ky in siblings.Keys)
 | |
| 				results += siblings[ky];
 | |
| 			if (results == "") return null;
 | |
| 			return results;
 | |
| 		}
 | |
| 
 | |
| 		private static string ShortVersion(string key)
 | |
| 		{
 | |
| 			switch (key)
 | |
| 			{
 | |
| 				case "NoteInstruction":
 | |
| 					return "N";
 | |
| 				case "CautionInstruction":
 | |
| 					return "C";
 | |
| 				case "Contingency":
 | |
| 					return "*";
 | |
| 				case "UnitaryInstruction":
 | |
| 					return "U";
 | |
| 				case "BinaryInstruction":
 | |
| 					return "B";
 | |
| 				case "JoinInstruction":
 | |
| 					return "J";
 | |
| 				case "UnitaryContingencyCallInstruction":
 | |
| 					return "R";
 | |
| 				default:
 | |
| 					return string.Format("[{0}]", key);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void btnTables_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			//Loop through content containing table(s) under td. 
 | |
| 			tbResults.Clear();
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			// Loop through XML Files
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				FindTables(chld.FullName);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 			ShowTables();
 | |
| 		}
 | |
| 
 | |
| 		private void ShowTables()
 | |
| 		{
 | |
| 			//throw new NotImplementedException();
 | |
| 		}
 | |
| 
 | |
| 		private void FindTables(string fileName)
 | |
| 		{
 | |
| 			LoadXml(fileName, null);
 | |
| 			//Find Content Attributes
 | |
| 			FindTables(MyXMLDoc.DocumentElement, GetProcedureNumber(fileName));
 | |
| 		}
 | |
| 		private void FindTables(XmlElement xe, string procNum)
 | |
| 		{
 | |
| 			FindTableContent(xe, procNum);
 | |
| 			foreach (XmlNode xn in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (xn is XmlElement)
 | |
| 					FindTables(xn as XmlElement, procNum);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void FindTableContent(XmlElement xn, string procNum)
 | |
| 		{
 | |
| 			if (xn.Attributes["content"] != null)
 | |
| 			{
 | |
| 				string xml = cleanupHTML(xn.Attributes["content"].Value, 0);
 | |
| 				if (xml == string.Empty) return;
 | |
| 				if (xml.Replace(" ", "") == xn.Name) return;
 | |
| 				if (!xml.Contains("<table")) return;
 | |
| 				XmlDocument xd = new XmlDocument();
 | |
| 				xd.LoadXml(xml.Replace("&","&"));
 | |
| 				XmlNodeList xl = xd.SelectNodes("//table");
 | |
| 				foreach (XmlNode xnn in xl)
 | |
| 				{
 | |
| 					if(xnn.ParentNode.Name == "td")
 | |
| 						Console.WriteLine("\"TWT\"\t\"{0}\"\t\"{1}\"\t\"{2}\"\t{3}\t{4}\t{5}\t{6}", procNum, GetPath(xn), GetPath2(xnn), xnn.Name,GetNext(xnn), GetPrevious(xnn), xnn.ParentNode.Name);
 | |
| 					else
 | |
| 						Console.WriteLine("\"TBL\"\t\"{0}\"\t\"{1}\"\t\"{2}\"\t{3}\t{4}\t{5}\t{6}", procNum, GetPath(xn), GetPath2(xnn), xnn.Name,GetNext(xnn), GetPrevious(xnn), xnn.ParentNode.Name);
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private object GetPrevious(XmlNode xnn)
 | |
| 		{
 | |
| 			if (xnn.PreviousSibling != null) return xnn.PreviousSibling.Name;
 | |
| 			return "No Previous";
 | |
| 		}
 | |
| 		private object GetNext(XmlNode xnn)
 | |
| 		{
 | |
| 			if (xnn.NextSibling != null) return xnn.NextSibling.Name;
 | |
| 			return "No Next";
 | |
| 		}
 | |
| 		private static string GetPath2(XmlNode xn)
 | |
| 		{
 | |
| 			if (xn == null) return "";
 | |
| 			else return GetPath2(xn.ParentNode) + ":" + xn.Name;
 | |
| 		}
 | |
| 
 | |
| 		private void FindFigures(XmlElement xe, string procNum)
 | |
| 		{
 | |
| 			FindImageContent(xe, procNum);
 | |
| 			foreach (XmlNode xn in xe.ChildNodes)
 | |
| 			{
 | |
| 				if (xn is XmlElement)
 | |
| 					FindImages(xn as XmlElement, procNum);
 | |
| 			}
 | |
| 		}
 | |
| 		private void FindFigureContent(XmlElement xn, string procname)
 | |
| 		{
 | |
| 			if (xn.Attributes["content"] != null)
 | |
| 			{
 | |
| 				string xml = cleanupHTML(xn.Attributes["content"].Value, 0);
 | |
| 				if (xml == string.Empty) return;
 | |
| 				if (xml.Replace(" ", "") == xn.Name) return;
 | |
| 				if (!xml.Contains("<table")) return;
 | |
| 				XmlDocument xd = new XmlDocument();
 | |
| 				xd.LoadXml(xml);
 | |
| 				XmlNodeList xl = xd.SelectNodes("//table");
 | |
| 				foreach (XmlNode xnn in xl)
 | |
| 				{
 | |
| 					Console.WriteLine("\"{0}\"\t\"{1}\"\t\"{2}\"", procname, GetPath(xn),xnn.Name);
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void bntTable2_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			VlnFlexGrid fg = new VlnFlexGrid();
 | |
| 			StepRTB rtb = new StepRTB();
 | |
| 			this.Controls.Add(fg);
 | |
| 			fg.Location = tbResults.Location;
 | |
| 			fg.Size = tbResults.Size;
 | |
| 			fg.Rows.Count = 5;
 | |
| 			fg.Cols.Count = 5;
 | |
| 			fg.BringToFront();
 | |
| 			;
 | |
| 			for (int i = 0; i < 5; i++)
 | |
| 				for (int j = 0; j < 5; j++)
 | |
| 				{
 | |
| 					rtb.Text = string.Format("{0},{1}", i, j);
 | |
| 					fg[i, j] = rtb.Rtf;
 | |
| 					fg.MyBorders.HorizontalLines[i, j] = GridLinePattern.Single;
 | |
| 					fg.MyBorders.VerticalLines[i, j] = GridLinePattern.Single;
 | |
| 				}
 | |
| 			CellRange cr = new CellRange();
 | |
| 			cr.c1 = 0;
 | |
| 			cr.c2 = 4;
 | |
| 			cr.r1 = 0;
 | |
| 			cr.r2 = 4;
 | |
| 			fg.SetBorders(cr, GridLinePattern.Single, GridLinePattern.Single, GridLinePattern.Single, GridLinePattern.Single, GridLinePattern.Single, GridLinePattern.Single);
 | |
| 			fg.Refresh();
 | |
| 			Application.DoEvents();
 | |
| 			Console.WriteLine(fg.GetXMLData());
 | |
| 			XmlDocument xd = new XmlDocument();
 | |
| 			using (StringReader sr = new StringReader(xmlSample1))
 | |
| 			{
 | |
| 				fg.ReadXml(sr);
 | |
| 				sr.Close();
 | |
| 			}
 | |
| 		}
 | |
| 		private static string _ProcNum;
 | |
| 		private void btnStepOrNo_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			// start by doing one then expand to all
 | |
| 			tbResults.Clear();
 | |
| 			tbResults.AppendText("\"ProcNum\"\t\"Section\"\t\"Title\"\t\"Step\"\t\"Text\"" +
 | |
| 				"\t\"Tables\"\t\"Images\"\t\"Style\"\t\"LastStyle\"\t\"NextStyle\"\t\"Notes\"\t\"Cautions\"\t\"Warnings\"" +
 | |
| 				"\t\"Contingency\"\t\"Binary\"\t\"Join\"\t\"Note\"\t\"Caution\"\t\"Unitary\"\r\n");
 | |
| 			FileInfo fi = new FileInfo(tbFile.Text);
 | |
| 			pbProcs.Maximum = fi.Directory.GetFiles("*.xml").Count();
 | |
| 			pbProcs.Value = 0;
 | |
| 			foreach (FileInfo chld in fi.Directory.GetFiles("*.xml"))
 | |
| 			{
 | |
| 				LoadXml(chld.FullName, null);
 | |
| 				_ProcNum = GetProcedureNumber(chld.FullName);
 | |
| 				StepOrNo(MyXMLDoc.DocumentElement);
 | |
| 				pbProcs.Value++;
 | |
| 				Application.DoEvents();
 | |
| 			}
 | |
| 		}
 | |
| 		private string _LastSectNo = "";
 | |
| 		private string _LastStyle="";
 | |
| 		private void StepOrNo(XmlNode xn)
 | |
| 		{
 | |
| 			if (xn.Name == "GrossStep" || xn.Name =="procedure")
 | |
| 			{
 | |
| 				foreach (XmlNode xc in xn.ChildNodes)
 | |
| 					StepOrNo(xc);
 | |
| 			}
 | |
| 			else if (xn.Name == "Step")
 | |
| 			{
 | |
| 				string sectNo = _ProcNum + xn.ParentNode.Attributes["number"].Value;
 | |
| 				string style = GetSectionStyle(xn);
 | |
| 				if (sectNo != _LastSectNo)
 | |
| 					_LastStyle = "";
 | |
| 				XmlNode nn = xn.NextSibling;
 | |
| 				while (nn != null && nn.Name == "esinfo")
 | |
| 					nn = nn.NextSibling;
 | |
| 				string nextStyle = "";
 | |
| 				if(nn != null)
 | |
| 					nextStyle = GetSectionStyle(nn);
 | |
| 				//if (xn.ParentNode.Attributes["number"].Value == "IV") Console.WriteLine("here");
 | |
| 				tbResults.AppendText(string.Format("\"{0}\"\t\"{1}\"\t\"{2}\"\t\"{3}\"\t\"{4}\"" +
 | |
| 					"\t\"{5}\"\t\"{6}\"\t\"{7}\"\t\"{8}\"\t\"{9}\"\t\"{10}\"\t\"{11}\"\t\"{12}\"" +
 | |
| 					"\t\"{13}\"\t\"{14}\"\t\"{15}\"\t\"{16}\"\t\"{17}\"\t\"{18}\"\r\n", _ProcNum
 | |
| 					, xn.ParentNode.Attributes["number"].Value, xn.ParentNode.Attributes["name"].Value
 | |
| 					, xn.Attributes["number"].Value, xn.Attributes["name"].Value
 | |
| 					,GetContainsTable(xn),GetContainsImage(xn),style,_LastStyle, nextStyle
 | |
| 					,GetContains(xn,"NOTE"),GetContains(xn,"CAUTION"),GetContains(xn,"WARNING")
 | |
| 					, GetContainsNode(xn, "Contingency"), GetContainsNode(xn, "BinaryI"), GetContainsNode(xn, "JoinI")
 | |
| 					, GetContainsNode(xn, "NoteI"), GetContainsNode(xn, "CautionI"), GetContainsNode(xn, "UnitaryI")));
 | |
| 				_LastStyle = style;
 | |
| 				_LastSectNo = sectNo;
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private string GetContainsNode(XmlNode xn, string lookfor)
 | |
| 		{
 | |
| 			if (xn.Name.StartsWith(lookfor)) return lookfor;
 | |
| 			foreach (XmlNode xc in xn.ChildNodes)
 | |
| 				if (GetContainsNode(xc, lookfor) != null) return lookfor;
 | |
| 			return null;
 | |
| 		}
 | |
| 		private string GetContains(XmlNode xn, string typ)
 | |
| 		{
 | |
| 			string retval = "";
 | |
| 			if (xn.InnerXml.Contains(typ)) retval = typ.ToLower();
 | |
| 				foreach (XmlNode xc in xn.ChildNodes)
 | |
| 				{
 | |
| 					if (xc.Name == "NoteInstruction" || xc.Name == "CautionInstruction")
 | |
| 						if (FirstTextIsType(xc, typ)) return typ;
 | |
| 						else return retval;
 | |
| 				}
 | |
| 			return retval;
 | |
| 		}
 | |
| 
 | |
| 		private static bool FirstTextIsType(XmlNode xn, string typ)
 | |
| 		{
 | |
| 			XmlAttribute xa = xn.Attributes["content"];
 | |
| 			string xmlbase = xa.Value;
 | |
| 			xmlbase = Regex.Replace(xmlbase, "<![^>]+>[\r\n]*", "");
 | |
| 			xmlbase = Regex.Replace(xmlbase, " style=\"\" style=\"", " style=\"");
 | |
| 			string pat = " style=\\\"([^\"]+)\\\" style=\\\"";
 | |
| 			xmlbase = Regex.Replace(xmlbase, pat, " style=\"$1");
 | |
| 
 | |
| 			XmlDocument xd = new XmlDocument();
 | |
| 			//TODO 20180913 0644 Not XML
 | |
| 			if (!xmlbase.Contains("<")) return false;
 | |
| 			xd.LoadXml(xmlbase);
 | |
| 			return FirstTextIsType1(xd.DocumentElement, typ);
 | |
| 		}
 | |
| 		private static bool FirstTextIsType1(XmlNode xn, string typ)
 | |
| 		{
 | |
| 			foreach (XmlNode xc in xn.ChildNodes)
 | |
| 			{
 | |
| 				if (xc is XmlText)
 | |
| 				{
 | |
| 					if ((xc as XmlText).Value.Contains(typ))
 | |
| 						return true;
 | |
| 					return false;
 | |
| 				}
 | |
| 				if (xc.Name == "body" || xc.Name == "p" || xc.Name == "li" || xc.Name == "span")
 | |
| 					return FirstTextIsType1(xc, typ);
 | |
| 			}
 | |
| 			return false;
 | |
| 		}
 | |
| 		private static string GetSectionStyle(XmlNode xn)
 | |
| 		{
 | |
| 			foreach (XmlNode xc in xn.ChildNodes)
 | |
| 				if (xc.Name == "BinaryInstruction" || xc.Name == "Contingency " || xc.Name=="UnitaryContingencyCallInstruction" || countChildNodes(xc)>0)
 | |
| 					if(xc.Name != "esinfo") return "Substeps";
 | |
| 			bool hasFreeForm = false;
 | |
| 			bool hasSpecificNotes = false;
 | |
| 			bool hasUnitary = false;
 | |
| 			foreach (XmlNode xc in xn.ChildNodes)
 | |
| 			{
 | |
| 				if (xc.Name == "NoteInstruction" || xc.Name == "CautionInstruction")
 | |
| 				{
 | |
| 					if (FirstTextIsType(xc, "NOTE") || FirstTextIsType(xc, "CAUTION") || FirstTextIsType(xc, "WARNING"))
 | |
| 					{
 | |
| 						hasSpecificNotes = true;
 | |
| 					}
 | |
| 					else
 | |
| 						hasFreeForm = true;
 | |
| 				}
 | |
| 				if (xc.Name == "UnitaryInstruction")
 | |
| 					hasUnitary = true;
 | |
| 			}
 | |
| 			if (hasFreeForm) return "Free Form";
 | |
| 			if (hasUnitary) return "Step or Free Form";
 | |
| 			return hasSpecificNotes ? "Specific Notes" : "Unknown";
 | |
| 		}
 | |
| 
 | |
| 		private static int countChildNodes(XmlNode xn)
 | |
| 		{
 | |
| 			if (xn.ChildNodes.Count == 0) return 0;
 | |
| 			int retval = 0;
 | |
| 			foreach (XmlNode xc in xn.ChildNodes)
 | |
| 			{
 | |
| 				if (xc.Name.EndsWith("Instruction") || xc.Name =="Contingency") retval++;
 | |
| 				retval += countChildNodes(xc);
 | |
| 			}
 | |
| 			//if (retval > 0 && xn.Name == "NoteInstruction") Console.WriteLine("here");
 | |
| 			return retval;
 | |
| 		}
 | |
| 
 | |
| 		private object GetContainsImage(XmlNode xn)
 | |
| 		{
 | |
| 			if (xn.InnerXml.Contains("<img ")) return "Image";
 | |
| 			return "";
 | |
| 		}
 | |
| 
 | |
| 		private object GetContainsTable(XmlNode xn)
 | |
| 		{
 | |
| 			if (xn.InnerXml.Contains("<table ")) return "Table";
 | |
| 			return "";
 | |
| 		}
 | |
| 	}
 | |
| 	public class RegexReplace
 | |
| 	{
 | |
| 		private string _Pattern;
 | |
| 		public string Pattern
 | |
| 		{
 | |
| 			get { return _Pattern; }
 | |
| 			set { _Pattern = value; }
 | |
| 		}
 | |
| 		private string _Replace;
 | |
| 		public string Replace
 | |
| 		{
 | |
| 			get { return _Replace; }
 | |
| 			set { _Replace = value; }
 | |
| 		}
 | |
| 		private Regex _RegEx;
 | |
| 		public Regex RegEx
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (_RegEx == null)
 | |
| 					_RegEx = new Regex(Pattern, RegexOptions.Compiled);
 | |
| 				return _RegEx;
 | |
| 			}
 | |
| 		}
 | |
| 		public RegexReplace(string pattern, string replace)
 | |
| 		{
 | |
| 			_Pattern = pattern;
 | |
| 			_Replace = replace;
 | |
| 		}
 | |
| 		public string DoReplace(string str)
 | |
| 		{
 | |
| 			return RegEx.Replace(str, Replace);
 | |
| 		}
 | |
| 	}
 | |
| 	public class StepLookup : SortedDictionary<string, StepInfo>
 | |
| 	{
 | |
| 		public StepInfo this[int i]
 | |
| 		{
 | |
| 			get
 | |
| 			{
 | |
| 				if (this.ContainsKey(i.ToString())) return base[i.ToString()];
 | |
| 				return null;
 | |
| 			}
 | |
| 			set
 | |
| 			{
 | |
| 				if (i > this.Count)
 | |
| 					throw new Exception("Gap in Stack");
 | |
| 				if (value == null)
 | |
| 					throw new Exception("Null StepInfo");
 | |
| 				//if (value.MyHLS.Ordinal==5 && (value.IsNote || value.IsCaution ))
 | |
| 				//	Volian.Base.Library.vlnStackTrace.ShowStackLocal(2,5,"=====> Adding Caution or Note on Step 5 {0}",value);
 | |
| 				if (this.ContainsKey(i.ToString()))
 | |
| 				{
 | |
| 					base[i.ToString()] = value;
 | |
| 					while (this.ContainsKey((i + 1).ToString()))
 | |
| 						base.Remove((base.Count - 1).ToString());
 | |
| 				}
 | |
| 				else base.Add(i.ToString(), value);
 | |
| 				//ListMySteps("Set ", this);
 | |
| 			}
 | |
| 		}
 | |
| 		public void AddOne(StepInfo previousStep)
 | |
| 		{
 | |
| 			this[this.Count] = previousStep;
 | |
| 		}
 | |
| 		private static void ListMySteps(string str, StepLookup mySteps)
 | |
| 		{
 | |
| 			int i = 0;
 | |
| 			foreach (string key in mySteps.Keys)
 | |
| 			{
 | |
| 				if (key != i.ToString())
 | |
| 					Console.WriteLine("{0} {1} {2} {3}", str, i, key, mySteps[key].DisplayText);
 | |
| 				i++;
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	public class StepText
 | |
| 	{
 | |
| 		private string _OriginalText;
 | |
| 		public string OriginalText
 | |
| 		{
 | |
| 			get { return _OriginalText; }
 | |
| 			set { _OriginalText = value; }
 | |
| 		}
 | |
| 		private int _Indent=0;
 | |
| 		public int Indent
 | |
| 		{
 | |
| 			get { return _Indent; }
 | |
| 			set { _Indent = value; }
 | |
| 		}
 | |
| 		private string _Tab=string.Empty;
 | |
| 		public string Tab
 | |
| 		{
 | |
| 			get { return _Tab; }
 | |
| 			set { _Tab = value; }
 | |
| 		}
 | |
| 		private string _Text;
 | |
| 		public string Text
 | |
| 		{
 | |
| 			get { return  _Text; }
 | |
| 			set { _Text = value; }
 | |
| 		}
 | |
| 		public StepText()
 | |
| 		{
 | |
| 		}
 | |
| 		private static Regex reg_SplitText = new Regex(@"^(([\t ]*)([a-z1-9A-Z][0-9]*[\.\)](?= |[^S0-9])|\*|)( *))((?![0-9]+\.[0-9]+ )[0-9A-Za-z][^\r\n]*)");
 | |
| 		private static Regex reg_SplitText1 = new Regex(@"([\t ]*)([1-9][0-9]*\.[0-9]+(?= *(Manually )?[A-Z]))( *)([^\r\n]+)");
 | |
| 		public StepText(string str)
 | |
| 		{
 | |
| 			OriginalText = str;
 | |
| 			//if (str.Contains("\\u9679?"))
 | |
| 			//	Console.WriteLine("here");
 | |
| 			if (str.Trim().StartsWith("T.S."))
 | |
| 			{
 | |
| 					Tab = "";
 | |
| 					Indent = str.Length -  str.TrimStart().Length;
 | |
| 					Text = str.Substring(Indent);
 | |
| 			}
 | |
| 			//if (str.Contains("3.1") || str.Contains("1.1") || str.Contains("Line up the valves for manual operation"))
 | |
| 			//	Console.WriteLine("here");
 | |
| 			Match m = reg_SplitText.Match(str.Replace("\\u9679?", "*"));
 | |
| 			if (m.Success)
 | |
| 			{
 | |
| 				Tab = m.Groups[3].Value;
 | |
| 				Indent = m.Groups[2].Length + Tab.Length + m.Groups[4].Length;
 | |
| 				Text = m.Groups[5].Value;
 | |
| 				//if (Text.Contains("OR") || Text.Contains("AND"))
 | |
| 				//	Console.WriteLine("here");
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				m = reg_SplitText1.Match(str.Replace("\\u9679?", "*"));
 | |
| 				if (m.Success)
 | |
| 				{
 | |
| 					Tab = m.Groups[1].Value;
 | |
| 					Indent = m.Groups[1].Length + Tab.Length + m.Groups[4].Length;
 | |
| 					Text = m.Groups[5].Value;
 | |
| 				}
 | |
| 				else
 | |
| 				{
 | |
| 					Tab = "";
 | |
| 					Indent = str.Length - str.TrimStart().Length;
 | |
| 					Text = str.Substring(Indent);
 | |
| 				}
 | |
| 			}
 | |
| 			//if(Regex.IsMatch(Text,@"^[1-9a-zA-Z][.\)]"))
 | |
| 			//	Console.WriteLine(Text);
 | |
| 		}
 | |
| 		public override string ToString()
 | |
| 		{
 | |
| 			return string.Format("{0} {1} {2}",Indent,Tab,Text);
 | |
| 		}
 | |
| 	}
 | |
| 	public class Node
 | |
| 	{
 | |
| 		private static SortedList<string, Node> _AllNodes = new SortedList<string, Node>();
 | |
| 		public static SortedList<string, Node> AllNodes
 | |
| 		{
 | |
| 			get { return Node._AllNodes; }
 | |
| 			set { Node._AllNodes = value; }
 | |
| 		}
 | |
| 		public static void Reset()
 | |
| 		{
 | |
| 			_AllNodes = new SortedList<string, Node>();
 | |
| 		}
 | |
| 		private string _Name;
 | |
| 		public string Name
 | |
| 		{
 | |
| 			get { return _Name; }
 | |
| 			set { _Name = value; }
 | |
| 		}
 | |
| 		private List<string> _Children = new List<string>();
 | |
| 		public List<string> Children
 | |
| 		{
 | |
| 			get { return _Children; }
 | |
| 			set { _Children = value; }
 | |
| 		}
 | |
| 		private Attributes _Attributes = new Attributes();
 | |
| 		public Attributes Attributes
 | |
| 		{
 | |
| 			get { return _Attributes; }
 | |
| 			set { _Attributes = value; }
 | |
| 		}
 | |
| 		private bool _HasText = false;
 | |
| 		public bool HasText
 | |
| 		{
 | |
| 			get { return _HasText; }
 | |
| 			set { _HasText = value; }
 | |
| 		}
 | |
| 		public Node(XmlElement xe)
 | |
| 		{
 | |
| 			_AllNodes.Add(xe.Name, this);
 | |
| 		}
 | |
| 		public static void Add(XmlElement xe)
 | |
| 		{
 | |
| 			BuildList(xe);
 | |
| 		}
 | |
| 		private static void BuildList(XmlElement xe)
 | |
| 		{
 | |
| 			Node nd;
 | |
| 			if (!_AllNodes.ContainsKey(xe.Name))
 | |
| 				nd = new Node(xe);
 | |
| 			else
 | |
| 				nd = _AllNodes[xe.Name];
 | |
| 			AdjustChildren(nd, xe.ChildNodes);
 | |
| 			AdjustAttributes(nd, xe.Attributes);
 | |
| 			foreach (XmlNode ch in xe.ChildNodes)
 | |
| 				// ChildNodes can contain XmlText as well as XmlElement nodes
 | |
| 				if (ch is XmlElement)
 | |
| 					BuildList(ch as XmlElement);
 | |
| 		}
 | |
| 		private static void AdjustAttributes(Node nd, XmlAttributeCollection xmlAttributeCollection)
 | |
| 		{
 | |
| 			foreach (XmlAttribute xa in xmlAttributeCollection)
 | |
| 				AdjustAttribute(nd, xa);
 | |
| 		}
 | |
| 		private static void AdjustAttribute(Node nd, XmlAttribute xa)
 | |
| 		{
 | |
| 				nd.Attributes.Add(xa);
 | |
| 		}
 | |
| 		private static void AdjustChildren(Node nd, XmlNodeList xmlNodeList)
 | |
| 		{
 | |
| 			foreach (XmlNode ne in xmlNodeList)
 | |
| 			{
 | |
| 				// XmlNodeList can contain XmlText as well as XmlElement nodes
 | |
| 				if (ne is XmlElement)
 | |
| 				{
 | |
| 					if (!nd.Children.Contains((ne as XmlElement).Name))
 | |
| 						nd.Children.Add((ne as XmlElement).Name);
 | |
| 				}
 | |
| 				else if (ne is XmlText)
 | |
| 					nd.HasText = true;
 | |
| 				else
 | |
| 					Console.WriteLine("Not Expected {0}", ne.GetType().FullName);
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	public class Attributes : Dictionary<string, Attribute>
 | |
| 	{
 | |
| 		public void Add(XmlAttribute xa)
 | |
| 		{
 | |
| 			if (!this.ContainsKey(xa.Name))
 | |
| 				base.Add(xa.Name, new Attribute(xa));
 | |
| 			else
 | |
| 			{
 | |
| 				Attribute att = this[xa.Name];
 | |
| 				att.Count++;
 | |
| 				att.MinValue = string.Compare(att.MinValue, xa.Value) > 0 ? xa.Value : att.MinValue;
 | |
| 				att.MaxValue = string.Compare(att.MinValue, xa.Value) < 0 ? xa.Value : att.MaxValue;
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	public class Attribute
 | |
| 	{
 | |
| 		public Attribute(XmlAttribute xa)
 | |
| 		{
 | |
| 			_Name = xa.Name;
 | |
| 			_MinValue = xa.Value;
 | |
| 			_MaxValue = xa.Value;
 | |
| 			_Count = 1;
 | |
| 		}
 | |
| 		private string _Name;
 | |
| 		public string Name
 | |
| 		{
 | |
| 			get { return _Name; }
 | |
| 			set { _Name = value; }
 | |
| 		}
 | |
| 		private string _MinValue;
 | |
| 		public string MinValue
 | |
| 		{
 | |
| 			get { return _MinValue; }
 | |
| 			set { _MinValue = value; }
 | |
| 		}
 | |
| 		private string _MaxValue;
 | |
| 		public string MaxValue
 | |
| 		{
 | |
| 			get { return _MaxValue; }
 | |
| 			set { _MaxValue = value; }
 | |
| 		}
 | |
| 		private int _Count = 0;
 | |
| 		public int Count
 | |
| 		{
 | |
| 			get { return _Count; }
 | |
| 			set { _Count = value; }
 | |
| 		}
 | |
| 	}
 | |
| }
 |