コード例 #1
0
		private TimeSpan ReadValueAsTimeSpan(ContactValueSeparators? expectedSeparators)
		{
			this.reader.AssertValidState(ContentLineNodeType.Parameter | ContentLineNodeType.Property);
			string s = this.ReadValueAsString(expectedSeparators).Trim();
			this.CheckType(ContactValueType.UtcOffset);
			return ContactCommon.ParseUtcOffset(s, this.reader.ComplianceTracker);
		}
コード例 #2
0
        public void WriteParameterValue(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            this.AssertValidState(WriteState.Parameter);
            if (this.firstParameterValue)
            {
                this.writer.WriteStartValue();
                this.firstParameterValue = false;
            }
            else
            {
                this.writer.WriteNextValue(ContentLineParser.Separators.Comma);
            }
            if (this.parameter == ParameterId.ValueType && value.Length > 0)
            {
                this.valueType = ContactCommon.GetValueTypeEnum(value);
            }
            bool flag = this.IsQuotingRequired(value);

            if (flag)
            {
                this.writer.WriteToStream(34);
            }
            this.writer.WriteToStream(value);
            if (flag)
            {
                this.writer.WriteToStream(34);
            }
        }
コード例 #3
0
        public static DateTime ParseDateTime(string s, ComplianceTracker tracker)
        {
            int length = s.Length;

            if (length < 15)
            {
                tracker.SetComplianceStatus(ComplianceStatus.InvalidValueFormat, CalendarStrings.InvalidDateTimeLength);
                return(ContactCommon.MinDateTime);
            }
            string text = "yyyyMMdd";
            int    num  = 8;

            if (s[4] == '-')
            {
                text = "yyyy-MM-dd";
                num  = 10;
            }
            if (s[num + 3] == ':')
            {
                text += "\\THH:mm:ss";
                num  += 9;
            }
            else
            {
                text += "\\THHmmss";
                num  += 7;
            }
            if (length < num)
            {
                tracker.SetComplianceStatus(ComplianceStatus.InvalidValueFormat, CalendarStrings.InvalidDateTimeLength);
                return(ContactCommon.MinDateTime);
            }
            return(ContactCommon.InternalParseDateTime(s, length, text, num, tracker));
        }
コード例 #4
0
 private void CalculateValueType()
 {
     if (this.isValueTypeInitialized)
     {
         return;
     }
     this.valueType = ContactValueType.Unknown;
     if (this.valueTypeParameter != null)
     {
         this.valueType = ContactCommon.GetValueTypeEnum(this.valueTypeParameter);
     }
     else
     {
         PropertyId propertyEnum = ContactCommon.GetPropertyEnum(this.propertyName);
         if (propertyEnum != PropertyId.Unknown)
         {
             this.valueType = ContactCommon.GetDefaultValueType(propertyEnum);
         }
     }
     if (this.valueType == ContactValueType.Unknown)
     {
         this.valueType = ContactValueType.Text;
     }
     this.isValueTypeInitialized = true;
 }
コード例 #5
0
 private void StartProperty(string name, PropertyId p)
 {
     this.EndProperty();
     this.AssertValidState(WriteState.Component);
     this.propertyName = name.ToUpper();
     this.valueType    = ContactCommon.GetDefaultValueType(p);
     this.writer.StartProperty(this.propertyName);
     this.firstPropertyValue = true;
     this.state = WriteState.Property;
 }
コード例 #6
0
        public void StartParameter(ParameterId parameterId)
        {
            string parameterString = ContactCommon.GetParameterString(parameterId);

            if (parameterString == null)
            {
                throw new ArgumentException(CalendarStrings.InvalidParameterId);
            }
            this.StartParameter(parameterString);
        }
コード例 #7
0
        public static DateTime ParseDate(string s, ComplianceTracker tracker)
        {
            DateTime result;

            if (!DateTime.TryParseExact(s, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out result) && !DateTime.TryParseExact(s, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out result))
            {
                return(ContactCommon.ParseDateTime(s, tracker));
            }
            return(result);
        }
コード例 #8
0
        public void StartProperty(PropertyId propertyId)
        {
            string propertyString = ContactCommon.GetPropertyString(propertyId);

            if (propertyString == null)
            {
                throw new ArgumentException(CalendarStrings.InvalidPropertyId);
            }
            this.StartProperty(propertyString, propertyId);
        }
コード例 #9
0
        private void WritePropertyValue(TimeSpan value, ContactValueSeparators separator)
        {
            if (ContactValueType.UtcOffset != this.valueType)
            {
                throw new ArgumentOutOfRangeException("valueType");
            }
            if (value.Days > 0 && this.validate)
            {
                throw new ArgumentException(CalendarStrings.UtcOffsetTimespanCannotContainDays, "value");
            }
            string value2 = ContactCommon.FormatUtcOffset(value);

            this.WritePropertyValue(value2, separator);
        }
コード例 #10
0
        public void StartProperty(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (this.validate && name.Length == 0)
            {
                throw new ArgumentException();
            }
            PropertyId propertyEnum = ContactCommon.GetPropertyEnum(name);

            this.StartProperty(name, propertyEnum);
        }
コード例 #11
0
		private DateTime ReadValueAsDateTime(ContactValueType type, ContactValueSeparators? expectedSeparators)
		{
			this.reader.AssertValidState(ContentLineNodeType.Parameter | ContentLineNodeType.Property);
			string s = this.ReadValueAsString(expectedSeparators).Trim();
			this.CheckType(type);
			if (type == ContactValueType.DateTime)
			{
				return ContactCommon.ParseDateTime(s, this.reader.ComplianceTracker);
			}
			if (type == ContactValueType.Time)
			{
				return ContactCommon.ParseTime(s, this.reader.ComplianceTracker);
			}
			return ContactCommon.ParseDate(s, this.reader.ComplianceTracker);
		}
コード例 #12
0
 public void StartParameter(string name)
 {
     if (this.validate)
     {
         if (name == null)
         {
             throw new ArgumentNullException("name");
         }
         if (name.Length == 0)
         {
             throw new ArgumentException();
         }
     }
     this.EndParameter();
     this.AssertValidState(WriteState.Property);
     this.parameter = ContactCommon.GetParameterEnum(name);
     this.writer.StartParameter(name);
     this.firstParameterValue = true;
     this.state = WriteState.Parameter;
 }
コード例 #13
0
        private void WritePropertyValue(DateTime value, ContactValueType valueType, ContactValueSeparators separator)
        {
            string value2;

            if (ContactValueType.DateTime == valueType || ContactValueType.Text == valueType)
            {
                value2 = ContactCommon.FormatDateTime(value);
            }
            else if (ContactValueType.Date == valueType)
            {
                value2 = ContactCommon.FormatDate(value);
            }
            else
            {
                if (ContactValueType.Time != valueType)
                {
                    throw new ArgumentOutOfRangeException("valueType");
                }
                value2 = ContactCommon.FormatTime(value);
            }
            this.WritePropertyValue(value2, separator);
        }
コード例 #14
0
        public static DateTime ParseTime(string s, ComplianceTracker tracker)
        {
            int length = s.Length;

            if (length < 6)
            {
                tracker.SetComplianceStatus(ComplianceStatus.InvalidValueFormat, CalendarStrings.InvalidDateTimeLength);
                return(ContactCommon.MinDateTime);
            }
            string format = "HHmmss";
            int    num    = 6;

            if (s[2] == ':')
            {
                format = "HH:mm:ss";
                num    = 8;
            }
            if (length < num)
            {
                tracker.SetComplianceStatus(ComplianceStatus.InvalidValueFormat, CalendarStrings.InvalidDateTimeLength);
                return(ContactCommon.MinDateTime);
            }
            return(ContactCommon.InternalParseDateTime(s, length, format, num, tracker));
        }
コード例 #15
0
        private static DateTime InternalParseDateTime(string s, int length, string format, int formatLength, ComplianceTracker tracker)
        {
            string text  = string.Empty;
            string text2 = string.Empty;

            if (length > formatLength)
            {
                if (s[formatLength] == ',')
                {
                    int num = formatLength + 1;
                    while (num < length && char.IsDigit(s[num]))
                    {
                        num++;
                    }
                    if (num == formatLength + 1)
                    {
                        tracker.SetComplianceStatus(ComplianceStatus.InvalidValueFormat, CalendarStrings.InvalidDateFormat);
                        return(ContactCommon.MinDateTime);
                    }
                    text2 = s.Substring(formatLength + 1, num - (formatLength + 1));
                    if (num < length)
                    {
                        text = s.Substring(num);
                    }
                }
                else
                {
                    text = s.Substring(formatLength);
                }
                s = s.Substring(0, formatLength);
            }
            DateTime dateTime;

            if (!DateTime.TryParseExact(s, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out dateTime))
            {
                tracker.SetComplianceStatus(ComplianceStatus.InvalidValueFormat, CalendarStrings.InvalidDateFormat);
                return(ContactCommon.MinDateTime);
            }
            if (!string.IsNullOrEmpty(text2))
            {
                if (text2.Length > 3)
                {
                    text2 = text2.Substring(0, 3);
                }
                int num2 = 0;
                if (!int.TryParse(text2, out num2))
                {
                    tracker.SetComplianceStatus(ComplianceStatus.InvalidValueFormat, CalendarStrings.InvalidDateFormat);
                    return(ContactCommon.MinDateTime);
                }
                for (int i = text2.Length; i < 3; i++)
                {
                    num2 *= 10;
                }
                dateTime += new TimeSpan(0, 0, 0, 0, num2);
            }
            if (!string.IsNullOrEmpty(text) && text != "Z")
            {
                dateTime += ContactCommon.ParseUtcOffset(text, tracker);
            }
            return(dateTime);
        }
コード例 #16
0
        public static string FormatTime(DateTime s)
        {
            string format = ContactCommon.RetrieveTimeFormatString(s.Millisecond != 0, s.Kind == DateTimeKind.Utc);

            return(s.ToString(format, DateTimeFormatInfo.InvariantInfo));
        }
コード例 #17
0
 public void WriteValueTypeParameter(ContactValueType type)
 {
     this.StartParameter(ParameterId.ValueType);
     this.WriteParameterValue(ContactCommon.GetValueTypeString(type));
     this.EndParameter();
 }