public static bool OpenEDIFile(EDIFileStream EdiFileStream) { if (FileReader != null) { FileReader.Dispose(); // if we're opening a 2nd (or more) file, close the stream from the previous one } FileReader = EdiFileStream; //Read the first 106 bytes, and validate that it at least looks like a 5010 X12 EDI file string Envelope = String.Empty; CurrentPageNumber = 0; try { Envelope = FileReader.ReadEnvelope(); //Check for X12 Control Segment Name if (String.IsNullOrEmpty(Envelope) || Envelope.Length != 106 || Envelope.Substring(0, 3) != "ISA") { throw new ArgumentException("File is not an X12 EDI file or file is missing control segment."); } TotalPages = FileReader.LoadSegmentOffset(); return(true); } catch (ArgumentException e) { return(false); } }
private void Open_File(object sender, RoutedEventArgs e) { var picker = new OpenFileDialog(); if (picker.ShowDialog() == true) { Mouse.OverrideCursor = Cursors.Wait; SearchResults.Text = String.Empty; FileName.Text = $"File Open: {picker.FileName}"; var fileStream = File.OpenRead(picker.FileName); var ediStream = new EDIFileStream(fileStream); bool fileOk = FileUtils.OpenEDIFile(ediStream); if (!fileOk) { Mouse.OverrideCursor = null; MessageBox.Show("Error: File is not an X12 EDI file. Please try a different file."); } else { TotalPages.Text = $"Total Pages: {Convert.ToString(FileUtils.TotalPages)}"; FileContent.Text = FileUtils.LoadPage(FileUtils.NavigationType.Next); CurrentPage.Text = $"Current Page: {Convert.ToString(FileUtils.CurrentPageNumber)}"; UpdateLineNumbers(); Mouse.OverrideCursor = null; } } }