public override void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
 {
     var fillFieldLogger = logger.CreateLevelLogger();
     updatedField = false;
     if (IsRequired)
     {
         if (String.IsNullOrEmpty(importValue))
         {
             fillFieldLogger.AddError(CategoryConstants.ImportedValueToFieldWasEmpty, String.Format("The Item '{0}' of template type: '{1}', field '{2}', but the imported value '{3}' was empty. This field must be provided when the field is required. The field was not updated.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
             return;
         }
     }
     Field field = newItem.Fields[NewItemField];
     if (field != null)
     {
         //try to parse date value
         DateTime date;
         if (!DateTime.TryParse(importValue, out date))
         {
             fillFieldLogger.AddError(TheDatetimeParsingFailed, String.Format("The DateTime parsing failed. Therefor the field was not updated on item '{0}' of template type: '{1}' in field the date value could not be parsed '{2}'. The date parse string was: {3}.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
             return;
         }
         string value = date.ToDateFieldValue();
         if (value != field.Value)
         {
             field.Value = value;
             updatedField = true;
         }
     }
     if (IsRequired && field == null)
     {
         fillFieldLogger.AddError(CategoryConstants.RequiredFieldNotFoundOnItem, String.Format("The Item '{0}' of template type: '{1}' didn't contain a field with name '{2}'. This field must be present because the 'Is Required Field' is checked.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField));
         return;
     }
 }
 public override void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
 {
     var fillFieldLogger = logger.CreateLevelLogger();
     updatedField = false;
     if (IsRequired)
     {
         if (String.IsNullOrEmpty(importValue))
         {
             fillFieldLogger.AddError(CategoryConstants.ImportedValueToFieldWasEmpty, String.Format("The Item '{0}' of template type: '{1}' has a field '{2}', but the imported value '{3}' was empty. This field must be provided when the field is required. The field was not updated.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
             return;
         }
     }
     //get the field as a link field and store the url
     LinkField lf = newItem.Fields[NewItemField];
     if (lf != null)
     {
         if (lf.Url != importValue)
         {
             lf.Url = importValue;
             updatedField = true;
         }
     }
     if(IsRequired && lf==null)
     {
         fillFieldLogger.AddError(CategoryConstants.RequiredFieldNotFoundOnItem, String.Format("The Item '{0}' of template type: '{1}' didn't contain a field with name '{2}'. This field must be present because the 'Is Required Field' is checked.", newItem.ID.ToString(), newItem.TemplateName, NewItemField));
         return;
     }
 }
 /// <summary>
 /// gets custom data from a DataRow
 /// </summary>
 /// <param name="importRow"></param>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 public override string GetFieldValue(object importRow, string fieldName, ref LevelLogger logger)
 {
     var getFieldLogger = logger.CreateLevelLogger();
     try
     {
         DataRow dataRow = importRow as DataRow;
         if (dataRow != null)
         {
             if (!String.IsNullOrEmpty(fieldName))
             {
                 object fieldValue = dataRow[fieldName];
                 return (fieldValue != null) ? fieldValue.ToString() : String.Empty;
             }
             else
             {
                 getFieldLogger.AddError(CategoryConstants.TheFieldnameArgumentWasNullOrEmpty, String.Format("The GetFieldValue method failed because the the 'fieldName' was null or empty. ImportRow: {0}.", GetImportRowDebugInfo(importRow)));
             }
         }
         else
         {
             getFieldLogger.AddError(CategoryConstants.TheImportRowWasNull, String.Format("The GetFieldValue method failed because the Import Row was null. FieldName: {0}.", fieldName));
         }
     }
     catch (Exception ex)
     {
         getFieldLogger.AddError(CategoryConstants.GetFieldValueFailed, String.Format("The GetFieldValue method failed with an exception. ImportRow: {0}. FieldName: {1}. Exception: {2}.", GetImportRowDebugInfo(importRow), fieldName, ex));
     }
     return String.Empty;
 }
 public virtual void Initialize(ref LevelLogger logger)
 {
     if (BaseDataMap.IsDisableItemsNotPresentInImport && BaseDataMap.DisableItemsFolderItem != null)
     {
         var disabledLogger = logger.CreateLevelLogger();
         InitializeItemsCache(BaseDataMap.DisableItemsFolderItem, BaseDataMap.IdentifyTheSameItemsByFieldDefinition.GetNewItemField(), ref disabledLogger);
     }
     var itemsAndParentLogger = logger.CreateLevelLogger();
     if (BaseDataMap.FolderByParentHierarchy)
     {
         InitializeItemsCache(BaseDataMap.Parent, BaseDataMap.IdentifyTheSameItemsByFieldDefinition.GetNewItemField() + "|" + BaseDataMap.IdentifyParentByWhatFieldOnParent, ref itemsAndParentLogger);
     }
     else
     {
         InitializeItemsCache(BaseDataMap.Parent, BaseDataMap.IdentifyTheSameItemsByFieldDefinition.GetNewItemField(), ref itemsAndParentLogger);
     }
 }
 public override string GetAbsoluteImageUrl(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
 {
     var getAbsoluteImageUrlLogger = logger.CreateLevelLogger();
     var src = StringUtil.ReadBetweenTags(importValue, SrcTagHtml, EndTagHtml);
     if (!IsRequired && String.IsNullOrEmpty(src))
     {
         return String.Empty;
     }
     if (IsRequired && String.IsNullOrEmpty(src))
     {
         getAbsoluteImageUrlLogger.AddError(CategoryConstants.TheSrcForTheImageWasNullOrEmpty, String.Format("The src for the image was null or empty. This must be provided since the isRequired value is set for this field. ImportRow: {0}.",
                              map.GetImportRowDebugInfo(importRow)));
     }
     return base.GetAbsoluteImageUrl(map, importRow, ref newItem, src, ref getAbsoluteImageUrlLogger);
 }
 public override byte[] GetImageAsBytes(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
 {
     var getImageLogger = logger.CreateLevelLogger();
     var src = GetAbsoluteImageUrl(map, importRow, ref newItem, importValue, ref getImageLogger);
     if (String.IsNullOrEmpty(src) && !IsRequired)
     {
         return null;
     }
     if (String.IsNullOrEmpty(src) && IsRequired)
     {
         getImageLogger.AddError(CategoryConstants.TheSrcForTheImageWasNullOrEmptyAfterReturnOfTheGetAbsoluteImageUrl, String.Format("The src for the image was null or empty after return of the GetAbsoluteImageUrl method in the ToImageFromImageHtmlTag field class. An src must be provided. ImportRow: {0}.",
                              map.GetImportRowDebugInfo(importRow)));
         return null;
     }
     return base.GetImageAsBytes(map, importRow, ref newItem, src, ref getImageLogger);
 }
 public static void PublishItemSmart(Data.Items.Item rootItem, Database source, Database target, Language lang, BaseDataMap map, ref LevelLogger logger)
 {
     var publishFullLogger = logger.CreateLevelLogger();
     if (rootItem == null)
     {
         publishFullLogger.AddError("RootItem cannot be [null]", "RootItem cannot be [null]");
         return;
     }
     try
     {
         ItemPublisher(Options(rootItem, source, target, lang, PublishMode.Smart)).Publish();
     }
     catch (Exception ex)
     {
         publishFullLogger.AddError("PublishItemSmart of item failed with exception.", String.Format("PublishItemSmart of item {0} failed. Exception: {1}", rootItem.ID, map.GetExceptionDebugInfo(ex)));
     }
 }
        public static bool AttachImageToItem(BaseDataMap map, object importRow, Item newItem, string newItemField, MediaItem imageItem, ref LevelLogger logger, string height = null, string width = null)
        {
            var attachImageLogger = logger.CreateLevelLogger();
            if (imageItem != null)
            {
                if (string.IsNullOrEmpty(newItemField))
                {
                    {
                        attachImageLogger.AddError(NewItemFieldIsNotDefinedForMediaitem, String.Format("NewItemField is not defined for mediaitem: {0}.",
                                               map.GetImportRowDebugInfo(importRow)));
                        return false;
                    }
                }
                if (!newItem.Editing.IsEditing)
                {
                    newItem.Editing.BeginEdit();
                }
                ImageField imageField = newItem.Fields[newItemField];
                if (imageField.MediaID != imageItem.ID)
                {
                    imageField.Clear();
                    imageField.MediaID = imageItem.ID;
                    if (!String.IsNullOrEmpty(height))
                    {
                        imageField.Height = height;
                    }
                    if (!String.IsNullOrEmpty(width))
                    {
                        imageField.Width = width;
                    }

                    if (!String.IsNullOrEmpty(imageItem.Alt))
                    {
                        imageField.Alt = imageItem.Alt;
                    }
                    else
                    {
                        imageField.Alt = imageItem.DisplayName;
                    }
                    return true;
                }
            }
            return false;
        }
        public void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
        {
            var fillFieldLogger = logger.CreateLevelLogger();

            updatedField = false;
            //ignore import value and store value provided
            Field f = newItem.Fields[NewItemField];
            if (f != null)
            {
                if (f.Value != Value)
                {
                    f.Value = Value;
                    updatedField = true;
                }
            }
            if (IsRequired && f == null)
            {
                fillFieldLogger.AddError(CategoryConstants.RequiredFieldNotFoundOnItem, String.Format("The Item '{0}' of template type: '{1}' didn't contain a field with name '{2}'. This field must be present because the 'Is Required Field' is checked.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField));
            }
        }
 public override void FillField(Providers.BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
 {
     var fillFieldLogger = logger.CreateLevelLogger();
     var xml = string.Empty;
     if (!String.IsNullOrEmpty(importValue))
     {
         const string pattern = @".+\@.+\..+";
         if (Regex.Match(importValue, pattern).Success)
         {
             xml = String.Format(SitecoreEmailLinkXml, importValue);
         }
         else
         {
             updatedField = false;
             fillFieldLogger.AddError(CategoryConstants.EmailWasInWrongFormatOnImportRow, String.Format("The import value '{0}' was not a correct email. The value was not stored on the field. Importrow: {1}. ", importValue, map.GetImportRowDebugInfo(importRow)));
             return;
         }
     }
     base.FillField(map, importRow, ref newItem, xml, out updatedField, ref fillFieldLogger);
 }
 public override string GetFieldValue(object importRow, string fieldName, ref LevelLogger logger)
 {
     var levelLogger = logger.CreateLevelLogger();
     try
     {
         var row = importRow as Dictionary<string, string>;
         if (row != null)
         {
             if (row.ContainsKey(fieldName))
             {
                 return row[fieldName];
             }
             Logger.AddError("Error", string.Format("The fieldName {0} didn't exist in the import row.", fieldName));
         }
     }
     catch (Exception ex)
     {
         levelLogger.AddError("GetFieldValue failed",
             string.Format(
                 "The GetFieldValue method failed with an exception. ImportRow: {0}. FieldName: {1}. Exception: {2}.",
                 GetImportRowDebugInfo(importRow), fieldName, ex));
     }
     return string.Empty;
 }
 /// <summary>
 /// uses the import value to search for a matching item in the SourceList and then stores the GUID
 /// </summary>
 /// <param name="map">provides settings for the import</param>
 /// <param name="importRow"></param>
 /// <param name="newItem">newly created item</param>
 /// <param name="importValue">imported value to match</param>
 public override void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
 {
     var fillFieldLogger = logger.CreateLevelLogger();
     updatedField = false;
     if (IsRequired)
     {
         if (String.IsNullOrEmpty(importValue))
         {
             fillFieldLogger.AddError(CategoryConstants.ImportedValueToFieldWasEmpty, String.Format("The Item '{0}' of template type: '{1}', field '{2}', but the imported value '{3}' was empty. This field must be provided when the field is required. The field was not updated.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
             return;
         }
     }
     if (!ID.IsID(SourceList))
     {
         fillFieldLogger.AddError(CategoryConstants.SourceListNotAnValidSitecoreId, String.Format(
                 "The 'Source List' provided was not an valid Sitecore ID. SourceList: {0}. The Fill Field method was aborted and the fieldvalue was not updated.", SourceList));
         return;
     }
     //get parent item of list to search
     Item i = newItem.Database.GetItem(SourceList);
     if (i != null)
     {
         if (!String.IsNullOrEmpty(importValue))
         {
             Field f = newItem.Fields[NewItemField];
             if (f != null)
             {
                 var guidValue = String.Empty;
                 if (!String.IsNullOrEmpty(MultiListDelimiter))
                 {
                     var keys = importValue.Split(new[] {MultiListDelimiter}, StringSplitOptions.RemoveEmptyEntries);
                     foreach (var keyValue in keys)
                     {
                         var trimmedKeyValue = keyValue.Trim();
                         string errorMessage = String.Empty;
                         var id = GetLookupId(map, importRow, ref newItem, trimmedKeyValue, i, ref fillFieldLogger);
                         if (!String.IsNullOrEmpty(errorMessage))
                         {
                             fillFieldLogger.AddError(CategoryConstants.ErrorToLocateTheLookupIdInMultiList, String.Format("An error occured in trying to locate the Lookup id in a MultiList attempt. The MultiListDelimiter: {0}. The importValue was '{1}'. Item: {2}. The errormessage was: {3}.",
                             MultiListDelimiter, importValue, map.GetItemDebugInfo(newItem), errorMessage));
                             return;
                         }
                         guidValue += id + "|";
                     }
                     if (guidValue.EndsWith("|"))
                     {
                         guidValue = guidValue.Substring(0, guidValue.Length - 1);
                     }
                 }
                 else
                 {
                     string errorMessage = String.Empty;
                     guidValue = GetLookupId(map, importRow, ref newItem, importValue, i, ref fillFieldLogger);
                     if (!String.IsNullOrEmpty(errorMessage))
                     {
                         fillFieldLogger.AddError(CategoryConstants.ErrorToLocateTheLookupId, String.Format("An error occured in trying to locate the Lookup id. The importValue was '{0}'. Item: {1}. The errormessage was: {2}.",
                             importValue, map.GetItemDebugInfo(newItem), errorMessage));
                         return;
                     }
                 }
                 if (String.IsNullOrEmpty(guidValue))
                 {
                     if (!DoNotRequireValueMatch)
                     {
                         fillFieldLogger.AddError(CategoryConstants.ImportedValueDidntResultInAIdToStore, String.Format(
                             "The Item '{0}' of template type: '{1}' has a field '{2}', but the imported value '{3}' didn't result in a ID to store.",
                             map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
                         return;
                     }
                 }
                 if (f.Value != guidValue)
                 {
                     f.Value = guidValue;
                     updatedField = true;
                 }
             }
             if (IsRequired && f == null)
             {
                 fillFieldLogger.AddError(CategoryConstants.RequiredFieldNotFoundOnItem, String.Format(
                         "The Item '{0}' of template type: '{1}' didn't contain a field with name '{2}'. This field must be present because the 'Is Required Field' is checked.",
                         map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField));
                 return;
             }
         }
         else
         {
             if (IsRequired)
             {
                 fillFieldLogger.AddError(CategoryConstants.TheGuidDidntResultInAHitForLookup, String.Format("The Item '{0}' of template type: '{1}' had a Guid field '{2}' where the imported value '{3}' didn't result any hit. Because the 'Is Required Field' is checked there must be found a value i Sitecore. The field was not updated.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
                 return;
             }
             if (newItem[NewItemField] != importValue)
             {
                 newItem[NewItemField] = importValue;
                 updatedField = true;
             }
         }
     }
     if (IsRequired && i == null)
     {
         fillFieldLogger.AddError(CategoryConstants.TheGuidFieldHadASourcelistThatWasNull, String.Format("The Item '{0}' of template type: '{1}' had a Guid field '{2}' for which SourceList was null. This SourceList must be present because the 'Is Required Field' is checked.", map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField));
         return;
     }
 }
 /// <summary>
 /// gets a field value from an item
 /// </summary>
 /// <param name="importRow"></param>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 public override string GetFieldValue(object importRow, string fieldName, ref LevelLogger logger)
 {
     var getFieldValueLogger = logger.CreateLevelLogger();
     var importRowItem = importRow as Item;
     if (importRowItem != null)
     {
         if (!String.IsNullOrEmpty(fieldName))
         {
             switch (fieldName.ToLower())
             {
                 case ("@key"):
                     return importRowItem.Key;
                 case ("@name"):
                     return importRowItem.Name;
                 case ("@displayname"):
                     return importRowItem.DisplayName;
                 case ("@id"):
                     return importRowItem.ID.ToShortID().ToString();
                 case ("@parentid"):
                     return importRowItem.Parent != null
                                ? importRowItem.ParentID.ToShortID().ToString()
                                : string.Empty;
             }
             var field = importRowItem.Fields[fieldName];
             if (field != null)
             {
                 return importRowItem[fieldName];
             }
             getFieldValueLogger.AddError("The 'fieldName' didn't result in any field on the item", String.Format("The GetFieldValue method failed because the the 'fieldName' didn't result in any field on the item. ImportRow: {0}.", GetImportRowDebugInfo(importRow)));
         }
         else
         {
             getFieldValueLogger.AddError(CategoryConstants.TheFieldnameArgumentWasNullOrEmpty, String.Format("The GetFieldValue method failed because the the 'fieldName' was null or empty. ImportRow: {0}.", GetImportRowDebugInfo(importRow)));
         }
     }
     else
     {
         getFieldValueLogger.AddError(CategoryConstants.TheImportRowWasNull, String.Format(
                            "The GetFieldValue method failed because the Import Row was null. FieldName: {0}.",
                            fieldName));
     }
     return String.Empty;
 }
        public override void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
        {
            var fillFieldLogger = logger.CreateLevelLogger();
            try
            {
                updatedField = false;

                if (ID.IsNullOrEmpty(MediaItemId))
                {
                    fillFieldLogger.AddError(CategoryConstants.TheImageMediaLibraryPathIsNotSet, String.Format("The image media library path is not set. ImportRow: {0}.", map.GetImportRowDebugInfo(importRow)));
                    return;
                }
                var getImageAlTextLogger = fillFieldLogger.CreateLevelLogger("GetImageAltText");
                var imageAltText = GetImageAltText(map, importRow, ref newItem, importValue, ref fillFieldLogger);
                if (getImageAlTextLogger.HasErrors())
                {
                    getImageAlTextLogger.AddError(CategoryConstants.GetimagealttextMethodFailed, String.Format("The method GetImageAltText failed. ImportRow: {0}.", map.GetImportRowDebugInfo(importRow)));
                    return;
                }
                var getOriginalFileNameLogger = fillFieldLogger.CreateLevelLogger("GetOriginalFileNameWithExtension");
                var originalFileNameWithExtension = GetOriginalFileNameWithExtension(map, importRow, ref newItem, importValue, ref getOriginalFileNameLogger);
                if (getOriginalFileNameLogger.HasErrors())
                {
                    getOriginalFileNameLogger.AddError(CategoryConstants.GetoriginalfilenamewithextensionFailed, String.Format("The method GetOriginalFileNameWithExtension failed. ImportRow: {0}.", map.GetImportRowDebugInfo(importRow)));
                    return;
                }
                var getFileNameLogger = fillFieldLogger.CreateLevelLogger("GetFileName");
                var fileName = GetFileName(map, importRow, ref newItem, importValue, ref getFileNameLogger);
                if (getFileNameLogger.HasErrors())
                {
                    getFileNameLogger.AddError(CategoryConstants.GetfilenameFailed, String.Format("The method GetFileName failed. ImportRow: {0}.", map.GetImportRowDebugInfo(importRow)));
                    return;
                }
                fileName = StringUtility.GetNewItemName(fileName, map.ItemNameMaxLength);

                if (!IsRequired && String.IsNullOrEmpty(importValue))
                {
                    return;
                }
                var imageType = "";
                var getImageAsMemoryStreamLogger = fillFieldLogger.CreateLevelLogger("GetImageAsMemoryStream");
                var memoryStream = GetImageAsMemoryStream(map, importRow, ref newItem, importValue, ref getImageAsMemoryStreamLogger, out imageType);
                if (getImageAsMemoryStreamLogger.HasErrors())
                {
                    getImageAsMemoryStreamLogger.AddError(CategoryConstants.GetImageAsMemoryStreamFailed, String.Format("The method GetImageAsMemoryStream failed. ImportRow: {0}.", map.GetImportRowDebugInfo(importRow)));
                    return;
                }
                if (memoryStream == null && !IsRequired)
                {
                    return;
                }
                if (String.IsNullOrEmpty(originalFileNameWithExtension))
                {
                    if (!String.IsNullOrEmpty(imageType))
                    {
                        originalFileNameWithExtension = imageType;
                    }
                    else
                    {
                        originalFileNameWithExtension = ".jpeg";
                    }
                }

                var getMediaFolderLogger = fillFieldLogger.CreateLevelLogger("GetMediaFolderItem");
                var mediaItemId = GetMediaFolderItem(map, importRow, ref newItem, ref getMediaFolderLogger);
                if (mediaItemId == (ID)null)
                {
                    getMediaFolderLogger.AddError(CategoryConstants.GetMediaFolderItemReturnedANullItemForTheMediaFolderitem, String.Format("The method GetMediaFolderItem returned a null item for the media folderItem. ImportRow: {0}.", map.GetImportRowDebugInfo(importRow)));
                    return;
                }
                if (getMediaFolderLogger.HasErrors())
                {
                    getMediaFolderLogger.AddError(CategoryConstants.GetMediaFolderItemFailed, String.Format("The method GetMediaFolderItem failed with an error. ImportRow: {0}.", map.GetImportRowDebugInfo(importRow)));
                    return;
                }
                var imageItem = ImageHandler.ImageHelper(fileName, originalFileNameWithExtension, imageAltText, mediaItemId, IsReplaceIfExist, memoryStream, ref fillFieldLogger);
                if (imageItem != null)
                {
                    var height = GetImageHeight(map, importRow, ref newItem, importValue, ref fillFieldLogger);
                    var width = GetImageWidth(map, importRow, ref newItem, importValue, ref fillFieldLogger);
                    ImageHandler.AttachImageToItem(map, importRow, newItem, NewItemField, imageItem, ref fillFieldLogger, height, width);
                }
            }
            catch (Exception ex)
            {
                updatedField = false;
                fillFieldLogger.AddError(CategoryConstants.ExceptionOccuredWhileProcessingImageImages, String.Format(
                        "An exception occured in FillField in processing of the image/images. Exception: {0}. ImportRow: {1}.",
                        map.GetExceptionDebugInfo(ex), map.GetImportRowDebugInfo(importRow)));
            }
        }
 public virtual string GetOriginalFileNameWithExtension(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
 {
     var getOriginalLogger = logger.CreateLevelLogger();
     var getOriginalFileNameWithExtensionFromWhatField = GetOriginalFileNameWithExtensionFromWhatField;
     if (!String.IsNullOrEmpty(getOriginalFileNameWithExtensionFromWhatField))
     {
         var fileName = map.GetFieldValue(importRow, getOriginalFileNameWithExtensionFromWhatField, ref getOriginalLogger);
         if (!String.IsNullOrEmpty(fileName))
         {
             return fileName;
         }
     }
     return String.Empty;
 }
        public virtual MemoryStream GetImageAsMemoryStream(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger, out string imageType)
        {
            imageType = String.Empty;
            var getImageAsMemoryStreamLogger = logger.CreateLevelLogger();
            try
            {
                var image = ImageHandler.GetImageFromUrl(importValue);
                if (image == null)
                {
                    getImageAsMemoryStreamLogger.AddError(CategoryConstants.TheImageRetrievedFromUrlWasNull, String.Format("The image retrieved from the url was null. Src: '{0}'", importValue));
                    return null;
                }
                imageType = ImageHandler.GetImageType(image);

                var memoryStream = ImageHandler.ImageToMemoryStream(image);
                if (memoryStream == null)
                {
                    getImageAsMemoryStreamLogger.AddError(CategoryConstants.TheMemoryStreamRetrievedWasNull, String.Format("The 'memoryStream' retrieved was null. Src: '{0}'", importValue));
                    return null;
                }
                return memoryStream;
            }
            catch (Exception ex)
            {
                getImageAsMemoryStreamLogger.AddError(CategoryConstants.GetImageAsMemoryStreamFailed, String.Format("The GetImageAsMemoryStream failed with an exception. Src: '{0}'. Exception: {1}.", importValue, map.GetExceptionDebugInfo(ex)));
                return null;
            }
        }
 public virtual string GetTimeStampIdentifier(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
 {
     var getTimeStampLogger = logger.CreateLevelLogger();
     if (String.IsNullOrEmpty(GetTimeStampIdentifierFromWhatField))
     {
         getTimeStampLogger.AddError("No value in 'GetTimeStampIdentifierFromWhatField'", String.Format(
                 "The method GetTimeStampIdentifier failed because there wasn't any value in the field 'GetTimeStampIdentifierFromWhatField'. This field is used to retrieve the timestamp of last updated value on importRow. ImportRow: {0}.",
                 map.GetImportRowDebugInfo(importRow)));
         return null;
     }
     var getFieldValueLogger = getTimeStampLogger.CreateLevelLogger();
     var timeStamp = map.GetFieldValue(importRow, GetTimeStampIdentifierFromWhatField, ref getFieldValueLogger);
     if (String.IsNullOrEmpty(timeStamp))
     {
         getFieldValueLogger.AddError("GetTimeStampIdentifier failed", String.Format("The method GetTimeStampIdentifier failed because the 'timestamp' from the importRow was null or empty. Please make sure each importRow has a timestamp. ImportRow: {0}.",
                 map.GetImportRowDebugInfo(importRow)));
         return null;
     }
     return timeStamp;
 }
 protected IEnumerable ExecuteXPathQueryOnXElement(XElement xElement, string query, ref LevelLogger logger)
 {
     var executeXPathQueryLogger = logger.CreateLevelLogger();
     if (xElement != null)
     {
         try
         {
             if (query == Dot)
             {
                 return GetInnerXml(xElement);
             }
             return xElement.XPathEvaluate(query) as IEnumerable;
         }
         catch (Exception ex)
         {
             executeXPathQueryLogger.AddError("Exception occured ExecuteXPathQueryOnXElement executing the XPath", String.Format("An exception occured in the ExecuteXPathQueryOnXElement method executing the XPath query. Query: {0}. Exception: {1}.", query, GetExceptionDebugInfo(ex)));
         }
     }
     executeXPathQueryLogger.AddError("XDocument was null in ExecuteXPathQueryOnXElement", "In ExecuteXPathQueryOnXElement method the XDocument was null.");
     return null;
 }
 public virtual string GetFileName(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
 {
     var getFileNameLogger = logger.CreateLevelLogger();
     var fileNameFieldName = GetFileNameFromWhatField;
     if (String.IsNullOrEmpty(fileNameFieldName))
     {
         getFileNameLogger.AddError(CategoryConstants.GetFilenameFromwWhatFieldWasNullOrEmpty, String.Format("The 'GetFileNameFromWhatField' was null or empty. Please indicate which field the filename should be retrieved from. ImportRow: {0}.",
                 map.GetImportRowDebugInfo(importRow)));
         return null;
     }
     var fileName = map.GetFieldValue(importRow, fileNameFieldName, ref getFileNameLogger);
     if (String.IsNullOrEmpty(fileName))
     {
         getFileNameLogger.AddError(CategoryConstants.TheFilenameFromFieldWasNullOrEmpty, String.Format("The filename was attempted retrieved from the field '{0}', but it was null or empty. The image field name must be provided. ImportRow: {1}.",
                 fileNameFieldName, map.GetImportRowDebugInfo(importRow)));
         return null;
     }
     return fileName;
 }
 public override void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
 {
     var fillFieldLogger = logger.CreateLevelLogger();
     updatedField = false;
     if (IsRequired && string.IsNullOrEmpty(importValue))
     {
         fillFieldLogger.AddError(CategoryConstants.ImportedValueToFieldWasEmpty, String.Format(
                 "The Item '{0}' of template type: '{1}', field '{2}', but the imported value '{3}' was empty. This field must be provided when the field is required. The field was not updated.",
                 (object) map.GetItemDebugInfo(newItem), (object) newItem.TemplateName,
                 (object) NewItemField, (object) importValue));
         return;
     }
     if (!ID.IsID(SourceList))
     {
         fillFieldLogger.AddError(CategoryConstants.SourceListNotAnValidSitecoreId, String.Format(
                 "The 'Source List' provided was not an valid Sitecore ID. SourceList: {0}. The Fill Field method was aborted and the fieldvalue was not updated.",
                 SourceList));
         return;
     }
     var listParent = newItem.Database.GetItem(SourceList);
     if (listParent != null)
     {
         if (!string.IsNullOrEmpty(importValue))
         {
             var matchingChildItem = GetMatchingChildItem(map, listParent, importValue);
             var childItems = matchingChildItem as Item[] ?? matchingChildItem.ToArray();
             if (childItems.Any())
             {
                 var str = string.Empty;
                 foreach (var childItem in childItems)
                 {
                     if (childItem != null)
                     {
                         str += (str.Length > 0)
                                    ? "|" + childItem.ID
                                    : childItem.ID.ToString();
                     }
                 }
                 var field = newItem.Fields[NewItemField];
                 if (field != null)
                 {
                     if (string.IsNullOrEmpty(str))
                     {
                         fillFieldLogger.AddError(CategoryConstants.ImportedValueDidntResultInAIdToStore, String.Format(
                                 "The Item '{0}' of template type: '{1}' has a field '{2}', but the imported value '{3}' didn't result in a ID to store.",
                                 (object) map.GetItemDebugInfo(newItem), (object) newItem.TemplateName,
                                 (object) NewItemField, (object) importValue));
                         return;
                     }
                     if (field.Value != str)
                     {
                         field.Value = str;
                         updatedField = true;
                     }
                 }
                 if (IsRequired && field == null)
                 {
                     fillFieldLogger.AddError(CategoryConstants.RequiredFieldNotFoundOnItem, String.Format(
                             "The Item '{0}' of template type: '{1}' didn't contain a field with name '{2}'. This field must be present because the 'Is Required Field' is checked.",
                             map.GetItemDebugInfo(newItem), newItem.TemplateName,
                             NewItemField));
                     return;
                 }
             }
             else if (!this.DoNotRequireValueMatch)
             {
                 fillFieldLogger.AddError(CategoryConstants.DidntLocateALookupItemWithTheValue, String.Format(
                         "The Item '{0}' of template type: '{1}' didn't locate a lookup Item with the value '{2}'.",
                         newItem.ID.ToString(), newItem.TemplateName, importValue));
                 return;
             }
         }
         else if (this.IsRequired)
         {
             fillFieldLogger.AddError(CategoryConstants.TheGuidDidntResultInAHitForLookup, String.Format(
                 "The Item '{0}' of template type: '{1}' had a Guid field '{2}' where the imported value '{3}' didn't result any hit. Because the 'Is Required Field' is checked there must be found a value i Sitecore. The field was not updated.",
                 (object) map.GetItemDebugInfo(newItem), (object) newItem.TemplateName,
                 (object) NewItemField, (object) importValue));
             return;
         }
         else if (newItem[NewItemField] != importValue)
         {
             newItem[NewItemField] = importValue;
             updatedField = true;
         }
     }
     if (IsRequired && listParent == null)
     {
         fillFieldLogger.AddError(CategoryConstants.TheGuidFieldHadASourcelistThatWasNull, String.Format(
             "The Item '{0}' of template type: '{1}' had a Guid field '{2}' for which SourceList was null. This SourceList must be present because the 'Is Required Field' is checked.",
             (object) map.GetItemDebugInfo(newItem), (object) newItem.TemplateName,
             (object) this.NewItemField));
     }
 }
 public virtual void InitializeItemsCache(Item parent, string fieldNameForKeys, ref LevelLogger logger)
 {
     if (parent == null)
     {
         logger.AddError("Parent was null in InitializeItemsCache", "The parent was null.");
         return;
     }
     if (String.IsNullOrEmpty(fieldNameForKeys))
     {
         logger.AddError("The fieldNameForKeys was null or empty.", String.Format("The fieldNameForKeys was null or empty. fieldNameForKeys: {0}", fieldNameForKeys));
         return;
     }
     var startKey = GetBaseCacheKey(parent, ref logger);
     var fieldNameKeys = fieldNameForKeys.Split('|');
     using (new LanguageSwitcher(BaseDataMap.ImportToLanguageVersion))
     {
         var getItemsByKeyLogger = logger.CreateLevelLogger();
         string pattern = "{0}//*";
         var query = String.Format(pattern, parent.Paths.FullPath);
         try
         {
             var items = BaseDataMap.SitecoreDB.SelectItems(query);
             if (items != null)
             {
                 if (items.Any())
                 {
                     foreach (var item in items)
                     {
                         if (item != null)
                         {
                             foreach (var fieldNameKey in fieldNameKeys)
                             {
                                 if (!String.IsNullOrEmpty(fieldNameKey))
                                 {
                                     var keyValue = item[fieldNameKey];
                                     if (!String.IsNullOrEmpty(keyValue))
                                     {
                                         AddToCache(startKey, item, fieldNameKey, keyValue, ref getItemsByKeyLogger);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             getItemsByKeyLogger.AddError("Exception in InitializeItemsCache", ex.Message);
         }
     }
 }
 public virtual List<Item> GetExistingItemsToSyncByKey(Item rootItem, Item currentParent, string toWhatField, string keyValue, ref LevelLogger logger)
 {
     var getItemsbyKeyLogger = logger.CreateLevelLogger();
     var items = GetItemsByKey(rootItem, toWhatField, keyValue, ref getItemsbyKeyLogger, true);
     return items;
 }
        public override void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
        {
            var fillFieldLogger = logger.CreateLevelLogger();
            try
            {
                updatedField = false;
                string errorMessage = String.Empty;
                string newTimeStamp;
                var isUpdateMediaItemLogger = fillFieldLogger.CreateLevelLogger();
                var isUpdateMediaItem = IsUpdateMediaItem(map, importRow, ref newItem, importValue, ref isUpdateMediaItemLogger, out newTimeStamp);
                if (isUpdateMediaItemLogger.HasErrors())
                {
                    fillFieldLogger.AddError("IsUpdateMediaItem failed with error", String.Format("The method IsUpdateMediaItem failed with the following error: {0}. ImportRow: {1}.",
                            errorMessage, map.GetImportRowDebugInfo(importRow)));
                    DeleteMediaItemIfEmpty(map, ref newItem, ref fillFieldLogger);
                    return;
                }
                if (isUpdateMediaItem)
                {
                    var getImageAltLogger = fillFieldLogger.CreateLevelLogger();
                    var imageAltText = GetImageAltText(map, importRow, ref newItem, importValue, ref getImageAltLogger);
                    if (getImageAltLogger.HasErrors())
                    {
                        getImageAltLogger.AddError("GetImageAltText failed with error", String.Format(
                                "The method GetImageAltText failed with the following error: {0}. ImportRow: {1}.",
                                errorMessage, map.GetImportRowDebugInfo(importRow)));
                        DeleteMediaItemIfEmpty(map, ref newItem, ref getImageAltLogger);
                        return;
                    }
                    var getOriginalLogger = fillFieldLogger.CreateLevelLogger();
                    var originalFileNameWithExtension = GetOriginalFileNameWithExtension(map, importRow, ref newItem,
                                                                                         importValue, ref getOriginalLogger);
                    if (getOriginalLogger.HasErrors())
                    {
                        getOriginalLogger.AddError("GetOriginalFileNameWithExtensio failed", String.Format("The method GetOriginalFileNameWithExtension failed with the following error: {0}. ImportRow: {1}.",
                                errorMessage, map.GetImportRowDebugInfo(importRow)));
                        DeleteMediaItemIfEmpty(map, ref newItem, ref getOriginalLogger);
                        return;
                    }
                    if (!IsRequired && String.IsNullOrEmpty(importValue))
                    {
                        return;
                    }
                    var imageType = "";
                    var getImageAsMemoryLogger = fillFieldLogger.CreateLevelLogger();
                    var memoryStream = GetImageAsMemoryStream(map, importRow, ref newItem, importValue, ref getImageAsMemoryLogger, out imageType);
                    if (getImageAsMemoryLogger.HasErrors())
                    {
                        getImageAsMemoryLogger.AddError("GetImageAsStream failed", String.Format("The method GetImageAsStream failed with the following error: {0}. ImportRow: {1}.",
                                errorMessage, map.GetImportRowDebugInfo(importRow)));
                        DeleteMediaItemIfEmpty(map, ref newItem, ref getImageAsMemoryLogger);
                        return;
                    }
                    if (memoryStream == null && !IsRequired)
                    {
                        return;
                    }
                    if (String.IsNullOrEmpty(originalFileNameWithExtension))
                    {
                        if (!String.IsNullOrEmpty(imageType))
                        {
                            originalFileNameWithExtension = imageType;
                        }
                        else
                        {
                            originalFileNameWithExtension = DefaultMediaType;
                        }
                    }

                    var imageHelperLogger = fillFieldLogger.CreateLevelLogger();
                    var imageItem = ImageHandler.ImageHelper(newItem.Name, originalFileNameWithExtension, imageAltText,
                                                             newItem.Parent.ID, true, memoryStream, ref imageHelperLogger);
                    if (imageItem != null)
                    {
                        newItem = imageItem;
                        newItem.Editing.BeginEdit();
                        newItem[Utility.Constants.FieldNameDataSyncTimeStamp] = newTimeStamp;
                        updatedField = true;
                    }
                }
            }
            catch (Exception ex)
            {
                updatedField = false;
                fillFieldLogger.AddError("Exception occured in FillField processing image/images", String.Format(
                        "An exception occured in FillField in processing of the image/images. Exception: {0}. ImportRow: {1}.",
                        map.GetExceptionDebugInfo(ex), map.GetImportRowDebugInfo(importRow)));
            }
        }
 public virtual bool IsUpdateMediaItem(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger, out string newTimeStamp)
 {
     var isUpdateMediaItemLogger = logger.CreateLevelLogger();
     newTimeStamp = null;
     if (UpdateMediaItemStrategy == UpdateStrategy.AlwaysUpdate)
     {
         return true;
     }
     if (UpdateMediaItemStrategy == UpdateStrategy.OnlyWhenUpdatedTimestamp)
     {
         var getTimeLogger = isUpdateMediaItemLogger.CreateLevelLogger();
         var importRowTimeStamp = GetTimeStampIdentifier(map, importRow, ref newItem, importValue, ref getTimeLogger);
         if (getTimeLogger.HasErrors())
         {
             return false;
         }
         if (importRowTimeStamp == null)
         {
             isUpdateMediaItemLogger.AddError("IsUpdateMediaItem failed when 'importRowTimeStamp' was null", String.Format(
                     "The method IsUpdateMediaItem failed because the 'importRowTimeStamp' was null. This field is used to retrieve the timestamp of last updated value on importRow. ImportRow: {0}.",
                     map.GetImportRowDebugInfo(importRow)));
             return false;
         }
         newTimeStamp = importRowTimeStamp;
         var lastUpdatedTimeStamp = newItem[Sitecore.SharedSource.DataSync.Utility.Constants.FieldNameDataSyncTimeStamp];
         if (!String.IsNullOrEmpty(lastUpdatedTimeStamp))
         {
             return !lastUpdatedTimeStamp.Trim().ToLower().Equals(importRowTimeStamp.Trim().ToLower());
         }
         // If the timestamp field is empty, then we must update
         return true;
     }
     var mediaItem = (MediaItem)newItem;
     if (mediaItem != null)
     {
         return !mediaItem.HasMediaStream(FieldNameBlog);
     }
     isUpdateMediaItemLogger.AddError("Item could not be case to mediaItem in IsUpdateMediaItem", String.Format("The method IsUpdateMediaItem failed because the item could not be casted to a mediaItem and therefor we couldn't be determined if the item had a MediaStream. ImportRow: {0}.",
             map.GetImportRowDebugInfo(importRow)));
     return false;
 }
 private string GetLookupId(BaseDataMap map, object importRow, ref Item newItem, string importValue, Item sourceListRootItem, ref LevelLogger logger)
 {
     var getLookupIdLogger = logger.CreateLevelLogger();
     IEnumerable<Item> t = GetMatchingChildItem(map, sourceListRootItem, importValue);
     if (t.Count() > 1)
     {
         getLookupIdLogger.AddError(CategoryConstants.ImportedValueResultInMoreThanOneLookupItem, String.Format(
                 "The Item '{0}' of template type: '{1}' has a field '{2}', but the imported value '{3}' did result in more that one lookup item. The field was not updated.",
                 map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
         return String.Empty;
     }
     if (t.Count() == 1)
     {
         var guid = t.First().ID.ToString();
         if (String.IsNullOrEmpty(guid))
         {
             getLookupIdLogger.AddError(CategoryConstants.ImportedValueDidntResultInAIdToStore, String.Format(
                         "The Item '{0}' of template type: '{1}' has a field '{2}', but the imported value '{3}' didn't result in a ID to store.",
                         map.GetItemDebugInfo(newItem), newItem.TemplateName, NewItemField, importValue));
             return String.Empty;
         }
         return guid;
     }
     else
     {
         if (!DoNotRequireValueMatch)
         {
             getLookupIdLogger.AddError(CategoryConstants.DidntLocateALookupItemWithTheValue, String.Format("The Item '{0}' of template type: '{1}' didn't locate a lookup Item with the value '{2}'.",
                 newItem.ID.ToString(), newItem.TemplateName, importValue));
             return String.Empty;
         }
     }
     return String.Empty;
 }
 public virtual string GetImageAltText(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
 {
     var getImageAltText = logger.CreateLevelLogger();
     var getImageAltTextIfNotProvidedFromWhatField = GetImageAltTextIfNotProvidedFromWhatField;
     if (!String.IsNullOrEmpty(getImageAltTextIfNotProvidedFromWhatField))
     {
         var altText = map.GetFieldValue(importRow, getImageAltTextIfNotProvidedFromWhatField, ref getImageAltText);
         if (!String.IsNullOrEmpty(altText))
         {
             return Helper.TitleCaseString(altText);
         }
     }
     return String.Empty;
 }
        /// <summary>
        /// gets custom data from a DataRow
        /// </summary>
        /// <param name="importRow"></param>
        /// <param name="fieldName"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public override string GetFieldValue(object importRow, string fieldName, ref LevelLogger logger)
        {
            var getFieldValueLogger = logger.CreateLevelLogger();
            try
            {
                var xElement = importRow as XElement;
                if (xElement != null)
                {
                    if (!String.IsNullOrEmpty(fieldName))
                    {
                        try
                        {
                            // First retrieve the fieldName as an attribute
                            var attribute = xElement.Attribute(fieldName);
                            if (attribute != null)
                            {
                                string value = attribute.Value;
                                if (!String.IsNullOrEmpty(value))
                                {
                                    return value;
                                }
                            }
                            else
                            {
                                // Then retrieve the fieldname as an subelement
                                var subElements = xElement.Elements(fieldName);
                                var elementsList = subElements.ToList();
                                if (elementsList.Count() > 1)
                                {
                                    // Log eror since document format is wrong. Has two or more elements with same name.
                                    getFieldValueLogger.AddError("Found more than one subelement with FieldName", String.Format(
                                            "The GetFieldValue method failed because the fieldName '{0}' resulted in more than one subelement in the Import Row. FieldName: {0}. ImportRow: {1}.",
                                            fieldName, GetImportRowDebugInfo(importRow)));
                                }
                                else if (elementsList.Count() == 1)
                                {
                                    var subElement = elementsList.First();
                                    if (subElement != null)
                                    {
                                        var value = subElement.Value;
                                        if (!String.IsNullOrEmpty(value))
                                        {
                                            return value;
                                        }
                                    }
                                }
                            }
                        }
                        catch (XmlException)
                        {
                            // We do nothing since this is most likely because we have a xpath query as the fieldname.
                        }

                        // Now finally try to retrieve through a xPath query
                        var executeXPathLogger = getFieldValueLogger.CreateLevelLogger();
                        var result = ExecuteXPathQueryOnXElement(xElement, fieldName, ref executeXPathLogger);
                        if (executeXPathLogger.HasErrors())
                        {
                            executeXPathLogger.AddError("Failure in ExecuteXPathQueryOnXElement", String.Format("The GetFieldValue method failed in executing the ExecuteXPathQueryOnXElement method."));
                        }
                        string fieldValue;
                        if (result is string)
                        {
                            return result as string;
                        }
                        var enumerable = result as IList<object> ?? result.Cast<object>().ToList();
                        if (TryParseAttribute(enumerable, out fieldValue, ref getFieldValueLogger))
                        {
                            return fieldValue;
                        }
                        if (TryParseElement(enumerable, out fieldValue, ref getFieldValueLogger))
                        {
                            return fieldValue;
                        }
                    }
                    else
                    {
                        getFieldValueLogger.AddError(CategoryConstants.TheFieldnameArgumentWasNullOrEmpty, String.Format("The GetFieldValue method failed because the 'fieldName' was null or empty. FieldName: {0}. ImportRow: {1}.", fieldName, GetImportRowDebugInfo(importRow)));
                    }
                }
                else
                {
                    getFieldValueLogger.AddError(CategoryConstants.TheImportRowWasNull, String.Format("The GetFieldValue method failed because the Import Row was null. FieldName: {0}.", fieldName));
                }
            }
            catch (Exception ex)
            {
                getFieldValueLogger.AddError(CategoryConstants.GetFieldValueFailed, String.Format("The GetFieldValue method failed with an exception. ImportRow: {0}. FieldName: {1}. Exception: {2}.", GetImportRowDebugInfo(importRow), fieldName, ex));
            }
            return String.Empty;
        }
        public virtual byte[] GetImageAsBytes(BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
        {
            var getImageAsBytesLogger = logger.CreateLevelLogger();
            try
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                var image = ImageHandler.GetImageFromUrl(importValue);
                if (image == null)
                {
                    getImageAsBytesLogger.AddError(CategoryConstants.TheImageRetrievedFromUrlWasNull, String.Format("The image retrieved from the url was null. Src: '{0}'", importValue));
                    return null;
                }

                var imageBytes = ImageHandler.ImageToByteArray(image);
                if (imageBytes == null)
                {
                    getImageAsBytesLogger.AddError(CategoryConstants.TheImageBytesRetrievedWasNull, String.Format("The 'imageBytes' retrieved was null. Src: '{0}'", importValue));
                    return null;
                }
                return imageBytes;
            }
            catch (Exception ex)
            {
                getImageAsBytesLogger.AddError(CategoryConstants.GetImageAsBytesFailedWithException, String.Format("The GetImageAsBytes failed with an exception. Src: '{0}'. Exception: {1}.", importValue, map.GetExceptionDebugInfo(ex)));
                return null;
            }
        }
        public override byte[] GetImageAsBytes(Providers.BaseDataMap map, object importRow, ref Item newItem, string importValue, ref LevelLogger logger)
        {
            var getImageAsBytesLogger = logger.CreateLevelLogger();
            try
            {
                if (IsRequired && String.IsNullOrEmpty(importValue))
                {
                    getImageAsBytesLogger.AddError("Required field was null or empty in GetImageAsBytes", String.Format(
                            "The 'GetImageAsBytes' could not retrieve an image since the importValue was null or empty. The field was marked as required. " +
                            "ImportRow: {0}.",
                            map.GetImportRowDebugInfo(importRow)));
                    return null;
                }
                if (!IsRequired && String.IsNullOrEmpty(importValue))
                {
                    return null;
                }
                if (String.IsNullOrEmpty(ImageFilesToImportAbsolutePath))
                {
                    getImageAsBytesLogger.AddError("The setting 'ImageFilesToImportAbsolutePath' was null or empty", String.Format(
                            "The setting 'ImageFilesToImportAbsolutePath' was null or empty. Therefor the image could not be found, since there is no place to search for it. Plase provide a value." +
                            "ImportValue: {0}. ImportRow: {1}.", importValue, map.GetImportRowDebugInfo(importRow)));
                    return null;
                }
                var searchPattern = importValue + "*.*";
                var directoryInfo = new DirectoryInfo(ImageFilesToImportAbsolutePath);
                var files = directoryInfo.GetFiles(searchPattern, SearchTopDirectoryOnly);

                if (files.Length == 0)
                {
                    getImageAsBytesLogger.AddError("Attempt to find a file failed in GetImageAsBytes", String.Format(
                            "In the GetImageAsBytes method the attempt to find a file failed. No file was found in the search for file '{0}' in the folder '{1}'." +
                            " ImportValue: {2}. ImportRow: {3}. SearchTopDirectoryOnlye: {4}.", searchPattern,
                            ImageFilesToImportAbsolutePath, importValue, map.GetImportRowDebugInfo(importRow),
                            SearchTopDirectoryOnly));
                    return null;
                }
                if (files.Length > 1)
                {
                    getImageAsBytesLogger.AddError("More than one file found in GetImageAsBytes", String.Format(
                            "In the GetImageAsBytes method there where found more than one file in the search for file '{0}' in the folder '{1}'." +
                            " ImportValue: {2}. ImportRow: {3}. SearchTopDirectoryOnlye: {4}.", searchPattern,
                            ImageFilesToImportAbsolutePath, importValue, map.GetImportRowDebugInfo(importRow),
                            SearchTopDirectoryOnly));
                    return null;
                }
                var file = files.First();
                if (file != null)
                {
                    try
                    {
                        byte[] bytes = File.ReadAllBytes(file.FullName);
                        return bytes;
                    }
                    catch (Exception ex)
                    {
                        getImageAsBytesLogger.AddError("Exception occured trying to ReadAllBytes from GetImageAsBytes", String.Format(
                                "In the GetImageAsBytes method an exception occured in trying to ReadAllBytes from file '{0}'. SearchPattern: '{1}' in the folder '{2}'." +
                                " ImportValue: {3}. ImportRow: {4}. SearchTopDirectoryOnlye: {5}. Exception: {6}.",
                                file.FullName, searchPattern, ImageFilesToImportAbsolutePath, importValue,
                                map.GetImportRowDebugInfo(importRow), SearchTopDirectoryOnly,
                                map.GetExceptionDebugInfo(ex)));
                        return null;
                    }
                }
                getImageAsBytesLogger.AddError("One file found but it was null in GetImageAsBytes", String.Format(
                        "In the GetImageAsBytes method one file was found, but it was null. SearchPattern: '{0}' in the folder '{1}'." +
                        " ImportValue: {2}. ImportRow: {3}. SearchTopDirectoryOnlye: {4}.",
                        searchPattern, ImageFilesToImportAbsolutePath, importValue, map.GetImportRowDebugInfo(importRow),
                        SearchTopDirectoryOnly));
                return null;
            }
            catch (Exception ex)
            {
                getImageAsBytesLogger.AddError(CategoryConstants.GetImageAsBytesFailedWithException, String.Format("In the GetImageAsBytes method an exception occured. ImageFilesToImportAbsolutePath: '{0}'." +
                                              " ImportValue: {1}. ImportRow: {2}. SearchTopDirectoryOnlye: {3}. Exception: {4}",
                                              ImageFilesToImportAbsolutePath, importValue, map.GetImportRowDebugInfo(importRow), SearchTopDirectoryOnly, map.GetExceptionDebugInfo(ex)));
                return null;
            }
        }
 /// <summary>
 /// retrieves all the import field values specified
 /// </summary>
 public IEnumerable<string> GetFieldValues(IEnumerable<string> fieldNames, object importRow, ref LevelLogger logger)
 {
     var list = new List<string>();
     foreach (string f in fieldNames)
     {
         var getFieldValuesLogger = logger.CreateLevelLogger();
         try
         {
             var value = GetFieldValue(importRow, f, ref getFieldValuesLogger);
             if (value == null)
             {
                 //errorMessage += String.Format("In GetFieldValues method the field value was null. This should not happen. An empty string was added. FieldName: '{0}'", f);
                 getFieldValuesLogger.AddError("Field value was null in GetFieldValues", String.Format("In GetFieldValues method the field value was null. This should not happen. An empty string was added. FieldName: '{0}'", f));
                 list.Add(String.Empty);
             }
             else
             {
                 list.Add(value.Trim());
             }
         }
         catch (ArgumentException ex)
         {
             if (string.IsNullOrEmpty(f))
             {
                 //errorMessage += String.Format("In GetFieldValues method the 'From' field name is empty. Exception: {0}", GetExceptionDebugInfo(ex));
                 getFieldValuesLogger.AddError("The 'From' field name empty in GetFieldValues", String.Format("In GetFieldValues method the 'From' field name is empty. Exception: {0}", GetExceptionDebugInfo(ex)));
             }
             else
             {
                 //errorMessage += String.Format("In GetFieldValues method the field name: '{0}' does not exist in the import row. Exception: {1}", f, GetExceptionDebugInfo(ex));
                 getFieldValuesLogger.AddError("FieldName do not exist on import row in GetFieldValues", String.Format("In GetFieldValues method the field name: '{0}' does not exist in the import row. Exception: {1}", f, GetExceptionDebugInfo(ex)));
             }
         }
     }
     return list;
 }