Example #1
0
        private static void StartSubscription(ContentList list)
        {
            var subscribe = Settings.GetValue <MailProcessingMode>(
                MailHelper.MAILPROCESSOR_SETTINGS,
                MailHelper.SETTINGS_MODE,
                list.Path) == MailProcessingMode.ExchangePush;

            if (subscribe)
            {
                // subscribe to email after saving content. this is done separately from saving the content,
                // since subscriptionid must be persisted on the content and we use cyclic retrials for that
                ExchangeHelper.Subscribe(list);
            }

            var parent = GetMailProcessorWorkflowContainer(list);

            if (parent == null)
            {
                return;
            }

            // get the workflow to start
            var incomingEmailWorkflow = list.GetReference <Node>("IncomingEmailWorkflow");

            if (incomingEmailWorkflow == null)
            {
                return;
            }

            // set the list as the related content
            var workflowC = Content.CreateNew(incomingEmailWorkflow.Name, parent, incomingEmailWorkflow.Name);

            workflowC["RelatedContent"] = list;

            try
            {
                workflowC.Save();

                InstanceManager.Start(workflowC.ContentHandler as WorkflowHandlerBase);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex, categories: ExchangeHelper.ExchangeLogCategory);
            }
        }