private List <OACYPerTransaction> FillUpOACYData(string ediFile, string fileName, char dataSeperator, char segmentSeperator) { string pipelineDUNS = ediFile.Substring(35, 9); OACY_DS ediOacy = new OACY_DS(ediFile , new char[] { segmentSeperator }//segement seperators , new char[] { dataSeperator } , fileName); return(modalFactory.Create(ediOacy.ReadOacyFile())); }
public ActionResult UploadFile(HttpPostedFileBase postedFile) { try { string filePath = string.Empty; if (postedFile != null) { string path = Server.MapPath("~/Uploads/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } filePath = path + Path.GetFileName(postedFile.FileName); string extension = Path.GetExtension(postedFile.FileName); postedFile.SaveAs(filePath); //Read the contents of CSV file. string ediFile = System.IO.File.ReadAllText(filePath); var dataSeperator = Convert.ToChar(ediFile[(ediFile.IndexOf("ISA") + "ISA".Length)]); var segmentSeperator = Convert.ToChar(ediFile[(ediFile.IndexOf("GS") - 1)]); OACY_DS ediOacy = new OACY_DS(ediFile , new char[] { segmentSeperator }//segement seperators , new char[] { dataSeperator } , "test"); var fg = ediOacy.ReadOacyFile(); EDIWrapperBase ediWrapper = new EDIWrapperBase(ediFile , new char[] { segmentSeperator }//segement seperators , new char[] { dataSeperator });//Dataseperators List <string[]> separateSTFiles = ediWrapper.EnvelopeBlocks(EDIEnvelopeNodes.ST, EDIEnvelopeNodes.SE); foreach (string[] separateFile in separateSTFiles) { string subEDIfile = ""; foreach (string element in separateFile) { subEDIfile = subEDIfile + element + Convert.ToChar(segmentSeperator); } EDIWrapperBase subEdiWrapper = new EDIWrapperBase(subEDIfile , new char[] { segmentSeperator }//segement seperators , new char[] { dataSeperator });//Dataseperators EDIFileType fileType = subEdiWrapper.FileType; switch (fileType) { case EDIFileType.NMQR: //inbox.DatasetID = (int)DTO.DataSet.Nomination_Quick_Response; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); //isProcessed = ProcessNmqrData(subEDIfile, pendingJob.TransactionId, inbox.PipelineID, dataSeperator, segmentSeperator); break; case EDIFileType.OACY: //inbox.DatasetID = (int)DTO.DataSet.Operational_Capacity; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); //isProcessed = ProcessOacyData(subEDIfile, pendingJob.TransactionId, inbox.PipelineID, dataSeperator, segmentSeperator); break; case EDIFileType.UNSC: //inbox.DatasetID = (int)DTO.DataSet.Unsubscribed_Capacity; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); //isProcessed = ProcessUnscData(subEDIfile, pendingJob.TransactionId, inbox.PipelineID, dataSeperator, segmentSeperator); break; case EDIFileType.RURD: //inbox.DatasetID = (int)DTO.DataSet.Response_to_Upload_of_Request_for_Download; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); //isProcessed = ProcessRurdData(subEDIfile, pendingJob.TransactionId, inbox.PipelineID, dataSeperator, segmentSeperator); break; case EDIFileType.SWNT: //inbox.DatasetID = (int)DTO.DataSet.System_Wide_Notices; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); //isProcessed = ProcessSwntData(subEDIfile, pendingJob.TransactionId, inbox.PipelineID, dataSeperator, segmentSeperator); break; case EDIFileType.SQTS: //inbox.DatasetID = (int)DTO.DataSet.Scheduled_Quantity; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); //isProcessed = ProcessSqtsData(subEDIfile, pendingJob.TransactionId, inbox.PipelineID, dataSeperator, segmentSeperator); break; case EDIFileType.Ack: //inbox.DatasetID = (int)DTO.DataSet.Ack_997; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); break; case EDIFileType.Unknown: //inbox.DatasetID = 99; //pendingJob.DatasetId = inbox.DatasetID; //_serviceInbox.Update(inbox); //_serviceInbox.Save(); //_serviceTaskMgrJob.Update(pendingJob); //_serviceTaskMgrJob.Save(); break; } } //EdiOptions options = new EdiOptions(); //options.ComponentSeparator = '>'; //options.ElementSeparator = dataSeperator; //options.SegmentTerminator = segmentSeperator; //EdiDocument ediDocument = new EdiDocument(ediFile,options); //var startNodeIndexes = Enumerable.Range(0, ediDocument.Segments.Count()) // .Where(i => ediDocument.Segments[i].Id.StartsWith("ST")) // .ToList(); //var endingNodeIdexes = Enumerable.Range(0, ediDocument.Segments.Count()) // .Where(i => ediDocument.Segments[i].Id.StartsWith("SE")) // .ToList(); //if (startNodeIndexes.Count != endingNodeIdexes.Count) //{ // //ST and SE don't match //} //else //{ // List<OACYPerTransaction> list = new List<OACYPerTransaction>(); // for (int i = 0; i < startNodeIndexes.Count; i++) // { // int countMatch = (endingNodeIdexes[i] - startNodeIndexes[i]) + 1; // var singleExtractedFile = ediDocument.Segments.ToList().GetRange(startNodeIndexes[i], countMatch); // var fileType = CheckEDIFileType(singleExtractedFile); // switch (fileType) // { // case EDIFileType.OACY: // ProcessOacyFiles(singleExtractedFile); // break; // case EDIFileType.UNSC: // ProcessUNSCFiles(singleExtractedFile); // break; // case EDIFileType.RURD: // ProcessRURDFiles(singleExtractedFile); // break; // case EDIFileType.SWNT: // ProcessSWNTFiles(singleExtractedFile); // break; // case EDIFileType.NMQR: // ProcessNMQRFiles(singleExtractedFile); // break; // case EDIFileType.SQTS: // ProcessSQTSFiles(singleExtractedFile); // break; // case EDIFileType.Ack: // break; // case EDIFileType.Unknown: // break; // default: // break; // } // } //} } } catch (Exception ex) { ViewBag.Message = "File upload failed!!"; } return(View()); }