Пример #1
0
        public static bool CheckSolutionExist(Sitecore.Data.Database database, string strategist, Item allocationItem, string strategy)
        {
            if (database == null)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Utilities.ContentEditorHelper:CheckSolutionExist, database cannot be null or empty"), typeof(ContentEditorHelper));
                return(false);
            }
            else if (String.IsNullOrEmpty(strategist))
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Utilities.ContentEditorHelper:CheckSolutionExist, strategy cannot be null or empty"), typeof(ContentEditorHelper));
                return(false);
            }
            else if (String.IsNullOrEmpty(allocationItem["Title"]))
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Utilities.ContentEditorHelper:CheckSolutionExist, allocation cannot be null or empty. Strategist: {0}", strategist), typeof(ContentEditorHelper));
                return(false);
            }

            string sharedPath   = "/sitecore/content/Shared Content/Investments/Strategists/#" + strategist + "#/#" + allocationItem.Name + "#/*[@@templatekey = 'solution' and @Code='" + strategy + "']";
            Item   strategyItem = database.SelectSingleItem(sharedPath);

            if (strategyItem == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        private bool mapItemToStrategist(Sitecore.Data.Database database, string strategist, Item allocationItem, string strategy, ID itemId)
        {
            bool bOk = false;

            try
            {
                if (ID.IsNullOrEmpty(itemId))
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.FactSheetImporter:mapMediaItemToStrategist, mediaItem cannot be null or empty. Strategist: {0}, allocation: {1}", strategist, allocationItem["Title"]), this);
                    return(false);
                }

                string sharedPath   = "/sitecore/content/Shared Content/Investments/Strategists/#" + strategist + "#/#" + allocationItem.Name + "#/*[@@templatekey = 'solution' and @Code='" + strategy + "']";
                Item   strategyItem = database.SelectSingleItem(sharedPath);

                if (strategyItem == null)
                {
                    Log.Error(String.Format("Genworth.SitecoreExt.Importers.FactSheetImporter:mapMediaItemToStrategist, solution node for strategy {0}, allocation approach {1}, does not exist, skipping. " +
                                            "This generally happens when the solution node is either missing or has a code that doesn't match the document naming convention. Path: {2}",
                                            strategist,
                                            allocationItem["Title"],
                                            sharedPath), this);
                    return(false);
                }

                Sitecore.Data.Fields.ReferenceField referenceField = strategyItem.Fields["Fact Sheet"];
                if (referenceField != null)
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        strategyItem.Editing.BeginEdit();
                        referenceField.Value = itemId.ToString();
                        strategyItem.Editing.EndEdit();
                    }
                }

                bOk = true;
            }
            catch (Exception ex)
            {
                Log.Error(String.Format("Genworth.SitecoreExt.Importers.FactSheetImporter:mapMediaItemToStrategist, strategist: {0}, allocation: {1}, solution: {2}, exception: {3}", strategist, allocationItem["Title"], strategy, ex.ToString()), this);
                bOk = false;
            }

            return(bOk);
        }