示例#1
0
        internal void Validate(int index, SyncColumnMapping item)
        {
            if (item == null)
            {
                throw SyncExpt.ArgumentNull("item");
            }
            if (item.Parent != null && this != item.Parent)
            {
                throw SyncExpt.Argument("", "item.Parent");
            }
            string serverColumn1 = item.ServerColumn;

            if (SyncUtil.IsEmpty(serverColumn1))
            {
                index = 1;
                string serverColumn2;
                do
                {
                    serverColumn2 = "ServerColumn" + index.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                    ++index;
                }while (-1 != this.IndexOfServerColumn(serverColumn2));
                item.ServerColumn = serverColumn2;
            }
            else
            {
                this.ValidateServerColumn(index, serverColumn1);
            }
            string clientColumn = item.ClientColumn;

            this.ValidateClientColumn(index, clientColumn);
        }
示例#2
0
        internal static long GetRowSizeForObjectCollection(SyncUtil.ObjectCollection row)
        {
            long num = 0L;

            foreach (object obj in row.EnumColumns())
            {
                string s        = obj as string;
                byte[] numArray = obj as byte[];
                if (obj == null)
                {
                    ++num;
                }
                else if (obj is Guid)
                {
                    num += 16L;
                }
                else if (s != null)
                {
                    num += (long)Encoding.Unicode.GetByteCount(s);
                }
                else if (numArray != null)
                {
                    num += (long)numArray.Length;
                }
                else
                {
                    num += SyncUtil.GetSizeForType(obj.GetType());
                }
            }
            return(num);
        }
示例#3
0
        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()
                }));
            }
        }
示例#4
0
        internal static bool CompareColumnNames(string quotePrefix, string quoteSuffix, string col1, string col2)
        {
            string unquotedString1;

            SyncUtil.RemoveStringQuotes(quotePrefix, quoteSuffix, col1, out unquotedString1);
            string unquotedString2;

            SyncUtil.RemoveStringQuotes(quotePrefix, quoteSuffix, col2, out unquotedString2);
            return(string.Compare(unquotedString1, unquotedString2, StringComparison.Ordinal) == 0);
        }
示例#5
0
        internal static void SetParameterValue(IDbCommand command, string parameterName, object value)
        {
            DbParameter parameter = SyncUtil.GetParameter(command, parameterName);

            if (parameter == null)
            {
                return;
            }
            parameter.Value = value;
        }
示例#6
0
 internal static bool ParseKeyZeroIfNull(object obj, out uint key)
 {
     key = 0U;
     if (obj is DBNull)
     {
         return(true);
     }
     else
     {
         return(SyncUtil.ParseKey(obj, out key));
     }
 }
示例#7
0
 internal static bool ParseTimestampZeroIfNull(object obj, out ulong timestamp)
 {
     timestamp = 0UL;
     if (obj is DBNull)
     {
         return(true);
     }
     else
     {
         return(SyncUtil.ParseTimestamp(obj, out timestamp));
     }
 }
示例#8
0
        internal static int GetSyncIntOutParameter(string parameter, IDbCommand command, out bool found)
        {
            found = true;
            DbParameter parameter1 = SyncUtil.GetParameter(command, parameter);

            if (parameter1 != null && parameter1.Value != null && !string.IsNullOrEmpty(parameter1.Value.ToString()))
            {
                return(int.Parse(parameter1.Value.ToString(), (IFormatProvider)CultureInfo.InvariantCulture));
            }
            found = false;
            return(0);
        }
示例#9
0
        //internal static IDataReader ExecuteDataReader(IDbCommand command, bool closeConnection, CommandFailureInjector.InjectCommandFailure injectCommandFailure, CommandFailureInjector.InjectCommandFailureRetryResponse failurecommandResponse)
        //{
        //    IDataReader dataReader = (IDataReader)null;
        //    for (int retryAttempts = 0; retryAttempts < 6; ++retryAttempts)
        //    {
        //        try
        //        {
        //            if (injectCommandFailure != null)
        //                injectCommandFailure();
        //            if (retryAttempts > 0)
        //            {
        //                SyncTracer.Info("Retrying SyncUtil.ExecuteDataReader, attempt {0} of {1}.", new object[2]
        //    {
        //      (object) retryAttempts,
        //      (object) 5
        //    });
        //                SyncUtil.OpenConnection(command.Connection);
        //            }
        //            dataReader = !closeConnection ? command.ExecuteReader() : command.ExecuteReader(CommandBehavior.CloseConnection);
        //            if (failurecommandResponse != null)
        //                failurecommandResponse(retryAttempts);
        //            return dataReader;
        //        }
        //        catch (DbException ex)
        //        {
        //            if (retryAttempts == 5)
        //            {
        //                SyncTracer.Error("Retrying SyncUtil.ExecuteDataReader failed after max retry attempts, due to exception: {0}", new object[1]
        //    {
        //      (object) ex.Message
        //    });
        //                throw;
        //            }
        //            else
        //            {
        //                SyncTracer.Warning("SyncUtil.ExecuteDataReader failed on attempt {0} of {1}, due to retryable exception: {2}", (object)retryAttempts, (object)5, (object)ex.Message);
        //                Thread.Sleep(100 * (int)Math.Pow(2.0, (double)retryAttempts));
        //            }
        //        }
        //    }
        //    return dataReader;
        //}

        internal static object GetSyncObjectOutParameter(string parameter, IDbCommand command, out bool found)
        {
            found = true;
            DbParameter parameter1 = SyncUtil.GetParameter(command, parameter);

            if (parameter1 != null)
            {
                return(parameter1.Value);
            }
            found = false;
            return((object)null);
        }
示例#10
0
 internal static void TryOpenConnection(IDbConnection connection)
 {
     for (int index = 0; index < 6; ++index)
     {
         try
         {
             if (index > 0)
             {
                 SyncTracer.Info("Retrying opening connection, attempt {0} of {1}.", new object[2]
                 {
                     (object)index,
                     (object)5
                 });
             }
             connection.Open();
             SqlConnection connection1 = connection as SqlConnection;
             if (connection1 == null)
             {
                 break;
             }
             using (SqlCommand sqlCommand = new SqlCommand("Select 1", connection1))
             {
                 sqlCommand.ExecuteScalar();
                 break;
             }
         }
         catch (SqlException ex)
         {
             if (index == 5)
             {
                 SyncTracer.Error("Open connection failed after max retry attempts, due to exception: {0}", new object[1]
                 {
                     (object)ex.Message
                 });
                 throw;
             }
             else if (!SyncUtil.RetryLitmus(ex))
             {
                 SyncTracer.Error("Open connection failed on attempt {0} of {1}, due to unretryable exception: {2}", (object)(index + 1), (object)5, (object)ex.Message);
                 throw;
             }
             else
             {
                 SyncTracer.Warning("Open connection failed on attempt {0} of {1}, due to retryable exception: {2}", (object)(index + 1), (object)5, (object)ex.Message);
                 Thread.Sleep(100 * (int)Math.Pow(2.0, (double)index));
             }
         }
     }
 }
示例#11
0
 /// <summary>
 /// Searches for a <see cref="T:Microsoft.Synchronization.Data.Server.SyncColumnMapping"/> object when given a column name, and returns the zero-based index of the first occurrence within the entire collection.
 /// </summary>
 ///
 /// <returns>
 /// The index position of <paramref name="clientColumn"/> if that string is found; otherwise -1 if it is not.
 /// </returns>
 /// <param name="clientColumn">The name of the column at the client for which to get the index in the <see cref="T:Microsoft.Synchronization.Data.Server.SyncColumnMappingCollection"/>.</param>
 public int IndexOfClientColumn(string clientColumn)
 {
     if (!SyncUtil.IsEmpty(clientColumn))
     {
         int count = this.Count;
         for (int index = 0; index < count; ++index)
         {
             if (clientColumn == this.Items[index].ClientColumn)
             {
                 return(index);
             }
         }
     }
     return(-1);
 }
示例#12
0
 /// <summary>
 /// Searches for a <see cref="T:Microsoft.Synchronization.Data.Server.SyncColumnMapping"/> object when given a column name. Returns the zero-based index of the first occurrence within the entire collection.
 /// </summary>
 ///
 /// <returns>
 /// The index position of <paramref name="serverColumn"/> if that string is found. Returns -1 if the string is not found.
 /// </returns>
 /// <param name="serverColumn">The name of the column at the server for which to get the index in the <see cref="T:Microsoft.Synchronization.Data.Server.SyncColumnMappingCollection"/>.</param>
 public int IndexOfServerColumn(string serverColumn)
 {
     if (!SyncUtil.IsEmpty(serverColumn))
     {
         int count = this.Count;
         for (int index = 0; index < count; ++index)
         {
             if (serverColumn == this.Items[index].ServerColumn)
             {
                 return(index);
             }
         }
     }
     return(-1);
 }
示例#13
0
        internal static bool VerifyKnowledgeKeyMapCompatibility(SyncKnowledge knowledgeA, SyncKnowledge knowledgeB)
        {
            bool          flag           = true;
            ReplicaKeyMap replicaKeyMap1 = knowledgeA.ReplicaKeyMap;
            ReplicaKeyMap replicaKeyMap2 = knowledgeB.ReplicaKeyMap;
            SyncId        syncId1;
            SyncId        syncId2;

            for (uint key = 0U; SyncUtil.TryGetReplicaId(replicaKeyMap1, key, out syncId1) && SyncUtil.TryGetReplicaId(replicaKeyMap2, key, out syncId2); ++key)
            {
                if (syncId1 != syncId2)
                {
                    flag = false;
                    break;
                }
            }
            return(flag);
        }
示例#14
0
        internal static void BuildSchemaTableInfoTableNames(string[] columnNameArray)
        {
            Dictionary <string, int> hash = new Dictionary <string, int>(columnNameArray.Length);
            int val1 = columnNameArray.Length;

            for (int index = columnNameArray.Length - 1; 0 <= index; --index)
            {
                string str = columnNameArray[index];
                if (str != null && 0 < str.Length)
                {
                    string key = str.ToLower(CultureInfo.InvariantCulture);
                    int    val2;
                    if (hash.TryGetValue(key, out val2))
                    {
                        val1 = Math.Min(val1, val2);
                    }
                    hash[key] = index;
                }
                else
                {
                    columnNameArray[index] = "";
                    val1 = index;
                }
            }
            int uniqueIndex = 1;

            for (int index1 = val1; index1 < columnNameArray.Length; ++index1)
            {
                string str = columnNameArray[index1];
                if (str.Length == 0)
                {
                    columnNameArray[index1] = "Column";
                    uniqueIndex             = SyncUtil.GenerateUniqueName(hash, ref columnNameArray[index1], index1, uniqueIndex);
                }
                else
                {
                    string index2 = str.ToLower(CultureInfo.InvariantCulture);
                    if (index1 != hash[index2])
                    {
                        SyncUtil.GenerateUniqueName(hash, ref columnNameArray[index1], index1, 1);
                    }
                }
            }
        }
示例#15
0
        internal static string BuildQuotedString(string quotePrefix, string quoteSuffix, string unQuotedString)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (!SyncUtil.IsEmpty(quotePrefix))
            {
                stringBuilder.Append(quotePrefix);
            }
            if (!SyncUtil.IsEmpty(quoteSuffix))
            {
                stringBuilder.Append(unQuotedString.Replace(quoteSuffix, quoteSuffix + quoteSuffix));
                stringBuilder.Append(quoteSuffix);
            }
            else
            {
                stringBuilder.Append(unQuotedString);
            }
            return(((object)stringBuilder).ToString());
        }
示例#16
0
        //internal static long GetRowSizeFromReader(IDataReader reader, DbDataReaderHandler readerHandler)
        //{
        //    long num = 0L;
        //    for (int i = 0; i < reader.FieldCount; ++i)
        //    {
        //        if (!readerHandler.IsTombstone || readerHandler.IdAndMetadataColumns[i])
        //        {
        //            Type fieldType = reader.GetFieldType(i);
        //            if (reader.IsDBNull(i))
        //                num += 5L;
        //            else if (fieldType == typeof(Guid))
        //                num += 16L;
        //            else if (fieldType == typeof(byte[]))
        //                num += reader.GetBytes(i, 0L, (byte[])null, 0, 0);
        //            else if (fieldType == typeof(string))
        //                num += reader.GetChars(i, 0L, (char[])null, 0, 0) * 2L;
        //            else
        //                num += SyncUtil.GetSizeForType(fieldType);
        //        }
        //    }
        //    return num;
        //}

        internal static long GetRowSizeFromDataRow(DataRow row)
        {
            bool flag = false;

            if (row.RowState == DataRowState.Deleted)
            {
                row.RejectChanges();
                flag = true;
            }
            long num = 0L;

            foreach (object obj in row.ItemArray)
            {
                string s        = obj as string;
                byte[] numArray = obj as byte[];
                if (obj is DBNull)
                {
                    num += 5L;
                }
                else if (obj is Guid)
                {
                    num += 16L;
                }
                else if (s != null)
                {
                    num += (long)Encoding.Unicode.GetByteCount(s);
                }
                else if (numArray != null)
                {
                    num += (long)numArray.Length;
                }
                else
                {
                    num += SyncUtil.GetSizeForType(obj.GetType());
                }
            }
            if (flag)
            {
                row.Delete();
            }
            return(num);
        }
示例#17
0
 internal static void ExecuteNonQueryWithNewTransaction(IDbCommand command)
 {
     for (int index = 0; index < 6; ++index)
     {
         try
         {
             if (index > 0)
             {
                 SyncTracer.Info("Retrying SyncUtil.ExecuteNonQueryWithNewTransaction, attempt {0} of {1}.", new object[2]
                 {
                     (object)index,
                     (object)5
                 });
                 SyncUtil.OpenConnection(command.Connection);
             }
             using (IDbTransaction dbTransaction = command.Connection.BeginTransaction())
             {
                 command.Transaction = dbTransaction;
                 command.ExecuteNonQuery();
                 dbTransaction.Commit();
                 break;
             }
         }
         catch (DbException ex)
         {
             if (index == 5)
             {
                 SyncTracer.Error("SyncUtil.ExecuteNonQueryWithNewTransaction failed after max retry attempts, due to exception: {0}", new object[1]
                 {
                     (object)ex.Message
                 });
                 throw;
             }
             else
             {
                 SyncTracer.Warning("SyncUtil.ExecuteNonQueryWithNewTransaction failed on attempt {0} of {1}, due to retryable exception: {2}", (object)index, (object)5, (object)ex.Message);
                 Thread.Sleep(100 * (int)Math.Pow(2.0, (double)index));
             }
         }
     }
 }
示例#18
0
        /// <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);
        }
示例#19
0
        internal static int GetSyncIntOutParameter(string parameter, IDbCommand command)
        {
            bool found;

            return(SyncUtil.GetSyncIntOutParameter(parameter, command, out found));
        }