Exemple #1
0
        public static void Subscribe(Node doclibrary, ExchangeService service)
        {
            if (service == null)
            {
                return;
            }

            var address = doclibrary["ListEmail"] as string;

            if (string.IsNullOrEmpty(address))
            {
                return;
            }

            var mailbox     = new Mailbox(address);
            var folderId    = new FolderId(WellKnownFolderName.Inbox, mailbox);
            var servicePath = string.Format(Settings.GetValue <string>(MailHelper.MAILPROCESSOR_SETTINGS, MailHelper.SETTINGS_SERVICEPATH), doclibrary.Path);

            var watermark = ExchangeHelper.GetWaterMark(doclibrary);

            var ps = service.SubscribeToPushNotifications(new List <FolderId> {
                folderId
            }, new Uri(servicePath), Settings.GetValue(MailHelper.MAILPROCESSOR_SETTINGS, MailHelper.SETTINGS_POLLINGINTERVAL, null, 120), watermark, EventType.NewMail);

            var loginfo = string.Concat(" - Path:", doclibrary.Path, ", Email:", address, ", Watermark:", watermark, ", SubscriptionId:", ps.Id);

            Logger.WriteInformation(Logger.EventId.NotDefined, "Exchange subscription" + loginfo, ExchangeHelper.ExchangeLogCategory);

            // persist subscription id to doclib, so that multiple subscriptions are handled correctly
            var user = User.Current;

            try
            {
                AccessProvider.Current.SetCurrentUser(User.Administrator);

                var retryCount = 3;
                while (retryCount > 0)
                {
                    try
                    {
                        doclibrary["ExchangeSubscriptionId"] = ps.Id;
                        doclibrary.Save();
                        break;
                    }
                    catch (NodeIsOutOfDateException)
                    {
                        retryCount--;
                        doclibrary = Node.LoadNode(doclibrary.Id);
                    }
                }
            }
            finally
            {
                AccessProvider.Current.SetCurrentUser(user);
            }
        }
Exemple #2
0
        public static FindItemsResults <Item> GetItems(ExchangeService service, Node doclibrary)
        {
            var address = doclibrary["ListEmail"] as string;

            if (string.IsNullOrEmpty(address))
            {
                return(null);
            }

            var items = ExchangeHelper.GetItems(service, address);

            return(items);
        }
Exemple #3
0
        public static void Subscribe(Node doclibrary)
        {
            var service = ExchangeHelper.CreateConnection(doclibrary["ListEmail"] as string);

            ExchangeHelper.Subscribe(doclibrary, service);
        }