private bool UpdateDocumentRepositoryState(string itemId, string repositoryName, string value, string database)
        {
            try
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    var item = ItemHelper.GetItemById(itemId, database);

                    item.Editing.BeginEdit();

                    var documentStateField = item.GetField("Marketing Collateral Distribution", "Repository Document State");
                    if (documentStateField != null)
                    {
                        var collection = Sitecore.Web.WebUtil.ParseUrlParameters(documentStateField.Value);
                        collection[repositoryName] = value;
                        var stateValues = new List <string>();
                        collection.AllKeys.ToList().ForEach(key => stateValues.Add(string.Format("{0}={1}", Sitecore.Web.WebUtil.UrlEncode(key), Sitecore.Web.WebUtil.UrlEncode(string.IsNullOrWhiteSpace(collection[key]) ? "N" : collection[key]))));
                        documentStateField.Value = string.Join("&", stateValues.ToArray());
                    }

                    item.Editing.EndEdit();

                    MailQProvider mailq = new MailQProvider();

                    var    toAddress = item.GetText("Submitter Name");
                    var    emailDic  = item.GetNameValueDictionary("Repository Owner Emails");
                    var    RepDic    = item.GetNameValueDictionary("Download Name");
                    string ccAdress  = null;
                    string FileName  = null;
                    emailDic.TryGetValue(repositoryName, out ccAdress);
                    RepDic.TryGetValue(repositoryName, out FileName);

                    mailq.SendEmailWithOutTemplate(
                        toAddress,
                        null,
                        ccAdress,
                        "Marketing Collateral Distribution - Status Updated",
                        string.Format("New state for '{0}' file. '{1}' Repository State changed to {2}", FileName, repositoryName.Replace("_", " "), value)
                        );
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error(string.Format("Error while updating document's repository state value. ItemId: {0}, repository: {1}, value: {2}", itemId ?? "null", repositoryName ?? "null", value ?? "null"), ex, this);
            }
            return(true);
        }
Esempio n. 2
0
        public void Execute()
        {
            if (!IsValidDateRange)
            {
                Log.Debug(string.Format("Genworth.SitecoreExt.ScheduledTasks.SitecorePublisherTask: Out of Time Range; Start: {0}, End: {1}; Now: {2}", StartUpWindow, EndingWindow, DateTime.Now), this);
                return;
            }

            try
            {
                MailQProvider mailq          = new MailQProvider();
                string        assetmarkNode  = Sitecore.Configuration.Settings.GetSetting("AssetMarkNode");
                string        sourceDatabase = Sitecore.Configuration.Settings.GetSetting("SourceDatabase");
                string        targetDatabase = Sitecore.Configuration.Settings.GetSetting("TargetDatabase");
                string        subject        = Sitecore.Configuration.Settings.GetSetting("Publish_Status_Subject");
                string        toAddress      = Sitecore.Configuration.Settings.GetSetting("Publish_Status_To_Address");
                bool          success        = false;

                Log.Debug("Genworth.SitecoreExt.ScheduledTasks.SitecorePublisherTask:Execute - start", this);

                success = SitecorePublisher.PublishItem(Sitecore.Configuration.Factory.GetDatabase(sourceDatabase).GetItem(assetmarkNode), true, Sitecore.Configuration.Factory.GetDatabase(sourceDatabase), Sitecore.Configuration.Factory.GetDatabase(targetDatabase), false);

                if (success)
                {
                    string body = ContentEditorHelper.GetPublishStatusEmailBody(success);
                    if (body != string.Empty)
                    {
                        mailq.SendEmailWithOutTemplate(toAddress, string.Empty, string.Empty, subject, body);
                    }
                }

                Log.Debug("Genworth.SitecoreExt.ScheduledTasks.SitecorePublisherTask:Execute - end", this);
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.ScheduledTasks.SitecorePublisherTask:Execute failed due to {0}", ex.Message), this);
            }
        }
Esempio n. 3
0
        public void Execute()
        {
            try
            {
                Log.Debug("Genworth.SitecoreExt.ScheduledTasks.MonthlyPerformanceImportTask:Execute - start", this);

                MailQProvider mailq = new MailQProvider();
                MonthlyPerformanceImporter importer = new MonthlyPerformanceImporter();
                List <string> lstProcessedFiles     = new List <string>();
                List <string> lstFailedfiles        = new List <string>();
                string        fileImportPath        = Sitecore.Configuration.Settings.GetSetting(FILE_IMPORT_PATH_KEY);
                string        toAddress             = Sitecore.Configuration.Settings.GetSetting(TO_ADDRESS);
                string        subject = Sitecore.Configuration.Settings.GetSetting(FILE_IMPORT_EMAIL_SUBJECT);
                bool          bStatus = true;

                if (!String.IsNullOrEmpty(fileImportPath))
                {
                    string fileName;
                    while (importer.GetFile(fileImportPath, out fileName))
                    {
                        bool bFileStatus = importer.ImportFile(fileImportPath, fileName);

                        if (bFileStatus)
                        {
                            lstProcessedFiles.Add(fileName + ".pdf");
                        }
                        else
                        {
                            lstFailedfiles.Add(fileName + ".pdf");
                        }

                        bStatus = bStatus && bFileStatus;
                    }
                }

                if (!bStatus)
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.ScheduledTasks.MonthlyPerformanceImportTask: import files failed"), this);
                }
                else
                {
                    if (lstProcessedFiles.Count > 0)
                    {
                        bStatus = importer.PublishSite();
                        if (!bStatus)
                        {
                            Log.Error(String.Format("Genworth.SitecoreExt.ScheduledTasks.MonthlyPerformanceImportTask: publish docs failed"), this);
                        }
                    }
                }

                string body = ContentEditorHelper.GetImporterEmailBody(lstProcessedFiles, lstFailedfiles, "Monthly Performance");
                if (body != string.Empty)
                {
                    mailq.SendEmailWithOutTemplate(toAddress, string.Empty, string.Empty, subject + " " + "Monthly Performance", body);
                }

                Log.Debug("Genworth.SitecoreExt.ScheduledTasks.MonthlyPerformanceImportTask:Execute - end", this);
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.ScheduledTasks.MonthlyPerformanceImportTask:Execute failed due to {0}", ex.Message), this);
            }
        }
        public void Execute()
        {
            if (!IsValidDateRange)
            {
                Log.Debug(string.Format("Genworth.SitecoreExt.ScheduledTasks.MarketingUtilityStatusTask: Out of Time Range; Start: {0}, End: {1}; Now: {2}", StartUpWindow, EndingWindow, DateTime.Now), this);
                return;
            }
            List <KeyValuePair <string, string> > summary = new List <KeyValuePair <string, string> >();

            try
            {
                Log.Debug(string.Format("Genworth.SitecoreExt.ScheduledTasks.MarketingUtilityStatusTask:Execute - start; Time Range; Start: {0}, End: {1}; Now: {2}", StartUpWindow, EndingWindow, DateTime.Now), this);

                var templates = ImporterHelper.GetExtendedDocumentTemplates();

                foreach (var template in templates)
                {
                    var items = GetItemsByTemplate(template);

                    Log.Debug(string.Format("Genworth.SitecoreExt.ScheduledTasks.MarketingUtilityStatusTask: Found {1} in {0}", template.TemplateFullName, items.Count()), this);

                    foreach (var item in items)
                    {
                        var createdDate = item.GetField("Statistics", "__created").GetDate();

                        var ownerEmailsDictionary   = item.GetNameValueDictionary("Repository Owner Emails");
                        var documentStateDictionary = item.GetNameValueDictionary("Repository Document State").Where(f => (ownerEmailsDictionary.ContainsKey(f.Key)) && (f.Value == "P" || f.Value == "R"));

                        if (documentStateDictionary.Count() < 1)
                        {
                            continue;
                        }

                        var repositoriesDictionary = GetRepositoryDictionary(item.GetMultilistItems("Repositories"));

                        // Add different emails.
                        var senderEmails = GetDifferentEmails(documentStateDictionary, ownerEmailsDictionary);

                        // Add submiter in case it is not included
                        AddDifferentString(senderEmails, item.GetText("Submitter Name"));

                        // Greate mail body
                        StringBuilder body = new StringBuilder();
                        body.AppendFormat("<h2>'{0}' file has repository status pending for approval</h2>", item.DisplayName);
                        body.AppendFormat("<p><b>Date: </b>{0}<br />", item.GetField("Statistics", "__created").GetDate());
                        body.AppendFormat("<b>Path: </b>{0}</p>", item.Paths.FullPath);

                        foreach (var ds in documentStateDictionary)
                        {
                            string key = null;
                            repositoriesDictionary.TryGetValue(ds.Key, out key);
                            body.AppendFormat("<b>Repository</b> '{0}' <b>status</b> '{1}'<br />", key ?? ds.Key, ds.Value);
                        }

                        string sBody = body.ToString();
                        foreach (var email in senderEmails)
                        {
                            // Add to summary
                            summary.Add(new KeyValuePair <string, string>(email.ToLower(), sBody));
                        }
                    }
                }

                var groups = summary.ToLookup(f => f.Key);
                Log.Debug(string.Format("Genworth.SitecoreExt.ScheduledTasks.MarketingUtilityStatusTask: Sending {0} emails", groups.Count()), this);

                MailQProvider mailq = new MailQProvider();
                foreach (var item in groups)
                {
                    var toAddress = item.Key;
                    var bodys     = item.Select(f => f.Value);

                    mailq.SendEmailWithOutTemplate(
                        "*****@*****.**",
                        null,
                        null,
                        "Marketing Collateral Distribution Utility - Repository status report " + toAddress,
                        string.Concat(bodys) + "<br/><br/>" + DateTime.Now
                        );
                }
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.ScheduledTasks.MarketingUtilityStatusTask:Execute failed due to {0}", ex.Message), this);
            }
            finally
            {
                Log.Debug("Genworth.SitecoreExt.ScheduledTasks.MarketingUtilityStatusTask: Ends", this);
            }
        }