Пример #1
0
        public Updater(string serverIP, int serverPort)
        {
            this.UpdateStarted    += new CbGeneric(Updater_UpdateStarted);
            this.UpdateDisruptted += new CbGeneric <string>(Updater_UpdateDisruptted);
            this.UpdateCompleted  += new CbGeneric(Updater_UpdateCompleted);

            DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);

            this.appDirPath = dir.FullName + "\\";

            this.rapidPassiveEngine = RapidEngineFactory.CreatePassiveEngine();
            this.rapidPassiveEngine.AutoReconnect = true;
            Random random = new Random();
            //初始化引擎并登录,返回登录结果
            bool canLogon = false;

            for (int i = 0; i < 100; i++)
            {
                string        userid        = random.Next(1000000).ToString("00000");
                LogonResponse logonResponse = rapidPassiveEngine.Initialize(userid, "", serverIP, serverPort, null);
                if (logonResponse.LogonResult == LogonResult.Succeed)
                {
                    canLogon = true;
                    break;
                }
            }
            if (!canLogon)
            {
                throw new Exception("连接自动更新服务器失败 !");
            }

            this.rapidPassiveEngine.ConnectionInterrupted += new CbGeneric(rapidPassiveEngine_ConnectionInterrupted);
            this.rapidPassiveEngine.RelogonCompleted      += new CbGeneric <LogonResponse>(rapidPassiveEngine_RelogonCompleted);
        }
Пример #2
0
        /// <summary>
        /// Start.
        /// </summary>
        /// <param name="serverIP">server ip</param>
        /// <param name="serverPort">server port</param>
        /// <param name="callerExe">callerExe</param>
        public void Start(string serverIP, int serverPort, string callerExe)
        {
            try
            {
                Random random = new Random();
                for (int i = 0; i < 100; i++)
                {
                    string        userID        = random.Next(1000000).ToString("00000");
                    string        logonPassword = string.Empty;
                    LogonResponse logonResponse = mRapidPassiveEngine.Initialize(userID, logonPassword, serverIP, serverPort, null);
                    if (logonResponse.LogonResult == LogonResult.Succeed)
                    {
                        break;
                    }
                }

                if (!File.Exists(UpdateConfiguration.ConfigurationPath))
                {
                    mUpdateConfiguration.Save();
                }
                else
                {
                    mUpdateConfiguration = (UpdateConfiguration)AgileConfiguration.Load(UpdateConfiguration.ConfigurationPath);
                }

                GetUpdateInfo(out mFileRelativePathListNeedDownloaded, out mFileListNeedRemoved);
                mFileCountNeedUpdated = mFileRelativePathListNeedDownloaded.Count;
                Event_FileCountNeedUpdated?.Invoke(mFileCountNeedUpdated);

                if (mFileCountNeedUpdated == 0 && mFileListNeedRemoved.Count == 0)
                {
                    return;
                }
                Event_UpdateStarted?.Invoke();

                Process[] processes = Process.GetProcessesByName(callerExe.Substring(0, callerExe.Length - 4));
                foreach (Process process in processes)
                {
                    process.Kill();
                }

                CbGeneric cbGeneric = new CbGeneric(UdpateThread);
                cbGeneric.BeginInvoke(null, null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Event_UpdateDisruptted?.Invoke(Resources.ConnectionFailed);
            }
        }