/// <summary>
 /// Initializes a new instance of the <see cref="EdiParseManager"/> class.
 /// </summary>
 /// <param name="writeableDataLocationFactory">
 /// The writeable data location factory.
 /// </param>
 /// <param name="parseEngine">
 /// The parse engine.
 /// </param>
 /// <param name="ediStructureEngine">
 /// The edi structure engine.
 /// </param>
 public EdiParseManager(IWriteableDataLocationFactory writeableDataLocationFactory, IEdiParseEngine parseEngine, IEdiStructureWriterEngine ediStructureEngine)
 {
     this._ediStructureEngine = ediStructureEngine;
     this._writeableDataLocationFactory = writeableDataLocationFactory ?? new WriteableDataLocationFactory();
     this._ediParseEngine = parseEngine ?? new EdiParseEngine();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EdiWorkspace"/> class.
        /// </summary>
        /// <param name="ediDocument">
        /// The EDI document.
        /// </param>
        /// <param name="writeableDataLocationFactory">
        /// The writable Data Location Factory.
        /// </param>
        /// <param name="ediParseEngine">
        /// The EDI Parse Engine.
        /// </param>
        public EdiWorkspace(IReadableDataLocation ediDocument, IWriteableDataLocationFactory writeableDataLocationFactory, IEdiParseEngine ediParseEngine)
        {
            this._ediMetadata = ediParseEngine.ParseEDIMessage(ediDocument);
            IFileReader fr = new FileReaderImpl(ediDocument, EdiConstants.EndOfLineRegEx, EdiConstants.CharsetEncoding);

            foreach (var documentPosition in this._ediMetadata.DocumentIndex)
            {
                int start = documentPosition.StartLine;
                this._writeableDataLocation = writeableDataLocationFactory.GetTemporaryWriteableDataLocation();
                using (TextWriter osw = new StreamWriter(this._writeableDataLocation.OutputStream, EdiConstants.CharsetEncoding))
                {
                    while (fr.MoveNext())
                    {
                        int idx = fr.LineNumber;

                        // If this next line is within the bounds of the start and end location then write the current line to the writer  
                        if (idx >= start)
                        {
                            string line = fr.CurrentLine;
                            Write(osw, line + EdiConstants.EndTag);

                            // WriteLineSeparator(osw);

                            // Keep going until we encounter the end segment indicator
                            if (line.StartsWith(EdiPrefix.EndMessageAdministration.ToString()))
                            {
                                break;
                            }
                        }
                    }

                    osw.Flush();
                }

                if (documentPosition.IsData)
                {
                    IEdiDataDocument dataDocument = new EdiDataDocument(this._writeableDataLocation, documentPosition, this._ediMetadata);
                    this._dataDocuments.Add(dataDocument);
                    this._keyFamilyReferences.Add(dataDocument.DataReader.DataSetHeaderObject.DataStructureReference.StructureReference.MaintainableReference);
                }
                else
                {
                    ////IEdiStructureDocument doc = new EDIStructureDocumentImpl(wdl, documentPosition, this._ediMetadata);
                    ////this._beans.Add(doc.SdmxObjects);
                    this._writeableDataLocation.Close();
                }
            }

            this.CreateHeader();
        }