コード例 #1
0
ファイル: SyncUtil.cs プロジェクト: weedkiller/CrmSync
        internal static bool OpenConnection(IDbConnection connection)
        {
            SyncExpt.CheckArgumentNull((object)connection, "connection");
            bool flag = false;

            switch (connection.State)
            {
            case ConnectionState.Closed:
                if (SyncTracer.IsVerboseEnabled())
                {
                    if (connection is SqlConnection)
                    {
                        SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder();
                        connectionStringBuilder.ConnectionString = connection.ConnectionString;
                        if (!string.IsNullOrEmpty(connectionStringBuilder.Password))
                        {
                            connectionStringBuilder.Password = "******";
                        }
                        SyncTracer.Verbose("Connecting using string: {0}", new object[1]
                        {
                            (object)connectionStringBuilder.ConnectionString
                        });
                    }
                    else
                    {
                        SyncTracer.Verbose("Connecting to database: {0}", new object[1]
                        {
                            (object)connection.Database
                        });
                    }
                }
                if (connection is SqlConnection || connection is IConnectionWrapper)
                {
                    SyncUtil.TryOpenConnection(connection);
                }
                else
                {
                    connection.Open();
                }
                flag = true;
                goto case ConnectionState.Open;

            case ConnectionState.Open:
                return(flag);

            case ConnectionState.Broken:
                SyncTracer.Verbose("Closing broken connection");
                connection.Close();
                goto case ConnectionState.Closed;

            default:
                throw new DbSyncException(SyncResource.FormatString("UnhandledConnectionState", new object[1]
                {
                    (object)((object)connection.State).ToString()
                }));
            }
        }
コード例 #2
0
ファイル: TestSyncAdapter.cs プロジェクト: weedkiller/CrmSync
 internal void MapFromClientToServer(DataTable dataTable)
 {
     SyncExpt.CheckArgumentNull((object)dataTable, "dataTable");
     if (this.ColumnMappings == null)
     {
         return;
     }
     foreach (DataColumn dataColumn in (InternalDataCollectionBase)dataTable.Columns)
     {
         int index = this.ColumnMappings.IndexOfClientColumn(dataColumn.ColumnName);
         if (index >= 0)
         {
             dataColumn.ColumnName = this.ColumnMappings[index].ServerColumn;
         }
     }
 }
コード例 #3
0
ファイル: TestSyncAdapter.cs プロジェクト: weedkiller/CrmSync
        /// <summary>
        /// Populates the schema information for the table that is specified in <see cref="P:Microsoft.Synchronization.Data.Server.SyncAdapter.TableName"/>.
        /// </summary>
        ///
        /// <returns>
        /// A <see cref="T:System.Data.DataTable"/> that contains the schema information.
        /// </returns>
        /// <param name="dataTable">The <see cref="T:System.Data.DataTable"/> to be populated with schema information.</param><param name="connection">An <see cref="T:System.Data.IDbConnection"/> object that is used to connect to the server database.</param><exception cref="T:System.ArgumentNullException"><paramref name="connection"/> is a null.</exception><exception cref="T:Microsoft.Synchronization.Data.SchemaException"><see cref="P:Microsoft.Synchronization.Data.Server.SyncAdapter.SelectIncrementalInsertsCommand"/> or <see cref="P:Microsoft.Synchronization.Data.Server.SyncAdapter.SelectIncrementalUpdatesCommand"/>  is a null, or the schema could not be retrieved.</exception>
        public DataTable FillSchema(DataTable dataTable, IDbConnection connection)
        {
            SyncExpt.CheckArgumentNull((object)connection, "connection");
            bool flag = SyncUtil.OpenConnection(connection);

            if (this.SelectIncrementalInsertsCommand == null && this.SelectIncrementalUpdatesCommand == null)
            {
                throw SyncExpt.MissingSelectStatementError(this.TableName, "ServerSyncProvider", "http://www.microsoft.com/sql/");
            }
            IDbCommand cmd = this.SelectIncrementalInsertsCommand == null ? this.SelectIncrementalUpdatesCommand : this.SelectIncrementalInsertsCommand;

            SetDummySessionParameters(cmd);
            cmd.Connection = connection;
            SyncDbAdapter syncDbAdapter = new SyncDbAdapter();

            syncDbAdapter.SelectCommand = (DbCommand)cmd;
            if (dataTable == null)
            {
                dataTable        = new DataTable();
                dataTable.Locale = CultureInfo.InvariantCulture;
            }
            syncDbAdapter.FillSchema(dataTable, SchemaType.Source);
            IDataReader dataReader = cmd.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);

            try
            {
                DataTable schemaTable = dataReader.GetSchemaTable();
                if (schemaTable == null)
                {
                    throw SyncExpt.FillSchemaError(dataTable.TableName, "ServerSyncProvider", "http://www.microsoft.com/sql/", (Exception)null);
                }
                if (schemaTable.Columns.Contains("DataTypeName"))
                {
                    foreach (DataRow dataRow in (InternalDataCollectionBase)schemaTable.Rows)
                    {
                        string name = (string)dataRow["ColumnName"];
                        if (dataTable.Columns.Contains(name))
                        {
                            DataColumn column = dataTable.Columns[name];
                            if (column != null)
                            {
                                object obj1 = dataRow["DataTypeName"];
                                if (obj1 != null)
                                {
                                    SetDataColumnExtendedProperty(column, "DataTypeName", (object)obj1.ToString());
                                }
                                if (column.DataType.Equals(Type.GetType("System.Decimal")))
                                {
                                    object obj2 = dataRow["NumericPrecision"];
                                    if (obj2 != null)
                                    {
                                        SetDataColumnExtendedProperty(column, "NumericPrecision", obj2);
                                    }
                                    object obj3 = dataRow["NumericScale"];
                                    if (obj3 != null)
                                    {
                                        SetDataColumnExtendedProperty(column, "NumericScale", obj3);
                                    }
                                }
                                object obj4 = dataRow["ColumnSize"];
                                if (obj4 != null)
                                {
                                    if ((int.MaxValue == (int)obj4 || 1073741823 == (int)obj4) && (column.DataType.Equals(Type.GetType("System.String")) || column.DataType.Equals(Type.GetType("System.Byte[]"))))
                                    {
                                        SetDataColumnExtendedProperty(column, "ColumnLength", (object)-1);
                                    }
                                    else
                                    {
                                        SetDataColumnExtendedProperty(column, "ColumnLength", obj4);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (DbException ex)
            {
                throw SyncExpt.FillSchemaError(dataTable.TableName, "ServerSyncProvider", "http://www.microsoft.com/sql/", (Exception)ex);
            }
            finally
            {
                dataReader.Close();
            }
            if (flag)
            {
                connection.Close();
            }
            this.MapFromServerToClient(dataTable);
            return(dataTable);
        }