string statusFilePath = Directory.GetCurrentDirectory().ToString() + "\\Status\\"; foreach (string file in Directory.GetFiles(statusFilePath, "wpasset*.txt")) { string filename = Path.GetFileNameWithoutExtension(file); string content = File.ReadAllText(file); string statusfilename = Directory.GetCurrentDirectory().ToString() + "\\\\Status\\\\" + "test.xml"; // string statusFilePath1 = Directory.GetCurrentDirectory().ToString() + "\\\\Status\\\\" + "*.xml"; Regex expression = new Regex(@"##(?<parent>\w+)\r\n(?<children>[\w ]+)\r\n((?<values>[\S ]+)(\r\n(?!#)|$))+", RegexOptions.None); XElement xeRoot = new XElement("wpassetd"); //root node foreach (Match m in expression.Matches(content)) { XElement xeParent = new XElement(m.Groups["parent"].Value); string[] children = m.Groups["children"].Value.Split(' '); // Use space as delimter for the children foreach (Capture cap in m.Groups["values"].Captures) { XElement xeChild = new XElement("data"); // Change the name 'child' to whatever suitable string[] values = cap.Value.Split(new string[] { ":" }, StringSplitOptions.None); // Check that the children and values counts are equal if (children.Length != values.Length) throw new Exception("The number of children and values mismatch."); for (int i = 0; i < children.Length; i++) { XElement xeChildValue = new XElement(children[i].ToLower()); //xeChildValue.Value = values[i]; //xeChildValue.Value = String.Format("![CDATA[{0}]]", values[i]); XCData cdata = new XCData(values[i]); xeChildValue.Add(cdata); xeChild.Add(xeChildValue); } xeParent.Add(xeChild); } xeRoot.Add(xeParent); } XDocument xmldoc = new XDocument(); string result; xmldoc.Add(xeRoot); xmldoc.Save(statusfilename); result = Path.GetFileName(statusfilename); //xmldoc.Save(@"test.xml");
2015-04-07 14:49:33:(INFO) : Category: HandleOutPut: Starting log 2015-04-07 14:49:33 2015-04-07 14:49:33:(WARN) : Category: IsRunAsAdmin: The user running this process is not an elevated administrator. Some commands will not work properly without it. Please make sure that the process has local administrator privileges and "Run as administrator"(UAC). 2015-04-07 14:49:33:(INFO) : Category: -Unknown Operation-: 2015-04-07 14:49:37:(ERROR) : Category: error: Failed while calling WS-Management call 2015-04-07 14:49:37:(ERROR) : Category:The caller is unauthorized. 2015-04-07 14:49:37:(WARN) : Category: -Initializing connection-: Failed connecting locally , will try to connect using the remote server. 2015-04-07 14:49:41:(ERROR) : Category: LoadXMLFromFile: The profile does not contain the mandatory tag. 2015-04-07 14:49:41:(ERROR) : Category: Exit: ***********Exit with code 38. Details: Error with XML file (possible reasons - the file does not exist or access to it is denied; the file contains incorrect parameters; incorrect or missing encryption password/parameter; invalid data)
<myfile> <errorcode>38</errorcode> <error>Failed while calling WS-Management call.-Initializing connection-:Failed connecting locally , will try to connect using the remote server. LoadXMLFromFile: The XML does not contain the mandatory tag.Error with XML file (possible reasons - the file does not exist or access to it is denied; the file contains incorrect parameters; incorrect or missing encryption password/parameter; invalid data) </error> </myfile>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)