Пример #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);
		}
Пример #2
0
		public object Deserialize<T>(Mediachase.Ibn.Core.Business.EntityObject entity)
		{
			if(entity.PrimaryKeyId != null)
			{
				McCalAddress mcCalAddress = Resource as McCalAddress;
				if (mcCalAddress != null)
				{
					mcCalAddress.MetaObjectId = entity.PrimaryKeyId.Value;
				}
			}

			foreach (EntityObjectProperty entityProp in entity.Properties)
			{
				iCal2EntityMapping.MappingResult mapRes = iCal2EntityMapping.EntityProp2iCalProp<T>(entityProp.Name);
				if (entityProp.Value == null || mapRes == null)
					continue;

				if (mapRes.Name.StartsWith("X-"))
				{
					Resource.AddParameter(mapRes.Name, entityProp.Value.ToString());
					continue;
				}
				switch (mapRes.Name)
				{
					case "Authority":
						Resource.Scheme = Uri.UriSchemeMailto;
						Resource.Authority = entityProp.Value.ToString();
						break;
				}

			}
			return Resource;
		}
Пример #3
0
        /// <summary>
        /// Получает объект типа McEvent из дерева связанных EntityObject (EntityObjectHierarchy)
        /// </summary>
        /// <param name="entityHierarchy">The entity hierarchy.</param>
        /// <returns></returns>
        public static McEvent GetMcEventFromEntityObjectHierarchy(EntityObjectHierarchy entityHierarchy)
        {
            McEvent             retVal     = new McEvent();
            McSerializerFactory factory    = new McSerializerFactory();
            IEntitySerializable serializer = factory.Create <IEntitySerializable>(retVal);

            retVal = (McEvent)serializer.Deserialize <CalendarEventEntity>(entityHierarchy.InnerEntity);
            foreach (EntityObjectHierarchy child in entityHierarchy.Childrens)
            {
                if (child.InnerEntity.MetaClassName == CalendarEventRecurrenceEntity.ClassName)
                {
                    McRecurrencePattern rPattern = new McRecurrencePattern();
                    retVal.AddChild(rPattern);
                    serializer = factory.Create <IEntitySerializable>(rPattern);
                    if (serializer != null)
                    {
                        rPattern     = (McRecurrencePattern)serializer.Deserialize <CalendarEventRecurrenceEntity>(child.InnerEntity);
                        retVal.RRule = new RecurrencePattern[] { rPattern };
                    }
                }
                else if (child.InnerEntity.MetaClassName == CalendarEventResourceEntity.ClassName)
                {
                    McCalAddress resource = new McCalAddress();
                    retVal.AddChild(resource);
                    serializer = factory.Create <IEntitySerializable>(resource);
                    if (serializer != null)
                    {
                        resource = (McCalAddress)serializer.Deserialize <CalendarEventResourceEntity>(child.InnerEntity);
                        retVal.AddChild(resource);
                        if (((CalendarEventResourceEntity)child.InnerEntity).ResourceEventOrganizator)
                        {
                            retVal.Organizer = resource;
                        }
                        else
                        {
                            List <Cal_Address> oldVals = new List <Cal_Address>();
                            if (retVal.Attendee != null)
                            {
                                oldVals.AddRange(retVal.Attendee);
                            }
                            oldVals.Add(resource);
                            retVal.Attendee = oldVals.ToArray();
                        }
                    }
                }
                else if (child.InnerEntity.MetaClassName == CalendarEventEntity.ClassName)
                {
                    McEvent exception = GetMcEventFromEntityObjectHierarchy(child);
                    if (exception != null)
                    {
                        retVal.AddReccurenceException(exception);
                    }
                }
            }

            return(retVal);
        }