Exemplo n.º 1
0
		public EntityObjectHierarchy Serialize<T>()
		{
			CalendarEventResourceEntity retVal = new CalendarEventResourceEntity();
			McCalAddress mcCalAddress = Resource as McCalAddress;
			if (mcCalAddress != null)
			{
				retVal.PrimaryKeyId = mcCalAddress.MetaObjectId;
			}
		
			//Copy Cal_Address parameters to entity object
			foreach (string paramName in Resource.Parameters.Keys)
			{
				iCal2EntityMapping.MappingResult mapRes = iCal2EntityMapping.iCalProp2EntityProp<T>(paramName);
				if (mapRes != null && Resource.Parameters.ContainsKey(paramName))
				{
					foreach (string paramValue in ((Parameter)Resource.Parameters[paramName]).Values)
					{
						retVal[mapRes.Name] =  EntityPropConverter.ToEntityProperty(mapRes.ValueType, paramValue);
					}
				}
			}

			retVal.Email = Resource.EmailAddress;

			return new EntityObjectHierarchy(retVal);
		}
        /// <summary>
        /// Serializes this instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public EntityObjectHierarchy Serialize <T>()
        {
            CalendarEventRecurrenceEntity recurrenceEntity = new CalendarEventRecurrenceEntity();

            recurrenceEntity.DayOfMonth = RPattern.ByMonthDay.Count != 0 ? RPattern.ByMonthDay[0] : 0;
            eBitDayOfWeek dayOfWeekMask = eBitDayOfWeek.Unknown;
            eInstanceType instance      = eInstanceType.InstanceFirst;

            //Primary key
            McRecurrencePattern mcRecurrencePattern = RPattern as McRecurrencePattern;

            if (mcRecurrencePattern != null)
            {
                recurrenceEntity.PrimaryKeyId = mcRecurrencePattern.MetaObjectId;
            }
            //Copy RPATTERN Parameters to entity property
            foreach (string paramName in RPattern.Parameters.Keys)
            {
                iCal2EntityMapping.MappingResult mapRes = iCal2EntityMapping.iCalProp2EntityProp <T>(paramName);
                if (mapRes != null && RPattern.Parameters.ContainsKey(paramName))
                {
                    foreach (string paramValue in ((Parameter)RPattern.Parameters[paramName]).Values)
                    {
                        recurrenceEntity[mapRes.Name] = EntityPropConverter.ToEntityProperty(mapRes.ValueType, paramValue);
                    }
                }
            }

            foreach (DaySpecifier daySpec in RPattern.ByDay)
            {
                if (daySpec.Num != int.MinValue)
                {
                    instance = (eInstanceType)daySpec.Num;
                }
                switch (daySpec.DayOfWeek)
                {
                case DayOfWeek.Sunday:
                    dayOfWeekMask |= eBitDayOfWeek.Sunday;
                    break;

                case DayOfWeek.Friday:
                    dayOfWeekMask |= eBitDayOfWeek.Friday;
                    break;

                case DayOfWeek.Monday:
                    dayOfWeekMask |= eBitDayOfWeek.Monday;
                    break;

                case DayOfWeek.Saturday:
                    dayOfWeekMask |= eBitDayOfWeek.Saturday;
                    break;

                case DayOfWeek.Thursday:
                    dayOfWeekMask |= eBitDayOfWeek.Thursday;
                    break;

                case DayOfWeek.Tuesday:
                    dayOfWeekMask |= eBitDayOfWeek.Tuesday;
                    break;

                case DayOfWeek.Wednesday:
                    dayOfWeekMask |= eBitDayOfWeek.Wednesday;
                    break;
                }
            }
            recurrenceEntity.DayOfWeekMask = (int)dayOfWeekMask;
            recurrenceEntity.Instance      = (int)instance;
            recurrenceEntity.Interval      = RPattern.Interval;

            eRecurrenceType recType = eRecurrenceType.RecursDaily;

            if (RPattern.Frequency == FrequencyType.Daily)
            {
                recType = eRecurrenceType.RecursDaily;
            }
            else if (RPattern.Frequency == FrequencyType.Weekly)
            {
                recType = eRecurrenceType.RecursWeekly;
            }
            else if (RPattern.Frequency == FrequencyType.Yearly)
            {
                recType = eRecurrenceType.RecursYearly;
            }
            //TODO: MOTH YEAR NTLR
            recurrenceEntity.RecurrenceType = (int)recType;
            recurrenceEntity.MonthOfYear    = RPattern.ByMonth.Count != 0 ? RPattern.ByMonth[0] : 0;
            if (RPattern.Until != null)
            {
                recurrenceEntity.PatternEndDate = DateTime.SpecifyKind(RPattern.Until.Value, DateTimeKind.Local);
            }
            recurrenceEntity.Occurrences = RPattern.Count == int.MinValue ? 0 : RPattern.Count;

            return(new EntityObjectHierarchy(recurrenceEntity));
        }
Exemplo n.º 3
0
        public virtual EntityObjectHierarchy Serialize <T>()
        {
            CalendarEventEntity eventEntity = new CalendarEventEntity();

            //Primary key serialize
            if (InnerEvent.UID != null)
            {
                eventEntity.PrimaryKeyId = PrimaryKeyId.Parse(InnerEvent.UID.ToString());
            }
            //Calculated field
            if (InnerEvent.IsReccuring)
            {
                eventEntity.IsRecurring = true;
            }
            //not standart iCal Property serialize to entity property
            foreach (Property property in InnerEvent.Properties.Values)
            {
                iCal2EntityMapping.MappingResult mapRes = iCal2EntityMapping.iCalProp2EntityProp <T>(property.Name);
                if (mapRes != null)
                {
                    eventEntity[mapRes.Name] = EntityPropConverter.ToEntityProperty(mapRes.ValueType, property.Value);
                }
            }
            //Copy exist iCal type property to entity object
            //CATEGORIES
            if (InnerEvent.Categories != null)
            {
                foreach (TextCollection category in InnerEvent.Categories)
                {
                    eventEntity.Categories = (eventEntity.Categories + "," + category.ToString()).TrimStart(',');
                }
            }
            //PRIORITY
            if (InnerEvent.Priority != null)
            {
                eventEntity.Importance = InnerEvent.Priority;
            }
            //CLASS
            eventEntity.Sensitivy = (int)eSesitivity.Normal;
            if (InnerEvent.Class != null)
            {
                eventEntity.Sensitivy = Convert.ToInt32(InnerEvent.Class.ToString());
            }
            //SUMMARY
            if (InnerEvent.Summary != null)
            {
                eventEntity.Subject = InnerEvent.Summary;
            }
            //LOCATION
            if (InnerEvent.Location != null)
            {
                eventEntity.Location = InnerEvent.Location;
            }
            //DESCRIPTION
            if (InnerEvent.Description != null)
            {
                eventEntity.Body = InnerEvent.Description;
            }

            //Type properties serialized always in local time
            //DTSTART
            eventEntity.Start = InnerEvent.DTStart.Value;
            //DTEND
            eventEntity.End = InnerEvent.DTEnd.Value;

            //RECURRENCE ID
            if (InnerEvent.Recurrence_ID != null)
            {
                eventEntity.RecurrenceId = InnerEvent.Recurrence_ID.Value;
            }

            return(new EntityObjectHierarchy(eventEntity));
        }