Ejemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 public void CloseDatabase()
 {
     if (mDriver != null)
     {
         mDriver.Stop();
         mDriver = null;
     }
     if (realEnginer != null)
     {
         realEnginer.Dispose();
         realEnginer = null;
     }
     mDatabaseName = string.Empty;
 }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="database"></param>
        public void Load(string database, string checkKey)
        {
            if (database == mDatabaseName)
            {
                return;
            }

            if (mDriver != null)
            {
                mDriver.Stop();
            }

            if (System.IO.Path.IsPathRooted(database))
            {
                this.mDatabaseName = System.IO.Path.GetFileNameWithoutExtension(database);
            }
            else
            {
                this.mDatabaseName = database;
            }
            PathHelper.helper.CheckDataPathExist();
            if (CheckDatabaseExist(mDatabaseName) && IsRunInLocal())
            {
                LoggerService.Service.Info("DatabaseRunner", "开始从本地加载数据库:" + mDatabaseName);
                var mDatabase = new RealDatabaseSerise().LoadByName(mDatabaseName);

                string skey = mDatabase.Version + mDatabase.UpdateTime;

                if (skey != checkKey)
                {
                    LoggerService.Service.Warn("Proxy", "代理使用的数据库和服务器使用的数据库不一致,将从网络进行加载");
                    this.mRealDatabase = mProxy.LoadRealDatabase();
                    mSecurityRunner    = new SecurityRunner()
                    {
                        Document = mProxy.LoadSecurity()
                    };
                }
                else
                {
                    this.mRealDatabase = mDatabase;
                    mSecurityRunner    = new SecurityRunner()
                    {
                        Document = new SecuritySerise().LoadByName(mDatabaseName)
                    };
                }
                LoggerService.Service.Info("DatabaseRunner", "从本地加载数据库完成");
            }
            else
            {
                LoggerService.Service.Info("DatabaseRunner", "开始从远程加载数据库");
                this.mRealDatabase = mProxy.LoadRealDatabase();
                mSecurityRunner    = new SecurityRunner()
                {
                    Document = mProxy.LoadSecurity()
                };
                LoggerService.Service.Info("DatabaseRunner", "从远程加载数据库完成");
            }

            realEnginer = new RealEnginer(mRealDatabase);
            realEnginer.Init();

            RegistorInterface();
            IsReady = true;

            mDriver = new NetTransformDriver()
            {
                Client = mProxy.NetworkClient, WorkMode = mWorkMode, PollCircle = mPollCircle
            };
            mDriver.ValueUpdateEvent += MDriver_ValueUpdateEvent;

            mProxy.NetworkClient.DatabaseChangedAction = (realchanged, hischanged, securitychanged) => {
                if (CheckDatabaseExist(mDatabaseName) && IsRunInLocal())
                {
                    //Stopwatch sw = new Stopwatch();
                    //sw.Start();
                    LoggerService.Service.Info("DatabaseRunner", "开始从本地加载数据库:" + mDatabaseName);

                    if (realchanged)
                    {
                        mDriver.Stop();

                        var mDatabase = new RealDatabaseSerise().LoadByName(mDatabaseName);
                        this.mRealDatabase = mDatabase;

                        var oldeng = realEnginer;
                        realEnginer = new RealEnginer(this.mRealDatabase);
                        realEnginer.Init();


                        mDriver.Start(realEnginer);

                        oldeng.Dispose();
                    }

                    if (securitychanged)
                    {
                        try
                        {
                            if (mSecurityRunner != null)
                            {
                                mSecurityRunner.Stop();
                            }
                        }
                        catch
                        {
                        }
                        mSecurityRunner.Document = new SecuritySerise().LoadByName(mDatabaseName);
                        mSecurityRunner.Start();
                    }

                    RegistorInterface();
                    //sw.Stop();

                    LoggerService.Service.Info("DatabaseRunner", "从本地加载数据库完成");
                }
                else
                {
                    //Stopwatch sw = new Stopwatch();
                    //sw.Start();

                    if (realchanged)
                    {
                        mDriver.Stop();

                        LoggerService.Service.Info("DatabaseRunner", "开始从远程加载数据库");
                        //通过远程下载数据库
                        this.mRealDatabase = mProxy.LoadRealDatabase();

                        var oldeng = realEnginer;
                        realEnginer = new RealEnginer(this.mRealDatabase);
                        realEnginer.Init();

                        mDriver.Start(realEnginer);
                        oldeng.Dispose();
                        LoggerService.Service.Info("DatabaseRunner", "从远程加载数据库完成");
                    }

                    if (securitychanged)
                    {
                        LoggerService.Service.Info("DatabaseRunner", "开始从远程加载安全配置");
                        try
                        {
                            if (mSecurityRunner != null)
                            {
                                mSecurityRunner.Stop();
                            }
                        }
                        catch
                        {
                        }
                        mSecurityRunner.Document = mProxy.LoadSecurity();
                        mSecurityRunner.Start();
                        LoggerService.Service.Info("DatabaseRunner", "从远程加载安全配置完成");
                    }

                    RegistorInterface();
                    //sw.Stop();
                }
            };
            mSecurityRunner.Start();
            mDriver.Start(realEnginer);
        }