/// <summary> /// Создает событие. Логика регистрация в метаданных происходит в базовом классе /// </summary> /// <param name="change">The change.</param> /// <param name="data">The data.</param> /// <returns></returns> protected override void CreateDataItem(ItemChange change, ItemMetadata item, EntityObjectHierarchy data) { if (data == null) { throw new ArgumentNullException("data"); } EntityObject eventEntity = data.InnerEntity; //Дата начала события DateTime eventDtStart = (DateTime)eventEntity[CalendarEventEntity.FieldStart]; //В начале создаем событие без регистрации в мета данных события PrimaryKeyId?eventId = eventEntity.PrimaryKeyId = BusinessManager.Create(eventEntity); //Устанавливаем отношение родительского элемента с дочерними EventHelper.NormailzeReferences(data); foreach (EntityObjectHierarchy child in data.Childrens) { CalendarEventEntity exceptionEvent = child.InnerEntity as CalendarEventEntity; if (exceptionEvent != null) { //Формируем id exception в соответвии принятым форматом DateTime recurrenceId = exceptionEvent.RecurrenceId; exceptionEvent.PrimaryKeyId = EventHelper.CreateExceptionId(eventId.Value, eventDtStart, recurrenceId); } //Вызываем создание дочерних элементов BusinessManager.Create(child.InnerEntity); //создаем дочерние элементы exception if (exceptionEvent != null) { foreach (EntityObjectHierarchy exceptionChild in child.Childrens) { CalendarEventResourceEntity exceptionResource = exceptionChild.InnerEntity as CalendarEventResourceEntity; if (exceptionResource != null) { //устанавливаем связь ресурса с event (exception) exceptionResource.EventId = exceptionEvent.PrimaryKeyId.Value; BusinessManager.Create(exceptionChild.InnerEntity); } } } } item.SetCustomField(SyncReplicaMetadata.URI_COLUMNNAME, (Guid)eventId); }