예제 #1
0
        public Language GetImportItemLanguage(string fieldName, Database db)
        {
            Language l = LanguageManager.DefaultLanguage;

            //check the field
            string langID = ImportItem.GetItemField(fieldName, Logger);

            if (string.IsNullOrEmpty(langID))
            {
                Logger.Log("The 'Import Language' field is not set on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, fieldName);
                return(l);
            }

            //check item
            Item iLang = db.GetItem(langID);

            if (iLang.IsNull())
            {
                Logger.Log("The 'Import Language' Item is null on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, fieldName);
                return(l);
            }

            //check language
            l = LanguageManager.GetLanguage(iLang.Name);
            if (l == null)
            {
                Logger.Log("The 'Import Language' name is not valid on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, fieldName);
            }

            return(l);
        }
예제 #2
0
        public SitecoreDataMap(Database db, string connectionString, Item importItem, ILogger l)
            : base(db, connectionString, importItem, l)
        {
            //get 'from' language
            ImportFromLanguage = GetImportItemLanguage("Import From Language");

            //get recursive setting
            RecursivelyFetchChildren = ImportItem.GetItemBool("Recursively Fetch Children");

            //populate property definitions
            PropertyDefinitions = GetPropDefinitions(ImportItem);

            ReferenceFieldDefinitions = GetReferenceFieldDefinitions(importItem);

            //populate template definitions
            TemplateMappingDefinitions = GetTemplateDefinitions(ImportItem);

            ComponentMappingDefinitions = GetComponentDefinitions(ImportItem);

            ImportRoot         = GetImportRootItem();
            DeleteOnOverwrite  = ImportItem.GetItemBool("Delete On Overwrite");
            PreserveChildren   = ImportItem.GetItemBool("Preserve Children on Delete");
            AllowItemNameMatch = ImportItem.GetItemBool("Allow Item Name Match");

            PathRewrites = ImportItem.GetItemField("Path Rewrites", Logger)
                           .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                           .ToDictionary(s => s.Split(';')[0], s => s.Split(';')[1]);
        }
예제 #3
0
        public CustomItemBase GetImportToTemplate()
        {
            CustomItemBase template = null;

            //check field value
            string templateID = ImportItem.GetItemField("Import To What Template", Logger);

            if (string.IsNullOrEmpty(templateID))
            {
                Logger.Log("the 'To What Template' field is not set", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, "Import To What Template");
                return(null);
            }

            //check template item
            Item templateItem = ToDB.Items[templateID];

            if (templateItem.IsNull())
            {
                Logger.Log("the 'To What Template' item is null", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, "Import To What Template");
                return(null);
            }

            //determine template item type
            if ((BranchItem)templateItem != null)
            {
                template = (BranchItem)templateItem;
            }
            else
            {
                template = (TemplateItem)templateItem;
            }

            return(template);
        }
예제 #4
0
        public PmbiDataMap(Database db, string connectionString, Item importItem, ILogger l) : base(db, connectionString, importItem, l)
        {
            // Get start path
            StartPath = ImportItem.GetItemField("Start Path", Logger);

            // Get template id
            TemplateId = ImportItem.GetItemField("Template ID", Logger);

            // Get year
            Year = ImportItem.GetItemField("Year", Logger);


            ArticleNumberPrefix = importItem.Fields[ArticleNumberPrefixStr].Value;
            var val = importItem.Fields[LastArticleNumber].Value;

            if (string.IsNullOrWhiteSpace(val))
            {
                ArticleNumber = 0;
            }
            else
            {
                int articleNumber;
                int.TryParse(importItem.Fields[LastArticleNumber].Value, out articleNumber);
                ArticleNumber = articleNumber;
            }
        }
예제 #5
0
        protected IEnumerable <Item> GetImportedArticles()
        {
            var templateId = ImportItem.GetItemField("Import To What Template", Logger);
            var articles   =
                ImportToWhere.Axes.GetDescendants()
                .Where(i => i.TemplateID.ToString() == templateId && i.Fields[CreatedDate].Value.Contains(Year));

            return(articles);
        }
        /// <summary>
        /// gets the parent of the new item created. will create folders based on name or date if configured to
        /// </summary>
        public virtual Item GetParentNode(object importRow, string newItemName)
        {
            Item thisParent = ImportToWhere;

            if (FolderByDate)
            {
                FolderTemplate = GetImportFolderTemplate();
                DateField      = ImportItem.GetItemField("Date Field", Logger);
                DateTime date      = DateTime.Now;
                string   dateValue = string.Empty;

                try {
                    dateValue = GetFieldValue(importRow, DateField);
                } catch (ArgumentException ex) {
                    Logger.Log(newItemName, (string.IsNullOrEmpty(DateField))
                        ? "the date name field is empty"
                        : "the field name does not exist in the import row", ProcessStatus.DateParseError, DateField);
                }

                if (string.IsNullOrEmpty(dateValue))
                {
                    Logger.Log(newItemName, "Couldn't folder by date. The date value was empty", ProcessStatus.DateParseError, DateField);
                    return(thisParent);
                }

                if (!DateTime.TryParse(dateValue, out date) &&
                    !DateTime.TryParseExact(dateValue, new string[] { "d/M/yyyy", "d/M/yyyy HH:mm:ss" }, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                {
                    Logger.Log(newItemName, "date could not be parsed", ProcessStatus.DateParseError, DateField, dateValue);
                    return(thisParent);
                }

                thisParent = GetDateParentNode(ImportToWhere, date, FolderTemplate);
            }
            else if (FolderByName)
            {
                FolderTemplate = GetImportFolderTemplate();
                thisParent     = GetNameParentNode(ImportToWhere, newItemName.Substring(0, 1), FolderTemplate);
            }
            return(thisParent);
        }
예제 #7
0
        public Item GetImportToWhereItem()
        {
            Item toWhere = null;

            //check field value
            string toWhereID = ImportItem.GetItemField("Import To Where", Logger);

            if (string.IsNullOrEmpty(toWhereID))
            {
                Logger.Log("the 'To Where' field is not set on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, "Import To Where");
                return(null);
            }

            //check item
            toWhere = ToDB.Items[toWhereID];
            if (toWhere.IsNull())
            {
                Logger.Log("the 'To Where' item is null on the import item", ImportItem.Paths.FullPath, LogType.ImportDefinitionError, "Import To Where", toWhereID);
            }

            return(toWhere);
        }
예제 #8
0
        public Item GetImportRootItem()
        {
            Item toWhere = null;

            //check field value
            string toWhereID = ImportItem.GetItemField("Import Root", Logger);

            if (string.IsNullOrEmpty(toWhereID))
            {
                Logger.Log("SitecoreDataMap.GetImportRootItem", string.Format("the 'Import Root' field is not set on the import item {0}", ImportItem.Paths.FullPath));
                return(null);
            }

            //check item
            toWhere = FromDB.Items[toWhereID];
            if (toWhere.IsNull())
            {
                Logger.Log("SitecoreDataMap.GetImportRootItem", string.Format("the 'Import Root' item is null on the import item", ImportItem.Paths.FullPath));
            }

            return(toWhere);
        }
예제 #9
0
        public TemplateItem GetImportFolderTemplate()
        {
            if (!FolderByName && !FolderByDate && !FolderByPath)
            {
                return(null);
            }

            //setup a default type to an ordinary folder
            TemplateItem defaultTemplate = ToDB.Templates[CommonFolderTemplateID];

            //if they specify a type then use that
            string folderID = ImportItem.GetItemField("Folder Template", Logger);

            if (string.IsNullOrEmpty(folderID))
            {
                return(defaultTemplate);
            }

            //check the folder template
            TemplateItem fTemplate = ToDB.Templates[folderID];

            return((fTemplate == null) ? defaultTemplate : fTemplate);
        }
예제 #10
0
 public CSVDataMap(Database db, string ConnectionString, Item importItem, ILogger l)
     : base(db, ConnectionString, importItem, l)
 {
     FieldDelimiter = ImportItem.GetItemField("Field Delimiter", Logger);
     EncodingType   = ImportItem.GetItemField("Encoding Type", Logger);
 }
예제 #11
0
 public EscenicAutonomyArticleDataMap(Database db, string ConnectionString, Item importItem, ILogger l)
     : base(db, ConnectionString, importItem, l)
 {
     PublicationPrefix = ImportItem.GetItemField("Publication Prefix", Logger);
 }