public bool ArchiveAnsweredRfi(Microsoft.Exchange.WebServices.Data.Item email, Entity.Store store) { var message = Microsoft.Exchange.WebServices.Data.EmailMessage.Bind(this.GetEmailService, email.Id, EmailProperties ); var subject = message.Subject; var parser = new Parser(); var success = false; if (parser.IsAnsweredQuestion(subject)) { if (message.Sender.Name == "Amy Mills" && message.ToRecipients[0].Name == "RFI") { Logger.LoggerAsync.InstanceOf.GeneralLogger.Warn("Going to archive answered RFIs for {0}", message.Categories[0]); var results = this.GetMessagesOfSameCategory(message); success = this.MoveEmailsToFolder(results, store); } } return(success); }
/// <summary> /// Returns <paramref name="propertyDefinition"/> property value from Exchange storage <paramref name="item"/>. /// If property value not reachable, returns default <paramref name="propertyDefinition"/> value. /// </summary> /// <typeparam name="T">Return value type.</typeparam> /// <param name="item"><see cref="Exchange.Item"/> instance.</param> /// <param name="propertyDefinition"><see cref="Exchange.PropertyDefinition"/> instance.</param> /// <returns><paramref name="propertyDefinition"/> value from <paramref name="item"/> if value reachable, /// dafault <paramref name="propertyDefinition"/> value otherwise.</returns> public static T SafeGetValue <T>(this Exchange.Item item, Exchange.PropertyDefinition propertyDefinition) { T value; item.TryGetProperty(propertyDefinition, out value); return(value); }
protected ExchangeBase(SyncItemSchema schema, Exchange.Item item, TimeZoneInfo timeZoneInfo) { Schema = schema; Item = item; if (item != null) { DateTime version = item.SafeGetValue <DateTime>(Exchange.ItemSchema.LastModifiedTime); Version = TimeZoneInfo.ConvertTimeFromUtc(version.ToUniversalTime(), timeZoneInfo); } }
/// <summary> /// Creates new <see cref="ExchangeAppointment"/> instance. /// </summary> /// <param name="schema"><see cref="SyncItemSchema"/> instance.</param> /// <param name="item"><see cref="Exchange.Item"/> instance.</param> /// <param name="remoteId">Remote item instance unique identifier.</param> /// <param name="timezone"><see cref="TimeZoneInfo"/> instance.</param> /// <returns><see cref="ExchangeAppointment"/> instance.</returns> private ExchangeAppointment CreateExchangeAppointment(SyncItemSchema schema, Exchange.Item item, string remoteId, TimeZoneInfo timezone) { var schemaParam = new ConstructorArgument("schema", schema); var itemParam = new ConstructorArgument("item", item); var timeZoneParam = new ConstructorArgument("timeZoneInfo", timezone); var remoteIdParam = new ConstructorArgument("remoteId", remoteId); return(remoteId.IsEmpty() ? ClassFactory.Get <ExchangeAppointment>(schemaParam, itemParam, timeZoneParam) : ClassFactory.Get <ExchangeAppointment>(schemaParam, itemParam, remoteIdParam, timeZoneParam)); }
/// <summary> /// Method is moving item from one to another folder. /// </summary> /// <param name="item">Item to move.</param> /// <param name="destinationFolder">Destination folder.</param> /// <param name="moveOperation">Move operation (Copy or Move).</param> internal void MoveItem(Item item, Folder destinationFolder, MoveOperation moveOperation) { //Item itemToMove = Item.Bind(ewsSession, item.Id); switch (moveOperation) { case MoveOperation.Copy: item.Copy(destinationFolder.Id); break; case MoveOperation.Move: item.Move(destinationFolder.Id); break; } }
/// <summary>Returns activity instance for exchange appointment, in case of changed remote id.</summary> /// <param name="context">Synchronization context.</param> /// <param name="exchangeItem">Exchange item in external storage.</param> /// <param name="storedId">Id of bpm activity, stored in external property of exchange item.</param> /// <param name="localItem">Local storage item.</param> /// <returns>Activity instance.</returns> protected Entity GetSyncedActivityWithChangedRemoteId(SyncContext context, Exchange.Item exchangeItem, Guid storedId, LocalItem localItem) { Entity instance; var syncValueName = localItem.Schema.SyncValueName; var schema = context.UserConnection.EntitySchemaManager.GetInstanceByName("Activity"); instance = schema.CreateEntity(context.UserConnection); if (!localItem.Entities["Activity"].Any(se => se.EntityId.Equals(storedId)) && instance.FetchFromDB(storedId)) { SyncEntity syncEntity = SyncEntity.CreateNew(instance); var isCurrentUserOwner = context.UserConnection.CurrentUser.ContactId == instance.GetTypedColumnValue <Guid>("OwnerId"); syncEntity.Action = isCurrentUserOwner ? SyncAction.Update : SyncAction.None; context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId set action {0} for {1}", syncEntity.Action, GetDisplayName()); localItem.AddOrReplace("Activity", syncEntity); if (syncValueName == ExchangeConsts.ExchangeAppointmentClassName) { context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId ExchangeAppointmentClassName action update for {0}", GetDisplayName()); Action = SyncAction.Update; syncEntity.Action = SyncAction.Update; } else { Action = isCurrentUserOwner ? SyncAction.Update : SyncAction.None; context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId action {0} for {1}", Action, GetDisplayName()); if (isCurrentUserOwner) { ActualizeOldMetadata(context, storedId, Id); } } } else { context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetSyncedActivityWithChangedRemoteId not found entity action {0} for {1}", Action, GetDisplayName()); instance = GetEntityInstance <Entity>(context, localItem, "Activity"); } return(instance); }
private bool MoveAttachmentsToFolder(Microsoft.Exchange.WebServices.Data.Item item, Entity.Store store) { var fileHandler = new Utilities.FileHandler(store); if (item.HasAttachments) { var success = fileHandler.SaveAttachmentsToFolder(item.Attachments); if (success) { item.Attachments.Clear(); item.Update(ConflictResolutionMode.AlwaysOverwrite); } } return(false); }
/// <summary> /// Returns activity instance. /// </summary> /// <param name="context">Synchronization context.</param> /// <param name="exchangeItem">Sync element in external storage.</param> /// <param name="localItem">Sync element in local storage.</param> protected Entity GetActivity(SyncContext context, Exchange.Item exchangeItem, ref LocalItem localItem) { Entity instance; Object localId; if (exchangeItem.TryGetProperty(ExchangeUtilityImpl.LocalIdProperty, out localId)) { context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetActivity use localId action {0} for {1}", Action, GetDisplayName()); instance = GetSyncedActivityWithChangedRemoteId(context, exchangeItem, Guid.Parse(localId.ToString()), localItem); } else { context.LogInfo(SyncAction.None, SyncDirection.DownloadAndUpload, "GetActivity not use localId action {0} for {1}", Action, GetDisplayName()); instance = GetEntityInstance <Entity>(context, localItem, "Activity"); } return(instance); }
/// <summary> /// Creates new <see cref="ExchangeAppointment"/> instance. /// </summary> /// <param name="schema"><see cref="SyncItemSchema"/> instance.</param> /// <param name="item"><see cref="Exchange.Item"/> instance.</param> /// <param name="timezone"><see cref="TimeZoneInfo"/> instance.</param> /// <returns><see cref="ExchangeAppointment"/> instance.</returns> private ExchangeAppointment CreateExchangeAppointment(SyncItemSchema schema, Exchange.Item item, TimeZoneInfo timezone) { return(CreateExchangeAppointment(schema, item, string.Empty, timezone)); }
/// <summary> /// Creates new <see cref="ExchangeTask"/> instance, using <paramref name="schema"/>, remote storage item /// instance and remote storage item id. /// </summary> /// <param name="schema">Entity sync schema instance.</param> /// <param name="item">Remote storage item.</param> /// <param name="remoteId">Remote storage item id.</param> /// <param name="timeZoneInfo">Current user timezone.</param> public ExchangeTask(SyncItemSchema schema, Exchange.Item item, string remoteId, TimeZoneInfo timeZoneInfo) : this(schema, item, timeZoneInfo) { RemoteId = remoteId; }
/// <summary> /// Creates new <see cref="ExchangeTask"/> instance, using <paramref name="schema"/> and remote storage item. /// </summary> /// <param name="schema">Entity sync schema instance.</param> /// <param name="item">Remote storage item.</param> /// <param name="timeZoneInfo">Current user timezone.</param> public ExchangeTask(SyncItemSchema schema, Exchange.Item item, TimeZoneInfo timeZoneInfo) : base(schema, item, timeZoneInfo) { _propertySet.RequestedBodyType = Exchange.BodyType.Text; _propertySet.Add(ExchangeUtilityImpl.LocalIdProperty); }
/// <summary> /// Initializes a new instance of the <see cref="DeclineMeetingInvitationMessage"/> class. /// </summary> /// <param name="referenceItem">The reference item.</param> internal DeclineMeetingInvitationMessage(Item referenceItem) : base(referenceItem) { }
/// <summary> /// Executes CRUD operations for remote storage item. /// </summary> /// <param name="context">Sync context.</param> /// <param name="syncItem">Remote storage item.</param> public override void ApplyChanges(SyncContext context, IRemoteItem syncItem) { SyncAction action = syncItem.Action; if (action == SyncAction.None || GetCurrentActionIgnored(action)) { return; } var exchangeSyncItem = (ExchangeBase)syncItem; Exchange.Item exchangeItem = exchangeSyncItem.Item; string displayName = ""; string syncValueName = syncItem.Schema.SyncValueName; bool dontSendNotifications = syncValueName == ExchangeConsts.ExchangeAppointmentClassName; try { switch (action) { case SyncAction.Create: displayName = exchangeSyncItem.DisplayName; if (dontSendNotifications) { var exchangeAppointment = ((Exchange.Appointment)exchangeItem); exchangeAppointment.Save(Exchange.SendInvitationsMode.SendToNone); } else { exchangeItem.Save(); } UpdateAppointmentExtraParameters(syncValueName, syncItem); break; case SyncAction.Update: displayName = exchangeSyncItem.DisplayName; if (dontSendNotifications) { ((Exchange.Appointment)exchangeItem).Update(Exchange.ConflictResolutionMode.AlwaysOverwrite, Exchange.SendInvitationsOrCancellationsMode.SendToNone); } else { exchangeItem.Update(Exchange.ConflictResolutionMode.AlwaysOverwrite); } break; default: if (exchangeSyncItem.State != SyncState.Deleted) { if (dontSendNotifications) { ((Exchange.Appointment)exchangeItem).Delete(Exchange.DeleteMode.MoveToDeletedItems, Exchange.SendCancellationsMode.SendToNone); } else { exchangeItem.Delete(Exchange.DeleteMode.MoveToDeletedItems); } exchangeSyncItem.State = SyncState.Deleted; } break; } LogMessage(context, action, SyncDirection.Upload, OperationInfoLczStrings[action], null, displayName, syncValueName); } catch (Exception ex) { LogMessage(context, action, SyncDirection.Upload, OperationInfoLczStrings[action], ex, displayName, syncValueName); } }