コード例 #1
0
ファイル: SegmentContext.cs プロジェクト: poiswe/ediFabric
        /// <summary>
        /// Initializes a new instance of the <see cref="SegmentContext"/> class.
        /// </summary>
        /// <param name="ediSegment">The edi segment.</param>
        /// <param name="interchangeContext">The interchange context.</param>
        /// <param name="format">The edi format.</param>
        public SegmentContext(string ediSegment, InterchangeContext interchangeContext, EdiFormats format)
        {
            if (string.IsNullOrEmpty(ediSegment)) throw new ArgumentNullException("ediSegment");
            if (interchangeContext == null) throw new ArgumentNullException("interchangeContext");

            // Blank segments shouldn't have gone that far
            var splitted = ediSegment.Split(interchangeContext.DataElementSeparator.ToCharArray(), StringSplitOptions.None);
            if (splitted.Length < 2) throw new Exception("Segment is blank.");

            Name = splitted[0];
            Value = null;
            ParentId = null;

            // UNA segments don't have values
            if (ediSegment.StartsWith(EdiSegments.Una))
            {
                Name = EdiSegments.Una;
            }

            // Handle blank segments, e.g. BHT+'
            if (format == EdiFormats.Hipaa)
            {
                var splittedElement = splitted[1].Split(interchangeContext.ComponentDataElementSeparator.ToCharArray(), StringSplitOptions.None);
                Value = splittedElement[0];
                if (ediSegment.StartsWith(EdiSegments.Hl) && !string.IsNullOrEmpty(splitted[2])) ParentId = splitted[2];
            }
        }
コード例 #2
0
        /// <summary>
        /// Converts message context into system type  
        /// </summary>
        /// <param name="format">Message format.</param>
        /// <param name="version">Message version.</param>
        /// <param name="tag">Message tag.</param>
        /// <param name="origin">Message origin.</param>
        /// <returns>
        /// The system type.
        /// </returns>
        private Type ToSystemType(EdiFormats format, string version, string tag, string origin)
        {
            const string definitions = "EdiFabric.Definitions";

            if (string.IsNullOrEmpty(version)) throw new NullReferenceException("version");
            if (string.IsNullOrEmpty(tag)) throw new NullReferenceException("tag");

            var typeFullName = definitions + "." + format + "_" + version + "_" + tag;
            if (!string.IsNullOrEmpty(origin))
                typeFullName = typeFullName + "_" + origin;

            typeFullName = typeFullName + ".M_" + tag;
            typeFullName = typeFullName + ", " + definitions;

            var systemType = Type.GetType(typeFullName);

            if (systemType == null)
                throw new ParserException(string.Format("Can't find type for type name = {0}", typeFullName));

            return systemType;
        }