private static SyncTransferData CreateTransferData(EntityObject entityObject) { SyncTransferData retVal = null; string transferName; if (_entity2transfer.TryGetValue(entityObject.MetaClassName, out transferName)) { switch (transferName) { case AppointmentTransferData.DataName: retVal = new AppointmentTransferData(); break; case RecurrencePatternTransferData.DataName: retVal = new RecurrencePatternTransferData(); break; case RecipientTransferData.DataName: retVal = new RecipientTransferData(); break; } if (retVal != null) { CopyProperies(entityObject, retVal); } } return(retVal); }
/// <summary> /// Копирует properties из SyncTRansferedData -> EntityObject /// </summary> /// <param name="src">The SRC.</param> /// <param name="dst">The DST.</param> private static void CopyProperies(SyncTransferData src, EntityObject dst) { foreach (KeyValuePair <string, object> pair in src.Properties) { dst[pair.Key] = pair.Value; } }
private static void CopyProperies(EntityObject src, SyncTransferData dst) { foreach (string key in new List <string>(dst.Properties.Keys)) { object srcValue = src[key]; if (srcValue == null) { System.Reflection.PropertyInfo propInfo = dst.GetType().GetProperty(key); if (propInfo != null) { srcValue = propInfo.PropertyType.IsValueType ? Activator.CreateInstance(propInfo.PropertyType) : null; } } //Избавляемся от ibn framework зависимых типов. if (srcValue != null) { if (srcValue.GetType() == typeof(PrimaryKeyId)) { srcValue = srcValue.ToString(); } else if (srcValue.GetType() == typeof(PrimaryKeyId?)) { srcValue = ((PrimaryKeyId?)srcValue).HasValue ? srcValue.ToString() : null; } dst.Properties[key] = srcValue; } } }
private static EntityObject CreateEntityObject(SyncTransferData transferData) { EntityObject retVal = null; string entityName; if (_transfer2entity.TryGetValue(transferData.SyncDataName, out entityName)) { switch (entityName) { case CalendarEventEntity.ClassName: retVal = new CalendarEventEntity(); break; case CalendarEventRecurrenceEntity.ClassName: retVal = new CalendarEventRecurrenceEntity(); break; case CalendarEventResourceEntity.ClassName: retVal = new CalendarEventResourceEntity(); break; } if (retVal != null) { CopyProperies(transferData, retVal); } } return(retVal); }
SyncTransferData IFactoryMethod <SyncTransferData> .Create(object obj) { SyncTransferData retVal = null; EntityObjectHierarchy data = obj as EntityObjectHierarchy; if (data != null) { retVal = CreateTransferData(data.InnerEntity); foreach (EntityObjectHierarchy child in data.Childrens) { retVal.Childrens.Add(Create <SyncTransferData>(child)); } } return(retVal); }
/// <summary> /// Converts to transfer data. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> protected override object ConvertToTransferData(EntityObjectHierarchy data) { if (data == null) { throw new ArgumentNullException("data"); } if (data.InnerEntity.MetaClassName != CalendarEventEntity.ClassName) { throw new FormatException("event must be parrent element in hierarchy"); } TransferDataConverFactory converFactory = new TransferDataConverFactory(); SyncTransferData retVal = converFactory.Create <SyncTransferData>(data); return(retVal); }
public object Deserialize(SyncTransferData data) { RecipientTransferData recipTransfData = data as RecipientTransferData; string retVal = null; if (recipTransfData != null) { if (!string.IsNullOrEmpty(recipTransfData.Email)) { retVal = recipTransfData.Email; } else { retVal = recipTransfData.Name; } } return retVal; }
/// <summary> /// Преобразует TranferData в объект Outlook RecurrencePattern /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public object Deserialize(SyncTransferData data) { TransferProperty2OutlookProperty(RecurrencePatternTransferData.FieldRecurrenceType, data); IEnumerable <string> recurProp; if (!_recurTypeFieldMap.TryGetValue(RPattern.RecurrenceType, out recurProp)) { throw new ArgumentException("Invalid recurrence pattern"); } foreach (string property in recurProp) { TransferProperty2OutlookProperty(property, data); } return(RPattern); }
public object Deserialize(SyncTransferData data) { RecipientTransferData recipTransfData = data as RecipientTransferData; string retVal = null; if (recipTransfData != null) { if (!string.IsNullOrEmpty(recipTransfData.Email)) { retVal = recipTransfData.Email; } else { retVal = recipTransfData.Name; } } return(retVal); }
EntityObjectHierarchy IFactoryMethod <EntityObjectHierarchy> .Create(object obj) { EntityObjectHierarchy retVal = null; SyncTransferData data = obj as SyncTransferData; if (data != null) { EntityObject entity = CreateEntityObject(data); if (entity != null) { retVal = new EntityObjectHierarchy(entity); foreach (SyncTransferData child in data.Childrens) { retVal.Childrens.Add(Create <EntityObjectHierarchy>(child)); } } } return(retVal); }
/// <summary> /// Converts from transfer data. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> protected override EntityObjectHierarchy ConvertFromTransferData(object data) { SyncTransferData transferData = data as SyncTransferData; if (transferData == null) { throw new NotSupportedException("transfer data not supported"); } EntityObjectHierarchy retVal = null; TransferDataConverFactory converFactory = new TransferDataConverFactory(); if (transferData.SyncDataName != AppointmentTransferData.DataName) { throw new FormatException("invalid structire transfer data"); } retVal = converFactory.Create <EntityObjectHierarchy>(transferData); return(retVal); }
public object Deserialize(SyncTransferData data) { if (data == null) throw new ArgumentNullException("data"); AppointmentTransferData appData = data as AppointmentTransferData; if (appData == null) throw new NullReferenceException("appData"); bool isException = appData.RecurrenceId != DateTime.MinValue; object propVal = data.Properties[AppointmentTransferData.FieldImportance]; if(propVal != null) { eImportance importance = (eImportance)(int)propVal; switch (importance) { case eImportance.Low: InnerAppointment.Importance = Outlook.OlImportance.olImportanceLow; break; case eImportance.Normal: InnerAppointment.Importance = Outlook.OlImportance.olImportanceNormal; break; case eImportance.High: InnerAppointment.Importance = Outlook.OlImportance.olImportanceHigh; break; } } InnerAppointment.Start = (DateTime)data.Properties[AppointmentTransferData.FieldStart]; InnerAppointment.End = (DateTime)data.Properties[AppointmentTransferData.FieldEnd]; InnerAppointment.Subject = (string)data.Properties[AppointmentTransferData.FieldSubject]; InnerAppointment.Location = (string)data.Properties[AppointmentTransferData.FieldLocation]; InnerAppointment.Body = (string)data.Properties[AppointmentTransferData.FieldBody]; //case "DTSTART.TZID": //case "DTEND.TZID": //Для exception данный свойства модифицировать нельзя if (!isException) { InnerAppointment.Categories = (string)data.Properties[AppointmentTransferData.FieldCategories]; propVal = data.Properties[AppointmentTransferData.FieldSensitivy]; if (propVal != null) { eSesitivity sensitivity = (eSesitivity)(int)data.Properties[AppointmentTransferData.FieldSensitivy]; switch (sensitivity) { case eSesitivity.Confidential: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olConfidential; break; case eSesitivity.Normal: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olNormal; break; case eSesitivity.Personal: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olPersonal; break; case eSesitivity.Private: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olPrivate; break; } } } return InnerAppointment; }
/// <summary> /// Transfers the property2 outlook property. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="data">The data.</param> private void TransferProperty2OutlookProperty(string propertyName, SyncTransferData data) { object propValue = data.Properties[propertyName]; if (propValue == null) return; if (propertyName == RecurrencePatternTransferData.FieldRecurrenceType) { eRecurrenceType recType = (eRecurrenceType)(int)propValue; switch (recType) { case eRecurrenceType.RecursDaily: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursDaily; break; case eRecurrenceType.RecursMonthly: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursMonthly; break; case eRecurrenceType.RecursMonthNth: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursMonthNth; break; case eRecurrenceType.RecursWeekly: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursWeekly; break; case eRecurrenceType.RecursYearly: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursYearly; break; case eRecurrenceType.RecursYearNth: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursYearNth; break; } } else if (propertyName == RecurrencePatternTransferData.FieldDayOfWeekMask) { eBitDayOfWeek dayOfWeekMask = (eBitDayOfWeek)(int)propValue; RPattern.DayOfWeekMask = (Outlook.OlDaysOfWeek)(int)dayOfWeekMask; } else if (propertyName == RecurrencePatternTransferData.FieldPatternEndDate) { RPattern.PatternEndDate = (DateTime)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldDayOfMonth) { RPattern.DayOfMonth = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldInstance) { RPattern.Instance = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldInterval) { RPattern.Interval = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldMonthOfYear) { RPattern.MonthOfYear = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldOccurrences) { RPattern.Occurrences = (int)propValue; } }
/// <summary> /// Преобразует TranferData в объект Outlook RecurrencePattern /// </summary> /// <param name="data">The data.</param> /// <returns></returns> public object Deserialize(SyncTransferData data) { TransferProperty2OutlookProperty(RecurrencePatternTransferData.FieldRecurrenceType, data); IEnumerable<string> recurProp; if(!_recurTypeFieldMap.TryGetValue(RPattern.RecurrenceType, out recurProp)) { throw new ArgumentException("Invalid recurrence pattern"); } foreach (string property in recurProp) { TransferProperty2OutlookProperty(property, data); } return RPattern; }
/// <summary> /// Transfers the property2 outlook property. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="data">The data.</param> private void TransferProperty2OutlookProperty(string propertyName, SyncTransferData data) { object propValue = data.Properties[propertyName]; if (propValue == null) { return; } if (propertyName == RecurrencePatternTransferData.FieldRecurrenceType) { eRecurrenceType recType = (eRecurrenceType)(int)propValue; switch (recType) { case eRecurrenceType.RecursDaily: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursDaily; break; case eRecurrenceType.RecursMonthly: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursMonthly; break; case eRecurrenceType.RecursMonthNth: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursMonthNth; break; case eRecurrenceType.RecursWeekly: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursWeekly; break; case eRecurrenceType.RecursYearly: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursYearly; break; case eRecurrenceType.RecursYearNth: RPattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursYearNth; break; } } else if (propertyName == RecurrencePatternTransferData.FieldDayOfWeekMask) { eBitDayOfWeek dayOfWeekMask = (eBitDayOfWeek)(int)propValue; RPattern.DayOfWeekMask = (Outlook.OlDaysOfWeek)(int) dayOfWeekMask; } else if (propertyName == RecurrencePatternTransferData.FieldPatternEndDate) { RPattern.PatternEndDate = (DateTime)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldDayOfMonth) { RPattern.DayOfMonth = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldInstance) { RPattern.Instance = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldInterval) { RPattern.Interval = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldMonthOfYear) { RPattern.MonthOfYear = (int)propValue; } else if (propertyName == RecurrencePatternTransferData.FieldOccurrences) { RPattern.Occurrences = (int)propValue; } }
public object Deserialize(SyncTransferData data) { if (data == null) { throw new ArgumentNullException("data"); } AppointmentTransferData appData = data as AppointmentTransferData; if (appData == null) { throw new NullReferenceException("appData"); } bool isException = appData.RecurrenceId != DateTime.MinValue; object propVal = data.Properties[AppointmentTransferData.FieldImportance]; if (propVal != null) { eImportance importance = (eImportance)(int)propVal; switch (importance) { case eImportance.Low: InnerAppointment.Importance = Outlook.OlImportance.olImportanceLow; break; case eImportance.Normal: InnerAppointment.Importance = Outlook.OlImportance.olImportanceNormal; break; case eImportance.High: InnerAppointment.Importance = Outlook.OlImportance.olImportanceHigh; break; } } InnerAppointment.Start = (DateTime)data.Properties[AppointmentTransferData.FieldStart]; InnerAppointment.End = (DateTime)data.Properties[AppointmentTransferData.FieldEnd]; InnerAppointment.Subject = (string)data.Properties[AppointmentTransferData.FieldSubject]; InnerAppointment.Location = (string)data.Properties[AppointmentTransferData.FieldLocation]; InnerAppointment.Body = (string)data.Properties[AppointmentTransferData.FieldBody]; //case "DTSTART.TZID": //case "DTEND.TZID": //Для exception данный свойства модифицировать нельзя if (!isException) { InnerAppointment.Categories = (string)data.Properties[AppointmentTransferData.FieldCategories]; propVal = data.Properties[AppointmentTransferData.FieldSensitivy]; if (propVal != null) { eSesitivity sensitivity = (eSesitivity)(int)data.Properties[AppointmentTransferData.FieldSensitivy]; switch (sensitivity) { case eSesitivity.Confidential: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olConfidential; break; case eSesitivity.Normal: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olNormal; break; case eSesitivity.Personal: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olPersonal; break; case eSesitivity.Private: InnerAppointment.Sensitivity = Outlook.OlSensitivity.olPrivate; break; } } } return(InnerAppointment); }