Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dr"></param>
        /// <param name="del"></param>
        /// <returns></returns>
        public static T CreateItem <T>(DataRow dr, CreateObjectDelegate <T> del)
        {
            T obj = default(T);

            if (dr != null)
            {
                if (del != null)
                {
                    obj = del.Invoke();
                }
                else
                {
                    obj = Activator.CreateInstance <T>();
                }
                if (obj != null)
                {
                    foreach (DataColumn column in dr.Table.Columns)
                    {
                        PropertyInfo prop = obj.GetType().GetProperty(column.ColumnName);
                        if (prop != null)
                        {
                            if (!object.ReferenceEquals(dr[column.ColumnName], DBNull.Value))
                            {
                                prop.SetValue(obj, dr[column.ColumnName], null);
                            }
                            else
                            {
                                prop.SetValue(obj, null, null);
                            }
                        }
                    }
                }
            }
            return(obj);
        }
Ejemplo n.º 2
0
        private long TimeTestCreation(CreateObjectDelegate @delegate, TestObjectMarshall testObject, AppDomain appDomain, string exeAssembly)
        {
            _stopwatch.Reset();
            _stopwatch.Start();

            for (int i = 0; i < _repeatNumber; i++)
            {
                _mbrt = @delegate.Invoke(testObject, appDomain, exeAssembly);
            }

            _stopwatch.Stop();
            return(_stopwatch.ElapsedMilliseconds);
        }
Ejemplo n.º 3
0
        private IInArchive LoadArchiveFile(CreateObjectDelegate createObject, Stream fs, List <ArchiveFormat> lstAF)
        {
            int signatureMaxLength = FormatSetting.FileSignatures.Values.OrderByDescending(v => v.Length).First().Length;

            byte[] signatureBuffer = new byte[signatureMaxLength];
            fs.Position = 0;
            int bytesRead        = fs.Read(signatureBuffer, 0, signatureMaxLength);
            var matchedSignature = FormatSetting.FileSignatures.Where(kv => signatureBuffer.Take(kv.Value.Length).SequenceEqual(kv.Value))
                                   .FirstOrDefault();

            if (matchedSignature.Key != ArchiveFormat.Undefined)
            {
                lstAF.Add(matchedSignature.Key);
            }
            var lstAFTemp = FormatSetting.FormatGuidMapping.Select(x => x.Key).Except(lstAF).ToList();

            lstAF.AddRange(lstAFTemp);
            ulong checkPos = 32 * 1024;

            this.Format = ArchiveFormat.Undefined;
            Guid interfaceId = typeof(IInArchive).GUID;

            foreach (var af in lstAF)
            {
                Guid   classId = FormatSetting.FormatGuidMapping[af];
                object tmp     = null;
                createObject.Invoke(ref classId, ref interfaceId, out tmp);
                IInArchive archive7z = tmp as IInArchive;
                fs.Position = 0;
                try
                {
                    int code = archive7z.Open(new QizFileStream(fs), ref checkPos, null);
                    if (code == 0)
                    {
                        this.Format = af;
                        return(archive7z);
                    }
                    Marshal.ReleaseComObject(archive7z);
                }
                catch (Exception)
                {
                    if (archive7z != null)
                    {
                        Marshal.ReleaseComObject(archive7z);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        private long TimeTestCreation(CreateObjectDelegate @delegate ,TestObjectMarshall  testObject, AppDomain appDomain, string exeAssembly)
        {
            _stopwatch.Reset();
            _stopwatch.Start();

            for (int i = 0; i < _repeatNumber; i++ )
            {
                _mbrt = @delegate.Invoke(testObject, appDomain, exeAssembly);
            }

            _stopwatch.Stop();
            return _stopwatch.ElapsedMilliseconds;
        }