Provides by-name member-access to objects of a given type
        /// <summary>
        /// Create new SQL Script generetor
        /// </summary>
        /// <param name="tableName">Table name to insert data</param>
        /// <param name="typeAccessor">TypeAccessor to access record value</param>
        /// <param name="listColumnName">List column name</param>
        /// <param name="listColumnType">List column type</param>
        public SQLScriptGenerator(string tableName, TypeAccessor typeAccessor, List<ColumnInformation> listColumnInformation)
        {
            //
            // Set control value
            this._tableName = tableName;
            this._typeAccessor = typeAccessor;
            this._listColumnInformation = listColumnInformation;

            //
            // Set value for insert template
            this.UpdateTableNameToTemplate(tableName);
            this.UpdateListColumnToTemplate(listColumnInformation);
        }
 /// <summary>
 /// Create new orphan record validation thread
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="dbContext"></param>
 public OrphanRecordValidationThread(OrphanRecordValidationThreadManager manager,
                                     DbContext dbContext,
                                     string tableName,
                                     TypeAccessor typeAccessor,
                                     List<ReferenceInformation> listReference)
 {
     this._manager = manager;
     this._dbContext = dbContext;
     this._tableName = tableName;
     this._typeAccessor = typeAccessor;
     this._listReferences = listReference;
     this._isDone = false;
 }
        public Wrapper(object value)
        {
            _value   = value;
            Accessor = TypeAccessor.Create(value.GetType());

            var atts = value.GetType().GetProperties().SelectMany(p => p.CustomAttributes).SelectMany(g => g.NamedArguments).Where(c => c.MemberName == "Name")
                       .Select(v => v.TypedValue.Value.ToString());

            Map = value.GetType().GetProperties()
                  .Select(x => new
            {
                Name = x.Name, Att = x.CustomAttributes.SelectMany(v => v.NamedArguments).Where(c => c.MemberName == "Name").Select(v => v.TypedValue.Value.ToString()).FirstOrDefault()
            })
                  .ToDictionary(key => key.Name, val => val.Att ?? val.Name);

            if (!Map.ContainsKey("@id"))
            {
                Map.Add("@id", "@id");
            }

            if (!Map.ContainsKey("@context"))
            {
                Map.Add("@context", "@context");
            }

            if (!Map.ContainsKey("@type"))
            {
                Map.Add("@type", "@type");
            }

//            Map = Map.Concat(GetType().GetProperties()
//                .Select(x => new
//                {
//                    Name = x.Name, Att = x.CustomAttributes.SelectMany(v => v.NamedArguments).Where(c => c.MemberName == "Name").Select(v => v.TypedValue.Value.ToString()).FirstOrDefault()
//                })
//                .ToDictionary(key => key.Name, val => val.Att ?? val.Name)).ToDictionary(x => x.Key, x => x.Value);


            var others = value.GetType().GetProperties().Where(x => x.CustomAttributes.All(y => y.AttributeType != typeof(DataMemberAttribute))).Select(c => c.Name);

            var thisatts = GetType().GetProperties().SelectMany(p => p.CustomAttributes).SelectMany(g => g.NamedArguments).Where(c => c.MemberName == "Name")
                           .Select(v => v.TypedValue.Value.ToString());

            MemberNames = atts.Concat(others).Concat(thisatts).ToArray();

            MemberNames = Accessor.GetMembers().Select(a => a.Name).Concat(GetType().GetProperties().Select(p => p.Name)).ToArray();

            MemberNames = Map.Values.Select(x => x).ToArray();
        }
 public TypeAccessorWrapper(object target, TypeAccessor accessor)
 {
     this.target = target;
     this.accessor = accessor;
 }
        /// <summary>
        /// Start insert thread
        /// </summary>
        /// <param name="tasks"></param>
        /// <param name="entityType"></param>
        public void Insert(string tableName, List<ColumnInformation> listColumnInformation, TypeAccessor typeAccessor)
        {
            this._isDone = false;
            this._listTasks = new List<object>();
            this._tableName = tableName;
            this._listColumnInformation = listColumnInformation;
            this._typeAccessor = typeAccessor;

            //
            // Try to start SQL thread
            try
            {
                this._thread = new Thread(ThreadInsert);
                this._thread.Start();
            }
            catch (Exception excStartSQLThread)
            {
                LogService.Log.Error("Can not create new SQL Thread.", excStartSQLThread);
                this._isDone = true;
            }
        }
        /// <summary>
        /// Generate SQL script to insert
        /// </summary>
        /// <param name="listOfTasks">List of record need to be generated insert script</param>
        /// <param name="tableName">Table name</param>
        /// <param name="typeAccessor">Type accessor to access column value</param>
        /// <param name="listColumnInformation">Store column infomration of table</param>
        /// <param name="filePath">File path to store sql script</param>
        public void Insert(List<object> listOfTasks, string tableName, TypeAccessor typeAccessor, List<ColumnInformation> listColumnInformation, string filePath)
        {
            //
            // Initialize
            this._listOfTasks = listOfTasks;
            this._numberOfTasks = this._listOfTasks.Count;
            this._currentIndex = 0;
            if (this._numberOfTasks == 0)
            {
                //
                // Create dump file
                try
                {
                    StreamWriter writer = new StreamWriter(filePath);
                    writer.Close();
                }
                catch (Exception excCreateDumpFile)
                {
                    LogService.Log.Error("Can not create dump file to map " + tableName, excCreateDumpFile);
                }
                return;
            }

            //
            // Okay, calculate, how many thread do we need ?
            int numberOfThreads = this._maxThread;
            if (this._numberOfTasks < numberOfThreads * this._minTaskForThread)
            {
                numberOfThreads = this._numberOfTasks / this._minTaskForThread;
                if (numberOfThreads == 0)
                {
                    numberOfThreads = 1;
                }
            }

            //
            // Create thread
            LogService.Log.Info("Creating " + numberOfThreads.ToString() + " SQL threads to insert data.");
            this._listSQLThread = new List<SQLThread>();
            for (int counter = 0; counter < numberOfThreads; ++counter)
            {
                SQLThread sqlThread = new SQLThread(this, true);
                this._listSQLThread.Add(sqlThread);
                sqlThread.Insert(tableName, listColumnInformation, typeAccessor);
            }

            //
            // Wait until done
            bool isDone = false;
            while (isDone == false)
            {
                isDone = true;
                foreach (SQLThread sqlThread in this._listSQLThread)
                {
                    if (sqlThread.IsDone == false)
                    {
                        isDone = false;
                        break;
                    }
                }
            }

            //
            // Write sql script to file
            this.WriteSQLScript(tableName, filePath);
        }
        /// <summary>
        /// Generate SQL script to insert
        /// </summary>
        /// <param name="listOfTasks">List of record need to be generated insert script</param>
        /// <param name="tableName">Table name</param>
        /// <param name="typeAccessor">Type accessor to access column value</param>
        /// <param name="listColumnInformation">Store column infomration of table</param>
        public void Insert(List<object> listOfTasks, string tableName, TypeAccessor typeAccessor, List<ColumnInformation> listColumnInformation)
        {
            //
            // Initialize
            this._listOfTasks = listOfTasks;
            this._numberOfTasks = this._listOfTasks.Count;
            this._currentIndex = 0;
            if (this._numberOfTasks == 0)
            {
                return;
            }

            //
            // Okay, calculate, how many thread do we need ?
            int numberOfThreads = this._maxThread;
            if (this._numberOfTasks < numberOfThreads * this._minTaskForThread)
            {
                numberOfThreads = this._numberOfTasks / this._minTaskForThread;
                if (numberOfThreads == 0)
                {
                    numberOfThreads = 1;
                }
            }

            //
            /// Tempory disable trigger
            this._destinationDatabase.GetNewDbContext().Database.ExecuteSqlCommand("ALTER TABLE " + tableName + " DISABLE TRIGGER ALL");

            //
            // Create thread
            LogService.Log.Info("Creating " + numberOfThreads.ToString() + " SQL threads to insert data.");
            this._listSQLThread = new List<SQLThread>();
            for (int counter = 0; counter < numberOfThreads; ++counter)
            {
                SQLThread sqlThread = new SQLThread(this, false);
                this._listSQLThread.Add(sqlThread);
                sqlThread.Insert(tableName, listColumnInformation, typeAccessor);
            }

            //
            // Wait until done
            bool isDone = false;
            while (isDone == false)
            {
                isDone = true;
                foreach(SQLThread sqlThread in this._listSQLThread)
                {
                    if (sqlThread.IsDone == false)
                    {
                        isDone = false;
                        break;
                    }
                }
            }

            //
            // Turn on trigger
            this._destinationDatabase.GetNewDbContext().Database.ExecuteSqlCommand("ALTER TABLE " + tableName + " ENABLE TRIGGER ALL");
        }
Beispiel #8
0
 public TypeAccessorWrapper(object target, TypeAccessor accessor)
 {
     this.target   = target;
     this.accessor = accessor;
 }
Beispiel #9
0
        private string GetCsvValue(PropertyInfo info, TypeAccessor accessor)
        {
            Type propertyType = info.PropertyType;
            if (propertyType == typeof (string))
            {
                string value = (string) accessor[this, info.Name];
                if (!string.IsNullOrEmpty(value)) return string.Format("\"{0}\"", PrepareCsvValue(value));
            }

            if (propertyType == typeof (DateTime))
                return string.Format("\"{0}\"", GetDate((DateTime)accessor[this, info.Name]));
            if (propertyType == typeof(DateTime?))
                return string.Format("\"{0}\"", GetNullableDate((DateTime?)accessor[this, info.Name]));

            return string.Format("{0}", accessor[this, info.Name]);
        }
Beispiel #10
0
            public void Setup()
            {
                obj = new FastMemberPerformance();
                dlr = obj;
                prop = typeof(FastMemberPerformance).GetProperty("Value");
                descriptor = TypeDescriptor.GetProperties(obj)["Value"];

                // FastMember specific code
                accessor = FastMember.TypeAccessor.Create(typeof(FastMemberPerformance));
                wrapped = FastMember.ObjectAccessor.Create(obj);

                type = typeof(FastMemberPerformance);
            }