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;
     }
 }
        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));
            }
        }
 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;
 }
 /// <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;
     }
 }
 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));
     }
 }
 private static void DeleteMediaItemIfEmpty(BaseDataMap map, ref Item newItem, ref LevelLogger logger)
 {
     var mediaItem = (MediaItem)newItem;
     if (mediaItem != null)
     {
         if (!mediaItem.HasMediaStream(FieldNameBlog))
         {
             logger.AddInfo("Deleted Empty MediaItem Without Blob", String.Format("The media doesn't contain any Blob value (no image). To prevent an empty Media Item without a blob to remain in the Media Library, the MediaItem was deleted. Item: {0}", map.GetItemDebugInfo(newItem)));
             newItem.Delete();
             newItem = null;
             logger.IncrementCounter("DeletedEmptyMediaItem");
         }
     }
 }
 public virtual void FillField(BaseDataMap map, object importRow, ref Item newItem, string importValue, out bool updatedField, ref LevelLogger logger)
 {
     var fillFieldLogger = logger.CreateLevelLogger();
     updatedField = false;
     //store the imported value as is
     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 f = newItem.Fields[NewItemField];
     if (f != null)
     {
         if (f.Value != importValue)
         {
             fillFieldLogger.AddInfo(CategoryConstants.UpdatedField, String.Format("Updated value in field from '{0}' to '{1}'", LimitText(f.Value), LimitText(importValue)));
             f.Value = importValue;
             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));
     }
 }