示例#1
0
 private static void Test(GuiController controller)
 {
     new Thread(() =>
     {
         Thread.Sleep(500);
         controller.OnMessage(new Api.Message(MessageType.Started).Json);
         Thread.Sleep(1000);
         for (int i = 0; i < 5; i++)
         {
             var fakeApi = new Api.Message(MessageType.ProgressUpdated)
             {
                 States = new Dictionary <string, UploadJobState> {
                     { "Job", new UploadJobState {
                           status = $"{i}", total = 5, current = i
                       } }
                 }
             };
             controller.OnMessage(fakeApi.Json);
             Thread.Sleep(100);
         }
         controller.OnMessage(new Api.Message(MessageType.Completed).Json);
         Thread.Sleep(5000);
         controller.OnMessage(new Api.Message(MessageType.Started).Json);
         Thread.Sleep(2000);
         controller.OnMessage(new Api.Message(MessageType.Completed).Json);
     }).Start();
 }
示例#2
0
        public void Update(Api.Message message)
        {
            switch (message.Type)
            {
            case MessageType.Started:
                TogglePanel(new PanelProgress());
                Show();
                return;

            case MessageType.Completed:
                var completedPanel = new PanelCompleted(configRemain.HasValue);
                completedPanel.btnClose.Click += (o, ev) => Hide();
                if (configRemain.HasValue)
                {
                    remain = configRemain.Value;
                    completedPanel.lblTimer.Text = remain.ToString();
                }
                TogglePanel(completedPanel);
                return;
            }

            if (message.Type == MessageType.ProgressUpdated && currentPanel is PanelProgress pnlProg)
            {
                var state = message.States.Values.FirstOrDefault();
                if (state == null)
                {
                    return;
                }
                if (!state.isBytes)
                {
                    pnlProg.lblProgress.Text = $"{state.current} / {state.total}";
                }
                else
                {
                    pnlProg.lblProgress.Text = Win32.BytesToString(state.current) + " / " + Win32.BytesToString(state.total);
                }
                pnlProg.lblStatus.Text = state.status;
                if (state.current > state.total)
                {
                    state.total = state.current;
                }
                pnlProg.progressBar1.Maximum = (int)state.total;
                pnlProg.progressBar1.Value   = (int)state.current;
            }
        }