コード例 #1
0
        public void TableMapping_ColumnsCount_Contracts()
        {
            using (var ctx = GetContext())
            {
                var allTypes = new[]
                {
                    typeof(ContractBase),
                    typeof(Contract),
                    typeof(ContractFixed),
                    typeof(ContractStock),
                    typeof(ContractKomb1),
                    typeof(ContractKomb2),
                };

                var mappings = allTypes.ToDictionary(x => x, ctx.Db);


                using (var dataTable = DataTableHelper.Create(mappings, new ContractBase[0]))
                {
                    foreach (DataColumn column in dataTable.Columns)
                    {
                        Console.WriteLine(column.ColumnName);
                    }

                    Assert.AreEqual(34, dataTable.Columns.Count);
                }
            }
        }
コード例 #2
0
        public void CreateDataTableWith1MilRows()
        {
            using (var ctx = GetContext())
            {
                var allTypes = new[]
                {
                    typeof(ContractBase),
                    typeof(Contract),
                    typeof(ContractFixed),
                    typeof(ContractStock),
                    typeof(ContractKomb1),
                    typeof(ContractKomb2),
                };

                var mappings = allTypes.ToDictionary(x => x, ctx.Db);

                var sw = new Stopwatch();
                sw.Start();
                using (var dataTable = DataTableHelper.Create(mappings, GetContracts(1000000)))
                {
                }

                sw.Stop();
                Console.WriteLine(sw.Elapsed.TotalMilliseconds);
            }
        }
コード例 #3
0
    public string GetRootJson()
    {
        EciRequest request = new EciRequest(MESService.MesBdZyLoad);

        request.Type = "GetRoot";

        EciResponse response     = SOA.Execute(request);
        DataTable   dataResponse = response.DataTable;

        DataTable data = DataTableHelper.Create("ID,PARENTID,TEXT,STATE,TAG", 1).DataTable;

        data.Rows[0]["ID"]    = dataResponse.Rows[0]["GUID"];
        data.Rows[0]["TEXT"]  = dataResponse.Rows[0]["NAME"];
        data.Rows[0]["STATE"] = "closed";

        EntityBase entity = data.ToEntity();

        entity.JsonKeyIsLower     = true;
        entity.Attributes         = new EntityBase();
        entity.Attributes["root"] = "true";

        List <EntityBase> list = new List <EntityBase>();

        list.Add(entity);

        string content = list.ToJson(true);

        return(content);
    }
コード例 #4
0
        /*
         * public override void Run<T>(IEnumerable<T> entities, BulkInsertOptions options)
         * {
         *  var baseType = typeof(T);
         *  var allTypes = baseType.GetDerivedTypes(true);
         *
         *  var neededMappings = allTypes.ToDictionary(x => x, x => EfMap.Get(Context)[x]);
         *
         *  using (var dataTable = DataTableHelper.Create(neededMappings, entities))
         *  {
         *      using (var sqlBulkCopy = new SqlBulkCopy(transaction.Connection, options.SqlBulkCopyOptionsValue, transaction))
         *      {
         *          sqlBulkCopy.BatchSize = options.BatchSizeValue;
         *          sqlBulkCopy.BulkCopyTimeout = options.TimeOutValue;
         *          if (options.CallbackMethod != null)
         *          {
         *              sqlBulkCopy.NotifyAfter = options.NotifyAfterValue;
         *              sqlBulkCopy.SqlRowsCopied +=  options.CallbackMethod;
         *          }
         *
         *          sqlBulkCopy.DestinationTableName = dataTable.TableName;
         #if !NET40
         *          sqlBulkCopy.EnableStreaming = options.EnableStreamingValue;
         #endif
         *          foreach (DataColumn col in dataTable.Columns)
         *          {
         *              sqlBulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
         *          }
         *
         *          sqlBulkCopy.WriteToServer(dataTable);
         *      }
         *  }
         * }
         */

        public override void Run <T>(IEnumerable <T> entities, SqlTransaction transaction, SqlBulkCopyOptions options, int batchSize)
        {
            var baseType = typeof(T);
            var allTypes = baseType.GetDerivedTypes(true);

            var neededMappings = allTypes.ToDictionary(x => x, x => Context.Db(x));

            using (var dataTable = DataTableHelper.Create(neededMappings, entities))
            {
                using (var sqlBulkCopy = new SqlBulkCopy(transaction.Connection, options, transaction))
                {
                    sqlBulkCopy.BatchSize            = batchSize;
                    sqlBulkCopy.DestinationTableName = dataTable.TableName;
#if !NET40
                    //sqlBulkCopy.EnableStreaming = true;
#endif

                    foreach (DataColumn col in dataTable.Columns)
                    {
                        sqlBulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
                    }

                    sqlBulkCopy.WriteToServer(dataTable);

                    /*
                     * // if there are any reference objects
                     * if (tableMapping.Relations.Length > 0)
                     * {
                     *  // can be done only with identity columns
                     *  var identityColumn = tableMapping.Columns.FirstOrDefault(x => x.IsIdentity);
                     *  if (identityColumn != null)
                     *  {
                     *      var command = transaction.Connection.CreateCommand();
                     *      command.CommandText = "SELECT max(" + identityColumn.ColumnName + ") from " + dataTable.TableName;
                     *      command.Transaction = transaction;
                     *
                     *      var res = command.ExecuteScalar();
                     *      var lastId = long.Parse(res.ToString());
                     *      var firstId = lastId - dataTable.Rows.Count + 1;
                     *
                     *
                     *
                     *  }
                     * }
                     */
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets a DataTable from a entity collection.
        /// </summary>
        private DataTable GetDataTable(ICollection <T> entityCollection)
        {
            string tableName = GetTableName <T>();
            Dictionary <string, Type> columns = new Dictionary <string, Type>();
            ICollection <object[]>    rows    = new List <object[]>();

            ICollection <PropertyInfo> properties = typeof(T).GetProperties();

            foreach (PropertyInfo propertyInfo in properties)
            {
                columns.Add(GetColumnName(propertyInfo), GetColumnType(propertyInfo));
            }

            foreach (T entity in entityCollection)
            {
                rows.Add(properties.Select(property => property.GetValue(entity, null)).ToArray());
            }

            return(DataTableHelper.Create(tableName, columns, rows));
        }
コード例 #6
0
        public void TableMapping_ColumnsCount_TableWithComplexType()
        {
            using (var ctx = new TestContext())
            {
                var tableMapping = ctx.Db <TestUser>();

                var user = new TestUser
                {
                    FirstName = "fn",
                    LastName  = "ln",
                    Contact   =
                        new Contact
                    {
                        PhoneNumber = "123456",
                        Address     =
                            new Address
                        {
                            City       = "Tallinn",
                            Country    = "Estonia",
                            County     = "Harju",
                            PostalCode = "-"
                        }
                    }
                };

                Console.WriteLine("TestUser table should contain 8 columns");
                var mappings = new Dictionary <Type, IEntityMap> {
                    { typeof(TestUser), tableMapping }
                };
                using (var dataTable = DataTableHelper.Create(mappings, new[] { user }))
                {
                    foreach (DataColumn column in dataTable.Columns)
                    {
                        Console.WriteLine(column.ColumnName);
                    }

                    Assert.AreEqual(8, dataTable.Columns.Count);
                }
            }
        }
コード例 #7
0
        String ExecuteQuery(String schema)
        {
            InvokeResultDescriptor result = new InvokeResultDescriptor();
            String res = String.Empty;

            try
            {
                String       sessionId = String.Empty;
                MdxQueryArgs args      = XmlSerializationUtility.XmlStr2Obj <MdxQueryArgs>(schema);
                if (args != null)
                {
                    sessionId = args.SessionId;
                    DefaultQueryExecuter queryExecuter = new DefaultQueryExecuter(GetConnection(args.Connection));
                    if (args.Queries.Count > 0)
                    {
                        result.ContentType = InvokeContentType.MultidimData;

                        switch (args.Type)
                        {
                        case QueryTypes.Update:
                        case QueryTypes.CommitTransaction:
                        case QueryTypes.RollbackTransaction:
                            List <String> results = new List <String>();
                            result.ContentType = InvokeContentType.UpdateResult;
                            foreach (var query in args.Queries)
                            {
                                try
                                {
                                    // Method return a value of one (1).
                                    queryExecuter.ExecuteNonQuery(query, ref sessionId);
                                    results.Add(String.Empty);
                                }
                                catch (AdomdConnectionException connection_ex)
                                {
                                    results.Add(connection_ex.Message);
                                }
                                catch (AdomdErrorResponseException response_ex)
                                {
                                    results.Add(response_ex.Message);
                                }
                                catch (AdomdUnknownResponseException unknown_ex)
                                {
                                    results.Add(unknown_ex.Message);
                                }
                                catch (InvalidOperationException invalid_ex)
                                {
                                    results.Add(invalid_ex.Message);
                                }
                            }
                            res = XmlSerializationUtility.Obj2XmlStr(results, Common.Namespace);
                            break;

                        case QueryTypes.Select:
                            try
                            {
                                res = queryExecuter.GetCellSetDescription(args.Queries[0], ref sessionId);
                            }
                            catch (AdomdConnectionException connection_ex)
                            {
                                res = connection_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdErrorResponseException response_ex)
                            {
                                res = response_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdUnknownResponseException unknown_ex)
                            {
                                res = unknown_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (InvalidOperationException invalid_ex)
                            {
                                res = invalid_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            break;

                        case QueryTypes.DrillThrough:
                            try
                            {
                                var table = queryExecuter.ExecuteReader(args.Queries[0], ref sessionId);
                                if (table != null)
                                {
                                    res = XmlSerializationUtility.Obj2XmlStr(DataTableHelper.Create(table));
                                }
                            }
                            catch (AdomdConnectionException connection_ex)
                            {
                                res = connection_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdErrorResponseException response_ex)
                            {
                                res = response_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (AdomdUnknownResponseException unknown_ex)
                            {
                                res = unknown_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            catch (InvalidOperationException invalid_ex)
                            {
                                res = invalid_ex.Message;
                                result.ContentType = InvokeContentType.Error;
                            }
                            break;
                        }
                    }
                }
                result.Content = res;
                System.Diagnostics.Debug.WriteLine("CellSetData size: " + res.Length);

                if (UseCompress)
                {
                    DateTime start = DateTime.Now;
                    // Архивация строки
                    String compesed = ZipCompressor.CompressAndConvertToBase64String(res);
                    System.Diagnostics.Debug.WriteLine("CellSetData compression time: " + (DateTime.Now - start).ToString());
                    System.Diagnostics.Debug.WriteLine("CellSetData compressed size: " + compesed.Length);

                    result.Content   = compesed;
                    result.IsArchive = true;
                }

                result.Headers.Add(new Header(InvokeResultDescriptor.SESSION_ID, sessionId));
                result.Headers.Add(new Header(InvokeResultDescriptor.CONNECTION_ID, args.Connection));
            }
            catch (Exception ex)
            {
                throw;
            }
            return(InvokeResultDescriptor.Serialize(result));
        }
コード例 #8
0
        private DataTable CreateDataTable()
        {
            DataTable dt = DataTableHelper.Create("标题", "页面地址", "下载地址", "文件名", "图片", "观看次数", "评分", "错误信息");

            return(dt);
        }