public static string GetFile(string fileName) { Log log = new Tools.Log("C:\\Temp\\SinexLog.txt"); SinexPoLine poLine = new SinexPoLine(); string result = ""; string html = ""; //string url = @"http://integration.sinexmarine.com/webservices/integrationservice.asmx/getVendors?companyid=bf8385ef-b76d-4f5e-9b0c-6b2dac723e6f"; string url = @"http://integration.sinexmarine.com/webservices/integrationservice.asmx/poLineItemExport?companyid=bf8385ef-b76d-4f5e-9b0c-6b2dac723e6f&status=Approved"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } return(result); }
public string Test() { Log log = new Tools.Log("C:\\Temp\\SinexLog.txt"); SinexPoLine poLine = new SinexPoLine(); string result = ""; string html = ""; //string url = @"http://integration.sinexmarine.com/webservices/integrationservice.asmx/getVendors?companyid=bf8385ef-b76d-4f5e-9b0c-6b2dac723e6f"; string url = @"http://integration.sinexmarine.com/webservices/integrationservice.asmx/poLineItemExport?companyid=bf8385ef-b76d-4f5e-9b0c-6b2dac723e6f&status=Approved"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } log.Write(result); log.Write("-"); log.Write("-"); log.Write("-"); log.Write("-"); log.Write("-"); string record = result; //MessageBox.Show(record); int startRecord = result.IndexOf("{") - 1; int endRecord = result.LastIndexOf("]") - 1; int endIndex = endRecord - startRecord + 1; record = result.Substring(startRecord + 1, endIndex); log.Write(record); MessageBox.Show(record); poLine = JsonConvert.DeserializeObject <SinexPoLine>(record); return(""); }
public void AddLine(SinexPoLine line) { lines.Add(line); }
public static void TraverseFile(string file) { int errorCount = 0; List <PurchaseOrderHeader> listPurchaseOrders = new List <PurchaseOrderHeader>(); PurchaseOrderHeader poHeader; PmTransaction pmTransaction; Log log = new Log(@"C:\Sinex\TraverseLog.txt"); log.Clear(); TextFile.WriteTextFile(@"C:\Sinex\File.txt", file); CurrentStructure currentStructure = CurrentStructure.start; int currentIndex = 0; int fileLength = file.Length; Bracket nextBracket = new Bracket(); nextBracket = NextBracket(file, currentIndex); bool continueLoop = true; int recordStart = 0; int recordEnd = 0; string record = ""; SinexPo po = new SinexPo(); SinexPoLine poLine = new SinexPoLine(); string recordString; Log xmlLog = new Tools.Log(@"C:\Sinex\recordXml.txt"); xmlLog.Clear(); while (continueLoop) { nextBracket = NextBracket(file, currentIndex); // log.Write("Next => " + nextBracket.ToString()); if (nextBracket.Index != -1) { #region switch switch (nextBracket.BracketType) { case "[": switch (currentStructure) { case CurrentStructure.start: currentStructure = CurrentStructure.poLoop; break; case CurrentStructure.poLoop: currentStructure = CurrentStructure.lineLoop; break; case CurrentStructure.lineLoop: MessageBox.Show($"1 - Bad Config " + currentStructure + ", " + currentStructure.ToString()); break; default: MessageBox.Show("Bad Config"); break; } break; case "]": switch (currentStructure) { case CurrentStructure.start: MessageBox.Show($"2 - Bad Config " + currentStructure + ", " + currentStructure.ToString()); break; case CurrentStructure.poLoop: currentStructure = CurrentStructure.start; break; case CurrentStructure.lineLoop: currentStructure = CurrentStructure.poLoop; break; default: MessageBox.Show($"3 - Bad Config " + currentStructure + ", " + currentStructure.ToString()); break; } break; case "{": switch (currentStructure) { case CurrentStructure.poLoop: recordStart = nextBracket.Index; recordEnd = file.IndexOf("lineItems", recordStart) - 2; record = file.SubFromTo(recordStart, recordEnd) + "}"; JsonSerializerSettings microsoftDateFormatSettings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; //log.Write(record); po = JsonConvert.DeserializeObject <SinexPo>(record, microsoftDateFormatSettings); XNode node = JsonConvert.DeserializeXNode(record, "Root"); //xmlLog.Write(node.ToString()); recordString = po.ToString(); log.Write(" "); log.Write(" "); log.Write("HEADER => " + recordString); log.Write($" - {po.requiredBy}, {po.poCreatedBy}, {po.shipTo}"); pmTransaction = new PmTransaction(po, GetGPConnection()); //pmTransaction.Insert("TWO"); string xml = pmTransaction.ToEconnectXML(); //xmlLog.Write("----------------------------------------------"); //xmlLog.Write(xml); //xml = xml.RemoveNode("<connection>"); //xmlLog.Write("----------------------------------------------"); //xmlLog.Write(xml); //xml = xml.RemoveNode("PmTransaction", true); //xmlLog.Write("----------------------------------------------"); //xmlLog.Write(xml); //xml = xml.RemoveNode("?xml", true); //xmlLog.Write("----------------------------------------------"); //xmlLog.Write(xml); //xml = xml.Replace("</PmTransaction>", ""); //xmlLog.Write("----------------------------------------------"); //xmlLog.Write(xml); //string header = "<eConnect xmlns:dt=\"urn:schemas - microsoft - com:datatypes\">"; //header = header + "<PMTransactionType>"; //header = header + "<eConnectProcessInfo>"; //header = header + "</eConnectProcessInfo>"; //header = header + "<taPMTransactionInsert>"; //string footer ="</taPMTransactionInsert>"; //footer = footer + "</PMTransactionType>"; //footer = footer + "</eConnect>"; //xml = header + xml + footer; //xmlLog.Write("----------------------------------------------"); xmlLog.Write(xml); errorCount = errorCount + pmTransaction.InsertXml(xml); break; case CurrentStructure.lineLoop: recordStart = nextBracket.Index; recordEnd = file.IndexOf("}", recordStart) - 1; record = file.SubFromTo(recordStart, recordEnd) + "}"; poLine = JsonConvert.DeserializeObject <SinexPoLine>(record); recordString = poLine.ToString(); log.Write("LINE => " + recordString); po.AddLine(poLine); break; } break; po.ToLog(log); } #endregion Switch currentIndex = nextBracket.Index + 1; if (currentIndex >= fileLength) { continueLoop = false; } } else { continueLoop = false; } } }