예제 #1
0
        /// <summary>
        /// Parses the input row, returning the Tag and Value in a tagValuePair.
        ///  Note: this method REQUIRES that the rowLeader and RowTrailer be present
        /// </summary>
        /// <param name="row">String containing a row of data from the file header</param>
        /// <returns>The Tag-Value pair extracted from the row</returns>
        private ChainInfo.tagValuePair parseHeaderRow(string row)
        {
            ChainInfo.tagValuePair val = new ChainInfo.tagValuePair();
            string curRow = row.Substring(FileHandler.headerRowLeader.Length);
            int    pos    = curRow.IndexOf(FileHandler.headerTagDelim);

            val.tagName  = curRow.Substring(0, pos);
            val.tagValue = curRow.Substring(pos + FileHandler.headerTagDelim.Length);

            // Take care of RowTrailer, if necessary:
            if (!FileHandler.headerRowTrailer.StartsWith(OpenMedICUtils.newLine))
            {
                // Must remove everything up to the newLine, if any:
                pos = FileHandler.headerRowTrailer.IndexOf(OpenMedICUtils.newLine);
                if (pos > -1)
                {                       // There IS a newLine -- remove everything up to that
                }
                else
                {
                    // No newLine -- remove whole rowTrailer:
                    pos = FileHandler.headerRowTrailer.Length;
                }

                val.tagValue = val.tagValue.Substring(0, val.tagValue.Length - pos);
            }

            return(val);
        }
예제 #2
0
        private void readHeader()
        {
            ChainInfo.tagValuePair val = new ChainInfo.tagValuePair();
            string       headerRow;
            StreamReader fNew = new StreamReader(fPathName);

            try
            {
                // Scan forward to desired starting point:
                if (curReadStartPos > 0)
                {
                    // Scan forward to desired starting point:
                    fNew.BaseStream.Seek(curReadStartPos, System.IO.SeekOrigin.Begin);
                }

                for (int i = 0; i < 10000; i++)                 // more than 10K lines of header would be a problem...
                {
                    headerRow             = fNew.ReadLine();
                    this.curReadStartPos += headerRow.Length + OpenMedICUtils.newLine.Length;

                    if (headerRow == FileHandler.headerEndDelim)
                    {                           // End of the header
                                                // We are done:
                        break;
                    }
                    else if (!headerRow.StartsWith(FileHandler.headerRowLeader))
                    {                           // NOT  a new header row
                                                // Hmmm, this is a continuation of the last value!
                        val.tagValue += FileHandler.headerRowTrailer + headerRow;
                        // Now overwrite what we wrote on the last write:
                        setInitValueByTag(initValues, val);
                        // If there are even more rows, we'll update this again later...
                    }
                    else if (!OpenMedICUtils.isEmpty(headerRow))
                    {                           // NOT empty (must be a new header row)
                        val = parseHeaderRow(headerRow);
                        // Update initValues -- this is either the "live" object or
                        // it's the local-only object, depending on our mode:
                        setInitValueByTag(initValues, val);
                    }
                    // Check for run-away (unterminated) headers:
                    if (i > 9998)
                    {
                        // Bad!
                        throw new FileLoadException("The header is not terminated or too big!  "
                                                    + "Already processed " + i + " rows without finding the Header Terminator row (\""
                                                    + FileHandler.headerEndDelim + "\")!",
                                                    this.fPathName);
                    }
                }
            }
            finally
            {
                fNew.Close();
            }
        }
예제 #3
0
        private void setInitValueByTag(ChainInfo initSet, ChainInfo.tagValuePair tagVal)
        {
            // Get the tag:
            ChainInfo.varTags tag = ChainInfo.getTagFromValue(tagVal.tagName);
            // Set appropriately -- try ChainInfo first:
            bool matched = initSet.setByTag(tag, tagVal.tagValue);

            if (!matched)               // It was not an ChainInfo, try DataInfo:
            {
                matched = initSet.dataInfo.setByTag(tag, tagVal.tagValue);
            }
            if (!matched)               // Not a DataInfo, try a PatientInfo
            {
                matched = initSet.patientInfo.setByTag(tag, tagVal.tagValue);
            }
            if (!matched)
            {
                matched = initSet.fileInfo.setByTag(tag, tagVal.tagValue);
            }
            if (!matched)
            {
                // None of the above -- ????
            }
        }