Пример #1
0
        public override ConversionResult Convert(int sourceDataTypeId, int targetDataTypeId, bool updatePropertyTypes, bool publish, bool test = true)
        {
            var result = new ConversionResult(Services, sourceDataTypeId, targetDataTypeId, updatePropertyTypes, publish, test);

            foreach (var ac in result.AffectedContent)
            {
                var oldValue     = ac.Content.GetValue <string>(ac.PropertyType.Alias);
                var newValue     = convert(oldValue);
                var seemedToWork = (!String.IsNullOrWhiteSpace(newValue));

                if (!String.IsNullOrWhiteSpace(oldValue))
                {
                    result.PropertyResults.Add(new PropertyResult()
                    {
                        ContentName   = ac.Content.Name,
                        ContentId     = ac.Content.Id,
                        PropertyAlias = ac.PropertyType.Alias,
                        PropertyValue = oldValue.TruncateAtWord(1000000),
                        NewValue      = newValue,
                        IsCompatible  = seemedToWork
                    });

                    if (!test && seemedToWork)
                    {
                        //save the new properties
                        ac.Content.SetValue(ac.PropertyType.Alias, newValue);
                        Services.ContentService.Save(ac.Content);
                        //publish?
                    }
                }
            }

            result         = result.Summarize();
            result.Message = "Complete.";

            if (result.SuccessfulConversions >= result.FailedConversions)
            {
                result.IsCompatible = true;
                if (!test)
                {
                    result.UpdatePropertyTypes();
                }
            }
            else
            {
                result.IsCompatible = false;
            }

            return(result);
        }