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 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);
        }
예제 #3
0
        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);
        }