Example #1
0
        protected TemplateMapping GetTemplateMapping(Item item)
        {
            string tID = item.TemplateID.ToString();

            return((TemplateMappingDefinitions.ContainsKey(tID))
                ? TemplateMappingDefinitions[tID]
                : null);
        }
Example #2
0
        public override CustomItemBase GetNewItemTemplate(object importRow)
        {
            Item   iRow = (Item)importRow;
            string tID  = iRow.TemplateID.ToString();

            if (!TemplateMappingDefinitions.ContainsKey(tID))
            {
                return(base.GetNewItemTemplate(importRow));
            }

            TemplateMapping tm = TemplateMappingDefinitions[tID];
            BranchItem      b  = (BranchItem)SitecoreDB.Items[tm.ToWhatTemplate];

            return((CustomItemBase)b);
        }
Example #3
0
        public SitecoreDataMap(Database db, string connectionString, Item importItem) : base(db, connectionString, importItem)
        {
            Item fLang = SitecoreDB.GetItem(importItem.Fields["Import From Language"].Value);

            ImportFromLanguage = LanguageManager.GetLanguage(fLang.Name);

            CheckboxField cf = importItem.Fields["Recursively Fetch Children"];

            RecursivelyFetchChildren = cf.Checked;

            //deal with sitecore properties if any
            Item Props = GetItemByTemplate(importItem, PropertiesFolderID);

            if (Props.IsNotNull())
            {
                ChildList c = Props.GetChildren();
                if (c.Any())
                {
                    foreach (Item child in c)
                    {
                        //create an item to get the class / assembly name from
                        BaseMapping bm = new BaseMapping(child);
                        if (!string.IsNullOrEmpty(bm.HandlerAssembly))
                        {
                            if (!string.IsNullOrEmpty(bm.HandlerClass))
                            {
                                //create the object from the class and cast as base field to add it to field definitions
                                IBaseProperty bp = null;
                                try {
                                    bp = (IBaseProperty)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child });
                                } catch (FileNotFoundException fnfe) {
                                    Log("Error", string.Format("the property:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly));
                                }
                                if (bp != null)
                                {
                                    PropertyDefinitions.Add(bp);
                                }
                                else
                                {
                                    Log("Error", string.Format("the property: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass));
                                }
                            }
                            else
                            {
                                Log("Error", string.Format("the property: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass));
                            }
                        }
                        else
                        {
                            Log("Error", string.Format("the property: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly));
                        }
                    }
                }
                else
                {
                    Log("Warn", "there are no properties to import");
                }
            }

            Item Temps = GetItemByTemplate(importItem, TemplatesFolderID);

            if (Temps.IsNotNull())
            {
                ChildList c = Temps.GetChildren();
                if (c.Any())
                {
                    foreach (Item child in c)
                    {
                        //create an item to get the class / assembly name from
                        TemplateMapping tm = new TemplateMapping(child);
                        if (string.IsNullOrEmpty(tm.FromWhatTemplate))
                        {
                            Log("Error", string.Format("the template mapping field 'FromWhatTemplate' on '{0}' is not defined", child.Name));
                            break;
                        }
                        if (string.IsNullOrEmpty(tm.ToWhatTemplate))
                        {
                            Log("Error", string.Format("the template mapping field 'ToWhatTemplate' on '{0}' is not defined", child.Name));
                            break;
                        }
                        TemplateMappingDefinitions.Add(tm.FromWhatTemplate, tm);
                    }
                }
            }
        }