public bool Start()
        {
            if (Settings.GetValue(MailHelper.MAILPROCESSOR_SETTINGS, MailHelper.SETTINGS_MODE, null, MailProcessingMode.ExchangePull) != MailProcessingMode.ExchangePush)
            {
                return(false);
            }

            // renew subscriptions
            //  1: go through doclibs with email addresses
            var doclibs = ContentQuery.Query("+TypeIs:DocumentLibrary +ListEmail:* -ListEmail:\"\"");

            if (doclibs.Count > 0)
            {
                SnLog.WriteInformation(String.Concat("Exchange subscription service enabled, running subscriptions (", doclibs.Count.ToString(), " found)"), categories: ExchangeHelper.ExchangeLogCategory);
                foreach (var doclib in doclibs.Nodes)
                {
                    try
                    {
                        ExchangeHelper.Subscribe(doclib);
                    }
                    catch (Exception ex)
                    {
                        SnLog.WriteException(ex, categories: ExchangeHelper.ExchangeLogCategory);
                    }
                }
            }
            else
            {
                SnLog.WriteInformation("Exchange subscription service enabled, no subscriptions found.", categories: ExchangeHelper.ExchangeLogCategory);
            }

            return(true);
        }
        public bool Start()
        {
            if (!Configuration.SubscriptionServiceEnabled)
            {
                return(false);
            }

            // renew subscriptions
            //  1: go through doclibs with email addresses
            var doclibs = ContentQuery.Query("+TypeIs:DocumentLibrary +ListEmail:* -ListEmail:\"\"");

            if (doclibs.Count > 0)
            {
                Logger.WriteInformation("Exchange subscription service enabled, running subscriptions (" + doclibs.Count.ToString() + " found)", ExchangeHelper.ExchangeLogCategory);
                foreach (var doclib in doclibs.Nodes)
                {
                    try
                    {
                        ExchangeHelper.Subscribe(doclib);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteException(ex, ExchangeHelper.ExchangeLogCategory);
                    }
                }
            }
            else
            {
                Logger.WriteInformation("Exchange subscription service enabled, no subscriptions found.", ExchangeHelper.ExchangeLogCategory);
            }

            return(true);
        }
示例#3
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(Configuration.PushNotificationServicePath, doclibrary.Path);

            var watermark = ExchangeHelper.GetWaterMark(doclibrary);

            var ps = service.SubscribeToPushNotifications(new List <FolderId> {
                folderId
            }, new Uri(servicePath), Configuration.StatusPollingIntervalInMinutes, watermark, EventType.NewMail);

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

            Logger.WriteInformation("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);
            }
        }
示例#4
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);
        }
示例#5
0
        public static void Subscribe(Node doclibrary)
        {
            var service = ExchangeHelper.CreateConnection(doclibrary["ListEmail"] as string);

            ExchangeHelper.Subscribe(doclibrary, service);
        }