Exemple #1
0
        /// <summary> This method takes in integer values for the year and month and day
        /// and performs validations, it then sets the value in the object
        /// formatted as an HL7 date value with year and month and day precision (YYYYMMDD).
        /// </summary>
        public virtual void setYearMonthDayPrecision(int yr, int mnth, int dy)
        {
            try
            {
                //ensure that the year field is four digits long
                if (Convert.ToString(yr).Length != 4)
                {
                    String            msg = "The input year value must be four digits long";
                    DataTypeException e   = new DataTypeException(msg);
                    throw e;
                }

                GregorianCalendar cal = new GregorianCalendar();

                //validate the input month/day combination
                new DateTime(yr, mnth, dy, cal);
                year          = yr;
                month         = mnth;
                day           = dy;
                value_Renamed = Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2) + DataTypeUtil.preAppendZeroes(dy, 2);
            }
            catch (DataTypeException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new DataTypeException("An unexpected exception ocurred", e);
            }
        }
Exemple #2
0
        /// <summary>
        /// This method takes in integer values for the hour and minute and performs validations,
        /// it then sets the value field formatted as an HL7 time value
        /// with hour and minute precision (HHMM).
        /// </summary>
        public virtual void SetHourMinutePrecision(int hr, int min)
        {
            try
            {
                HourPrecision = hr;

                // validate input minute value
                if ((min < 0) || (min > 59))
                {
                    var msg = "The minute value of the TM datatype must be >=0 and <=59";
                    var e   = new DataTypeException(msg);
                    throw e;
                }

                Minute      = min;
                Second      = 0;
                FractSecond = 0;
                GMTOffset   = 0;

                // Here the offset is not defined, we should omit showing it in the
                // return value from the getValue() method
                omitOffsetFg = 'y';
                valueRenamed = valueRenamed + DataTypeUtil.PreAppendZeroes(min, 2);
            }
            catch (DataTypeException e)
            {
                // TODO: this will remove the stack trace - is that correct?
                throw e;
            }
            catch (Exception e)
            {
                throw new DataTypeException(e.Message);
            }
        }
Exemple #3
0
        } //end constructor

        /// <summary> This method takes in integer values for the hour and minute and performs validations,
        /// it then sets the value field formatted as an HL7 time value
        /// with hour and minute precision (HHMM).
        /// </summary>
        public virtual void setHourMinutePrecision(int hr, int min)
        {
            try
            {
                this.HourPrecision = hr;
                //validate input minute value
                if ((min < 0) || (min > 59))
                {
                    System.String     msg = "The minute value of the TM datatype must be >=0 and <=59";
                    DataTypeException e   = new DataTypeException(msg);
                    throw e;
                } //end if
                minute        = min;
                second        = 0;
                fractionOfSec = 0;
                offSet        = 0;
                //Here the offset is not defined, we should omit showing it in the
                //return value from the getValue() method
                omitOffsetFg  = 'y';
                value_Renamed = value_Renamed + DataTypeUtil.preAppendZeroes(min, 2);
            }
            //end try
            catch (DataTypeException e)
            {
                throw e;
            }
            //end catch
            catch (System.Exception e)
            {
                throw new DataTypeException(e.Message);
            } //end catch
        }
        public void DataTypeException_Constructors()
        {
            var ex1 = new DataTypeException();

            Assert.IsNull(ex1.InnerException);

            var ex2 = new DataTypeException("foo");

            Assert.AreEqual("foo", ex2.Message);
            Assert.IsNull(ex2.InnerException);
            Assert.IsTrue(ex2.ToString().Contains("foo"));

            var iex = new Exception();
            var ex3 = new DataTypeException("foo", iex);

            Assert.AreEqual("foo", ex3.Message);
            Assert.AreSame(iex, ex3.InnerException);
            Assert.IsTrue(ex3.ToString().Contains("foo"));

            AssertEx.ThrowsException <ArgumentNullException>(() => new DataTypeException(default(DataTypeError)), ex => Assert.AreEqual("error", ex.ParamName));

            var err = new DataTypeError(typeof(int), "bar", new[] { typeof(List <int>) });
            var ex4 = new DataTypeException(err);

            Assert.AreSame(err, ex4.Error);
            Assert.IsTrue(ex4.ToString().Contains("bar"));
        }
Exemple #5
0
        /// <summary> This method takes in integer values for the year and month and performs validations,
        /// it then sets the value field formatted as an HL7 date
        /// value with year and month precision (YYYYMM).
        /// Note: The first month = 1 = January.
        /// </summary>
        public virtual void SetYearMonthPrecision(int yr, int mnth)
        {
            try
            {
                // ensure that the year field is four digits long
                if (Convert.ToString(yr).Length != 4)
                {
                    var msg = "The input year value must be four digits long";
                    var e   = new DataTypeException(msg);
                    throw e;
                }

                var cal = new GregorianCalendar();

                // validate the input month
                new DateTime(yr, mnth, 1, cal);
                Year         = yr;
                Month        = mnth;
                Day          = 0;
                valueRenamed = Convert.ToString(yr) + DataTypeUtil.PreAppendZeroes(mnth, 2);
            }
            catch (DataTypeException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new DataTypeException("An unexpected exception occurred", e);
            }
        }
 /// <summary> This method takes in integer values for the year and month and day
 /// and performs validations, it then sets the value in the object
 /// formatted as an HL7 date value with year and month and day precision (YYYYMMDD).
 /// </summary>
 public virtual void setYearMonthDayPrecision(int yr, int mnth, int dy)
 {
     try
     {
         System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar();
         SupportClass.CalendarManager.manager.Clear(cal);
         //ensure that the year field is four digits long
         if (System.Convert.ToString(yr).Length != 4)
         {
             System.String     msg = "The input year value must be four digits long";
             DataTypeException e   = new DataTypeException(msg);
             throw e;
         }
         //validate the input month/day combination
         SupportClass.CalendarManager.manager.Set(cal, yr, (mnth - 1), dy);
         SupportClass.CalendarManager.manager.GetDateTime(cal); //for error detection
         year          = yr;
         month         = mnth;
         day           = dy;
         value_Renamed = System.Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2) + DataTypeUtil.preAppendZeroes(dy, 2);
     }
     catch (DataTypeException e)
     {
         throw e;
     }
     catch (System.Exception e)
     {
         throw new DataTypeException("An unexpected exception ocurred", e);
     }
 }
Exemple #7
0
        /// <summary>
        /// This method takes in integer values for the hour, minute, seconds, and fractional seconds
        /// (going to the ten thousandths precision).
        /// The method performs validations and then sets the value field formatted as an
        /// HL7 time value with a precision that starts from the hour and goes down to the ten thousandths
        /// of a second (HHMMSS.SSSS).
        /// Note: all of the precisions from tenths down to ten thousandths of a
        /// second are optional. If the precision goes below ten thousandths of a second then the second
        /// value will be rounded to the nearest ten thousandths of a second.
        /// </summary>
        public virtual void SetHourMinSecondPrecision(int hr, int min, float sec)
        {
            try
            {
                SetHourMinutePrecision(hr, min);

                // multiply the seconds input value by 10000 and round the result
                // then divide the number by ten thousand and store it back.
                // This will round the fractional seconds to the nearest ten thousandths
                var secMultRound = (int)Math.Round((double)(10000F * sec));
                sec = secMultRound / 10000F;

                // Now store the second and fractional component
                Second = (int)Math.Floor(sec);

                // validate input seconds value
                if ((Second < 0) || (Second >= 60))
                {
                    var msg = "The (rounded) second value of the TM datatype must be >=0 and <60";
                    var e   = new DataTypeException(msg);
                    throw e;
                }

                var fractionOfSecInt = (int)(secMultRound - (Second * 10000));
                FractSecond = fractionOfSecInt / 10000F;
                var fractString = string.Empty;

                // Now convert the fractionOfSec field to a string without the leading zero
                if (FractSecond != 0.0F)
                {
                    fractString = FractSecond.ToString().Substring(1);
                }

                // Now update the value field
                GMTOffset = 0;

                // Here the offset is not defined, we should omit showing it in the
                // return value from the getValue() method
                omitOffsetFg = 'y';
                valueRenamed = valueRenamed + DataTypeUtil.PreAppendZeroes(Second, 2) + fractString;
            }
            catch (DataTypeException e)
            {
                // TODO: this will remove the stack trace - is that correct?
                throw e;
            }
            catch (Exception e)
            {
                throw new DataTypeException("An unexpected exception occurred", e);
            }
        }
        public void DataTypeException_Serialize()
        {
            var err = new DataTypeError(typeof(int), "bar", new[] { typeof(List <int>) });
            var ex  = new DataTypeException(err);

            var ms = new MemoryStream();

            new BinaryFormatter().Serialize(ms, ex);

            ms.Position = 0;
            var res = (DataTypeException) new BinaryFormatter().Deserialize(ms);

            Assert.AreEqual(err.Message, res.Error.Message);
            Assert.AreEqual(err.Type, res.Error.Type);
            AssertEx.AreSequenceEqual(err.Stack, res.Error.Stack);
        }
Exemple #9
0
 /// <summary> This method takes in integer values for the hour, minute, seconds, and fractional seconds
 /// (going to the tenthousandths precision).
 /// The method performs validations and then sets the value field formatted as an
 /// HL7 time value with a precision that starts from the hour and goes down to the tenthousandths
 /// of a second (HHMMSS.SSSS).
 /// Note: all of the precisions from tenths down to tenthousandths of a
 /// second are optional. If the precision goes below tenthousandths of a second then the second
 /// value will be rounded to the nearest tenthousandths of a second.
 /// </summary>
 public virtual void setHourMinSecondPrecision(int hr, int min, float sec)
 {
     try
     {
         this.setHourMinutePrecision(hr, min);
         //multiply the seconds input value by 10000 and round the result
         //then divide the number by tenthousand and store it back.
         //This will round the fractional seconds to the nearest tenthousandths
         int secMultRound = (int)System.Math.Round((double)(10000F * sec));
         sec = secMultRound / 10000F;
         //Now store the second and fractional component
         second = (int)System.Math.Floor(sec);
         //validate input seconds value
         if ((second < 0) || (second >= 60))
         {
             System.String     msg = "The (rounded) second value of the TM datatype must be >=0 and <60";
             DataTypeException e   = new DataTypeException(msg);
             throw e;
         } //end if
         int fractionOfSecInt = (int)(secMultRound - (second * 10000));
         fractionOfSec = fractionOfSecInt / 10000F;
         System.String fractString = "";
         //Now convert the fractionOfSec field to a string without the leading zero
         if (fractionOfSec != 0.0F)
         {
             fractString = (fractionOfSec.ToString()).Substring(1);
         } //end if
         //Now update the value field
         offSet = 0;
         //Here the offset is not defined, we should omit showing it in the
         //return value from the getValue() method
         omitOffsetFg  = 'y';
         value_Renamed = value_Renamed + DataTypeUtil.preAppendZeroes(second, 2) + fractString;
     }
     //end try
     catch (DataTypeException e)
     {
         throw e;
     }
     //end catch
     catch (System.Exception e)
     {
         throw new DataTypeException("An unexpected exception ocurred", e);
     } //end catch
 }
Exemple #10
0
 /// <summary> This method takes in integer values for the year and month and performs validations,
 /// it then sets the value field formatted as an HL7 date
 /// value with year and month precision (YYYYMM).
 /// Note: The first month = 1 = January.
 /// </summary>
 public virtual void setYearMonthPrecision(int yr, int mnth)
 {
     try
     {
         System.Globalization.GregorianCalendar cal = new System.Globalization.GregorianCalendar();
         SupportClass.CalendarManager.manager.Clear(cal);
         //ensure that the year field is four digits long
         if (System.Convert.ToString(yr).Length != 4)
         {
             System.String msg = "The input year value must be four digits long";
             DataTypeException e = new DataTypeException(msg);
             throw e;
         }
         //validate the input month
         //GregorianCalendar cal = new GregorianCalendar(yr,(mnth-1),1);
         SupportClass.CalendarManager.manager.Set(cal, yr, (mnth - 1), 1);
         SupportClass.CalendarManager.manager.GetDateTime(cal); //for error detection
         year = yr;
         month = mnth;
         day = 0;
         value_Renamed = System.Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2);
     }
     catch (DataTypeException e)
     {
         throw e;
     }
     catch (System.Exception e)
     {
         throw new DataTypeException("An unexpected exception ocurred", e);
     }
 }
Exemple #11
0
		/// <summary> This method takes in integer values for the year and month and day
		/// and performs validations, it then sets the value in the object
		/// formatted as an HL7 date value with year and month and day precision (YYYYMMDD).
		/// </summary>
		public virtual void setYearMonthDayPrecision(int yr, int mnth, int dy)
		{
			try
			{
				//ensure that the year field is four digits long
				if (Convert.ToString(yr).Length != 4)
				{
					String msg = "The input year value must be four digits long";
					DataTypeException e = new DataTypeException(msg);
					throw e;
				}

				GregorianCalendar cal = new GregorianCalendar();

				//validate the input month/day combination
				new DateTime(yr, mnth, dy, cal);
				year = yr;
				month = mnth;
				day = dy;
				value_Renamed = Convert.ToString(yr) + DataTypeUtil.preAppendZeroes(mnth, 2) + DataTypeUtil.preAppendZeroes(dy, 2);
			}
			catch (DataTypeException e)
			{
				throw e;
			}
			catch (Exception e)
			{
				throw new DataTypeException("An unexpected exception ocurred", e);
			}
		}
Exemple #12
0
            internal TcAdsSymbolInfo CreateArrayElement(TcAdsSymbolInfo parentArrayInstance, TcAdsDataType parentArrayType, int subIndex)
            {
                if (parentArrayInstance == null)
                {
                    throw new ArgumentNullException("arrayInstance");
                }
                if (parentArrayType == null)
                {
                    throw new ArgumentNullException("parentArrayType");
                }
                TcAdsSymbolInfo info     = null;
                ITcAdsDataType  baseType = parentArrayType.BaseType;

                if (baseType == null)
                {
                    DataTypeException innerException = new DataTypeException("Base type of Array '{0}' not defined!", parentArrayType);
                    throw new AdsSymbolException("Cannot create array element!", parentArrayInstance, innerException);
                }
                bool isBitType = parentArrayInstance.IsBitType;
                ReadOnlyDimensionCollection dimensions = parentArrayType.Dimensions;
                int elementSize = this.calcElementBaseSize(parentArrayInstance);

                if (subIndex < parentArrayType.Dimensions.ElementCount)
                {
                    info = new TcAdsSymbolInfo(this._parser, parentArrayInstance, subIndex)
                    {
                        size           = (uint)elementSize,
                        typeEntryFlags = this.createElementTypeEntryFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        flags          = this.createElementSymbolFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        dataTypeId     = (baseType == null) ? AdsDatatypeId.ADST_BIGTYPE : baseType.DataTypeId
                    };
                    if (baseType != null)
                    {
                        info.typeName  = baseType.Name;
                        info.arrayInfo = baseType.Dimensions.ToArray();
                    }
                    else
                    {
                        info.typeName  = parentArrayType.BaseTypeName;
                        info.arrayInfo = null;
                    }
                    info.comment = parentArrayInstance.Comment;
                    this.calcArrayElementIndexGroupIndexOffset(subIndex, parentArrayInstance, elementSize, out info.indexGroup, out info.indexOffset);
                    string str = ArrayIndexConverter.SubIndexToIndexString(parentArrayType.Dimensions.LowerBounds, parentArrayType.Dimensions.UpperBounds, subIndex);
                    info.instancePath = parentArrayInstance.instancePath + str;
                    info.shortName    = parentArrayInstance.shortName + str;
                    info.attributes   = parentArrayInstance.attributes;
                }
                if ((subIndex == parentArrayType.Dimensions.ElementCount) && ((parentArrayType.Flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.Oversample)) != AdsDataTypeFlags.None))
                {
                    info = new TcAdsSymbolInfo(this._parser, parentArrayInstance, subIndex)
                    {
                        size           = (uint)elementSize,
                        typeEntryFlags = this.createElementTypeEntryFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        flags          = this.createElementSymbolFlags(parentArrayInstance, (TcAdsDataType)baseType)
                    };
                    if (info.typeEntryFlags.HasFlag(AdsDataTypeFlags.None | AdsDataTypeFlags.Static))
                    {
                        info.indexGroup  = 0xf019;
                        info.indexOffset = 0;
                    }
                    else
                    {
                        info.indexGroup  = parentArrayInstance.indexGroup;
                        info.indexOffset = parentArrayInstance.indexOffset;
                    }
                    if (baseType != null)
                    {
                        info.dataTypeId = baseType.DataTypeId;
                        info.typeName   = baseType.Name;
                    }
                    else
                    {
                        info.dataTypeId = AdsDatatypeId.ADST_BIGTYPE;
                        info.typeName   = parentArrayType.BaseTypeName;
                    }
                    info.comment = parentArrayInstance.Comment;
                    string str2 = ArrayIndexConverter.OversamplingSubElementToString(subIndex);
                    info.instancePath = parentArrayInstance.instancePath + str2;
                    info.shortName    = parentArrayInstance.shortName + str2;
                    if ((parentArrayType.Flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem))
                    {
                        info.indexGroup  = 0xf017;
                        info.indexOffset = parentArrayType.TypeHashValue;
                    }
                    info.attributes = parentArrayInstance.attributes;
                }
                return(info);
            }