public override void HandleEvent(object sender, EventArgs e)
        {
            Logging.Logger.GetLogger().Info("Handling update application event!");

            var progress = new InternalNodeProgress("Update Application");
            var progressWindow = new ProgressWindow(progress);
            Task.Run(() =>
            {
                try
                {
                    var message = this.Engine.UpdateManager.FetchLatestVersionAndStartUpdate(progress);
                    this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Update", message);
                }
                catch (Exception ex)
                {

                    Logging.Logger.GetLogger()
                            .Error(String.Format("Can not update because {0}", ex));
                    this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not launch", String.Format(
                        "Caused by an internal error, we can not update right now. Detail: {0}", ex.Message));
                }
                finally
                {
                    progressWindow.CrossThreadClose();
                }
            });
            progressWindow.ShowDialog();
        }
        public override void HandleEvent(object sender, EventArgs e)
        {
            Logging.Logger.GetLogger().Info("Handling update instance event!");

            var instance = this.Engine.UiControl.MajorWindow.SelectInstance;
            if (instance == null)
            {
                Logging.Logger.GetLogger().Warn("Did not select any instance. Ignore!");
                return;
            }

            var progress = new InternalNodeProgress(String.Format("Launching instance {0}", instance.InstanceName));
            var progressWindow = new ProgressWindow(progress);
            Task.Run(() =>
            {
                try
                {
                    var message = this.Engine.InstanceManager.UpdateInstance(progress, instance.InstanceName);
                    Logging.Logger.GetLogger().InfoFormat(message);
                    this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Successful updated", message);

                }
                catch (NoAvailableUpdateException ex)
                {
                    Logging.Logger.GetLogger().Info(ex.Message);
                    this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "No available update",
                        ex.Message);
                }
                catch (WrongStateException ex)
                {
                    Logging.Logger.GetLogger().ErrorFormat("Update instance {0} encountered an error: {1}", instance.InstanceName, ex.Message);
                    this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not update",
                        String.Format(
                            "Encounter an wrong state error. Detail:{0}",
                            ex.Message));

                }
                catch (Exception ex)
                {
                    Logging.Logger.GetLogger().ErrorFormat("Update instance {0} encountered an error:\n{1}", instance.InstanceName, ex);
                    this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not update",
                        String.Format(
                            "Caused by an internal error, we can not update this instance right now.Detail:{0}",
                            ex.Message));

                }
                finally
                {
                    progressWindow.CrossThreadClose();
                }

            });
            progressWindow.ShowDialog();
        }
        public static void MainTest()
        {
            var progress = new LeafNodeProgress("Common");
            ProgressWindow progressWindow = new ProgressWindow(progress);

            var t = Task.Run(() =>
            {
                do
                {
                    Thread.Sleep(1000);
                    progress.Percent += 5.5D;
                    Console.WriteLine("Progress update to {0}!", progress.Percent);
                } while (true);
            });

            progressWindow.ShowDialog();

            //var t = Task.Run(() =>
            //{
            //    progressWindow = new ProgressWindow(progress);
            //    progressWindow.Show();
            //    Console.WriteLine("Show progress!");
            //});
        }
        public override void HandleEvent(object sender, EventArgs e)
        {
            Logging.Logger.GetLogger().Info("Handling launch instance event!");

            InstanceEntity instance = this.Engine.UiControl.MajorWindow.SelectInstance;
            var progress = new InternalNodeProgress(String.Format("Launching instance {0}", instance.InstanceName));
            var progressWindow = new ProgressWindow(progress);
            Task.Run(() =>
            {
                try
                {
                    this.Engine.GameProcess = this.Engine.InstanceManager.LaunchInstance(progress, instance.InstanceName,
                        this.Engine.AuthServer.CurrentPlayer);
                    this.Engine.GameProcess.Exited += (s, o) =>
                    {
                        this.Engine.UiControl.ShowMainWindow();
                    };
                    this.Engine.UiControl.HideMainWindow();
                    this.Engine.GameProcess.BeginOutputReadLine();
                    this.Engine.GameProcess.OutputDataReceived += (s, ea) =>
                    {

                        if (!String.IsNullOrEmpty(ea.Data))
                        {
                            Logging.Logger.GetLogger().InfoFormat(">>>GAME<<<: {0}", ea.Data);
                        }
                    };
                }
                catch (WebException ex)
                {
                    var response = ((HttpWebResponse) ex.Response);
                    switch (response.StatusCode)
                    {
                        case HttpStatusCode.NotFound:
                        {
                            Logging.Logger.GetLogger()
                                .ErrorFormat("Can not find file on server when donloading:{0}", response.ResponseUri);
                            this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not launch",
                                String.Format(
                                    "Can not find file on server when donloading:{0}", response.ResponseUri));
                            break;
                        }
                        case HttpStatusCode.Forbidden:
                        {
                            Logging.Logger.GetLogger()
                             .ErrorFormat("You have no right to access this server when downloading: {0}", response.ResponseUri);
                            this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not launch",
                                String.Format(
                                    "You have no right to access this server when downloading: {0}", response.ResponseUri));

                            break;
                        }
                        default:
                        {

                            Logging.Logger.GetLogger()
             .Error(String.Format("Encounter an network error during build environment: {0}", ex));
                            this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not launch", String.Format(
                                "Encounter an network error during build environment: {0}", ex.Message));

                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.Logger.GetLogger()
                        .Error(String.Format("Can not launch this instance because {0}", ex));
                    this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not launch", String.Format(
                        "Caused by an internal error, we can not launch this instance right now. Detail: {0}", ex.Message));
                }
                finally
                {
                    progressWindow.CrossThreadClose();
                }
            });
            progressWindow.ShowDialog();
        }