Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new instance of a <see cref="T:ILoggingProvider"/> of the type <typeparamref name="t"/>.
 /// </summary>
 /// <param name="t"><see cref="T:Type"/> of <see cref="T:ILoggingProvider"/> to instantiate.</param>
 /// <returns><see cref="T:ILoggingProvider"/></returns>
 public static ILoggingProvider Create( Type t )
 {
     if ( t.NotNull() ) return ( t.GetInstance() as ILoggingProvider );
     else throw new PersistenceException(
                         String.Format( System.Globalization.CultureInfo.InvariantCulture,
                                         Resources.Strings.Logger_Invalid_Type,
                                         t.ToString() ) );
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VApiController"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="json">The constructor json.</param>
        private VApiController(Type type, string json)
        {
            this.ActionController = type.GetInstance(json) as IVApiActionController;

            Ensure.IsNotNull(this.ActionController, "The instance don't implement IApiActionControllerName interface");

            this.Key = this.TryResolveKey();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VRegisterTaskPipelineAttribute"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="json">The JSON.</param>
        public VRegisterTaskPipelineAttribute(Type type, string json)
        {
            this.Json = json;
            Ensure.IsNotNull(type, "type");

            this.Configuration = type.GetInstance(this.Json) as IVTaskPipelineConfiguration;

            Ensure.IsNotNull(this.Configuration, "The type not implement the IVTaskPipelineConfiguration");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="VRegisterVLogErrorCodesAttribute"/> class.
        /// </summary>
        /// <param name="executabletype">The class type to execute.</param>
        /// <param name="json">The JSON.</param>
        public VRegisterVLogErrorCodesAttribute(Type executabletype, string json)
        {
            Ensure.IsNotNull(executabletype, "executable type");
            this.ActionTypeJson = json;

            this.Instance = executabletype.GetInstance(json) as IVExecute;
            Ensure.IsNotNull(this.Instance, "The type not implements the IVExecute interface");

            this.ActionType = executabletype;
            this.Order = byte.MaxValue;
        }
Ejemplo n.º 5
0
        public static object MapDataToType(object fromObject, Type toType)
        {
            var output = toType.GetInstance();
            List<PropertyInfo> fromProperties = fromObject.GetType().GetProperties().ToList();
            List<PropertyInfo> toProperties = toType.GetProperties().ToList();

            var matchingProperties =
                from f in fromProperties
                join t in toProperties
                on f.Name equals t.Name
                where f.PropertyType == t.PropertyType
                select new { Name = f.Name, Value = f.GetValue(fromObject, null) };

            foreach (var match in matchingProperties)
            {
                toType.GetProperty(match.Name).SetValue(output, match.Value, null);
            }

            return output;
        }
        private void GenerateRowMembers(Type rowType)
        {
            var codeNamespace = GetNamespace(rowType);

            Row row = (Row)rowType.GetInstance();

            foreach (var field in row.GetFields())
            {
                cw.Indented(field.PropertyName ?? field.Name);
                sb.Append("?: ");
                var enumField = field as IEnumTypeField;
                if (enumField != null && enumField.EnumType != null)
                {
                    HandleMemberType(enumField.EnumType, codeNamespace);
                }
                else
                {
                    var dataType = field.ValueType;
                    HandleMemberType(dataType, codeNamespace);
                }

                sb.AppendLine(";");
            }
        }
Ejemplo n.º 7
0
        private void GenerateRowMembers(Type rowType)
        {
            bool anyMetadata = false;
            var codeNamespace = GetNamespace(rowType);

            Row row = (Row)rowType.GetInstance();

            var idRow = row as IIdRow;
            if (idRow != null)
            {
                cw.Indented("[InlineConstant] public const string IdProperty = \"");
                var field = ((Field)idRow.IdField);
                sb.Append(field.PropertyName ?? field.Name);
                sb.AppendLine("\";");
                anyMetadata = true;
            }

            var isActiveRow = row as IIsActiveRow;
            if (isActiveRow != null)
            {
                cw.Indented("[InlineConstant] public const string IsActiveProperty = \"");
                var field = (isActiveRow.IsActiveField);
                sb.Append(field.PropertyName ?? field.Name);
                sb.AppendLine("\";");
                anyMetadata = true;
            }

            var nameRow = row as INameRow;
            if (nameRow != null)
            {
                cw.Indented("[InlineConstant] public const string NameProperty = \"");
                var field = (nameRow.NameField);
                sb.Append(field.PropertyName ?? field.Name);
                sb.AppendLine("\";");
                anyMetadata = true;
            }

            var localTextPrefix = row.GetFields().LocalTextPrefix;
            if (!string.IsNullOrEmpty(localTextPrefix))
            {
                cw.Indented("[InlineConstant] public const string LocalTextPrefix = \"");
                sb.Append(localTextPrefix);
                sb.AppendLine("\";");
                anyMetadata = true;
            }

            var attr = rowType.GetCustomAttribute<LookupScriptAttribute>();
            if (attr == null)
            {
                var script = lookupScripts.FirstOrDefault(x =>
                    x.BaseType != null &&
                    x.BaseType.IsGenericType &&
                    x.BaseType.GetGenericArguments().Any(z => z == rowType));

                if (script != null)
                    attr = script.GetCustomAttribute<LookupScriptAttribute>();
            }

            if (attr != null)
            {
                cw.Indented("[InlineConstant] public const string LookupKey = \"");
                sb.Append(attr.Key);
                sb.AppendLine("\";");

                sb.AppendLine();
                cw.Indented("public static Lookup<");
                sb.Append(MakeFriendlyName(rowType, null, null));
                sb.Append("> Lookup { [InlineCode(\"Q.getLookup('");
                sb.Append(attr.Key);
                sb.AppendLine("')\")] get { return null; } }");

                anyMetadata = true;
            }

            if (anyMetadata)
                sb.AppendLine();

            foreach (var field in row.GetFields())
            {
                cw.Indented("public ");

                var enumField = field as IEnumTypeField;
                if (enumField != null && enumField.EnumType != null)
                {
                    HandleMemberType(enumField.EnumType, codeNamespace, UsingNamespaces);
                    sb.Append('?');
                }
                else
                {
                    var dataType = field.ValueType;
                    HandleMemberType(dataType, codeNamespace, UsingNamespaces);
                }

                sb.Append(" ");
                sb.Append(field.PropertyName ?? field.Name);
                sb.AppendLine(" { get; set; }");
            }

            sb.AppendLine();
            cw.IndentedLine("[Imported, PreserveMemberCase]");
            cw.IndentedLine("public static class Fields");
            cw.InBrace(delegate
            {
                foreach (var field in row.GetFields())
                {
                    cw.Indented("[InlineConstant] public const string ");
                    sb.Append(field.PropertyName ?? field.Name);
                    sb.Append(" = \"");
                    sb.Append(field.PropertyName ?? field.Name);
                    sb.AppendLine("\";");
                }
            });
        }
Ejemplo n.º 8
0
        private void GenerateRowMembers(Type rowType)
        {
            Row row = (Row)rowType.GetInstance();
            foreach (var field in row.GetFields())
            {
                cw.Indented("public ");

                var enumField = field as IEnumTypeField;
                if (enumField != null && enumField.EnumType != null)
                {
                    HandleMemberType(enumField.EnumType);
                    sb.Append('?');
                }
                else
                {
                    var dataType = field.ValueType;
                    HandleMemberType(dataType);
                }

                sb.Append(" ");
                sb.Append(field.PropertyName ?? field.Name);
                sb.AppendLine(" { get; set; }");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified culture 
        /// information.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Object"/> that represents the converted value.
        /// </returns>
        /// <param name="culture">
        /// The <see cref="T:System.Globalization.CultureInfo"/> to use as the current culture. 
        /// </param>
        /// <param name="value">The <see cref="T:System.Object"/> to convert. </param>
        /// <param name="propertyType">The property type that the converter will convert to.</param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed.</exception>
        public override object ConvertFrom(CultureInfo culture, object value, Type propertyType)
        {
            if (value.IsNullOrEmptyString())
            {
                // Value types return default instance.
                return propertyType.GetInstance();
            }

            if (value is string)
            {
                string strValue = (string)value;
                if (strValue.IndexOf(',') != -1)
                {
                    long convertedValue = 0;
                    string[] values = this.GetStringArray(strValue, culture);

                    // ReSharper disable once LoopCanBeConvertedToQuery
                    foreach (string v in values)
                    {
                        // OR assignment. Stolen from ComponentModel EnumConverter.
                        convertedValue |= Convert.ToInt64((Enum)Enum.Parse(propertyType, v, true), culture);
                    }

                    return Enum.ToObject(propertyType, convertedValue);
                }

                return Enum.Parse(propertyType, strValue, true);
            }

            if (value is int)
            {
                // Should handle most cases.
                if (Enum.IsDefined(propertyType, value))
                {
                    return Enum.ToObject(propertyType, value);
                }
            }

            if (value != null)
            {
                var valueType = value.GetType();
                if (valueType.IsEnum)
                {
                    // This should work for most cases where enums base type is int.
                    return Enum.ToObject(propertyType, Convert.ToInt64(value, culture));
                }

                if (valueType.IsEnumerableOfType(typeof(string)))
                {
                    long convertedValue = 0;
                    var enumerable = ((IEnumerable<string>)value).ToList();

                    if (enumerable.Any())
                    {
                        // ReSharper disable once LoopCanBeConvertedToQuery
                        foreach (string v in enumerable)
                        {
                            convertedValue |= Convert.ToInt64((Enum)Enum.Parse(propertyType, v, true), culture);
                        }

                        return Enum.ToObject(propertyType, convertedValue);
                    }

                    return propertyType.GetInstance();
                }
            }

            Enum[] enums = value as Enum[];
            if (enums != null)
            {
                long convertedValue = 0;
                // ReSharper disable once LoopCanBeConvertedToQuery
                foreach (Enum e in enums)
                {
                    convertedValue |= Convert.ToInt64(e, culture);
                }

                return Enum.ToObject(propertyType, convertedValue);
            }

            return base.ConvertFrom(culture, value, propertyType);
        }
Ejemplo n.º 10
0
        private void GenerateRowMetadata(Type rowType)
        {
            Row row = (Row)rowType.GetInstance();

            var idRow = row as IIdRow;
            var isActiveRow = row as IIsActiveRow;
            var nameRow = row as INameRow;
            var lookupAttr = rowType.GetCustomAttribute<LookupScriptAttribute>();
            if (lookupAttr == null)
            {
                var script = lookupScripts.FirstOrDefault(x =>
                    x.BaseType != null &&
                    x.BaseType.IsGenericType &&
                    x.BaseType.GetGenericArguments().Any(z => z == rowType));

                if (script != null)
                    lookupAttr = script.GetCustomAttribute<LookupScriptAttribute>();
            }

            sb.AppendLine();
            cw.Indented("export namespace ");
            sb.Append(rowType.Name);

            cw.InBrace(delegate
            {
                bool anyMetadata = false;

                if (idRow != null)
                {
                    cw.Indented("export const idProperty = '");
                    var field = ((Field)idRow.IdField);
                    sb.Append(field.PropertyName ?? field.Name);
                    sb.AppendLine("';");
                    anyMetadata = true;
                }

                if (isActiveRow != null)
                {
                    cw.Indented("export const isActiveProperty = '");
                    var field = (isActiveRow.IsActiveField);
                    sb.Append(field.PropertyName ?? field.Name);
                    sb.AppendLine("';");
                    anyMetadata = true;
                }

                if (nameRow != null)
                {
                    cw.Indented("export const nameProperty = '");
                    var field = (nameRow.NameField);
                    sb.Append(field.PropertyName ?? field.Name);
                    sb.AppendLine("';");
                    anyMetadata = true;
                }

                var localTextPrefix = row.GetFields().LocalTextPrefix;
                if (!string.IsNullOrEmpty(localTextPrefix))
                {
                    cw.Indented("export const localTextPrefix = '");
                    sb.Append(localTextPrefix);
                    sb.AppendLine("';");
                    anyMetadata = true;
                }

                if (lookupAttr != null)
                {
                    cw.Indented("export const lookupKey = '");
                    sb.Append(lookupAttr.Key);
                    sb.AppendLine("';");

                    sb.AppendLine();
                    cw.Indented("export function getLookup(): Q.Lookup<");
                    sb.Append(rowType.Name);
                    sb.Append(">");
                    cw.InBrace(delegate
                    {
                        cw.Indented("return Q.getLookup<");
                        sb.Append(rowType.Name);
                        sb.Append(">('");
                        sb.Append(lookupAttr.Key);
                        sb.AppendLine("');");
                    });

                    anyMetadata = true;

                }

                if (anyMetadata)
                    sb.AppendLine();

                cw.Indented("export namespace ");
                sb.Append("Fields");

                cw.InBrace(delegate
                {
                    foreach (var field in row.GetFields())
                    {
                        cw.Indented("export declare const ");
                        sb.Append(field.PropertyName ?? field.Name);
                        sb.AppendLine(": string;");
                    }
                });

                sb.AppendLine();
                cw.Indented("[");
                int i = 0;
                foreach (var field in row.GetFields())
                {
                    if (i++ > 0)
                        sb.Append(", ");
                    sb.Append("'");
                    sb.Append(field.PropertyName ?? field.Name);
                    sb.Append("'");
                }
                sb.AppendLine("].forEach(x => (<any>Fields)[x] = x);");
            });
        }