Ejemplo n.º 1
0
        private static void PopulateEnumerationValues(X12_IdDataType idType, XmlSchemaElement element)
        {
            if (idType == null || idType.AllowedValues == null || idType.AllowedValues.Count == 0)
            {
                return;
            }

            XmlSchemaSimpleType            simpleType  = element.SchemaType as XmlSchemaSimpleType;
            XmlSchemaSimpleTypeRestriction restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;

            foreach (KeyValuePair <string, string> kvp in idType.AllowedValues)
            {
                XmlSchemaEnumerationFacet facet = new XmlSchemaEnumerationFacet();
                facet.Value = kvp.Key;
                if (!string.IsNullOrEmpty(kvp.Value))
                {
                    XmlSchemaAnnotation    annotation = new XmlSchemaAnnotation();
                    XmlSchemaDocumentation doc        = new XmlSchemaDocumentation();
                    doc.Markup = TextToNodeArray(kvp.Value);
                    annotation.Items.Add(doc);
                    facet.Annotation = annotation;
                }

                restriction.Facets.Add(facet);
            }
        }
        public static bool IsSameSegment(this IPluglet pluglet, string segmentName, string[] segmentDetails, bool ignoreOccurrenceCheck)
        {
            bool isSameSegment = false;

            if (pluglet.PlugletType == PlugletType.Segment || pluglet.PlugletType == PlugletType.CompositeData)
            {
                // Set currentOccur based on number of occurances
                // option-1 (not clean design, but quick and dirty) - Maintain count in IPluglet and reset it on EDIReader.Initialize
                // option-2 - Refer to document fragment (result of EDI reader) and get current occurrence count
                int currentOccur = pluglet.CurrentOccurrences;

                if (string.Equals(pluglet.Tag, segmentName, StringComparison.InvariantCultureIgnoreCase) &&
                    (ignoreOccurrenceCheck == true
                     ||
                     (currentOccur == 0 ||
                      (pluglet.IsRepeatable &&
                       (pluglet.RepetitionInfo.MaxOccurs == -1 || pluglet.RepetitionInfo.MaxOccurs > currentOccur)))))
                {
                    if (pluglet.ContainsTriggerChildField)
                    {
                        for (int i = 0; i < pluglet.Children.Count; i++)
                        {
                            IPluglet child = pluglet.Children[i];
                            if (child.IsTriggerField)
                            {
                                // For trigger field pluglet should is of type ID (enum) and one of the value should match the dataSegmentValue
                                X12_IdDataType dataType = child.DataType as X12_IdDataType;
                                if (dataType != null &&
                                    (i + 1) < segmentDetails.Length &&
                                    !string.IsNullOrWhiteSpace(segmentDetails[i + 1]))
                                {
                                    string dataSegmentValue = segmentDetails[i + 1].Trim().ToUpperInvariant();
                                    foreach (string value in dataType.AllowedValues.Keys)
                                    {
                                        if (value.ToUpperInvariant().Equals(dataSegmentValue))
                                        {
                                            isSameSegment = true;
                                            break;
                                        }
                                    }

                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        isSameSegment = true;
                    }
                }
            }

            return(isSameSegment);
        }
        private static object GetPlugletDataType(X12BaseDataType dataType)
        {
            string dataTypeString = dataType == null ? string.Empty : dataType.ToString();

            if (string.IsNullOrWhiteSpace(dataTypeString) == false)
            {
                X12_IdDataType idDataType = dataType as X12_IdDataType;
                if (idDataType != null)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(dataTypeString);
                    if (idDataType.AllowedValues != null)
                    {
                        foreach (KeyValuePair <string, string> kvp in idDataType.AllowedValues)
                        {
                            if (!string.IsNullOrEmpty(kvp.Value))
                            {
                                Contingency contingency = idDataType.GetContingencies(kvp.Key);
                                if (contingency != null && contingency.ContingencyValues != null && contingency.ContingencyValues.Count > 0)
                                {
                                    sb.AppendFormat(" '{0}:{1}:Contingencies{{", kvp.Key, kvp.Value);
                                    sb.AppendFormat(string.Join(",", contingency.ContingencyValues));
                                    sb.AppendFormat("}}'");
                                }
                                else
                                {
                                    sb.AppendFormat(" '{0}:{1}'", kvp.Key, kvp.Value);
                                }
                            }
                        }
                    }
                    dataTypeString = sb.ToString();
                }
            }

            return(dataTypeString);
        }
Ejemplo n.º 4
0
        public static X12BaseDataType CreateX12DataTypeFromXmlSchema(XmlSchemaElement element, bool bDesignTime, string dataTypeName, string stringMinL, string stringMaxL)
        {
            if (string.IsNullOrEmpty(dataTypeName))
            {
                dataTypeName = "STRING";
            }

            else
            {
                dataTypeName = dataTypeName.ToUpper();
            }

            X12BaseDataType dataType = null;
            int             minL, maxL;

            minL = maxL = -1;
            Dictionary <string, string> allowedValues = null;

            if (string.Equals(dataTypeName, IDNew_DataTypeName, StringComparison.OrdinalIgnoreCase))
            {
                allowedValues = DataTypeHelper.RetrieveFacetMetadata(element, stringMinL, stringMaxL, out minL, out maxL);
            }

            switch (dataTypeName)
            {
            case RNew_DataTypeName:
                dataType = new X12_RDataType(RNew_DataTypeName, minL, maxL);
                break;

            case "STRING":
            case "SYSTEM.STRING":
            case EFACT_A_DataTypeName:
            case EFACT_AN_DataTypeName:
            case ANNew_DataTypeName:
                dataType = new X12_AnDataType(ANNew_DataTypeName, minL, maxL);
                break;

            case IDNew_DataTypeName:
                dataType = new X12_IdDataType(IDNew_DataTypeName, allowedValues);
                break;

            case DateNew_DataTypeName:
                dataType = new X12_DtDataType(DateNew_DataTypeName, minL, maxL);
                break;

            case TimeNew_DataTypeName:
                dataType = new X12_TmDataType(TimeNew_DataTypeName, minL, maxL);
                break;

            case EFACT_N_DataTypeName:
            case NNew_DataTypeName:
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            default:
                if (dataTypeName.Length == 2 && dataTypeName.StartsWith("N", StringComparison.Ordinal) &&
                    dataTypeName[1] >= '0' && dataTypeName[1] <= '9')
                {
                    dataType = X12_NDataType.GetDataTypeWithPrecision(dataTypeName[1] - '0',
                                                                      minL, maxL);
                }

                else
                {
                    throw new Exception(string.Format("{0} data type is not supported", dataTypeName));
                }

                break;
            }

            return(dataType);
        }
Ejemplo n.º 5
0
        public static X12BaseDataType CreateX12DataTypeFromXmlSchema2(XmlSchemaElement element, bool bDesignTime)
        {
            string          dataTypeName;
            X12BaseDataType dataType = null;
            XmlSchemaSimpleTypeRestriction restriction = null;
            int minL, maxL;

            minL = maxL = -1;
            Dictionary <string, string> sortedList = null;

            if (element.ElementType is XmlSchemaSimpleType)
            {
                XmlSchemaSimpleType sType = (XmlSchemaSimpleType)element.ElementType;
                XmlQualifiedName    name  = sType.QualifiedName;
                dataTypeName = sType.Name;

                restriction = sType.Content as XmlSchemaSimpleTypeRestriction;
                if (restriction != null)
                {
                    dataTypeName = name.Name != null && name.Name.StartsWith(ID_DataTypeName, StringComparison.Ordinal)
                        ? ID_DataTypeName : restriction.BaseTypeName.Name;
                    sortedList = DataTypeHelper.RetrieveFacets(restriction, out minL, out maxL);
                }
                //Console.WriteLine("Element name = " + element.Name + " SimpleType name = " + dataTypeName);
            }

            else
            {
                XmlSchemaDatatype dType = (XmlSchemaDatatype)element.ElementType;
                dataTypeName = dType.ValueType.ToString();
                //Console.WriteLine("Element name = " + element.Name + " DataType name = " + dType.ValueType);
            }

            switch (dataTypeName.ToUpper())
            {
            case R_DataTypeName:
                dataType = new X12_RDataType(R_DataTypeName, minL, maxL);
                break;

            case "STRING":
            case "SYSTEM.STRING":
            case EFACT_A_DataTypeName:
            case EFACT_AN_DataTypeName:
            case AN_DataTypeName:
                dataType = new X12_AnDataType(AN_DataTypeName, minL, maxL);
                break;

            case ID_DataTypeName:
                dataType = new X12_IdDataType(ID_DataTypeName, sortedList);
                break;

            case Date_DataTypeName:
                dataType = new X12_DtDataType(Date_DataTypeName, minL, maxL);
                break;

            case Time_DataTypeName:
                dataType = new X12_TmDataType(Time_DataTypeName, minL, maxL);
                break;

            case EFACT_N_DataTypeName:
            case N_DataTypeName:
                dataType = X12_NDataType.GetDataTypeWithPrecision(0, minL, maxL);
                break;

            default:
                if (dataTypeName.Length == 6 && dataTypeName.StartsWith("X12_N", StringComparison.Ordinal) &&
                    dataTypeName[5] >= '0' && dataTypeName[5] <= '9')
                {
                    dataType = X12_NDataType.GetDataTypeWithPrecision(dataTypeName[5] - '0',
                                                                      minL, maxL);
                }

                else
                {
                    //throw new Exception(string.Format("{0} data type is not supported", dataTypeName));
                    dataType = new X12_AnDataType(AN_DataTypeName, -1, -1);
                }

                break;
            }

            return(dataType);
        }