Exemplo n.º 1
0
        public bool ReadRaw(XmlReader reader,
                            SifVersion version,
                            SifElement parent,
                            SifFormatter formatter)
        {
            string name = reader.LocalName;

            if (name.Equals(fDateElement))
            {
                String   dateValue = ConsumeElementTextValue(reader, version);
                DateTime?date      = formatter.ToDate(dateValue);
                if (date.HasValue)
                {
                    DateTime    tsValue  = date.Value;
                    SifDateTime dateTime = new SifDateTime(tsValue);
                    parent.SetField(dateTime.CreateField(parent, fElementDef));
                }
            }
            else if (name.Equals(fTimeElement))
            {
                String   timeValue = ConsumeElementTextValue(reader, version);
                DateTime?time      = formatter.ToTime(timeValue);
                if (time.HasValue)
                {
                    DateTime val = time.Value;
                    // See if the Timestamp field already exists on the parent
                    SimpleField timeStampField = parent.GetField(fElementDef);
                    if (timeStampField == null)
                    {
                        // Doesn't exist, create it
                        SifDateTime dateTime = new SifDateTime(val);
                        parent.SetField(dateTime.CreateField(parent, fElementDef));
                    }
                    else
                    {
                        // Exists, update the time portion of the date
                        SifDateTime sdt = (SifDateTime)timeStampField.SifValue;
                        if (sdt != null && sdt.Value.HasValue)
                        {
                            DateTime tsValue = sdt.Value.Value;
                            tsValue = tsValue.Add(val.TimeOfDay);
                            sdt     = new SifDateTime(tsValue);
                            // Overwrite the current value
                            parent.SetField(sdt.CreateField(parent, fElementDef));
                        }
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private void AssertTimeParsing(DateTime?assertedDateTime, SifFormatter formatter, string test, String statement)
        {
            DateTime?parsedValue;

            parsedValue = formatter.ToTime(test);
            Console.WriteLine(statement);
            Console.WriteLine("parsing: " + test);
            Console.WriteLine("Asserted: {0} : {1}", assertedDateTime.Value, assertedDateTime.Value.ToFileTimeUtc());
            Console.WriteLine("Parsed: {0} : {1}", parsedValue.Value, parsedValue.Value.ToFileTimeUtc());
            Console.WriteLine();
            assertTimes(statement, assertedDateTime, parsedValue);
        }
Exemplo n.º 3
0
        public bool ReadRaw(XmlReader reader,
                            SifVersion version,
                            SifElement parent,
                            SifFormatter formatter)
        {
            String elementName = fElementDef.Name;

            if (!reader.LocalName.Equals(elementName))
            {
                return(false);
            }

            String value = ConsumeElementTextValue(reader, version);

            if (value != null && value.Length > 0)
            {
                DateTime?time    = formatter.ToTime(value);
                SifTime  sifTime = new SifTime(time);
                parent.SetField(sifTime.CreateField(parent, fElementDef));
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool ReadRaw( XmlReader reader,
                             SifVersion version,
                             SifElement parent,
                             SifFormatter formatter )
        {
            String elementName = fElementDef.Name;
            if ( !reader.LocalName.Equals( elementName ) )
            {
                return false;
            }

            String value = ConsumeElementTextValue( reader, version );

            if ( value != null && value.Length > 0 )
            {
                DateTime? time = formatter.ToTime( value );
                SifTime sifTime = new SifTime( time );
                parent.SetField( sifTime.CreateField( parent, fElementDef ) );
            }
            return true;
        }
Exemplo n.º 5
0
        public bool ReadRaw( XmlReader reader,
                             SifVersion version,
                             SifElement parent,
                             SifFormatter formatter )
        {
            string name = reader.LocalName;

            if ( name.Equals( fDateElement ) )
            {
                String dateValue = ConsumeElementTextValue( reader, version );
                DateTime? date = formatter.ToDate( dateValue );
                if ( date.HasValue )
                {
                    DateTime tsValue = date.Value;
                    SifDateTime dateTime = new SifDateTime( tsValue );
                    parent.SetField( dateTime.CreateField( parent, fElementDef ) );
                }
            }
            else if ( name.Equals( fTimeElement ) )
            {
                String timeValue = ConsumeElementTextValue( reader, version );
                DateTime? time = formatter.ToTime( timeValue );
                if ( time.HasValue )
                {
                    DateTime val = time.Value;
                    // See if the Timestamp field already exists on the parent
                    SimpleField timeStampField = parent.GetField( fElementDef );
                    if ( timeStampField == null )
                    {
                        // Doesn't exist, create it
                        SifDateTime dateTime = new SifDateTime( val );
                        parent.SetField( dateTime.CreateField( parent, fElementDef ) );
                    }
                    else
                    {
                        // Exists, update the time portion of the date
                        SifDateTime sdt = (SifDateTime) timeStampField.SifValue;
                        if ( sdt != null && sdt.Value.HasValue )
                        {
                            DateTime tsValue = sdt.Value.Value;
                            tsValue = tsValue.Add( val.TimeOfDay );
                            sdt = new SifDateTime( tsValue );
                            // Overwrite the current value
                            parent.SetField( sdt.CreateField( parent, fElementDef ) );
                        }
                    }
                }
            }
            else
            {
                return false;
            }

            return true;
        }
Exemplo n.º 6
0
        private void assertThrowsFormatException(SifFormatter formatter)
        {
            bool threwProperException = false;

            // Boolean
            try
            {
                formatter.ToBool("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("NumberFormatException was not thrown for toBoolean()", threwProperException);

            // DECIMAL
            threwProperException = false;
            try
            {
                formatter.ToDecimal("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for toDecimal()", threwProperException);

            // DATE
            threwProperException = false;
            try
            {
                formatter.ToDate("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for ToDate()", threwProperException);


            //
            // DateTime and Duration are not supported by the SIF1xFormatter
            //
            if (!(formatter is Sif1xFormatter))
            {
                // DATETIME
                threwProperException = false;
                try
                {
                    formatter.ToDateTime("asdf");
                }
                catch (FormatException)
                {
                    threwProperException = true;
                }
                Assertion.Assert("IllegalArgumentException was not thrown for ToDateTime()", threwProperException);

                // DURATION
                threwProperException = false;
                try
                {
                    formatter.ToTimeSpan("asdf");
                }
                catch (FormatException)
                {
                    threwProperException = true;
                }

                Assertion.Assert("IllegalArgumentException was not thrown for toDuration()", threwProperException);
            }
            // INT
            threwProperException = false;
            try
            {
                formatter.ToInt("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for toint()", threwProperException);

            // TIME
            threwProperException = false;
            try
            {
                formatter.ToTime("asdf");
            }
            catch (FormatException)
            {
                threwProperException = true;
            }
            Assertion.Assert("IllegalArgumentException was not thrown for toTime()", threwProperException);
        }