Ejemplo n.º 1
0
        private static bool DoObjectMemberInitialization(object target, bool beforeFieldInit, object state)
        {
            if (target.GetType().IsPrimitive ||
                target is string || target is Enum
                )
            {
            }
            else
            {
                //Call the initialize to all members
                foreach (FieldInfo fieldInfo in ChoType.GetFields(target.GetType()))
                {
                    if (fieldInfo.IsReadOnly())
                    {
                        continue;
                    }

                    object fieldValue = ChoType.GetFieldValue(target, fieldInfo.Name);
                    if (fieldValue == null)
                    {
                        continue;
                    }

                    if (!(fieldValue is string) && fieldValue is IEnumerable)
                    {
                        foreach (object fieldItemValue in (IEnumerable)fieldValue)
                        {
                            DoInitialize(fieldItemValue, beforeFieldInit, state);
                        }

                        DoInitialize(fieldValue, beforeFieldInit, state);
                    }
                    else
                    {
                        DoInitialize(fieldValue, beforeFieldInit, state);
                    }
                }
            }

            if (target is IChoObjectInitializable)
            {
                return(((IChoObjectInitializable)target).Initialize(beforeFieldInit, state));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        protected void SetFields(Type elementType, KeyValuePair <string, Type>[] membersInfo = null)
        {
            Dictionary <string, ChoObjectDataReaderProperty> prop = new Dictionary <string, ChoObjectDataReaderProperty>();

            Fields = new List <ChoObjectDataReaderProperty>();

            if (membersInfo != null)
            {
                var dict = membersInfo.GroupBy(kvp => kvp.Key).ToDictionary(g => g.Key, g => g.FirstOrDefault());
                var m    = ChoType.GetMembers(elementType).Where(m1 => dict.ContainsKey(m1.Name));
                if (m.Any())
                {
                    foreach (var mi in m)
                    {
                        prop.Add(mi.Name, new ChoObjectDataReaderProperty(mi));
                    }
                }
                else
                {
                    if (elementType.IsSimple())
                    {
                        prop.Add("Value", new ChoObjectDataReaderProperty("Value", elementType, true));
                    }
                    else
                    {
                        foreach (KeyValuePair <string, Type> kvp in membersInfo)
                        {
                            if (!prop.ContainsKey(kvp.Key))
                            {
                                prop.Add(kvp.Key, new ChoObjectDataReaderProperty(kvp.Key, kvp.Value));
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (MemberInfo info in ChoType.GetMembers(elementType))
                {
                    if (!prop.ContainsKey(info.Name))
                    {
                        prop.Add(info.Name, new ChoObjectDataReaderProperty(info));
                    }
                }
            }

            Fields = new List <ChoObjectDataReaderProperty>(prop.Values.ToArray());
        }
Ejemplo n.º 3
0
        internal static void Initialize()
        {
            //ChoStreamProfile.Clean(ChoReservedDirectoryName.Others, ChoType.GetLogFileName(typeof(ChoTypesManager)));

            StringBuilder topMsg = new StringBuilder();

            ChoStringMsgBuilder parseMethodsMsg  = new ChoStringMsgBuilder("Below are the loaded parse methods");
            ChoStringMsgBuilder formatMethodsMsg = new ChoStringMsgBuilder("Below are the loaded format methods");
            ChoStringMsgBuilder msg = new ChoStringMsgBuilder("Below are the loaded type objects");

            foreach (Type type in ChoType.GetTypes(typeof(ChoStringObjectFormattableAttribute)))
            {
                if (ChoTypesManagerSettings.IsExcludedType(type))
                {
                    continue;
                }

                ChoTypeObjectParseInfo  typeObjectParseInfo  = new ChoTypeObjectParseInfo();
                ChoTypeObjectFormatInfo typeObjectFormatInfo = new ChoTypeObjectFormatInfo();
                try
                {
                    //typeObjectFormatInfo.TypeObject = typeObjectParseInfo.TypeObject = ChoObject.CreateInstance(type);
                    msg.AppendFormatLine(type.FullName);
                }
                catch (ChoFatalApplicationException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    msg.AppendFormatLine("{0}: [{1}]", type.FullName, ex.Message);
                }

                LoadObjectParser(parseMethodsMsg, type, typeObjectParseInfo);
                LoadObjectFormatter(formatMethodsMsg, type, typeObjectFormatInfo);
            }

            _typeObjectsParseInfoArr  = TypeObjectsParseInfo.Values.ToArray();
            _typeObjectsFormatInfoArr = TypeObjectsFormatInfo.Values.ToArray();

            //_typeObjectsParseInfo.Clear();
            //_typeObjectsFormatInfo.Clear();

            topMsg.Append(parseMethodsMsg.ToString() + Environment.NewLine + Environment.NewLine);
            topMsg.Append(formatMethodsMsg.ToString() + Environment.NewLine + Environment.NewLine);
            topMsg.Append(msg.ToString() + Environment.NewLine + Environment.NewLine);
            _helpText = topMsg.ToString();
        }
Ejemplo n.º 4
0
        public static IList <Property> CreatePropertyMethods(Type type)
        {
            var returnValue = new List <Property>();

            //returnValue.Add(new Property("CustomerID", typeof(string)));
            //return returnValue;
            foreach (MemberInfo info in ChoType.GetMembers(type))
            {
            }

            foreach (PropertyInfo prop in type.GetProperties())
            {
                returnValue.Add(new Property(prop));
            }
            return(returnValue);
        }
        protected override void Init(Type recordType)
        {
            base.Init(recordType);

            ChoKVPRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoKVPRecordObjectAttribute>(recordType);

            if (recObjAttr != null)
            {
                Separator             = recObjAttr.Separator;
                RecordStart           = recObjAttr.RecordStart;
                RecordEnd             = recObjAttr.RecordEnd;
                LineContinuationChars = recObjAttr.LineContinuationChars;
            }

            DiscoverRecordFields(recordType);
        }
        protected override void Init(Type recordType)
        {
            base.Init(recordType);

            ChoFixedLengthRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoFixedLengthRecordObjectAttribute>(recordType);

            if (recObjAttr != null)
            {
                RecordLength = recObjAttr.RecordLength;
            }

            if (FixedLengthRecordFieldConfigurations.Count == 0)
            {
                DiscoverRecordFields(recordType);
            }
        }
Ejemplo n.º 7
0
        public static object ConvertValueToObjectMemberType(object target, MemberInfo memberInfo, object value)
        {
            ChoGuard.ArgumentNotNull(target, "Target");
            object memberValue = value;

            if (target is Type)
            {
                return(ChoConvert.ConvertFrom(null, memberValue, ChoType.GetMemberType((Type)target, memberInfo.Name),
                                              ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo)));
            }
            else
            {
                return(ChoConvert.ConvertFrom(target, memberValue, ChoType.GetMemberType(target.GetType(), memberInfo.Name),
                                              ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo)));
            }
        }
Ejemplo n.º 8
0
        private static IEnumerable <MethodInfo> GetShellExtensionMethods()
        {
            Type[] shellExtTypes = ChoType.GetTypes <ChoShellExtensionAttribute>();
            if (shellExtTypes.IsNullOrEmpty())
            {
                yield break;
            }

            foreach (Type type in shellExtTypes)
            {
                foreach (MethodInfo methodInfo in ChoType.GetMethods(type, typeof(ChoShellExtensionContextMenuAttribute)))
                {
                    yield return(methodInfo);
                }
            }
        }
Ejemplo n.º 9
0
        public static bool IsValidFor(this object @this, string mn, out Exception aggEx)
        {
            ChoGuard.ArgumentNotNullOrEmpty(mn, "MemberName");

            aggEx = null;
            MemberInfo mi = ChoType.GetMemberInfo(@this.GetType(), mn);

            if (mi != null)
            {
                return(IsValidFor(@this, mi, out aggEx));
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 10
0
        public static void DoObjectLevelValidation(this object recObject, ChoRecordConfiguration configuration, IEnumerable <ChoRecordFieldConfiguration> fieldConfigurations)
        {
            if (recObject == null)
            {
                return;
            }

            if ((configuration.ObjectValidationMode & ChoObjectValidationMode.ObjectLevel) == ChoObjectValidationMode.ObjectLevel)
            {
                if (configuration.Validator == null)
                {
                    if (configuration.HasConfigValidators)
                    {
                        IDictionary <string, Object> dict = null;
                        if (recObject is IDictionary <string, object> )
                        {
                            dict = recObject as IDictionary <string, Object>;
                        }
                        else
                        {
                            dict = new Dictionary <string, object>();

                            foreach (var pd in configuration.PIDict.Values)
                            {
                                dict.Add(pd.Name, ChoType.GetPropertyValue(recObject, pd));
                            }
                        }

                        ChoValidator.Validate(dict, configuration.ValDict);
                    }
                    else
                    {
                        if (!configuration.IsDynamicObject)
                        {
                            ChoValidator.Validate(recObject);
                        }
                    }
                }
                else
                {
                    if (recObject != null && configuration.Validator(recObject))
                    {
                        throw new ValidationException("Failed to validate '{0}' object. {1}".FormatString(recObject.GetType().FullName, Environment.NewLine));
                    }
                }
            }
        }
Ejemplo n.º 11
0
        protected override void Init(Type recordType)
        {
            base.Init(recordType);

            if (recordType == null)
            {
                return;
            }

            ChoJSONRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoJSONRecordObjectAttribute>(recordType);

            if (recObjAttr != null)
            {
            }

            DiscoverRecordFields(recordType);
        }
Ejemplo n.º 12
0
        protected virtual object Serialize(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            IList result = ChoActivator.CreateInstance(typeof(IList <>).MakeGenericType(targetType)) as IList;

            if (value != null && !value.GetType().IsCollectionType())
            {
                if (targetType == typeof(object) || targetType.IsSimple())
                {
                    foreach (var p in ChoTypeDescriptor.GetProperties(value.GetType()).Where(pd => ChoTypeDescriptor.GetPropetyAttribute <ChoIgnoreMemberAttribute>(pd) == null))
                    {
                        result.Add(ChoConvert.ConvertTo(ChoType.GetPropertyValue(value, p.Name), targetType, culture));
                    }
                }
            }

            return(result.OfType <object>().ToArray());
        }
        private void Init(Type recordType)
        {
            ChoFileHeaderAttribute recObjAttr = ChoType.GetAttribute <ChoFileHeaderAttribute>(recordType);

            if (recObjAttr != null)
            {
                HasHeaderRecord = true;
                IgnoreCase      = recObjAttr.IgnoreCase;
                FillChar        = recObjAttr.FillCharInternal;
                Justification   = recObjAttr.JustificationInternal;
                if (recObjAttr.TrimOptionInternal != null)
                {
                    TrimOption = recObjAttr.TrimOptionInternal.Value;
                }
                Truncate = recObjAttr.TruncateInternal;
            }
        }
Ejemplo n.º 14
0
        public static object GetObjectMemberValue(object target, MemberInfo memberInfo)
        {
            ChoGuard.ArgumentNotNull(target, "Target");

            object memberValue = ChoType.GetMemberValue(target, memberInfo);

            if (memberValue == null)
            {
                ChoPropertyInfoAttribute memberInfoAttribute = ChoType.GetMemberAttribute <ChoPropertyInfoAttribute>(memberInfo);
                if (memberInfoAttribute != null)
                {
                    memberValue = memberInfoAttribute.DefaultValue;
                }
            }

            return(memberValue);
        }
Ejemplo n.º 15
0
        private static MemberInfo CheckNExtractMemberInfo(object target, string memberName)
        {
            ChoGuard.ArgumentNotNull(target, "Target");

            MemberInfo memberInfo = ChoType.GetMemberInfo(target.GetType(), memberName);

            if (memberInfo == null)
            {
                throw new NullReferenceException(String.Format("Can't find {0} member in {1} type.", memberName, target.GetType().FullName));
            }
            if (memberInfo.MemberType != MemberTypes.Field &&
                memberInfo.MemberType != MemberTypes.Property)
            {
                throw new ChoApplicationException(String.Format("Member `{0}` is not a field/property in {1} type.", memberName, target.GetType().FullName));
            }
            return(memberInfo);
        }
Ejemplo n.º 16
0
        protected override void Init(Type recordType)
        {
            base.Init(recordType);

            if (recordType == null)
            {
                return;
            }

            ChoFileRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoFileRecordObjectAttribute>(recordType);

            if (recObjAttr != null)
            {
                AutoDiscoverFieldTypes = true;
                MaxScanRows            = 0;
                if (recObjAttr.BufferSize > 0)
                {
                    BufferSize = recObjAttr.BufferSize;
                }
                if (recObjAttr.Comments.IsNullOrWhiteSpace())
                {
                    Comments = new string[] { }
                }
                ;
                else
                {
                    Comments = recObjAttr.Comments.SplitNTrim(',');
                }
                Culture            = recObjAttr.Culture;
                EOLDelimiter       = recObjAttr.EOLDelimiter;
                IgnoreEmptyLine    = recObjAttr.IgnoreEmptyLine;
                ColumnCountStrict  = recObjAttr.ColumnCountStrict;
                ColumnOrderStrict  = recObjAttr.ColumnOrderStrict;
                QuoteChar          = recObjAttr.QuoteChar;
                QuoteAllFields     = recObjAttr.QuoteAllFieldsInternal;
                StringSplitOptions = recObjAttr.StringSplitOptions;
                if (!recObjAttr.Encoding.IsNullOrWhiteSpace())
                {
                    Encoding = Encoding.GetEncoding(recObjAttr.Encoding);
                }
                NullValue = recObjAttr.NullValue;
            }
            else
            {
            }
        }
Ejemplo n.º 17
0
        private static void DoObjectMemberConversion(object ultimateParent, object target)
        {
            if (target == null)
            {
                return;
            }

            if (target.GetType().IsPrimitive ||
                target is string || target is Enum
                )
            {
            }
            else
            {
                DoPostObjectMemberConversion(ultimateParent, target);

                //Call the initialize to all members
                foreach (FieldInfo fieldInfo in ChoType.GetFields(target.GetType()))
                {
                    if (fieldInfo.IsReadOnly())
                    {
                        continue;
                    }

                    object fieldValue = ChoType.GetFieldValue(target, fieldInfo.Name);
                    if (fieldValue == null)
                    {
                        continue;
                    }

                    if (!(fieldValue is string) && fieldValue is IEnumerable)
                    {
                        foreach (object fieldItemValue in (IEnumerable)fieldValue)
                        {
                            DoObjectMemberConversion(ultimateParent, fieldItemValue);
                        }

                        ChoType.SetFieldValue(target, fieldInfo.Name, fieldValue);
                    }
                    else
                    {
                        DoObjectMemberConversion(ultimateParent, fieldValue);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        protected virtual void Init(Type recordType)
        {
            if (recordType == null)
            {
                return;
            }

            ChoRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoRecordObjectAttribute>(recordType);

            if (recObjAttr != null)
            {
                ErrorMode                  = recObjAttr.ErrorMode;
                IgnoreFieldValueMode       = recObjAttr.IgnoreFieldValueMode;
                ThrowAndStopOnMissingField = recObjAttr.ThrowAndStopOnMissingField;
                ObjectValidationMode       = recObjAttr.ObjectValidationMode;
            }
        }
        protected override void Init(Type recordType)
        {
            base.Init(recordType);

            ChoCSVRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoCSVRecordObjectAttribute>(recordType);

            if (recObjAttr != null)
            {
                Delimiter         = recObjAttr.Delimiter;
                HasExcelSeparator = recObjAttr.HasExcelSeparatorInternal;
            }

            if (CSVRecordFieldConfigurations.Count == 0)
            {
                DiscoverRecordFields(recordType);
            }
        }
        // If the type of the value to convert is string, parses the string
        // and returns the integer to set the value of the property to.
        // This example first extends the integer array that supplies the
        // standard values collection if the user-entered value is not
        // already in the array.
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            value = ChoType.GetMemberValue(Target, DependentMemberName);

            object convertedObject = null;

            using (ChoBufferProfileEx outerProfile = new ChoBufferProfileEx(LogFileName, "Converting file to objects...."))
            {
                try
                {
                    if (value.GetType() == typeof(string))
                    {
                        convertedObject = GetObject(value as string, outerProfile);
                    }
                    else if (value.GetType() == typeof(string[]))
                    {
                        Hashtable convertedObjects = new Hashtable();
                        foreach (string fileName in (string[])value)
                        {
                            object element = GetObject(fileName, outerProfile);
                            if (KeyName == InternalHashKey)
                            {
                                convertedObjects.Add(element.GetHashCode().ToString(), element);
                            }
                            else
                            {
                                convertedObjects.Add(ChoType.GetMemberValue(element, KeyName).ToString(), element);
                            }
                        }

                        convertedObject = convertedObjects;
                    }
                }
                catch (ChoFatalApplicationException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    outerProfile.Append(ex);
                }
            }

            return(convertedObject);
        }
Ejemplo n.º 21
0
        public ChoConfigurableObject()
        {
            _configurationElementAttribute = ChoType.GetAttribute(GetType(), typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute;

            //Discover and Hook the event handlers
            if (BeforeConfigurationObjectMemberLoaded == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectMemberEventArgs>(ref BeforeConfigurationObjectMemberLoaded, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectMemberLoadedHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectMemberLoaded == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberEventArgs>(ref AfterConfigurationObjectMemberLoaded, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectMemberLoadedHandlerAttribute)), this);
            }
            if (ConfigurationObjectMemberLoadError == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberErrorEventArgs>(ref ConfigurationObjectMemberLoadError, ChoType.GetMethods(GetType(), typeof(ChoConfigurationObjectMemberLoadErrorHandlerAttribute)), this);
            }

            if (BeforeConfigurationObjectPersisted == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectEventArgs>(ref BeforeConfigurationObjectPersisted, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectPersistedHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectPersisted == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectEventArgs>(ref AfterConfigurationObjectPersisted, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectPersistedHandlerAttribute)), this);
            }

            if (BeforeConfigurationObjectMemberPersist == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectMemberEventArgs>(ref BeforeConfigurationObjectMemberPersist, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectMemberPersistHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectMemberPersist == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberEventArgs>(ref AfterConfigurationObjectMemberPersist, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectMemberPersistHandlerAttribute)), this);
            }

            if (AfterConfigurationObjectLoadedInternal == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectEventArgs>(ref AfterConfigurationObjectLoadedInternal, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectLoadedHandlerAttribute)), this);
            }
            if (ConfigurationObjectLoadError == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectErrorEventArgs>(ref ConfigurationObjectLoadError, ChoType.GetMethods(GetType(), typeof(ChoConfigurationObjectLoadErrorHandlerAttribute)), this);
            }
        }
Ejemplo n.º 22
0
        private bool ValidateOnWrite(ref object value)
        {
            var crs = Writer.ContractResolverState;
            var fc  = crs.FieldConfig;

            crs.Name = _fc == null?_mi.GetFullName() : crs.Name;

            var rec  = ChoType.GetMemberObjectMatchingType(crs.Name, crs.Record);
            var name = ChoType.GetFieldName(crs.Name);

            try
            {
                Validate(value);
            }
            catch (Exception ex)
            {
                ChoETLFramework.HandleException(ref ex);

                if (fc != null && fc.ErrorMode == ChoErrorMode.ThrowAndStop)
                {
                    throw;
                }

                if (fc != null)
                {
                    if (fc.ErrorMode == ChoErrorMode.IgnoreAndContinue)
                    {
                        return(false);
                    }
                    else
                    {
                        if (!RaiseRecordFieldWriteError(rec, crs.Index, name, ref value, ex))
                        {
                            throw new ChoWriterException($"Failed to write '{value}' value of '{crs.Name}' member.", ex);
                        }
                    }
                }
                else
                {
                    throw new ChoWriterException($"Failed to write '{value}' value of '{crs.Name}' member.", ex);
                }
            }

            return(true);
        }
Ejemplo n.º 23
0
        public static Dictionary <string, object> ToDictionary(this object target)
        {
            ChoGuard.ArgumentNotNull(target, "Target");

            if (target is IDictionary <string, object> )
            {
                return((Dictionary <string, object>)target);
            }

            Dictionary <string, object> dict = new Dictionary <string, object>();

            foreach (PropertyDescriptor pd in ChoTypeDescriptor.GetProperties(target.GetType()))
            {
                dict.Add(pd.Name, ChoType.GetPropertyValue(target, pd.Name));
            }

            return(dict);
        }
Ejemplo n.º 24
0
        public static string GetName(Type objType, ChoTypeNameSpecifier typeNameSpecifier)
        {
            ChoGuard.ArgumentNotNull(objType, "Type");
            ChoObjectNameableAttribute objectNameableAttribute = ChoType.GetAttribute(objType, typeof(ChoObjectNameableAttribute)) as ChoObjectNameableAttribute;

            string key = null;

            if (objectNameableAttribute != null)
            {
                key = objectNameableAttribute.Name;
            }
            else
            {
                key = objType.GetName(typeNameSpecifier);
            }

            return(key);
        }
Ejemplo n.º 25
0
        internal static Type GetPlugInType(Type plugInBuilderType)
        {
            ChoPlugInAttribute plugInAttribute = ChoType.GetAttribute <ChoPlugInAttribute>(plugInBuilderType);

            if (plugInAttribute == null)
            {
                return(null);
            }

            Type type = plugInAttribute.PlugInType;

            if (type == null)
            {
                throw new ChoPlugInException("Can't find plugin for '{0}' plugin builder.".FormatString(plugInBuilderType.Name));
            }

            return(type);
        }
Ejemplo n.º 26
0
        public static IQueryable <T> StageOnSqlServer <T>(this IEnumerable <T> items, ChoETLSqlServerSettings sqlServerSettings = null)
            where T : class
        {
            if (typeof(T) == typeof(ExpandoObject) || typeof(T) == typeof(object))
            {
                throw new NotSupportedException();
            }

            Dictionary <string, PropertyInfo> PIDict = ChoType.GetProperties(typeof(T)).ToDictionary(p => p.Name);

            sqlServerSettings = ValidateSettings <T>(sqlServerSettings);
            LoadDataToDb(items, sqlServerSettings, PIDict);

            var ctx   = new ChoETLSqlServerDbContext <T>(sqlServerSettings.ConnectionString);
            var dbSet = ctx.Set <T>();

            return(dbSet);
        }
Ejemplo n.º 27
0
        public virtual string GetParams()
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (Tuple <string, object> tuple in ChoObjectEx.AsDictionary((object)this, false, false))
            {
                if (stringBuilder.Length > 0)
                {
                    stringBuilder.Append(";");
                }
                MemberInfo memberInfo = ChoType.GetMemberInfo(this.GetType(), tuple.Item1);
                if (memberInfo != (MemberInfo)null && ChoType.GetAttribute <BrowsableAttribute>(memberInfo, false) == null)
                {
                    stringBuilder.AppendFormat(ChoStringEx.FormatString("{0}={1}", (object)tuple.Item1, NormalizeString(tuple.Item2 != null ? tuple.Item2.ToString() : string.Empty)));
                }
            }
            return(stringBuilder.ToString());
        }
Ejemplo n.º 28
0
        protected virtual void Init(Type recordType)
        {
            if (recordType == null)
            {
                return;
            }

            _recObject = new Lazy <object>(() => ChoActivator.CreateInstance(RecordType));
            ChoRecordObjectAttribute recObjAttr = ChoType.GetAttribute <ChoRecordObjectAttribute>(recordType);

            if (recObjAttr != null)
            {
                ErrorMode                  = recObjAttr.ErrorMode;
                IgnoreFieldValueMode       = recObjAttr.IgnoreFieldValueMode;
                ThrowAndStopOnMissingField = recObjAttr.ThrowAndStopOnMissingField;
                ObjectValidationMode       = recObjAttr.ObjectValidationMode;
            }
        }
Ejemplo n.º 29
0
        public string GetDescription(string name)
        {
            var m1 = ChoType.GetMembers(GetType()).Where(m => !ChoType.IsReadOnlyMember(m)).FirstOrDefault();

            if (m1 == null)
            {
                return(null);
            }

            if (ChoType.HasMemberAttribute <DescriptionAttribute>(m1))
            {
                return(m1.GetCustomAttribute <DescriptionAttribute>().Description);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 30
0
        public static IQueryable <T> StageOnSQLite <T>(this IEnumerable <T> items, ChoETLSqliteSettings sqliteSettings = null)
            where T : class
        {
            if (typeof(T).IsDynamicType() || typeof(T) == typeof(object))
            {
                throw new NotSupportedException();
            }

            Dictionary <string, PropertyInfo> PIDict = ChoType.GetProperties(typeof(T)).ToDictionary(p => p.Name);

            sqliteSettings = ValidateSettings <T>(sqliteSettings);
            LoadDataToDb(items, sqliteSettings, PIDict);

            var ctx   = new ChoETLSQLiteDbContext <T>(sqliteSettings.DatabaseFilePath);
            var dbSet = ctx.Set <T>();

            return(dbSet);
        }