예제 #1
0
        /// <summary>Синхронизация объекта</summary>
        /// <param name="tableName">Имя таблицы</param>
        /// <param name="wayOfSync">Способ синхронизации</param>
        /// <param name="filter">Фильтры</param>
        /// <param name="skipExists">Пропустить существующие</param>
        /// <param name="updId">Нужно обновить ID</param>
        private bool SyncObjects <T>(string tableName, WaysOfSync wayOfSync, FilterSettings filter, bool skipExists, bool updId) where T : dbObject
        {
            CatalogSynchronizer synchronizer = null;

            synchronizer = this.getCatalogSynchronizer(tableName);
            logBuilder.AppendLine();
            logBuilder.AppendLine();
            logBuilder.AppendLine(string.Format("{0}:", typeof(T).Name));

            Stopwatch totalWatch = new Stopwatch();

            totalWatch.Start();
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            string forWarehousesAndMapsSelect = string.Format(@"SELECT RTRIM({0}){0},RTRIM({1}){1},RTRIM({2}) {2} FROM {3} WHERE {4}=0",
                                                              dbObject.IS_SYNCED,
                                                              dbObject.BARCODE_NAME,
                                                              dbObject.SYNCREF_NAME,
                                                              tableName,
                                                              CatalogObject.MARK_FOR_DELETING);

            string forByLogProcessedSelect = string.Format(@"SELECT RTRIM({0}){0},RTRIM({1}){1},RTRIM({2}) {2} FROM {3} WHERE {4}=0 AND {5} = 0",
                                                           dbObject.IS_SYNCED,
                                                           dbObject.BARCODE_NAME,
                                                           dbObject.SYNCREF_NAME,
                                                           tableName,
                                                           CatalogObject.MARK_FOR_DELETING, CatalogObject.IS_SYNCED);

            bool isWarehouseTable = tableName.Equals("Contractors") || tableName.Equals("Maps");

            //Выбрать (Признак синхронизации, Штрих-код) всех не удаленных элементов с таблицы tableName
            string command = (useLoggingSyncronization & !isWarehouseTable) ?
                             forByLogProcessedSelect :
                             forWarehousesAndMapsSelect;
            DataTable table = null;

            using (SqlCeCommand query = dbWorker.NewQuery(command))
            {
                table = query.SelectToTable();
            }
            int rowsCount = (table ?? new DataTable()).Rows.Count;

            logBuilder.AppendLine(string.Format("init pdt query: {0} msec; rows: {1}", stopWatch.ElapsedMilliseconds, rowsCount));

            stopWatch.Reset();
            stopWatch.Start();

            if (filter == FilterSettings.None)
            {
                PerformQuery("StartSyncProcess", this.serverIdProvider.ServerId, tableName, table, (int)FilterSettings.NotMarkForDelete);
            }
            else
            {
                PerformQuery("StartSyncProcess", this.serverIdProvider.ServerId, tableName, table, (int)FilterSettings.NotMarkForDelete, (int)filter);
            }

            logBuilder.AppendLine(string.Format("StartSyncProcess: {0} msec; rows: {1}", stopWatch.ElapsedMilliseconds, rowsCount));

            stopWatch.Reset();
            stopWatch.Start();

            if (IsAnswerIsTrue)
            {
                removeMarkedObject(tableName);
                logBuilder.AppendLine(string.Format("removeMarkedObject: {0} msec", stopWatch.ElapsedMilliseconds));

                stopWatch.Reset();
                stopWatch.Start();

                updateObjOnLocalDb <T>(synchronizer, skipExists, updId);

                int localRowsCount = ((ResultParameters[1] as DataTable) ?? new DataTable()).Rows.Count;
                logBuilder.AppendLine(string.Format("updateObjOnLocalDb: {0} msec; rows: {1}", stopWatch.ElapsedMilliseconds, localRowsCount));

                stopWatch.Reset();
                stopWatch.Start();

                if (wayOfSync == WaysOfSync.TwoWay)
                {
                    int remoteTableRows = ((ResultParameters[2] as DataTable) ?? new DataTable()).Rows.Count;

                    updateObjOnServDb <T>(tableName);

                    logBuilder.AppendLine(string.Format("update greenhouse: {0} msec; rows:{1}", stopWatch.ElapsedMilliseconds, remoteTableRows));

                    stopWatch.Reset();
                    stopWatch.Start();
                }

                logBuilder.AppendLine(string.Format("{0} total: {1} msec", typeof(T).Name, totalWatch.ElapsedMilliseconds));

                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
 /// <summary>Синхронизация объекта</summary>
 /// <param name="wayOfSync">Способ синхронизации</param>
 /// <param name="filter">Фильтры</param>
 private bool SyncObjects <T>(WaysOfSync wayOfSync, FilterSettings filter) where T : dbObject
 {
     return(SyncObjects <T>(typeof(T).Name, wayOfSync, filter, false, true));
 }