public BaseDataMap(Database db, string connectionString, Item importItem)
        {
            //instantiate log
            log = new StringBuilder();

            //setup import details
            SitecoreDB = db;
            DatabaseConnectionString = connectionString;
            //get query
            Query = importItem.Fields["Query"].Value;
            if (string.IsNullOrEmpty(Query))
            {
                Log("Error", "the 'Query' field was not set");
            }
            //get parent and store it
            string parentID = importItem.Fields["Import To Where"].Value;

            if (!string.IsNullOrEmpty(parentID))
            {
                Item parent = SitecoreDB.Items[parentID];
                if (parent.IsNotNull())
                {
                    Parent = parent;
                }
                else
                {
                    Log("Error", "the 'To Where' item is null");
                }
            }
            else
            {
                Log("Error", "the 'To Where' field is not set");
            }
            //get new item template
            string templateID = importItem.Fields["Import To What Template"].Value;

            if (!string.IsNullOrEmpty(templateID))
            {
                Item templateItem = SitecoreDB.Items[templateID];
                if (templateItem.IsNotNull())
                {
                    NewItemTemplate = templateItem;
                }
                else
                {
                    Log("Error", "the 'To What Template' item is null");
                }
            }
            else
            {
                Log("Error", "the 'To What Template' field is not set");
            }
            //more properties
            ItemNameDataField = importItem.Fields["Pull Item Name from What Fields"].Value;
            ItemNameMaxLength = int.Parse(importItem.Fields["Item Name Max Length"].Value);
            //foldering information
            FolderByDate = ((CheckboxField)importItem.Fields["Folder By Date"]).Checked;
            FolderByName = ((CheckboxField)importItem.Fields["Folder By Name"]).Checked;
            DateField    = importItem.Fields["Date Field"].Value;
            if (FolderByName || FolderByDate)
            {
                //setup a default type to an ordinary folder
                Sitecore.Data.Items.TemplateItem FolderItem = SitecoreDB.Templates["{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}"];
                //if they specify a type then use that
                string folderID = importItem.Fields["Folder Template"].Value;
                if (!string.IsNullOrEmpty(folderID))
                {
                    FolderItem = SitecoreDB.Templates[folderID];
                }
                FolderTemplate = FolderItem;
            }

            //start handling fields
            Item Fields = GetItemByTemplate(importItem, FieldsFolderID);

            if (Fields.IsNotNull())
            {
                ChildList c = Fields.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
                                IBaseField bf = null;
                                try {
                                    bf = (IBaseField)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child });
                                } catch (FileNotFoundException fnfe) {
                                    Log("Error", string.Format("the field:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly));
                                }
                                if (bf != null)
                                {
                                    FieldDefinitions.Add(bf);
                                }
                                else
                                {
                                    Log("Error", string.Format("the field: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass));
                                }
                            }
                            else
                            {
                                Log("Error", string.Format("the field: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass));
                            }
                        }
                        else
                        {
                            Log("Error", string.Format("the field: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly));
                        }
                    }
                }
                else
                {
                    Log("Warn", "there are no fields to import");
                }
            }
            else
            {
                Log("Warn", "there is no 'Fields' folder");
            }
        }
Beispiel #2
0
 private static void AddField(string fieldName, Func <DatabaseMetadata, string> getter, Action <DatabaseMetadata, string> setter)
 {
     FieldDefinitions.Add(fieldName.ToLower(), new FieldDefinition(fieldName, getter, setter));
 }