public MonthlyPerformanceImporter() { Log.Debug("Genworth.SitecoreExt.ScheduledTasks.MonthlyPerformanceImporter:DocImporter", this); Database db = Factory.GetDatabase("master"); dictStrategists = ContentEditorHelper.GetStrategist(db, ContentEditorHelper.STRATEGIST_PATH); dictApproaches = ContentEditorHelper.GetAllocationApproches(db, ContentEditorHelper.ALLOCATION_PATH); dictCategories = ContentEditorHelper.GetLookupIds(db, ContentEditorHelper.CATEGORY_PATH); dictSources = ContentEditorHelper.GetLookupIds(db, ContentEditorHelper.SOURCE_PATH); }
public bool PublishSite() { try { ContentEditorHelper.PublishSite("/sitecore/content/Shared Content/Investments"); ContentEditorHelper.PublishSite("/sitecore/media library/Files/Investments/Strategist Performance"); } catch (Exception ex) { return(false); } return(true); }
public StrategistCommentaryImporter() { Log.Debug("Genworth.SitecoreExt.ScheduledTasks.StrategistCommentaryImporter:DocImporter", this); Database db = Factory.GetDatabase("master"); dictStrategists = ContentEditorHelper.GetStrategist(db, ContentEditorHelper.STRATEGIST_PATH); dictApproaches = ContentEditorHelper.GetAllocationApproches(db, ContentEditorHelper.ALLOCATION_PATH); dictCategories = ContentEditorHelper.GetLookupIds(db, ContentEditorHelper.CATEGORY_PATH); dictSources = ContentEditorHelper.GetLookupIds(db, ContentEditorHelper.SOURCE_PATH); dictManagers = ContentEditorHelper.GetManagers(db, ContentEditorHelper.MANAGER_PATH); dictDescriptions = ContentEditorHelper.GetDescriptions(db, ContentEditorHelper.DESCRIPTION_PATH); }
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); } }
public bool GetFile(string path, out string fileName) { bool bOk = false; fileName = string.Empty; try { Log.Debug("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:GetFile", this); fileName = ContentEditorHelper.GetFile(path, PERF_SHEET_FILE_PREFIX); if (fileName != string.Empty) { bOk = true; } } catch (Exception ex) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:GetFile, path {0}, exception: {1}", path, ex.ToString()), this); bOk = false; } return(bOk); }
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 bool ImportFile(string path, string fileName) { Log.Info(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:ImportFiles, base path {0}, file name {1}", path, fileName), this); bool bStatus = true; // overall function status bool bOk = true; // individual call status try { Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master"); MediaItem mediaItem = null; if (!File.Exists(Path.Combine(path, fileName + ".pdf"))) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:ImportFile, file not found, skipping file. Path: {0}", path), this); return(false); } string[] fields = fileName.Split('_'); if (fields.Length != PERF_SHEET_FIELD_COUNT) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:ImportFiles, expecting {0} fields but found {1}, file: {2}", PERF_SHEET_FIELD_COUNT, fields.Length, fileName), this); File.Move(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } string allocationCode = fields[PERF_SHEET_FIELD_ALLOCAPPROACH].ToUpper(); if (!dictApproaches.ContainsKey(allocationCode)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:ImportFiles, unable to lookup allocation code {0}", allocationCode), this); ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } Item allocationItem = dictApproaches[allocationCode]; string title = GenerateDocTitle(fileName); string contentPath = string.Empty; if (!String.IsNullOrEmpty(title)) { contentPath = "/sitecore/media library/Files/Investments/Strategist Performance/" + allocationItem["Title"] + "/" + title; mediaItem = ContentEditorHelper.UploadContent(master, Path.Combine(path, fileName + ".pdf"), contentPath); } if (mediaItem == null) { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } // set meta-data here Sitecore.Data.Items.Item item = master.GetItem(contentPath); using (new Sitecore.SecurityModel.SecurityDisabler()) { item.Editing.BeginEdit(); item["Description"] = fileName; // save original file name //item["DisplayName"] = title; item.Editing.EndEdit(); } // map media item to strategist docs ID itemId; bOk = mapMediaItemToSharedContent(master, allocationItem, title, mediaItem, out itemId); bStatus = bStatus && bOk; // update allocation node with latest doc string dateRange = fields[PERF_SHEET_FIELD_DATERANGE]; bOk = mapItemToAllocation(master, allocationItem, itemId, dateRange); bStatus = bStatus && bOk; // only move file if all parts of the process were successful if (bStatus) { // move to processed folder if (Directory.Exists(path + "\\Processed")) { string postFix = DateTime.Now.ToString("_MM-dd-yyyy-hh-mm-ss"); ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, "Processed", fileName + postFix + ".pdf")); } else { Log.Error("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:ImportFiles, processed directory does not exist", this); } } else { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); } } catch (Exception ex) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.MonthlyPerformanceImporter:MonthlyPerformanceImporter, file: {0}, exception: {1}", fileName, ex.ToString()), this); bStatus = false; } if (!bStatus) { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); } return(bStatus); }
public bool ImportFile(string path, string fileName) { if (String.IsNullOrEmpty(path)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, path is null or empty, skipping file."), this); return(false); } else if (String.IsNullOrEmpty(fileName)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, file is null or empty, skipping file. Path: {0}", path), this); return(false); } Log.Info(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, base path {0}, file name {1}", path, fileName), this); bool bStatus = true; // overall function status bool bOk = true; // individual call status try { Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master"); MediaItem mediaItem = null; bool isGPS = false; if (!File.Exists(Path.Combine(path, fileName + ".pdf"))) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, file not found, skipping file. Path: {0}", path), this); return(false); } string[] fields = fileName.Split('_'); if (fields.Length != STR_COM_SHEET_FIELD_COUNT) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, expecting {0} fields but found {1}, file: {2}", STR_COM_SHEET_FIELD_COUNT, fields.Length, fileName), this); ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } string strategistCode = fields[STR_COM_FIELD_STRATEGIST_CODE].ToUpper(); string allocationCode = fields[STR_COM_FIELD_ALLOCAPPROACH].ToUpper(); string strategyCode = fields[STR_COM_FIELD_STRATEGY].Replace("X", "").ToUpper(); // swap out placeholder value for empty string if (!dictStrategists.ContainsKey(strategistCode)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, could not look up strategist {0}, skipping file", strategistCode), this); ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } // Need to promote GPS & GPS Select to strategists to handle inconsistencies between EWM and Business logic. if (((strategistCode == "GFWM") && (allocationCode == "GFWMC")) || ((strategistCode == "GFWM") && (allocationCode == "GPS"))) { strategistCode = allocationCode; allocationCode = string.Empty; isGPS = true; } string strategist = dictStrategists[strategistCode]; Item allocationItem = null; if (!String.IsNullOrEmpty(allocationCode) && dictApproaches.ContainsKey(allocationCode)) { allocationItem = dictApproaches[allocationCode]; } string title = GenerateDocTitle(fileName); string contentPath = string.Empty; if (!String.IsNullOrEmpty(title)) { contentPath = "/sitecore/media library/Files/Investments/" + ContentEditorHelper.CleanNodeName(strategist) + "/Commentary/" + title; mediaItem = ContentEditorHelper.UploadContent(master, Path.Combine(path, fileName + ".pdf"), contentPath); } if (mediaItem == null) { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } // set meta-data here Sitecore.Data.Items.Item item = master.GetItem(contentPath); using (new Sitecore.SecurityModel.SecurityDisabler()) { item.Editing.BeginEdit(); item["Description"] = fileName; // save original file name //item["DisplayName"] = title; item.Editing.EndEdit(); } // map media item to strategist docs ID itemId; bOk = mapMediaItemToSharedContent(master, strategist, allocationItem, title, mediaItem, out itemId); bStatus = bStatus && bOk; //if (!isGPS) //{ // // update solution to point to latest doc // bOk = mapItemToStrategist(master, strategist, allocationItem, strategyCode, itemId); // bStatus = bStatus && bOk; //} // only move file if all parts of the process were successful if (bStatus) { // move to processed folder if (Directory.Exists(Path.Combine(path, "Processed"))) { string postFix = DateTime.Now.ToString("_MM-dd-yyyy-hh-mm-ss"); ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, "Processed", fileName + postFix + ".pdf")); } else { Log.Error("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, processed directory does not exist", this); } } else { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); } } catch (Exception ex) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.StrategistCommentaryImporter:ImportFile, file: {0}, exception: {1}", fileName, ex.ToString()), this); bStatus = false; } if (!bStatus) { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); } return(bStatus); }
public string GenerateDocTitle(string fileName) { Log.Debug("Genworth.SitecoreExt.Importers.ExpenseRatioImporter:GenerateDocTitle", this); StringBuilder title = new StringBuilder(); try { string[] fields = fileName.Split('_'); string allocationCode = fields[EXPENSE_RATIO_FIELD_ALLOCAPPROACH].ToUpper(); if (!String.IsNullOrEmpty(allocationCode) && !dictApproaches.ContainsKey(allocationCode)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.ExpenseRatioImporter:GenerateDocTitle, allocation dictionary does not contain the requested allocation, Filename: {0}, Allocation code: {1}", fileName, allocationCode), this); title.Append(fileName); } else { Item allocationItem = dictApproaches[allocationCode]; string year = fields[EXPENSE_RATIO_FIELD_YEAR]; string month = fields[EXPENSE_RATIO_FIELD_MONTH]; if (!String.IsNullOrEmpty(allocationItem["Title"])) { title.Append("Expense Ratios for " + allocationItem["Title"].Replace(".", "") + " as of " + month + "-" + ContentEditorHelper.GetLastDayOfMonth(int.Parse(month), int.Parse(year)) + "-" + year); } else { Log.Error(String.Format("Genworth.SitecoreExt.Importers.ExpenseRatioImporter:GenerateDocTitle, allocation description does not contain value for allocationCode " + allocationCode + ", Filename: {0}, Allocation code: {1}", fileName, allocationCode), this); title.Append(fileName); } } } catch (Exception ex) { Log.Error("Genworth.SitecoreExt.Importers.ExpenseRatioImporter:GenerateDocTitle, exception:" + ex.ToString(), this); } return(title.ToString()); }
public bool ImportFile(string path, string fileName) { if (String.IsNullOrEmpty(path)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFile, path is null or empty, skipping file."), this); return(false); } else if (String.IsNullOrEmpty(fileName)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFile, file is null or empty, skipping file. Path: {0}", path), this); return(false); } Log.Info(String.Format("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFile, base path {0}, file name {1}", path, fileName), this); bool bStatus = true; // overall function status bool bOk = true; // individual call status try { Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master"); MediaItem mediaItem = null; if (!File.Exists(Path.Combine(path, fileName + ".pdf"))) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFile, file not found, skipping file. Path: {0}", path), this); return(false); } string[] fields = fileName.Split('_'); if (fields.Length != ADV_MGR_SHEET_FIELD_COUNT) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFiles, expecting {0} fields but found {1}, file: {2}", ADV_MGR_SHEET_FIELD_COUNT, fields.Length, fileName), this); File.Move(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } string managerCode = fields[ADV_MGR_FIELD_MANAGER_CODE].ToUpper(); if (!dictManagers.ContainsKey(managerCode)) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFiles, unable to lookup manager code {0}", managerCode), this); ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } Item managerItem = dictManagers[managerCode]; string title = GenerateDocTitle(fileName); string contentPath = string.Empty; if (!String.IsNullOrEmpty(title)) { contentPath = "/sitecore/media library/Files/Investments/" + managerItem["Name"] + "/FactSheets/" + title; mediaItem = ContentEditorHelper.UploadContent(master, Path.Combine(path, fileName + ".pdf"), contentPath); } if (mediaItem == null) { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); return(false); } // set meta-data here Sitecore.Data.Items.Item item = master.GetItem(contentPath); using (new Sitecore.SecurityModel.SecurityDisabler()) { item.Editing.BeginEdit(); item["Description"] = fileName; // save original file name //item["DisplayName"] = title; item.Editing.EndEdit(); } // map media item to strategist docs bOk = mapMediaItemToSharedContent(master, managerItem, title, mediaItem); bStatus = bStatus && bOk; // only move file if all parts of the process were successful if (bStatus) { // move to processed folder if (Directory.Exists(path + "\\Processed")) { string postFix = DateTime.Now.ToString("_MM-dd-yyyy-hh-mm-ss"); ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, "Processed", fileName + postFix + ".pdf")); } else { Log.Error("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFiles, processed directory does not exist", this); } } else { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); } } catch (Exception ex) { Log.Error(String.Format("Genworth.SitecoreExt.Importers.AdvisorManagerFactSheetImpoter:ImportFile, file: {0}, exception: {1}", fileName, ex.ToString()), this); bStatus = false; } if (!bStatus) { ContentEditorHelper.MoveFile(Path.Combine(path, fileName + ".pdf"), Path.Combine(path, fileName + ".pdf.failed")); } return(bOk); }