Пример #1
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] multiValue = ToImproperMultiValue(s);
            Age[]    age        = new Age[multiValue.Length];
            for (int i = 0; i < age.Length; i++)
            {
                string item = multiValue[i];
                try
                {
                    if (item == null || item.Equals(""))
                    {
                        item = "000D";
                    }
                    age[i] = new Age(item);
                }
                catch (Exception e)
                {
                    throw new EncodingException("Age string format is invalid.",
                                                Name + "/item", item);
                }
            }
            return(age);
        }
Пример #2
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string unlimitedText = TransferSyntax.ToString(bytes);

            unlimitedText = unlimitedText.TrimEnd(null);
            return(new string[] { unlimitedText });
        }
Пример #3
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] multiValue = ToImproperMultiValue(s);
            Uid[]    uidValue   = new Uid[multiValue.Length];
            for (int i = 0; i < uidValue.Length; i++)
            {
                string item = multiValue[i];
                // trailing zero padding
                if (item.Length > 0)
                {
                    byte b = (byte)item[item.Length - 1];
                    if (b == 0)
                    {
                        item = item.Remove(item.Length - 1, 1);
                    }
                    item = item.Replace(" ", null);
                }
                if (item == null || item.Equals(""))
                {
                    item = "0";
                }
                uidValue[i] = new Uid(item);
            }
            return(uidValue);
        }
Пример #4
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string            shortText = TransferSyntax.ToString(bytes);
            ValueMultiplicity vm        = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                if (shortText.Length <= 1024)
                {
                    shortText = shortText.TrimEnd(null);
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 1024 characters is only allowed.",
                              Tag, Name + "/shortText", shortText);
                }
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.", Tag,
                          Name + "/VM, " + Name + "/shortText",
                          vm.ToString() + ", " + shortText);
            }
            return(new string[] { shortText });
        }
Пример #5
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[]  multiValue   = ToImproperMultiValue(s);
            decimal[] decimalValue = new decimal[multiValue.Length];
            for (int i = 0; i < decimalValue.Length; i++)
            {
                string item = multiValue[i];
                item = item.Trim();
                try
                {
                    if (item.Length > 0)
                    {
                        decimalValue[i] = decimal.Parse(item,
                                                        NumberStyles.Float,
                                                        NumberFormatInfo.InvariantInfo);
                    }
                }
                catch (Exception e)
                {
                    throw new EncodingException(
                              "Decimal string format is invalid.",
                              Tag, Name + "/item", item);
                }
            }
            return(decimalValue);
        }
Пример #6
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string shortText = TransferSyntax.ToString(bytes);

            shortText = shortText.TrimEnd(null);
            return(new string[] { shortText });
        }
Пример #7
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] multiValue = ToProperMultiValue(s);
            long[]   intValue   = new long[multiValue.Length];
            for (int i = 0; i < intValue.Length; i++)
            {
                string item = multiValue[i];
                if (item.Length <= 12)
                {
                    item = item.Trim();
                    try
                    {
                        if (item.Length > 0)
                        {
                            intValue[i] = long.Parse(item);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new EncodingException(
                                  "Integer string format is invalid.", Tag,
                                  Name + "/item", item);
                    }
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 12 bytes is only allowed.", Tag,
                              Name + "/item", item);
                }
            }
            return(intValue);
        }
Пример #8
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[]          multiValue = ToImproperMultiValue(s);
            System.DateTime[] date       = new System.DateTime[multiValue.Length];
            for (int i = 0; i < date.Length; i++)
            {
                string item = multiValue[i];
                if (Regex.IsMatch(item, "^[0-9]{4}\\.?[0-9]{2}\\.?[0-9]{2}$"))
                {
                    item = item.Replace(".", null);
                    string year  = item.Substring(0, 4);
                    string month = item.Substring(4, 2);
                    string day   = item.Substring(6, 2);
                    try
                    {
                        date[i] = new System.DateTime(int.Parse(year),
                                                      int.Parse(month), int.Parse(day));
                    }
                    catch (Exception e)
                    {
                        throw new EncodingException("Date format is invalid.",
                                                    Tag, Name + "/item", item);
                    }
                }
            }
            return(date);
        }
Пример #9
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] applicationName = ToProperMultiValue(s);
            for (int i = 0; i < applicationName.Length; i++)
            {
                string item = applicationName[0];
                if (item.Length > 16)
                {
                    throw new EncodingException(
                              "A value of max. 16 bytes is only allowed.", Tag,
                              Name + "/item", item);
                }
                else if (Regex.IsMatch(item, "^[\\s]{16}$"))
                {
                    throw new EncodingException(
                              "No application name specified.", Tag, Name + "/item",
                              item);
                }
                else if (item.Length > 0)
                {
                    applicationName[i] = item.Trim();
                }
            }
            return(applicationName);
        }
Пример #10
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] multiValue = ToProperMultiValue(s);
            Uid[]    uidValue   = new Uid[multiValue.Length];
            for (int i = 0; i < uidValue.Length; i++)
            {
                string item = multiValue[i];
                if (item.Length > 64)
                {
                    throw new EncodingException(
                              "A value of max. 64 characters is only allowed.",
                              Tag, Name + "/item", item);
                }
                else if (item.Length > 0)
                {
                    // trailing zero padding
                    byte b = (byte)item[item.Length - 1];
                    if (b == 0)
                    {
                        item = item.Remove(item.Length - 1, 1);
                    }
                    item = item.Replace(" ", null);
                }
                if (item == null || item.Equals(""))
                {
                    throw new EncodingException("Uid is empty.", Tag,
                                                Name + "/item", item);
                }
                uidValue[i] = new Uid(item);
            }
            return(uidValue);
        }
Пример #11
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string            unlimitedText = TransferSyntax.ToString(bytes);
            ValueMultiplicity vm            = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                // 0xFFFFFFFF is reserved!
                if (unlimitedText.Length <= 0xFFFFFFFE)
                {
                    unlimitedText = unlimitedText.TrimEnd(null);
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 2^32 - 2 characters is only allowed.",
                              Tag, Name + "/unlimitedText", unlimitedText);
                }
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.", Tag,
                          Name + "/unlimitedText", unlimitedText);
            }
            return(new string[] { unlimitedText });
        }
Пример #12
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[]   multiValue = ToImproperMultiValue(s);
            TimeSpan[] time       = new TimeSpan[multiValue.Length];
            for (int i = 0; i < time.Length; i++)
            {
                string item = multiValue[i];
                if (item.Length > 0)
                {
                    item = item.TrimEnd(null);
                    if (Regex.IsMatch(item,
                                      "^[0-9]{2}(:?[0-9]{2}(:?[0-9]{2}(\\.[0-9]{1,6})?)?)?$"))
                    {
                        item = item.Replace(":", null).Replace(".", null);
                        string hour   = item.Substring(0, 2);
                        string minute = "0";
                        if (item.Length > 2)
                        {
                            minute = item.Substring(2, 2);
                        }
                        string second = "0";
                        if (item.Length > 4)
                        {
                            second = item.Substring(4, 2);
                        }
                        string millisecond = "0";
                        if (item.Length > 6)
                        {
                            millisecond = item.Substring(6, item.Length - 6);
                        }
                        try
                        {
                            time[i] = new TimeSpan(0, int.Parse(hour),
                                                   int.Parse(minute), int.Parse(second),
                                                   int.Parse(millisecond));
                        }
                        catch (Exception e)
                        {
                            throw new EncodingException(
                                      "Time format is invalid.",
                                      Tag, Name + "/item", item);
                        }
                    }
                    else
                    {
                        throw new EncodingException("Time format is invalid.",
                                                    Tag, Name + "/item", item);
                    }
                }
            }
            return(time);
        }
Пример #13
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[]   multiValue = ToImproperMultiValue(s);
            TimeSpan[] time       = new TimeSpan[multiValue.Length];
            for (int i = 0; i < time.Length; i++)
            {
                string item = multiValue[i];
                if (item.Length > 0)
                {
                    item = item.TrimEnd(null);
                    if (Regex.IsMatch(item,
                                      "^[0-9]{2}(:?[0-9]{2}(:?[0-9]{2}(\\.[0-9]{1,6})?)?)?$"))
                    {
                        item = item.Replace(":", null).Replace(".", null);
                        string hour   = item.Substring(0, 2);
                        string minute = "0";
                        if (item.Length > 2)
                        {
                            minute = item.Substring(2, 2);
                        }
                        string second = "0";
                        if (item.Length > 4)
                        {
                            second = item.Substring(4, 2);
                        }
                        string millisecond = "0";
                        if (item.Length > 6)
                        {
                            millisecond = item.Substring(6, item.Length - 6);
                        }
                        try
                        {
                            time[i] = new TimeSpan(0, int.Parse(hour),
                                                   int.Parse(minute), int.Parse(second),
                                                   int.Parse(millisecond));
                        }
                        catch (Exception e)
                        {
                            UnityEngine.Debug.LogWarning($"Date time format is invalid. tag: {Tag}, name: {Name}, item: {item}");
                            time[i] = TimeSpan.Zero;
                        }
                    }
                    else
                    {
                        UnityEngine.Debug.LogWarning($"Time format is invalid. tag: {Tag}, name: {Name}, item: {item}");
                        time[i] = TimeSpan.Zero;
                    }
                }
            }
            return(time);
        }
Пример #14
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] applicationName = ToImproperMultiValue(s);
            for (int i = 0; i < applicationName.Length; i++)
            {
                string item = applicationName[0];
                applicationName[i] = item.Trim();
            }
            return(applicationName);
        }
Пример #15
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] shortName = ToImproperMultiValue(s);
            for (int i = 0; i < shortName.Length; i++)
            {
                string item = shortName[i];
                shortName[i] = item.Trim();
            }
            return(shortName);
        }
Пример #16
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] longString = ToImproperMultiValue(s);
            for (int i = 0; i < longString.Length; i++)
            {
                string item = longString[i];
                longString[i] = item.Trim();
            }
            return(longString);
        }
Пример #17
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            s = s.TrimEnd(null);
            string[]          multiValue = ToImproperMultiValue(s);
            Type.PersonName[] personName = new Type.PersonName[multiValue.Length];
            for (int i = 0; i < personName.Length; i++)
            {
                string item = multiValue[i];
                personName[i] = new Type.PersonName(item);
            }
            return(personName);
        }
Пример #18
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] longString = ToProperMultiValue(s);
            for (int i = 0; i < longString.Length; i++)
            {
                string item = longString[i];
                if (item.Length <= 64)
                {
                    longString[i] = item.Trim();
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 64 characters is only allowed.",
                              Tag, Name + "/item", item);
                }
            }
            return(longString);
        }
Пример #19
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] shortName = ToProperMultiValue(s);
            for (int i = 0; i < shortName.Length; i++)
            {
                string item = shortName[i];
                if (item.Length <= 16)
                {
                    shortName[i] = item.Trim();
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 16 characters is only allowed.",
                              Tag, Name + "/item", item);
                }
            }
            return(shortName);
        }
Пример #20
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[] code = ToProperMultiValue(s);
            for (int i = 0; i < code.Length; i++)
            {
                string item = code[i];
                if (item.Length > 16)
                {
                    throw new EncodingException(
                              "A value of max. 16 bytes is only allowed.", Tag,
                              Name + "/item", item);
                }
                else if (item.Length > 0)
                {
                    code[i] = item.Trim();
                }
            }
            return(code);
        }
Пример #21
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            if (s.Length < 64 * 5)
            {
                s = s.TrimEnd(null);
                string[]          multiValue = ToProperMultiValue(s);
                Type.PersonName[] personName =
                    new Type.PersonName[multiValue.Length];
                for (int i = 0; i < personName.Length; i++)
                {
                    string item = multiValue[i];
                    personName[i] = new Type.PersonName(item);
                }
                return(personName);
            }
            else
            {
                throw new EncodingException(
                          "A value of max. 64 * 5 characters is only allowed.",
                          Tag, Name + "/s", s);
            }
        }
Пример #22
0
        protected override Array DecodeImproper(byte[] bytes)
        {
            string s = TransferSyntax.ToString(bytes);

            string[]          multiValue = ToImproperMultiValue(s);
            System.DateTime[] dateTime   = new System.DateTime[multiValue.Length];
            for (int i = 0; i < dateTime.Length; i++)
            {
                string item = multiValue[i];
                if (item.Length > 0)
                {
                    if (Regex.IsMatch(item, "^ [0-9]{10}" +
                                      "([0-9]{2} ([0-9]{2} (\\.[0-9]{6}" +
                                      "([\\+\\-][0-9]{4})? )? )? )? $",
                                      RegexOptions.IgnorePatternWhitespace))
                    {
                        item = item.Replace(".", null);
                        string year  = item.Substring(0, 4);
                        string month = item.Substring(4, 2);
                        string day   = item.Substring(6, 2);
                        string hour  = "0";
                        if (item.Length > 8)
                        {
                            hour = item.Substring(8, 2);
                        }
                        string minute = "0";
                        if (item.Length > 10)
                        {
                            minute = item.Substring(10, 2);
                        }
                        string second = "0";
                        if (item.Length > 12)
                        {
                            second = item.Substring(12, 2);
                        }
                        string millisecond = "0";
                        if (item.Length > 14)
                        {
                            millisecond = item.Substring(14, 6);
                        }
                        string timeZone = "+0";
                        if (item.Length > 20)
                        {
                            timeZone = item.Substring(20, 5);
                        }
                        // TODO: What to do with the time zone?
                        try
                        {
                            dateTime[i] = new System.DateTime(int.Parse(year),
                                                              int.Parse(month), int.Parse(day), int.Parse(hour),
                                                              int.Parse(minute), int.Parse(second),
                                                              int.Parse(millisecond));
                        }
                        catch (Exception e)
                        {
                            UnityEngine.Debug.LogWarning($"Date time format is invalid. tag: {Tag}, name: {Name}");
                            dateTime[i] = System.DateTime.Now;
                        }
                    }
                    else
                    {
                        UnityEngine.Debug.LogWarning($"Date time format is invalid. tag: {Tag}, name: {Name}");
                        dateTime[i] = System.DateTime.Now;
                    }
                }
            }
            return(dateTime);
        }