Beispiel #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();
     }
 }
 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();
     }
 }
Beispiel #3
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();
            }
        }
Beispiel #4
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();
     }
 }
Beispiel #5
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();
            }
        }
Beispiel #6
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();
        }
Beispiel #7
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);
        }
Beispiel #8
0
        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();
            }
        }