/// <summary> /// Compares the hierarchy. /// </summary> /// <param name="otherHierarchy">The other hierarchy.</param> /// <returns></returns> public bool CompareHierarchy(EntityObjectHierarchy otherHierarchy) { bool retVal = true; EntityComparer entityComp = CreateEntityComparer(_entityHierarchy.InnerEntity); if (entityComp == null || otherHierarchy.InnerEntity.MetaClassName != _entityHierarchy.InnerEntity.MetaClassName || !entityComp.CompareEntity(otherHierarchy.InnerEntity)) { retVal = false; } else { foreach (EntityObjectHierarchy childEntity in _entityHierarchy.Childrens) { if (childEntity.InnerEntity.MetaClassName != _entityHierarchy.InnerEntity.MetaClassName && IsRegisteredEntity(childEntity.InnerEntity)) { EntityHierarchyComparer entityHierarchyComp = new EntityHierarchyComparer(childEntity, _entityUsedPropMap); if (otherHierarchy.Childrens.Find(entityHierarchyComp.CompareHierarchy) == null) { retVal = false; break; } } } } return(retVal); }
/// <summary> /// Compares the hierarchy. /// </summary> /// <param name="otherHierarchy">The other hierarchy.</param> /// <returns></returns> public bool CompareHierarchy(EntityObjectHierarchy otherHierarchy) { bool retVal = true; EntityComparer entityComp = CreateEntityComparer(_entityHierarchy.InnerEntity); if (entityComp == null || otherHierarchy.InnerEntity.MetaClassName != _entityHierarchy.InnerEntity.MetaClassName || !entityComp.CompareEntity(otherHierarchy.InnerEntity)) { retVal = false; } else { foreach (EntityObjectHierarchy childEntity in _entityHierarchy.Childrens) { if (childEntity.InnerEntity.MetaClassName != _entityHierarchy.InnerEntity.MetaClassName && IsRegisteredEntity(childEntity.InnerEntity)) { EntityHierarchyComparer entityHierarchyComp = new EntityHierarchyComparer(childEntity, _entityUsedPropMap); if (otherHierarchy.Childrens.Find(entityHierarchyComp.CompareHierarchy) == null) { retVal = false; break; } } } } return retVal; }
/// <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); }
/// <summary> /// Возвращает список событий как виртуальных так и реальных. /// </summary> /// <param name="filterColl">The filter coll.</param> /// <param name="request">The request.</param> /// <returns></returns> private static IEnumerable <CalendarEventEntity> ListEvents(FilterElementCollection filterColl, CalendarEventListRequest request) { McEvent mcEvent = null; //Конструируем стандартный запрос LIST без критериев содержащих дату начала и конца события ListRequest moListRequest = (ListRequest)EventHelper.ConstructRequest <ListRequest>(request.Target, true); moListRequest.Filters = filterColl.ToArray(); moListRequest.Sorting = request.Sorting; //выполняем стандартный запрос ListResponse listResp = (ListResponse)BusinessManager.Execute(moListRequest); if (listResp != null && listResp.EntityObjects != null) { //Пробегаем по реальным events foreach (CalendarEventEntity entity in listResp.EntityObjects) { mcEvent = EventHelper.LoadCalEvent(entity.PrimaryKeyId.Value); if (mcEvent.IsReccuring) { iCalDateTime dtReccurBase = mcEvent.DTStart; //Пробегаем по виртуальным events foreach (Occurrence occur in mcEvent.GetOccurrences(mcEvent.DTStart, mcEvent.RecurrenceSeriesEndDate)) { //Создаем виртуальные события VirtualEventId vEventId = (VirtualEventId)entity.PrimaryKeyId; vEventId.RecurrenceId = EventHelper.iCalDateTime2Recurrence(dtReccurBase, occur.Period.StartTime); //Set virtual id mcEvent.UID = vEventId.ToString(); //Set recurrence-ID mcEvent.Recurrence_ID = occur.Period.StartTime; mcEvent.DTStart = occur.Period.StartTime; mcEvent.DTEnd = occur.Period.EndTime; EntityObjectHierarchy recurrenceEntity = EventHelper.ConstructEntityHierarchy(mcEvent); CalendarEventEntity occurEventEntity = recurrenceEntity.InnerEntity as CalendarEventEntity; if (occurEventEntity != null) { yield return(occurEventEntity); } } } else { yield return(entity); } } } }
/// <summary> /// Получает дерево связвнных entityObject из объектной модели эвента /// <remarks> /// Структура EntityObjectHierarchy События /// <event> /// <recurrencePattern> /// </recurrencePattern> /// <resource> /// </resource> /// <exception> /// <resource> /// </resource> /// </exception> /// </event> /// </remarks> /// </summary> /// <returns></returns> public EntityObjectHierarchy GetEntityObjectHierarchy() { EntityObjectHierarchy retVal = null; McSerializerFactory factory = new McSerializerFactory(); IEntitySerializable serializer = factory.Create <IEntitySerializable>(this); retVal = serializer.Serialize <CalendarEventEntity>(); if (RRule != null) { foreach (RecurrencePattern rpattern in RRule) { serializer = factory.Create <IEntitySerializable>(rpattern); retVal.Childrens.Add(serializer.Serialize <CalendarEventRecurrenceEntity>()); } } if (Organizer != null) { serializer = factory.Create <IEntitySerializable>(Organizer); if (serializer != null) { retVal.Childrens.Add(serializer.Serialize <CalendarEventResourceEntity>()); } } if (Attendee != null) { foreach (Cal_Address attendee in Attendee) { serializer = factory.Create <IEntitySerializable>(attendee); if (serializer != null) { retVal.Childrens.Add(serializer.Serialize <CalendarEventResourceEntity>()); } } } //exceptions if (RecurrenceException != null) { foreach (McEvent exception in RecurrenceException) { retVal.Childrens.Add(exception.GetEntityObjectHierarchy()); } } return(retVal); }
/// <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; }
/// <summary> /// Initializes a new instance of the <see cref="EntityHierarchyComparer"/> class. /// </summary> /// <param name="entityHierarchy">The entity hierarchy.</param> /// <param name="propMap">The prop map.</param> public EntityHierarchyComparer(EntityObjectHierarchy entityHierarchy, Dictionary <string, string[]> propMap) { _entityHierarchy = entityHierarchy; _entityUsedPropMap = propMap; }
/// <summary> /// Initializes a new instance of the <see cref="EntityHierarchyComparer"/> class. /// </summary> /// <param name="entityHierarchy">The entity hierarchy.</param> /// <param name="propMap">The prop map.</param> public EntityHierarchyComparer(EntityObjectHierarchy entityHierarchy, Dictionary<string, string[]> propMap) { _entityHierarchy = entityHierarchy; _entityUsedPropMap = propMap; }