public StrategySetCommand(ClientService clientService, BidActionManager bidActionManager, BiddingScreen biddingScreen)
 {
     this.clientService    = clientService;
     this.bidActionManager = bidActionManager;
     this.biddingScreen    = biddingScreen;
 }
Exemple #2
0
 public PriceTellCommand(BiddingScreen biddingScreen)
 {
     this.biddingScreen = biddingScreen;
 }
Exemple #3
0
        /// <summary>
        /// Updates this instance.
        /// </summary>
        private void Update()
        {
            logger.InfoFormat("Updating '{0}' files.", this._remoteConfig.Payloads.Length);

            // Clean up failed attempts.
            if (Directory.Exists(WorkPath))
            {
                logger.InfoFormat("WARNING: Work directory already exists.");
                try
                {
                    Directory.Delete(WorkPath, true);
                }
                catch (IOException)
                {
                    logger.InfoFormat("Cannot delete open directory '{0}'.", WorkPath);
                    return;
                }
            }

            Directory.CreateDirectory(WorkPath);

            // Download files in manifest.
            foreach (string updateFileName in this._remoteConfig.Payloads)
            {
                logger.InfoFormat("Fetching '{0}'.", updateFileName);
                var url  = this._remoteConfig.BaseUri + updateFileName;
                var file = Fetch.Get(url);
                if (file == null)
                {
                    logger.InfoFormat("Fetch {0} failed.", updateFileName);
                    return;
                }
                var info = new FileInfo(Path.Combine(WorkPath, updateFileName));
                Directory.CreateDirectory(info.DirectoryName);
                File.WriteAllBytes(Path.Combine(WorkPath, updateFileName), file);

                // Unzip
                if (Regex.IsMatch(updateFileName, @"\.zip"))
                {
                    try
                    {
                        var zipfile = Path.Combine(WorkPath, updateFileName);
                        using (var zip = ZipFile.Read(zipfile))
                            zip.ExtractAll(WorkPath, ExtractExistingFileAction.Throw);
                        File.Delete(zipfile);
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Unpack failed:", ex);
                        return;
                    }
                }
            }

            // Change the currently running executable so it can be overwritten.
            Process thisprocess = Process.GetCurrentProcess();
            string  me          = thisprocess.MainModule.FileName;
            string  bak         = me + ".bak";

            logger.InfoFormat("Renaming running process to '{0}'.", bak);
            if (File.Exists(bak))
            {
                File.Delete(bak);
            }
            File.Move(me, bak);
            File.Copy(bak, me);

            // Write out the new manifest.
            _remoteConfig.Write(Path.Combine(WorkPath, _localConfigFile.Name));

            // Copy everything.
            var directory = new DirectoryInfo(WorkPath);
            var files     = directory.GetFiles("*.*", SearchOption.AllDirectories);

            foreach (FileInfo file in files)
            {
                string destination = file.FullName.Replace(directory.FullName + @"\", "");
                logger.InfoFormat("installing file '{0}'.", destination);
                Directory.CreateDirectory(new FileInfo(destination).DirectoryName);
                file.CopyTo(destination, true);
            }

            // Clean up.
            logger.InfoFormat("Deleting work directory.");
            Directory.Delete(WorkPath, true);

            // Stop Business Thread
            try
            {
                BiddingScreen.StopCollectingThread();
            }
            catch (Exception e)
            {
                logger.Error("StopCollectingWorkThread error.", e);
            }

            Thread.Sleep(2 * 1000);

            // Restart.
            logger.InfoFormat("Spawning new process with FileName#{0}.", me);
            var spawn = Process.Start(me);

            var processStartInfo = new ProcessStartInfo
            {
                FileName        = me,
                UseShellExecute = true,
                // Arguments = arguments.ToString()
            };

            // var spawnProcess = Process.Start(processStartInfo);
            // ReStart();

            logger.InfoFormat("New process ID is {0}", spawn.Id);
            logger.InfoFormat("Closing old running process {0}.", thisprocess.Id);
            thisprocess.CloseMainWindow();
            thisprocess.Close();
            thisprocess.Dispose();
        }
Exemple #4
0
        private void InitBizComponent()
        {
            robot = ApplicationContext.me.Get <WindowSimulator>();
            // TODO: 开启异步会带来很多不一致,coding时必须实时注意 异步
            robot.SetEnableAsync(false);

            actionManager   = ApplicationContext.me.Get <BidActionManager>();
            biddingScreen   = ApplicationContext.me.Get <BiddingScreen>();
            conf            = ApplicationContext.me.Get <ProjectConfig>();
            loginActManager = ApplicationContext.me.Get <LoginActManager>();

            // 为了禁用js错误提示
            this.webBro.LoadCompleted += new LoadCompletedEventHandler((sender, e) =>
            {
                loginActManager.BeforeLogin();

                logger.InfoFormat("webBro.LoadCompleted - EnableAutoInputAccount is {0}.", conf.EnableAutoInputAccount);

                // TODO: 这里每次都会在每一个页面载入的时候, 都会执行这一段逻辑。所以不能开启这段逻辑
                if (conf.EnableAutoInputAccount)
                {
                    InputLoginAccount();
                }
            });
            this.webBro.Navigated += new NavigatedEventHandler(wbMain_Navigated);
            this.webBro.Navigate(new Uri(conf.BidLoginUrl));

            biddingScreen.SetWebBrowser(this.webBro);
            biddingScreen.SetShowUpBlock(this.RecoBlock);
            biddingScreen.StrategyBlock = this.StrategyBlock;
            biddingScreen.ActionBlock   = this.ActionBlock;

            biddingScreen.SetStrategyText();

            if (conf.EnableSaberRobot)
            {
                socketClient  = ApplicationContext.me.Get <SocketClient>();
                clientService = ApplicationContext.me.Get <ClientService>();

                socketClient.AfterSuccessConnected = (aa) =>
                {
                    try
                    {
                        clientService.DoClientRegister();
                    }
                    catch (Exception e)
                    {
                        logger.Error("DoClientLogin error", e);
                    }
                    return(aa);
                };
                socketClient.EnableSocketGuard = true;

                socketClient.StartClient();
            }

            var captchaTaskDaemon = ApplicationContext.me.Get <CaptchaTaskDaemon>();

            captchaTaskDaemon.SetCaptchaInputCallbackFunc(biddingScreen.CaptchaAnswerInputCallback);
            captchaTaskDaemon.RestartInquiryThread();

            string osName = KK.GetFitOSName();

            logger.InfoFormat("osName is {0}.", osName);

            foreach (int dictIdx in Enum.GetValues(typeof(DictIndex)))
            {
                if (dictIdx == 0)
                {
                    robot.SetDict(0, string.Format("Resource/dict/dict-{0}.txt", osName));
                    continue;
                }

                robot.SetDict(dictIdx, string.Format("Resource/dict/{0}/dict-{0}-{1}.txt", osName, dictIdx));
            }

            if (conf.EnableCorrectNetTime)
            {
                ThreadUtils.StartNewTaskSafe(() => {
                    var bo = TimeSynchronizer.SyncFromNtpServer();
                    logger.InfoFormat("TimeSynchronizer.SyncFromNtpServer result is {0}.", bo);
                });
            }
        }