Exemple #1
0
 public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
 {
     try
     {
         if (!pipelineContext.Faulted)
         {
             if (processorContext.TryGetOption(DictionaryKey, out string dictionaryKey))
             {
                 if (processorContext.TryGetOption(DefaultValue, out string defaultValue) && defaultValue != default(string))
                 {
                     pipelineContext.Context = Translate.TextByLanguage(dictionaryKey, Language.Current, defaultValue);
                 }
                 else
                 {
                     pipelineContext.Context = Translate.Text(dictionaryKey);
                 }
             }
             else
             {
                 pipelineContext.Faulted = true;
             }
         }
     }
     catch
     {
         pipelineContext.Faulted = true;
         throw;
     }
     finally
     {
         Next();
     }
 }
Exemple #2
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                switch (pipelineContext.Context)
                {
                case var item when int.TryParse(item.ToString(), out int intValue):
                    pipelineContext.Context = intValue;

                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
 public void Run(ModelContext pipelineContext, ProcessorSchema processorContext)
 {
     try
     {
         if (!pipelineContext.Faulted)
         {
             if (processorContext.TryGetOption(IdKey, out ID id))
             {
                 pipelineContext.Context = Context.Database.GetItem(id);
             }
             else if (processorContext.TryGetOption(IdKey, out string path))
             {
                 pipelineContext.Context = Context.Database.GetItem(path);
             }
             else
             {
                 pipelineContext.Faulted = true;
             }
         }
     }
     catch
     {
         pipelineContext.Faulted = true;
         throw;
     }
     finally
     {
         Next();
     }
 }
Exemple #4
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                switch (pipelineContext.Context)
                {
                case string stringValue when Enum.TryParse(stringValue, true, out T value):
                    pipelineContext.Context = value;

                    break;

                case string stringValue when TryMatchByAttribute(stringValue, out T value):
                    pipelineContext.Context = value;

                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #5
0
 public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
 {
     try
     {
         if (!pipelineContext.Faulted)
         {
             if (processorContext.TryGetOption(ConstantOptionKey, out T constantValue))
             {
                 pipelineContext.Context = constantValue;
             }
             else
             {
                 pipelineContext.Faulted = true;
             }
         }
     }
     catch
     {
         pipelineContext.Faulted = true;
         throw;
     }
     finally
     {
         Next();
     }
 }
 public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
 {
     try
     {
         if (!pipelineContext.Faulted)
         {
             if (pipelineContext.Context is IEnumerable <TSource> sourceEnumerable)
             {
                 pipelineContext.Context = sourceEnumerable
                                           .Select(i => i.As <TTarget>((pipeline, context) => context.Monitor = pipelineContext.Monitor))
                                           .ToList();
             }
             else
             {
                 pipelineContext.Faulted = true;
             }
         }
     }
     catch
     {
         pipelineContext.Faulted = true;
         throw;
     }
     finally
     {
         Next();
     }
 }
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                if (!pipelineContext.Faulted)
                {
                    switch (pipelineContext.Context)
                    {
                    case Item mediaItem when mediaItem.Paths.IsMediaItem:
                        pipelineContext.Context = MediaManager.GetMediaUrl(mediaItem);
                        break;

                    case Item contentItem when contentItem.Paths.IsContentItem:
                        pipelineContext.Context = LinkManager.GetItemUrl(contentItem);
                        break;

                    default:
                        pipelineContext.Faulted = true;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #8
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                switch (pipelineContext.Context)
                {
                case ImageField imageField when imageField.MediaItem != null:
                    pipelineContext.Context = imageField.Height;
                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                if (!pipelineContext.Faulted)
                {
                    switch (pipelineContext.Context)
                    {
                    case CheckboxField checkboxField:
                        pipelineContext.Context = checkboxField.Checked;
                        break;

                    case Field field when string.Equals(field.Type, "Checkbox", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = ((CheckboxField)field).Checked;

                        break;

                    default:
                        pipelineContext.Faulted = true;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #10
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                if (!pipelineContext.Faulted)
                {
                    switch (pipelineContext.Context)
                    {
                    case Item item:
                        pipelineContext.Context = item.Name;
                        break;

                    default:
                        pipelineContext.Faulted = true;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                switch (pipelineContext.Context)
                {
                case ImageField imageField when imageField.MediaItem != null:
                    pipelineContext.Context = imageField.MediaItem.DisplayName ?? imageField.MediaItem.Name;
                    break;

                case MediaItem mediaItem:
                    pipelineContext.Context = mediaItem.DisplayName ?? mediaItem.Name;
                    break;

                case Item item:
                    pipelineContext.Context = item.DisplayName ?? item.Name;
                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #12
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                switch (pipelineContext.Context)
                {
                case IEnumerable <Item> items:
                    pipelineContext.Context = items.Select(x => x.ID).ToList();
                    break;

                case Item item:
                    pipelineContext.Context = item.ID;
                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #13
0
        private bool GetPropertyInfo(PropertyContext context, ProcessorSchema processorContext, out PropertyInfo sourcePropertyInfo)
        {
            if (!processorContext.TryGetOption(SourcePropertyOptionKey, out string sourceProperty))
            {
                sourceProperty = context.PropertyInfo.Name;
            }

            sourcePropertyInfo = context.MappingContext.Input.GetType().GetProperty(sourceProperty);

            return(sourcePropertyInfo != null);
        }
Exemple #14
0
        public void Run(ModelContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                if (!pipelineContext.Faulted)
                {
                    switch (pipelineContext.Context)
                    {
                    case LookupField lookupField:
                        pipelineContext.Context = lookupField.TargetItem;
                        break;

                    case ReferenceField referenceField:
                        pipelineContext.Context = referenceField.TargetItem;
                        break;

                    case LinkField linkField:
                        pipelineContext.Context = linkField.TargetItem;
                        break;

                    case MultilistField treeField:
                        pipelineContext.Context = treeField.GetItems();
                        break;

                    case string stringValue:
                        pipelineContext.Context = Context.Item.Database.GetItem(stringValue);
                        break;

                    case ID idValue:
                        pipelineContext.Context = Context.Item.Database.GetItem(idValue);
                        break;

                    case ImageField imageField:
                        pipelineContext.Context = imageField.MediaItem;
                        break;

                    default:
                        pipelineContext.Faulted = true;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #15
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                if (!pipelineContext.Faulted)
                {
                    var mediaUrlOptions = new MediaUrlOptions();

                    if (processorContext.Options.ContainsKey(Width) &&
                        int.TryParse(processorContext.Options[Width].ToString(), out int width))
                    {
                        mediaUrlOptions.Width = width;
                    }

                    if (processorContext.Options.ContainsKey(Height) &&
                        int.TryParse(processorContext.Options[Height].ToString(), out int height))
                    {
                        mediaUrlOptions.Height = height;
                    }

                    switch (pipelineContext.Context)
                    {
                    case ImageField imageField when imageField.MediaItem != null:
                        pipelineContext.Context = HashingUtils.ProtectAssetUrl(MediaManager.GetMediaUrl(imageField.MediaItem, mediaUrlOptions));
                        break;

                    case MediaItem mediaItem:
                        pipelineContext.Context = HashingUtils.ProtectAssetUrl(MediaManager.GetMediaUrl(mediaItem, mediaUrlOptions));
                        break;

                    case Item item:
                        pipelineContext.Context = HashingUtils.ProtectAssetUrl(MediaManager.GetMediaUrl(item, mediaUrlOptions));
                        break;

                    default:
                        pipelineContext.Faulted = true;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #16
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                // Null or Empty value ensure
                switch (pipelineContext.Context)
                {
                // If the context is null, and we have a valid replacement switch context to the replacement.
                case null when processorContext.TryGetOption(EnsureReplacement, out object replacement):
                    pipelineContext.Context = replacement;

                    break;

                // If the context is an empty or null string, and we have a valid replacement switch context to the replacement.
                case string stringValue when string.IsNullOrEmpty(stringValue) &&
                    processorContext.TryGetOption(EnsureReplacement, out string replacement):
                    pipelineContext.Context = replacement;

                    pipelineContext.Faulted = false;
                    break;
                }

                // Type ensure
                if (processorContext.TryGetOption(EnsureType, out Type typeToEnsure))
                {
                    switch (pipelineContext.Context)
                    {
                    // Best case scenario we have a replacement of the same type to use.
                    case var _ when processorContext.TryGetOption(EnsureReplacement, out object replacement) &&
                        typeToEnsure.IsInstanceOfType(replacement) &&
                        !typeToEnsure.IsInstanceOfType(pipelineContext.Context):
                        pipelineContext.Context = replacement;

                        pipelineContext.Faulted = false;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #17
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                var parameters = new StringBuilder();

                if (processorContext.TryGetOption(DisableWebEditingOptionKey, out bool disableWebEditing))
                {
                    parameters.Append($"disable-web-editing={disableWebEditing}");
                }

                if (!pipelineContext.Faulted)
                {
                    switch (pipelineContext.Context)
                    {
                    case TextField field when processorContext.TryGetOption(RawFieldValue, out bool useRawFieldValue) && useRawFieldValue:
                        pipelineContext.Context = field.Value;

                        break;

                    case TextField field:
                        pipelineContext.Context = FieldRenderer.Render(field.InnerField.Item, field.InnerField.ID.ToString(), parameters.ToString());
                        break;

                    case ValueLookupField valueLookupField:
                        // Used for Unbound Droplist
                        pipelineContext.Context = valueLookupField.Value;
                        break;

                    default:
                        pipelineContext.Faulted = true;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                string parameters = string.Empty;

                if (processorContext.Options.ContainsKey(CssClass))
                {
                    parameters = AddParameter(parameters, $"class={processorContext.Options[CssClass]}");
                }

                if (processorContext.Options.ContainsKey(Width) &&
                    int.TryParse(processorContext.Options[Width].ToString(), out int width))
                {
                    parameters = AddParameter(parameters, $"w={width}");
                }

                if (processorContext.Options.ContainsKey(Height) &&
                    int.TryParse(processorContext.Options[Height].ToString(), out int height))
                {
                    parameters = AddParameter(parameters, $"h={height}");
                }

                switch (pipelineContext.Context)
                {
                case CustomField customField:
                    pipelineContext.Context = FieldRenderer.Render(customField.InnerField.Item, customField.InnerField.ID.ToString(), parameters);
                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #19
0
 public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
 {
     try
     {
         if (!pipelineContext.Faulted && GetPropertyInfo(pipelineContext, processorContext, out PropertyInfo sourcePropertyInfo))
         {
             pipelineContext.Context = FastPropertyAccessor.GetValue(sourcePropertyInfo, pipelineContext.MappingContext.Input);
         }
     }
     catch
     {
         pipelineContext.Faulted = true;
         throw;
     }
     finally
     {
         Next();
     }
 }
Exemple #20
0
 public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
 {
     try
     {
         if (!pipelineContext.Faulted)
         {
             FastPropertyAccessor.SetValue(pipelineContext.PropertyInfo, pipelineContext.MappingContext.Output, pipelineContext.Context);
         }
     }
     catch
     {
         pipelineContext.Faulted = true;
         throw;
     }
     finally
     {
         Next();
     }
 }
Exemple #21
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            if (processorContext.TryGetOption(Marker, out PropertyStageMarker marker))
            {
                if (processorContext.TryGetOption(TypeCheck, out Type checkType))
                {
                    if (checkType.IsInstanceOfType(pipelineContext.Context))
                    {
                        pipelineContext.Stage = marker;
                    }
                }
                else
                {
                    pipelineContext.Stage = marker;
                }
            }

            Next();
        }
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                if (!pipelineContext.Faulted)
                {
                    if (pipelineContext.Context is LinkField linkField)
                    {
                        switch (linkField.LinkType.ToLower())
                        {
                        case "internal" when linkField.TargetItem != null:
                            pipelineContext.Context = LinkManager.GetItemUrl(linkField.TargetItem);
                            break;

                        case "media" when linkField.TargetItem != null:
                            pipelineContext.Context = MediaManager.GetMediaUrl(linkField.TargetItem);
                            break;

                        case "anchor" when !string.IsNullOrEmpty(linkField.Anchor):
                            pipelineContext.Context = $"#{linkField.Anchor}";
                            break;

                        default:
                            pipelineContext.Context = linkField.Url;
                            break;
                        }
                    }
                    else
                    {
                        pipelineContext.Faulted = true;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #23
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                string dateTimeFormat = string.Empty;

                if (processorContext.Options.ContainsKey(DateTimeFormat))
                {
                    dateTimeFormat = processorContext.Options[DateTimeFormat].ToString();
                }

                switch (pipelineContext.Context)
                {
                case DateField field when !SitecoreContext.PageMode.IsExperienceEditor:
                    pipelineContext.Context = string.IsNullOrWhiteSpace(field.Value) ? string.Empty : field.DateTime.ToString(dateTimeFormat);
                    break;

                case DateField field:
                    pipelineContext.Context =
                        FieldRenderer.Render(field.InnerField.Item, field.InnerField.ID.ToString());
                    break;

                default:
                    pipelineContext.Faulted = true;
                    break;
                }
            }
            catch
            {
                pipelineContext.Faulted = true;
                throw;
            }
            finally
            {
                Next();
            }
        }
Exemple #24
0
        public void Run(ModelContext pipelineContext, ProcessorSchema processorContext)
        {
            pipelineContext.Context = $"Source was: '{pipelineContext.Context}'";

            Next();
        }
Exemple #25
0
 public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
 {
     Run((ModelContext)pipelineContext, processorContext);
 }
Exemple #26
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            pipelineContext.Context = "Processor5 Ran";

            Next();
        }
Exemple #27
0
        public void Run(PropertyContext pipelineContext, ProcessorSchema processorContext)
        {
            pipelineContext.Context = new TestOutput3().As <TestOutput3>();

            Next();
        }
Exemple #28
0
 public void Run(ModelContext pipelineContext, ProcessorSchema processorContext)
 {
     Next();
 }
        public void Run(ModelContext pipelineContext, ProcessorSchema processorContext)
        {
            try
            {
                if (!pipelineContext.Faulted)
                {
                    Field contextField = null;

                    switch (pipelineContext.Context)
                    {
                    case Item item:
                        if (processorContext.TryGetOption(FieldId, out ID fieldId))
                        {
                            contextField = item.Fields[fieldId];
                        }
                        else if (pipelineContext is PropertyContext propertyContext)
                        {
                            contextField = item.Fields[propertyContext.PropertyInfo.Name];
                        }
                        break;

                    case Field field:
                        contextField = field;
                        break;

                    case CustomField customField:
                        contextField = customField.InnerField;
                        break;
                    }

                    switch (contextField)
                    {
                    case null:
                        break;

                    case var _ when string.Equals(contextField.Type, "Checkbox", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new CheckboxField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Date", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Datetime", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new DateField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "File", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new FileField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Image", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new ImageField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Single-Line Text", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Multi-Line Text", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Countable Edit", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new TextField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Rich Text", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new HtmlField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Word Document", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new WordDocumentField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Campaign Tree", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Droptree", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new ReferenceField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Droplist", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new ValueLookupField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Grouped Droplink", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new GroupedDroplinkField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Grouped Droplist", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new GroupedDroplistField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Multilist", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Multilist with Search", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Accounts Multilist", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Checklist", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Treelist", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "TreelistEx", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new MultilistField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Name Lookup Value List", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "Name Value List", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new NameValueListField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Droplink", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new LookupField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "General Link", StringComparison.InvariantCultureIgnoreCase):
                    case var _ when string.Equals(contextField.Type, "General Link with Search", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new LinkField(contextField);

                        break;

                    case var _ when string.Equals(contextField.Type, "Version Link", StringComparison.InvariantCultureIgnoreCase):
                        pipelineContext.Context = new VersionLinkField(contextField);

                        break;

                    default:
                        pipelineContext.Context = contextField;
                        break;
                    }
                }
            }
            catch
            {
                pipelineContext.Faulted = true;

                throw;
            }
            finally
            {
                Next();
            }
        }