예제 #1
0
        public void Run(Form form = null)
        {
            Action run = () =>
            {
                while (m_actions.Count > 0)
                {
                    try
                    {
                        m_actions[0].Run();
                    }
                    catch (Exception ex)
                    {
                        Dbg.Log(ex.Message);
                    }
                    finally
                    {
                        m_actions.RemoveAt(0);
                    }
                }
            };

            var dlg = new BusyDialog();

            var task = new Task(run, TaskCreationOptions.LongRunning);

            task.OnSuccess(dlg.Dispose);
            task.Start();

            if (form != null)
            {
                dlg.ShowDialog(form);
            }
            else
            {
                dlg.ShowDialog();
            }

            Save();
        }
예제 #2
0
    public static T Execute <T>(DependencyObject parent, Func <T> action)
    {
        Window parentWindow = null;

        if (parent is Window)
        {
            parentWindow = parent as Window;
        }
        else
        {
            parentWindow = Window.GetWindow(parent);
        }
        T          val = default(T);
        Exception  le  = null;
        BusyDialog bd  = new BusyDialog();

        bd.Owner = parentWindow;
        ThreadPool.QueueUserWorkItem((o) =>
        {
            try
            {
                val = action();
            }
            catch (Exception ex)
            {
                le = ex;
            }
            bd.EndDialog();
        });
        bd.ShowDialog();
        if (le != null)
        {
            Trace.WriteLine(le.ToString());
            throw new Exception("Execute Exception", le);
        }
        return(val);
    }
예제 #3
0
        bool RegisterClient()
        {
            var busyDlg = new BusyDialog();

            busyDlg.Message = "Initialisation...";


            Action <Task <IEnumerable <ProfileInfo> > > onSuccess = t => busyDlg.Dispose();

            Action <Task> onErr = t =>
            {
                busyDlg.Dispose();
                //System.Windows.Forms.MessageBox.Show(t.Exception.InnerException.Message , null);
            };

            IEnumerable <ProfileInfo> profiles = null;
            var task = new Task <IEnumerable <ProfileInfo> >(() => profiles = Program.DialogManager.Profiles,
                                                             TaskCreationOptions.LongRunning);

            task.OnSuccess(onSuccess);
            task.OnError(onErr);

            task.Start();
            busyDlg.ShowDialog();

            if (profiles == null || !profiles.Any())
            {
                System.Windows.Forms.MessageBox.Show("Aucune réponse du serveur. Veuillez réessayer ultérieurement.",
                                                     AppText.APP_NAME, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

                Exit();
                return(false);
            }

            ClientInfo clInfo;

            using (var dlg = new ProfileDialog(profiles))
            {
                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    Exit();
                }

                clInfo = ClientInfo.CreateClient(dlg.SelectedProfile.ProfileID);
                clInfo.ContaclEMail = dlg.ContactEMail;
                clInfo.ContactName  = dlg.Contact;
                clInfo.ContactPhone = dlg.ContactPhone;
            }


            using (var dlg = new ConnectionDialog(clInfo))
            {
                dlg.ShowDialog();

                if (!dlg.IsRegistered)
                {
                    Exit();
                    return(false);
                }

                m_clInfo = Program.Settings.ClientInfo;
                DialogEngin.WriteHubDialog(SettingsManager.GetClientDialogFilePath(m_clInfo.ClientID),
                                           m_clInfo.ClientID, Enumerable.Empty <Message>());
            }

            return(true);
        }
예제 #4
0
파일: SettingsView.cs 프로젝트: Adel-dz/Hub
        void PostSetInfoMessage()
        {
            ClientInfo curClInfo = Program.Settings.ClientInfo;
            var        clInfo    = new ClientInfo(curClInfo.ClientID, curClInfo.ProfileID);

            clInfo.ContaclEMail = m_tbEmail.Text.Trim();
            clInfo.ContactName  = m_tbContact.Text.Trim();
            clInfo.ContactPhone = m_tbPhone.Text.Trim();

            byte[] msgData = clInfo.GetBytes();

            var dlg = new BusyDialog();

            Func <bool> postMessage = () =>
            {
                const int TIME_TO_SLEEP = 10 * 1000;
                int       nbAttempts    = 3;


                while (--nbAttempts >= 0)
                {
                    dlg.Message = "Envoi  des données vers le serveur...";
                    uint msgID = Program.DialogManager.SendMessage(Message_t.SetInfo, msgData);

                    if (msgID == 0)
                    {
                        continue;
                    }

                    dlg.Message = "En attente de la réponse du serveur...";
                    Thread.Sleep(TIME_TO_SLEEP);

                    dlg.Message = "Réception des données à partir du serveur...";
                    HubCore.DLG.Message resp = Program.DialogManager.ReceiveMessage(msgID);

                    Dbg.Assert(resp == null || resp.MessageCode == Message_t.Ok);

                    if (resp != null)
                    {
                        dlg.Message = "Transfert terminé.";
                        break;
                    }
                }

                return(nbAttempts >= 0);
            };

            Action <Task> onErr = t =>
            {
                dlg.Dispose();

                if (t.Exception != null)
                {
                    Dbg.Log(t.Exception.InnerException.Message);
                    Program.DialogManager.PostLog("Changement des informations utilisateur. Erreur lors de l'envoi: " +
                                                  t.Exception.InnerException.Message, true);
                }

                MessageBox.Show("Impossible de se connecter au serveur distant. Veuillez réessayer ultérieurement.",
                                null,
                                MessageBoxButtons.OK);
            };

            Action <Task <bool> > onSuccess = t =>
            {
                if (t.Result == false)
                {
                    onErr(t);
                }
                else
                {
                    Program.Settings.ClientInfo = clInfo;
                    ClientInfoChanged?.Invoke();
                    dlg.Dispose();
                }
            };

            var task = new Task <bool>(postMessage, TaskCreationOptions.LongRunning);

            task.OnSuccess(onSuccess);
            task.OnError(onErr);
            task.Start();
            dlg.ShowDialog();
        }