Exemplo n.º 1
0
 public SubClassMapping(Type documentType, DocumentMapping parent, string alias = null)
 {
     DocumentType = documentType;
     _inner = new DocumentMapping(documentType);
     _parent = parent;
     Alias = alias ?? documentType.GetTypeName().Replace(".", "_").SplitCamelCase().Replace(" ", "_").ToLowerInvariant();
 }
Exemplo n.º 2
0
        static string CreateMessage(Type messageType, IEnumerable<Exception> exceptions)
        {
            SendException sendException = exceptions
                .Where(x => x.GetType() == typeof(SendException))
                .Cast<SendException>()
                .FirstOrDefault();

            if (sendException != null)
            {
                return $"At least one exception occurred publishing {sendException.MessageType.GetTypeName()} to {sendException.Uri}";
            }

            return $"At least one exception occurred publishing {messageType.GetTypeName()}";
        }
        private static string FormatInvalidTokenErrorMessage(IMemberAccessToken token, Type type)
        {
            string memberName;
            string memberType;

            PropertyToken propertyToken = token as PropertyToken;
            if (propertyToken != null)
            {
                memberType = "property or field";
                memberName = propertyToken.PropertyName;
            }
            else
            {
                memberType = "indexer with arguments";

                var argumentsAsString = ((IndexerToken) token).Arguments.Where(a => a != null).Select(a => a.ToString());
                memberName = string.Join(",", argumentsAsString.ToArray());
            }

            return string.Format(CultureInfo.CurrentCulture, "Invalid {0} - '{1}' for type: {2}", memberType, memberName, type.GetTypeName());
        }
Exemplo n.º 4
0
		private IHydraTask CreateTask(Type taskType)
		{
			var task = taskType.CreateInstance<IHydraTask>();

			var settings = new HydraTaskSettings
			{
				Id = Guid.NewGuid(),
				WorkingFrom = TimeSpan.Zero,
				WorkingTo = TimeHelper.LessOneDay,
				IsDefault = true,
				TaskType = taskType.GetTypeName(false),
			};

			_entityRegistry.TasksSettings.Add(settings);
			_entityRegistry.TasksSettings.DelayAction.WaitFlush();

			InitTask(task, settings);

			var allSec = _entityRegistry.Securities.ReadById(Core.Extensions.AllSecurityId);

			task.Settings.Securities.Add(task.ToTaskSecurity(allSec));
			task.Settings.Securities.DelayAction.WaitFlush();

			return task;
		}
Exemplo n.º 5
0
        //Private
        private EditorViewModel GetEditor(ViewModelConfig viewModelConfig, PropertyInfo prop, Type type)
        {
            var detailViewAttr = prop.GetCustomAttribute<DetailViewAttribute>();

            var systemPropertyAttr = prop.GetCustomAttribute<SystemPropertyAttribute>();

            if (detailViewAttr == null && systemPropertyAttr != null)
            {
                detailViewAttr = new DetailViewAttribute()
                {
                    Name = prop.Name,
                    Visible = false
                };
            }

            if (detailViewAttr != null)
            {
                var maxLengthAttr = prop.GetCustomAttribute<MaxLengthAttribute>();
                var jsonIgnoreAttr = prop.GetCustomAttribute<JsonIgnoreAttribute>();

                bool hideLabel = detailViewAttr.HideLabel;

                if (!hideLabel)
                    hideLabel = String.IsNullOrEmpty(detailViewAttr.Name);

                var editor = new EditorViewModel
                {
                    Mnemonic = detailViewAttr.Mnemonic,
                    ParentViewModelConfig = viewModelConfig,
                    Title = detailViewAttr.Name ?? prop.Name,
                    Description = detailViewAttr.Description,
                    PropertyName = prop.Name,
                    PropertyType = prop.PropertyType,
                    IsLabelVisible = !hideLabel,
                    TabName = detailViewAttr.TabName ?? "[0]Основное",
                    GroupName = detailViewAttr.GroupName ?? Guid.NewGuid().ToString("N"),
                    IsReadOnly = !prop.CanWrite || detailViewAttr.ReadOnly,
                    IsRequired = detailViewAttr.Required,
                    Order = detailViewAttr.Order,
                    MaxLength = maxLengthAttr != null ? (int?)maxLengthAttr.Length : null,
                    DeferredLoading = detailViewAttr.DeferredLoading,
                    Width = detailViewAttr.Width != 0 ? (int?)detailViewAttr.Width : null,
                    Height = detailViewAttr.Height != 0 ? (int?)detailViewAttr.Height : null,
                    JsonIgnore = jsonIgnoreAttr != null,
                    IsSystemPropery = systemPropertyAttr != null,
                    Visible = detailViewAttr.Visible,
                    EditorType =
                        prop.PropertyType.IsBaseCollection()
                            ? prop.PropertyType.GetGenericType().GenericTypeArguments[0]
                            : prop.PropertyType,
                    Relationship = GetRelationship(prop.PropertyType, type),
                };

                var dataTypeAttr = prop.GetCustomAttribute<PropertyDataTypeAttribute>();

                if (dataTypeAttr == null)
                {
                    if (editor.EditorType == typeof(string) && editor.MaxLength == null)
                        editor.EditorTemplate = "MultilineText";
                    else if (editor.EditorType == typeof(int) || editor.EditorType == typeof(int?))
                        editor.EditorTemplate = "Integer";
                    else if (editor.EditorType == typeof(decimal) || editor.EditorType == typeof(decimal?))
                        editor.EditorTemplate = "Currency";
                    else if (editor.EditorType == typeof(double) || editor.EditorType == typeof(double?))
                        editor.EditorTemplate = "Double";
                    else if (editor.EditorType == typeof(DateTime) || editor.EditorType == typeof(DateTime?))
                        editor.EditorTemplate = "Date";
                    else if (editor.EditorType.IsEnum())
                        editor.EditorTemplate = "Enum";
                    else if (editor.EditorType == typeof(Period))
                        editor.EditorTemplate = "Period";
                    else if (editor.EditorType == typeof(Icon))
                        editor.EditorTemplate = "Icon";
                    else if (typeof(MultilanguageText).IsAssignableFrom(editor.EditorType))
                        editor.EditorTemplate = "Multilanguage";
                    else if (editor.EditorType == typeof(Url))
                        editor.EditorTemplate = "ComplexUrl";
                    else if (editor.EditorType == typeof(UrlMultilanguageText))
                        editor.EditorTemplate = "UrlMultilanguageText";
                    else if (editor.EditorType == typeof(LinkBaseObject))
                        editor.EditorTemplate = "LinkBaseObject";
                    else if (editor.EditorType == typeof(MultiEnum))
                        editor.EditorTemplate = "MultiEnum";
                    //else if (editor.EditorType == typeof(ValidationObjectBinding))
                    //    editor.EditorTemplate = "ValidationObjectBinding";
                    else
                    {
                        Type easyCollectionEntry =
                            prop.PropertyType.GetEntryOfUnboundedTypeOfCollection(typeof(EasyCollectionEntry<>));

                        if (easyCollectionEntry != null)
                        {
                            editor.EditorTemplate = "EasyCollection";
                            editor.ViewModelConfig = _viewModelConfigService.Get(easyCollectionEntry);
                        }
                        else
                        {
                            switch (editor.Relationship)
                            {
                                case Relationship.OneToMany:
                                    if (typeof(FileData).IsAssignableFrom(editor.EditorType))
                                        editor.EditorTemplate = "Files";
                                    else if (typeof(Base.LinkedObjects.Entities.Link).IsAssignableFrom(editor.EditorType))
                                        editor.EditorTemplate = "ListLinkedОbjects";
                                    else
                                        editor.EditorTemplate = "OneToMany";

                                    break;

                                case Relationship.ManyToMany:
                                    editor.EditorTemplate = "ManyToMany";
                                    break;

                                case Relationship.One:
                                    editor.EditorTemplate = "BaseObjectOne";
                                    break;

                                case Relationship.None:
                                    editor.EditorTemplate = editor.EditorType.Name;
                                    break;
                            }
                        }
                    }
                }
                else
                {
                    editor.EditorTemplate = dataTypeAttr.DataType != PropertyDataType.Custom
                        ? dataTypeAttr.DataType.ToString()
                        : dataTypeAttr.CustomDataType;

                    editor.EditorTemplateParams = dataTypeAttr.Params;
                }


                var configEditor = viewModelConfig.DetailView.Editors.FirstOrDefault(m => m.PropertyName == editor.PropertyName);

                if (configEditor != null)
                {
                    if (configEditor.Mnemonic != null)
                        editor.Mnemonic = configEditor.Mnemonic;

                    if (configEditor.Title != null)
                        editor.Title = configEditor.Title;

                    if (configEditor.IsLabelVisible != null)
                        editor.IsLabelVisible = configEditor.IsLabelVisible.Value;

                    if (configEditor.EditorTemplate != null)
                        editor.EditorTemplate = configEditor.EditorTemplate;

                    if (configEditor.TabName != null)
                        editor.TabName = configEditor.TabName;

                    if (configEditor.IsReadOnly != null)
                        editor.IsReadOnly = configEditor.IsReadOnly.Value;

                    if (configEditor.IsRequired != null)
                        editor.IsRequired = configEditor.IsRequired.Value;

                    if (configEditor.Order != null)
                        editor.Order = configEditor.Order.Value;

                    if (configEditor.Visible != null)
                        editor.Visible = configEditor.Visible.Value;
                }

                if (editor.ViewModelConfig == null)
                {
                    editor.ViewModelConfig = _viewModelConfigService.Get(editor.Mnemonic) ?? _viewModelConfigService.Get(editor.EditorType);

                    if (editor.ViewModelConfig == null && prop.PropertyType.IsAssignableFromBase())
                        throw new Exception(String.Format("The configuration file is not configured for type \"{0}\"", editor.EditorType.Name));
                }


                if (String.IsNullOrEmpty(editor.Mnemonic))
                    editor.Mnemonic = type.GetTypeName();

                return editor;
            }

            return null;
        }
Exemplo n.º 6
0
 private void SetType(Type enumType)
 {
     this.type = enumType.GetTypeName();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Produces the Linq expression that represents a particular FilterDescriptor
        /// </summary>
        /// <param name="type">Entity type</param>
        /// <param name="propertyPath">Left operand: Property on the entity type</param>
        /// <param name="filterOperator">One of the FilterOperator enum value</param>
        /// <param name="value">Right operand</param>
        /// <param name="isCaseSensitive">Boolean that specifies if the string operations are case sensitive or not</param>
        /// <returns>Resulting linq expression</returns>
        /// <exception cref="ArgumentException">When a filter descriptor references a property that could not be found.</exception>
        /// <exception cref="ArgumentException">When an exception occurs attempting to evaluate a filter descriptor.</exception>
        /// <exception cref="ArgumentException">When the supplied filter value has a type that cannot be compared to the property type.</exception>
        /// <exception cref="NotSupportedException">When attempting to use a property type/operator pair that is not supported.</exception>
        public static Expression BuildFilterExpression(
            Type type,
            string propertyPath,
            FilterOperator filterOperator,
            object value,
            bool isCaseSensitive)
        {
            Debug.Assert(type != null, "Unexpected null type");
            Debug.Assert(propertyPath != null, "Unexpected null propertyPath");

            Expression filterExpression = null;
            PropertyInfo pi;
            Expression propertyExpression;
            Expression valueExpression;

            try
            {
                pi = type.GetPropertyInfo(propertyPath);

                if (pi == null)
                {
                    throw new ArgumentException(string.Format(
                                CultureInfo.InvariantCulture,
                                CommonResources.PropertyNotFound,
                                propertyPath,
                                type.GetTypeName()));
                }
                // TODO: Remove this check.
                // It's a duplicate of one done in the DDS, but it's still required for the BuildFilterExpressions Test.
                else if (!IsSupportedOperator(pi.PropertyType, filterOperator))
                {
                    throw new NotSupportedException(string.Format(
                                CultureInfo.InvariantCulture,
                                DomainDataSourceResources.FilterNotSupported,
                                propertyPath,
                                type.GetTypeName(),
                                pi.PropertyType.GetTypeName(),
                                filterOperator));
                }

                propertyExpression = GenerateProperty(type, propertyPath, Expression.Parameter(type, string.Empty));
                valueExpression = GenerateConstant(value);
                Debug.Assert(propertyExpression != null, "Unexpected null propertyExpression in LinqHelper.BuildFilterExpression");
            }
            catch (Exception ex)
            {
                if (ex.IsFatal())
                {
                    throw;
                }

                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        DomainDataSourceResources.CannotEvaluateDescriptor,
                        propertyPath),
                        ex);
            }

            try
            {
                bool isEquality = filterOperator == FilterOperator.IsEqualTo || filterOperator == FilterOperator.IsNotEqualTo;
                if (isEquality && !propertyExpression.Type.IsValueType && !valueExpression.Type.IsValueType)
                {
                    if (propertyExpression.Type != valueExpression.Type)
                    {
                        if (propertyExpression.Type.IsAssignableFrom(valueExpression.Type))
                        {
                            valueExpression = Expression.Convert(valueExpression, propertyExpression.Type);
                        }
                        else if (valueExpression.Type.IsAssignableFrom(propertyExpression.Type))
                        {
                            propertyExpression = Expression.Convert(propertyExpression, valueExpression.Type);
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(
                                CultureInfo.InvariantCulture,
                                DomainDataSourceResources.IncompatibleOperands,
                                filterOperator.ToString(),
                                propertyExpression.Type.GetTypeName(),
                                valueExpression.Type.GetTypeName()));
                        }
                    }
                }
                else if (propertyExpression.Type.IsEnumType())
                {
                    // Convert the value to compare to the underlying type of the enum,
                    // preserving nullable and following the same rules the C# compiler does.
                    // Examples:
                    //    p.Enum > Enum.A         => p.Enum > 1
                    //    p.Enum > null           => p.Enum > Convert(null, Nullable<int>)
                    //    p.NullableEnum > Enum.A => p.Enum > Convert(Enum.A, Nullable<int>)
                    //    p.NullableEnum > null   => p.Enum > Convert(Enum.A, Nullable<int>)
                    Type underlyingType = Enum.GetUnderlyingType(TypeUtility.GetNonNullableType(propertyExpression.Type));
                    bool propertyIsNullable = propertyExpression.Type.IsNullableType();
                    if (propertyIsNullable)
                    {
                        underlyingType = typeof(Nullable<>).MakeGenericType(underlyingType);
                    }
                    if (valueExpression.Type != underlyingType)
                    {
                        if (value != null && !propertyIsNullable)
                        {
                            // convert to the underlying value and create a new constant
                            value = Convert.ChangeType(value, underlyingType, CultureInfo.InvariantCulture);
                            valueExpression = GenerateConstant(value);
                        }
                        else
                        {
                            // for nulls or comparisons against a nullable enum, we inject
                            // a conversion
                            valueExpression = Expression.Convert(valueExpression, underlyingType);
                        }
                    }

                    // Now that we've converted the enum value, we inject the appropriate conversion
                    // on the property expression
                    if (propertyExpression.Type != valueExpression.Type)
                    {
                        Expression e;
                        if ((e = PromoteExpression(propertyExpression, valueExpression.Type, true)) != null)
                        {
                            propertyExpression = e;
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(
                                CultureInfo.InvariantCulture,
                                DomainDataSourceResources.IncompatibleOperands,
                                filterOperator.ToString(),
                                propertyExpression.Type.GetTypeName(),
                                valueExpression.Type.GetTypeName()));
                        }
                    }
                }
                else if (pi.PropertyType.IsNullableType() && propertyExpression.Type != valueExpression.Type)
                {
                    ConstantExpression ce = valueExpression as ConstantExpression;
                    if (ce != null)
                    {
                        valueExpression = Expression.Constant(ce.Value, propertyExpression.Type);
                    }
                }

                filterExpression = BuildFilterExpression(propertyExpression, filterOperator, valueExpression, isCaseSensitive);
            }
            catch (Exception ex)
            {
                if (ex.IsFatal())
                {
                    throw;
                }

                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        DomainDataSourceResources.IncompatibleOperands,
                        filterOperator.ToString(),
                        propertyExpression.Type.GetTypeName(),
                        (valueExpression == nullLiteral) ? "null" : valueExpression.Type.GetTypeName()),
                        ex);
            }

            return filterExpression;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Builds the Linq Expression for the provided propertyPath and type properties
        /// </summary>
        /// <param name="type">Type that exposes the property</param>
        /// <param name="propertyPath">Public property. Can be nested.</param>
        /// <returns>Resulting property expression</returns>
        /// <exception cref="ArgumentException">When property is not found on the specified type.</exception>
        public static Expression BuildPropertyExpression(Type type, string propertyPath)
        {
            Debug.Assert(type != null, "Unexpected null type");
            Debug.Assert(propertyPath != null, "Unexpected null propertyPath");

            Expression propertyExpression = GenerateProperty(type, propertyPath, Expression.Parameter(type, string.Empty));

            if (propertyExpression == null)
            {
                throw new ArgumentException(string.Format(
                    CultureInfo.InvariantCulture,
                    CommonResources.PropertyNotFound,
                    propertyPath,
                    type.GetTypeName()));
            }

            return propertyExpression;
        }
Exemplo n.º 9
0
        public void Instance(Type pluginType, Instance instance)
        {
            if (_instanceStack.Any() && _instanceStack.Peek() == instance) return;

            if (_instanceStack.Contains(instance))
            {
                _writer.Line("Bi-Directional Relationship Detected w/ Instance {0}, PluginType {1}", instance.Description, pluginType.GetTypeName());
            }

            _instanceStack.Push(instance);


            if (pluginType != null) _writer.Line("PluginType: " + pluginType.GetFullName());

            var lifecycle = _pipeline.DetermineLifecycle(pluginType, instance);
            _writer.Line("Lifecycle: " + lifecycle.Description);

            var plan = instance.ResolveBuildPlan(pluginType ?? instance.ReturnedType, _pipeline.Policies);

            plan.AcceptVisitor(this);
            _instanceStack.Pop();
        }
Exemplo n.º 10
0
        public ViewModelConfig CreateViewModelConfig(Type type)
        {
            if (!type.IsBaseObject() && !type.IsDefined(typeof(ComplexTypeAttribute))) return null;

            string serviceName = "";

            if (type.IsBaseObject())
            {
                if (type.IsAssignableFrom(typeof(HCategory)))
                    serviceName = typeof(IBaseCategoryService<>).GetTypeName();
                else if (type.IsAssignableFrom(typeof(ICategorizedItem)))
                    serviceName = typeof(IBaseCategorizedItemService<>).GetTypeName();
                else
                    serviceName = typeof(IBaseObjectService<>).GetTypeName();
            }

            return new ViewModelConfig(
                mnemonic: type.GetTypeName(),
                entity: type.GetTypeName(),
                listView: new ListView(),
                detailView: new DetailView(),
                lookupProperty:
                    type.IsBaseObject()
                        ? (type.GetProperty("Title") ?? type.GetProperty("Name") ?? type.GetProperty("ID")).Name
                        : "",
                service: serviceName);
        }
Exemplo n.º 11
0
        private void RegisterType(Type type)
        {
            if (types.ContainsKey(type))
                return;

            string alias = type.GetTypeName();
            while (typeAliases.ContainsKey(alias))
            {
                alias = IncrementAlias(alias);
            }

            types.Add(type, alias);
            typeAliases.Add(alias, type);
        }