Beispiel #1
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);
        }
Beispiel #2
0
        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();
        }