Beispiel #1
0
        protected override SchemaRow ReadRow(ExcelWorksheet schemaWorksheet, int row)
        {
            if (row > schemaWorksheet.Dimension.End.Row)
            {
                return(null);
            }

            FlatFileSchemaRow schemaRow = new FlatFileSchemaRow();

            schemaRow.Grouping        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, GroupingIndex);
            schemaRow.Loop            = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, LoopIndex);
            schemaRow.Segment         = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, SegmentIndex);
            schemaRow.DataElementTag  = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, DataElementTagIndex);
            schemaRow.DataElementName = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, DataElementNameIndex);

            base.ReadBasicRowData(schemaWorksheet, schemaRow, row);

            // Check for invalid loop names
            if (string.IsNullOrWhiteSpace(schemaRow.Loop) == false &&
                string.Equals(schemaRow.Loop, "n/a", StringComparison.InvariantCultureIgnoreCase) == false &&
                schemaRow.Loop.Trim().Contains('|'))
            {
                AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(MinMaxIndex), string.Format("Invalid loop value {0}", schemaRow.Loop));
            }

            return(schemaRow);
        }
        protected void GetMinMax(string minMax, int row, out int minL, out int maxL)
        {
            minL = -1;
            maxL = -1;

            if (string.IsNullOrEmpty(minMax))
            {
                return;
            }

            string[] numbers = minMax.Split('/');

            if (numbers == null || numbers.Length != 2)
            {
                AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(MinMaxIndex), string.Format("Invalid MinMax value", minMax));
            }
            else
            {
                // TODO: enhance SchemaReaderException to have segment, row as properties
                if (int.TryParse(numbers[0], out minL) == false)
                {
                    AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(MinMaxIndex), string.Format("Cannot parse Min value {0}", numbers[0]));
                    //throw new SchemaReaderException(string.Format("Cannot parse Min value {0} on row {1}", numbers[0], row));
                }

                if (int.TryParse(numbers[1], out maxL) == false)
                {
                    AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(MinMaxIndex), string.Format("Cannot parse Max value {0}", numbers[1]));
                    //throw new SchemaReaderException(string.Format("Cannot parse Max value {0} on row {1}", numbers[1], row));
                }
            }
        }
        private void ReadMetadata(ExcelWorksheet schemaWorksheet)
        {
            int    row;
            string cellValue;

            for (row = 1; row < schemaWorksheet.Dimension.End.Row; ++row)
            {
                cellValue = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, 1);
                if (cellValue == null)
                {
                    continue;
                }

                if (string.Compare("Root Node", cellValue, true) == 0)
                {
                    RootNodeName = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, 3);

                    if (string.IsNullOrWhiteSpace(RootNodeName))
                    {
                        AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(3), string.Format("Root node name is empty", cellValue));
                    }

                    break;
                }
            }
        }
        protected override SchemaRow ReadRow(ExcelWorksheet schemaWorksheet, int row)
        {
            if (row > schemaWorksheet.Dimension.End.Row)
            {
                return(null);
            }

            XmlFileSchemaRow schemaRow = new XmlFileSchemaRow();

            // Read all first 5 cell value
            for (int i = 0; i < 5; i++)
            {
                schemaRow.ElementName = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, i + 1);
                if (string.IsNullOrWhiteSpace(schemaRow.ElementName) == false)
                {
                    schemaRow.Level = i + 1;
                    break;
                }
            }

            base.ReadBasicRowData(schemaWorksheet, schemaRow, row);

            // If data type is not-null then set IsLeafNode flag true
            schemaRow.IsLeafNode = !string.IsNullOrWhiteSpace(schemaRow.DataType);

            return(schemaRow);
        }
        protected override SchemaRow ReadRow(ExcelWorksheet schemaWorksheet, int row)
        {
            if (row > schemaWorksheet.Dimension.End.Row)
            {
                return(null);
            }

            X12SchemaRow schemaRow = new X12SchemaRow();

            schemaRow.Grouping        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, GroupingIndex);
            schemaRow.Loop            = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, LoopIndex);
            schemaRow.Segment         = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, SegmentIndex);
            schemaRow.DataElementTag  = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, DataElementTagIndex);
            schemaRow.DataElementName = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, DataElementNameIndex);

            base.ReadBasicRowData(schemaWorksheet, schemaRow, row);

            // This code was added during contingency field handling, however maps migration project generate spec certs without contingencies and hence the following code was removed.
            // if (string.IsNullOrWhiteSpace(schemaRow.DataElementTag) == false && string.Compare(schemaRow.DataElementTag, "HL03", true) == 0)
            //        schemaRow.IsTriggerField = true;

            // Check for invalid loop names
            if (string.IsNullOrWhiteSpace(schemaRow.Loop) == false &&
                string.Equals(schemaRow.Loop, "n/a", StringComparison.InvariantCultureIgnoreCase) == false &&
                schemaRow.Loop.Trim().Contains('|'))
            {
                AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(MinMaxIndex), string.Format("Invalid loop value {0}", schemaRow.Loop));
            }

            return(schemaRow);
        }
Beispiel #6
0
        private void ReadMetadata(DocumentPlug documentPlug, ExcelWorksheet schemaWorksheet)
        {
            int    row;
            string cellValue;
            int    delimiterCount = 0;

            for (row = 1; row < schemaWorksheet.Dimension.End.Row && delimiterCount < 2; ++row)
            {
                // column 1 has name 'Element Segment' or 'Segment Delimiter'
                // Column 3 has delimiter
                cellValue = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, 1);
                if (cellValue == null)
                {
                    continue;
                }

                if (string.Compare("Element Delimiter", cellValue, true) == 0)
                {
                    cellValue = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, 3);
                    // delimiter can be more than 1 char,
                    // split the string by ' ', convert each string to int
                    documentPlug.ElementDelimiters = GetDelimiters(cellValue);

                    if (documentPlug.ElementDelimiters == null)
                    {
                        AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(3), string.Format("'{0}' is invalid element delimiter", cellValue));
                    }

                    delimiterCount++;
                }
                else
                if (string.Compare("Segment Delimiter", cellValue, true) == 0)
                {
                    cellValue = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, 3);
                    documentPlug.SegmentDelimiters = GetDelimiters(cellValue);

                    if (documentPlug.SegmentDelimiters == null)
                    {
                        AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(3), string.Format("'{0}' is invalid segment delimiter", cellValue));
                    }

                    delimiterCount++;
                }
            }
        }
        protected void ReadBasicRowData(ExcelWorksheet schemaWorksheet, SchemaRow schemaRow, int row)
        {
            if (row > schemaWorksheet.Dimension.End.Row)
            {
                return;
            }

            schemaRow.MandatoryCode   = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, MandatoryCodeIndex);
            schemaRow.DataType        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, DataTypeIndex);
            schemaRow.MinMaxLength    = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, MinMaxIndex);
            schemaRow.EnumCode        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, EnumCodeIndex);
            schemaRow.EnumName        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, EnumNameIndex);
            schemaRow.EnumFlag        = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, EnumFlagIndex, true);
            schemaRow.MandatoryFlag   = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, MandatoryFlagIndex, true);
            schemaRow.IgnoreFlag      = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, IgnoreFlagIndex, true);
            schemaRow.Contingencies   = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, ContingenciesIndex, true);
            schemaRow.ContingencyType = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, ContingencyTypeIndex, true);

            if (TriggerFieldIndex != -1)
            {
                string triggerFieldText = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, TriggerFieldIndex, true);
                if (string.IsNullOrWhiteSpace(triggerFieldText) == false && triggerFieldText.Trim().ToUpperInvariant().Equals(TriggerFieldValue))
                {
                    schemaRow.IsTriggerField = true;
                }
            }

            if (string.IsNullOrWhiteSpace(schemaRow.EnumFlag))
            {
                schemaRow.EnumFlag = "?";
            }

            if (string.IsNullOrWhiteSpace(schemaRow.MandatoryFlag))
            {
                schemaRow.MandatoryFlag = "";
            }

            if (string.IsNullOrWhiteSpace(schemaRow.IgnoreFlag))
            {
                schemaRow.IgnoreFlag = "P";
            }
        }
Beispiel #8
0
        private void ReadMessageDomainIds(ExcelWorksheet schemaWorksheet, int row, BizRuleSet bizRuleSet)
        {
            int domainIdIndex = 3;
            int domainId;

            while (true)
            {
                string cellValue = GCExcelReaderHelper.ReadCell(schemaWorksheet, row, domainIdIndex);

                // Stop if cell value is non-integer
                if (cellValue == null || int.TryParse(cellValue, out domainId) == false)
                {
                    return;
                }

                bizRuleSet.MessageDomainIds.Add(domainId);

                domainIdIndex++;
            }
        }
Beispiel #9
0
        private List <string> ReadBizRuleRow(ExcelWorksheet schemaWorksheet, int columnCount, ref int row)
        {
            while (row <= schemaWorksheet.Dimension.End.Row &&
                   GCExcelReaderHelper.ReadCell(schemaWorksheet, row, 1) == null)
            {
                row++;
            }

            if (row > schemaWorksheet.Dimension.End.Row)
            {
                return(null);
            }

            List <string> bizRuleRow = new List <string>();

            for (int i = 1; i <= columnCount; i++)
            {
                bizRuleRow.Add(GCExcelReaderHelper.ReadCell(schemaWorksheet, row, i));
            }

            return(bizRuleRow);
        }
        // crossSegmentPointer = Path to data element followed by expected value in "[]" e.g. HLO->REF->REF01[PK]
        private void AddIdValue(SchemaRow segmentRow, int row, string crossSegmentPointer, List <string> optionalValues, Dictionary <string, string> allowedValues, Dictionary <string, Contingency> contingencies)
        {
            allowedValues.Add(segmentRow.EnumCode, segmentRow.EnumName);

            if (string.Compare(segmentRow.IgnoreFlag, "I", true) == 0 || string.Compare(segmentRow.EnumFlag, "?", true) == 0)
            {
                optionalValues.Add(segmentRow.EnumCode);
            }

            if (string.IsNullOrWhiteSpace(segmentRow.ContingencyType) == false)
            {
                segmentRow.ContingencyType = segmentRow.ContingencyType.Trim();
                if (string.Compare(segmentRow.ContingencyType, "E", true) != 0 && string.Compare(segmentRow.ContingencyType, "CS", true) != 0)
                {
                    AddValidationResult(ResultType.Error, row, GCExcelReaderHelper.GetColumnIndex(ContingencyTypeIndex), string.Format("Invalid contingency type {0}", segmentRow.ContingencyType));
                }
                else
                {
                    Contingency contingency = new Contingency();
                    if (string.Compare(segmentRow.ContingencyType, "E", true) == 0)
                    {
                        contingency.Type = ContingencyType.Enumeration;
                    }
                    else
                    if (string.Compare(segmentRow.ContingencyType, "CS", true) == 0)
                    {
                        contingency.Type = ContingencyType.CrossSegment;
                    }

                    AddPendingContingencies(row, segmentRow.Contingencies, contingency);
                    ResolveContingency(row, crossSegmentPointer, segmentRow.EnumCode);

                    contingencies.Add(segmentRow.EnumCode, contingency);
                }
            }
        }
        // here contingencyValues are row numbers
        private void AddPendingContingencies(int currentRow, string contingencyValues, Contingency currentRowContingency)
        {
            if (string.IsNullOrWhiteSpace(contingencyValues) == true)
            {
                AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex), "No contigency specified");
                return;
            }

            string[] contingencyValueArr  = contingencyValues.Split(',');
            int[]    contingencyValueRows = new int[contingencyValueArr.Length];
            int      contingencyRow;

            foreach (string contingencyValueRow in contingencyValueArr)
            {
                if (int.TryParse(contingencyValueRow.Trim(), out contingencyRow) == true)
                {
                    // Check if contingency value is already present
                    if (contingencyRow <= currentRow)
                    {
                        if (contingencyRow == currentRow)
                        {
                            AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex), "Same row cannot be marked as its own contingency");
                            continue;
                        }

                        string contingencyValue = null;

                        if (currentRowContingency.Type == ContingencyType.Enumeration && ContingencyValue.ContainsKey(contingencyRow))
                        {
                            contingencyValue = ContingencyValue[contingencyRow];
                        }
                        else
                        if (currentRowContingency.Type == ContingencyType.CrossSegment && ContingencyPath.ContainsKey(contingencyRow))
                        {
                            contingencyValue = ContingencyPath[contingencyRow];
                        }

                        if (contingencyValue != null)
                        {
                            currentRowContingency.AddContingencyValue(contingencyValue);
                        }
                        else
                        {
                            AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex),
                                                string.Format("Invalid contingency row {0}. Rule: Cotingency row should be marked as each other's contingency.", contingencyRow));
                        }
                    }
                    else
                    {
                        List <Contingency> contingencies;
                        if (PendingContingencies.TryGetValue(contingencyRow, out contingencies) == true)
                        {
                            contingencies.Add(currentRowContingency);
                        }
                        else
                        {
                            contingencies = new List <Contingency>();
                            contingencies.Add(currentRowContingency);
                            PendingContingencies.Add(contingencyRow, contingencies);
                        }
                    }
                }
                else
                {
                    AddValidationResult(ResultType.Error, currentRow, GCExcelReaderHelper.GetColumnIndex(ContingenciesIndex), string.Format("Invalid contingency row {0}", contingencyValueRow));
                }
            }
        }
        protected X12BaseDataType ReadDataType(SchemaRow segmentRow, ExcelWorksheet schemaWorksheet, string segmentPath, ref int row)
        {
            List <string> optionalValues = new List <string>();
            Dictionary <string, string>      allowedValues = new Dictionary <string, string>();
            Dictionary <string, Contingency> contingencies = new Dictionary <string, Contingency>();
            X12BaseDataType dataType;
            string          dataTypeName = segmentRow.DataType;
            string          currentTag   = segmentRow.GetDataElementTag();
            int             dataTypeRow  = row - 1;

            // In sample schema ISA016 has data type blank hence AN and default is set to AN
            if (string.IsNullOrEmpty(dataTypeName) == true)
            {
                dataTypeName = "AN";
                AddValidationResult(ResultType.Warning, dataTypeRow, GCExcelReaderHelper.GetColumnIndex(DataTypeIndex),
                                    string.Format("'{0}' segment is missing data type, treating it as AlphaNumeric", currentTag));
            }

            int minL, maxL;

            GetMinMax(segmentRow.MinMaxLength, row, out minL, out maxL);

            // add current row enum code if present
            if (string.IsNullOrWhiteSpace(segmentRow.EnumCode) == false && string.Compare(segmentRow.EnumFlag, "n", true) != 0)
            {
                AddIdValue(segmentRow, row, string.Format("{0}[{1}]", segmentPath, segmentRow.EnumCode), optionalValues, allowedValues, contingencies);
            }

            // Traverse all sub rows - these rows are mostly relevant for enums (containing enum values)
            // however sample schema shows multiple rows for other data types too
            while ((segmentRow = ReadRow(schemaWorksheet, row)) != null)
            {
                if ((string.IsNullOrEmpty(segmentRow.GetDataElementTag()) == false && string.Compare(segmentRow.GetDataElementTag(), currentTag, true) != 0) ||
                    IsDataTypeRowsOver(segmentRow, row))
                {
                    break;
                }

                switch (dataTypeName)
                {
                case "ID":
                    if (string.IsNullOrEmpty(segmentRow.EnumCode) == false && string.Compare(segmentRow.EnumFlag, "n", true) != 0)
                    {
                        AddIdValue(segmentRow, row, string.Format("{0}[{1}]", segmentPath, segmentRow.EnumCode), optionalValues, allowedValues, contingencies);
                    }
                    break;

                case "DT":
                case "AN":
                case "N0":
                case "N2":
                case "TM":
                case "R":
                    break;

                default:
                    //AddValidationResult(ResultType.Error, row, GetColumnIndex(EnumCodeIndex), string.Format("Unknown data type {0}", dataTypeName));
                    //throw new SchemaReaderException(string.Format("Unknown data type {0} on row {1}", dataTypeName, row));
                    break;
                }
                ++row;
            }

            switch (dataTypeName)
            {
            case "ID":
                if (allowedValues == null || allowedValues.Count == 0)
                {
                    dataType = new X12_AnDataType(dataTypeName, minL, maxL);
                    AddValidationResult(ResultType.Warning, dataTypeRow, GCExcelReaderHelper.GetColumnIndex(EnumCodeIndex),
                                        string.Format("'{0}' segment has ID type without any values, treating it as AlphaNumeric.", currentTag));
                }
                else
                {
                    dataType = new X12_IdDataType(dataTypeName, optionalValues, allowedValues, contingencies);
                }
                break;

            case "DT":
                dataType = new X12_DtDataType(dataTypeName, minL, maxL);
                break;

            case "Comp":
            case "AN":
                dataType = new X12_AnDataType(dataTypeName, minL, maxL);
                break;

            case "N":
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            case "N0":
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            case "N2":
                dataType = X12_NDataType.GetDataTypeWithPrecision(2, minL, maxL);
                break;

            case "TM":
                dataType = new X12_TmDataType(dataTypeName, minL, maxL);
                break;

            case "R":
                dataType = new X12_RDataType(dataTypeName, minL, maxL);
                break;

            default:
                AddValidationResult(ResultType.Error, dataTypeRow, GCExcelReaderHelper.GetColumnIndex(EnumCodeIndex), string.Format("Unknown data type {0}", dataTypeName));
                dataType = new X12_AnDataType(dataTypeName, minL, maxL);     // This is to avoid compiler error.
                //throw new SchemaReaderException(string.Format("Unknown data type {0} on row {1}", dataTypeName, row));
                break;
            }

            return(dataType);
        }