示例#1
0
 public SynchronizeCanUpdate(TableSynchronize tableSync, DBProvider dbProvider, int step,
                             OptimizationOption option, bool fastestMode, Service.SyncFlags flags)
 {
     _TableSync      = tableSync;
     _DBProvider     = dbProvider;
     _Step           = step;
     _OptimizeOption = option;
     _FastestMode    = fastestMode;
     _Flags          = flags;
 }
示例#2
0
        public void Run()
        {
            Global.UserRightProvider.CanDo(Right.RightItem.ManageDB);

            if (Parameters.Count < 1)
            {
                throw new ArgumentException("the number of parameters must large than 0. Parameter 1 is table name, Parameter 2 is step, Parameter 3 is optimize mode");
            }

            string tableName = Parameters[0];

            Data.DBProvider dbProvider = Data.DBProvider.GetDBProvider(tableName);

            if (dbProvider == null)
            {
                throw new StoredProcException(string.Format("Table name {0} does not exist!", Parameters[0]));
            }

            if (dbProvider.TableSynchronizeProgress >= 0 &&
                dbProvider.TableSynchronizeProgress < 100)
            {
                return;
            }


            int    option      = 0;
            int    step        = 5000;
            bool   fastestMode = true;
            string strFlags    = "";

            Service.SyncFlags flags = Service.SyncFlags.Insert | Service.SyncFlags.Rebuild;

            if (Parameters.Count > 1)
            {
                step = int.Parse(Parameters[1]);
            }

            if (Parameters.Count > 2)
            {
                option = int.Parse(Parameters[2]);
            }

            if (Parameters.Count > 3)
            {
                strFlags = Parameters[3];

                flags = (Service.SyncFlags)Hubble.Framework.Reflection.Emun.FromString(typeof(Service.SyncFlags), strFlags);

                flags &= ~Hubble.Core.Service.SyncFlags.Delete;
                flags &= ~Hubble.Core.Service.SyncFlags.Update;
                flags |= Hubble.Core.Service.SyncFlags.Rebuild;
                flags |= Hubble.Core.Service.SyncFlags.Insert;
            }

            Hubble.Core.Data.OptimizationOption optimizeOption;

            switch (option)
            {
            case 0:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Idle;
                break;

            case 1:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Minimum;
                break;

            case 2:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Middle;
                break;

            case 3:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Speedy;
                break;

            default:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Minimum;
                break;
            }

            bool notIndexOnly = false;

            try
            {
                if (!dbProvider.IndexOnly)
                {
                    notIndexOnly = true;
                    dbProvider.Table.IndexOnly = true;
                }

                Data.DBProvider.Truncate(tableName);

                if (notIndexOnly)
                {
                    dbProvider = Data.DBProvider.GetDBProvider(tableName);
                    dbProvider.Table.IndexOnly = false;
                }
            }
            catch
            {
                if (notIndexOnly)
                {
                    dbProvider = Data.DBProvider.GetDBProvider(tableName);
                    dbProvider.Table.IndexOnly = false;
                }
            }

            dbProvider = Data.DBProvider.GetDBProvider(tableName);

            dbProvider.SynchronizeWithDatabase(step, optimizeOption, fastestMode, flags);

            if ((flags & Hubble.Core.Service.SyncFlags.WaitForExit) != 0)
            {
                //Wait for exit

                while (true)
                {
                    if (dbProvider.TableSynchronizeProgress >= 100 ||
                        dbProvider.TableSynchronizeProgress < 0)
                    {
                        OutputMessage(string.Format("Table: {0} finished synchronizing!", Parameters[0]));
                        return;
                    }

                    System.Threading.Thread.Sleep(1000);
                }
            }

            OutputMessage(string.Format("Table: {0} is synchronizing now!", Parameters[0]));
        }
示例#3
0
        public void Run()
        {
            Global.UserRightProvider.CanDo(Right.RightItem.ManageDB);

            if (Parameters.Count < 1)
            {
                throw new ArgumentException("the number of parameters must large than 0. Parameter 1 is table name, Parameter 2 is step, Parameter 3 is optimize mode");
            }

            Data.DBProvider dbProvider = Data.DBProvider.GetDBProvider(Parameters[0]);

            if (dbProvider == null)
            {
                throw new StoredProcException(string.Format("Table name {0} does not exist!", Parameters[0]));
            }

            int    option      = 0;
            int    step        = 5000;
            bool   fastestMode = false;
            string strFlags    = "";

            Service.SyncFlags flags = Service.SyncFlags.Insert | Service.SyncFlags.Delete
                                      | Service.SyncFlags.Update;

            if (Parameters.Count > 1)
            {
                step = int.Parse(Parameters[1]);
            }

            if (Parameters.Count > 2)
            {
                option = int.Parse(Parameters[2]);
            }

            if (Parameters.Count > 3)
            {
                fastestMode = bool.Parse(Parameters[3]);
            }

            if (Parameters.Count > 4)
            {
                strFlags = Parameters[4];

                flags = (Service.SyncFlags)Hubble.Framework.Reflection.Emun.FromString(typeof(Service.SyncFlags), strFlags);
            }

            Hubble.Core.Data.OptimizationOption optimizeOption;

            switch (option)
            {
            case 0:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Idle;
                break;

            case 1:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Minimum;
                break;

            case 2:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Middle;
                break;

            case 3:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Speedy;
                break;

            default:
                optimizeOption = Hubble.Core.Data.OptimizationOption.Minimum;
                break;
            }

            dbProvider.SynchronizeWithDatabase(step, optimizeOption, fastestMode, flags);

            if ((flags & Hubble.Core.Service.SyncFlags.WaitForExit) != 0)
            {
                //Wait for exit
                int count = 0;

                while (true)
                {
                    if (dbProvider.TableSynchronizeProgress >= 100 ||
                        dbProvider.TableSynchronizeProgress < 0)
                    {
                        OutputMessage(string.Format("Table: {0} finished synchronizing!", Parameters[0]));
                        return;
                    }

                    if ((++count % 60) == 0)
                    {
                        Hubble.Core.Global.Report.WriteAppLog(string.Format("TableSynchronizeProgress = {0}% of table:{1}",
                                                                            dbProvider.TableSynchronizeProgress, dbProvider.TableName));
                    }

                    System.Threading.Thread.Sleep(1000);
                }
            }

            OutputMessage(string.Format("Table: {0} is synchronizing now!", Parameters[0]));
        }