示例#1
0
        void LoadRunningClientsAsync()
        {
            Dbg.Assert(!InvokeRequired);

            Func <TreeNode[]> load = () =>
            {
                var roots = new List <TreeNode>();

                foreach (HubClient hc in AppContext.ClientsManager.RunningClients)
                {
                    var profile = m_ndxerProfiles.Get(hc.ProfileID) as UserProfile;

                    var root = new TreeNode(profile.Name)
                    {
                        Tag = profile,
                        SelectedImageIndex = NDXIMG_PROFILE,
                        ImageIndex         = NDXIMG_PROFILE
                    };

                    root.Nodes.Add(CreateClientNode(hc));

                    roots.Add(root);
                }

                return(roots.ToArray());
            };


            var waitClue = new Waits.WaitClue(this);

            Action <Task> onErr = t =>
            {
                MessageBox.Show(t.Exception.InnerException.Message, Text);
                AppContext.LogManager.LogSysError("Chargement de la liste des clients actifs: " + t.Exception.InnerException.Message, true);

                waitClue.LeaveWaitMode();
            };

            Action <Task <TreeNode[]> > onSucces = t =>
            {
                m_tvClients.Nodes.Clear();

                m_tvClients.Nodes.AddRange(t.Result);
                m_tvClients.ExpandAll();

                waitClue.LeaveWaitMode();
            };


            var task = new Task <TreeNode[]>(load, TaskCreationOptions.LongRunning);

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

            waitClue.EnterWaitMode();
            task.Start();
        }
示例#2
0
        void LoadDataAsync()
        {
            Func <ListViewItem[]> load = () =>
            {
                var items = new List <ListViewItem>();

                items.Add(CreateLVI("ID", m_update.ID.ToString("X")));
                items.Add(CreateLVI("Crée le", m_update.CreationTime.ToString()));
                items.Add(CreateLVI("Version", m_update.Version.ToString()));
                items.Add(CreateLVI("Architecture", AppArchitectures.GetArchitectureName(m_update.AppArchitecture)));
                items.Add(CreateLVI(""));
                items.Add(CreateLVI("Fichiers:"));

                string fileName = m_update.ID.ToString("X");
                string filePath = Path.Combine(AppPaths.AppUpdateFolder, fileName);

                foreach (string item in FilesBag.GetContent(filePath))
                {
                    items.Add(CreateLVI(item));
                }

                return(items.ToArray());
            };

            var waitDlg = new Waits.WaitClue(this);

            Action <Task <ListViewItem[]> > onSuccess = t =>
            {
                m_lvData.Items.AddRange(t.Result);
                m_lvData.AdjustColumnsSize();
                waitDlg.LeaveWaitMode();
            };

            Action <Task> onErr = t =>
            {
                waitDlg.LeaveWaitMode();
                MessageBox.Show(t.Exception.InnerException.Message, null,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            };

            var task = new Task <ListViewItem[]>(load, TaskCreationOptions.LongRunning);

            task.OnSuccess(onSuccess);
            task.OnError(onErr);
            task.Start();
            waitDlg.EnterWaitMode();
        }
示例#3
0
        void LoadDataAsync()
        {
            var wb = new Waits.WaitClue(this);

            Func <ListViewItem[]> load = () =>
            {
                var lvItems = new List <ListViewItem>();

                foreach (ITRDatum d in m_dataBuilder.BuildAll())
                {
                    lvItems.Add(new ListViewItem(d.GetContent())
                    {
                        Tag = d.SpotValue.ID
                    });
                }

                return(lvItems.ToArray());
            };


            Action <Task <ListViewItem[]> > onSuccess = (t) =>
            {
                m_lvData.BeginUpdate();
                m_lvData.Items.Clear();
                m_lvData.Items.AddRange(t.Result);
                m_lvData.EndUpdate();
                wb.LeaveWaitMode();

                m_slRowCount.Text = $"{m_lvData.Items.Count} enregistrement(s)";
            };

            Action <Task> onErr = t =>
            {
                this.ShowError(t.Exception.InnerException.Message);
                wb.LeaveWaitMode();
            };

            var task = new Task <ListViewItem[]>(load, TaskCreationOptions.LongRunning);

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

            wb.EnterWaitMode();
            task.Start();
        }
示例#4
0
        void ConnectAsync()
        {
            Assert(!InvokeRequired);

            var waitBox = new Waits.WaitClue(this);

            Action <Task> onErr = t =>
            {
                waitBox.LeaveWaitMode();
                this.ShowError(t.Exception.InnerException.Message);
                Close();
            };


            var task = new Task(m_ndxerValues.Connect);

            task.OnError(onErr);
            task.OnSuccess(waitBox.LeaveWaitMode);

            task.Start();
            waitBox.EnterWaitMode();
        }
示例#5
0
        void LoadAllClientsAsync()
        {
            Dbg.Assert(!InvokeRequired);


            Func <IEnumerable <UserProfile> > loadProfiles = () =>
            {
                IEnumerable <UserProfile> profiles = from UserProfile prf in m_ndxerProfiles.Source.Enumerate()
                                                     select prf;
                return(profiles);
            };


            Func <IEnumerable <UserProfile>, TreeNode[]> loadClients = (IEnumerable <UserProfile> profiles) =>
            {
                var roots = new List <TreeNode>();

                foreach (UserProfile prf in profiles)
                {
                    var clients = from HubClient client in m_ndxerClients.Source.Enumerate()
                                  where client.ProfileID == prf.ID
                                  select CreateClientNode(client);

                    var root = new TreeNode(prf.Name, clients.ToArray())
                    {
                        Tag = prf,
                        SelectedImageIndex = NDXIMG_PROFILE,
                        ImageIndex         = NDXIMG_PROFILE
                    };

                    roots.Add(root);
                }

                return(roots.ToArray());
            };

            Func <TreeNode[]> load = () =>
            {
                IEnumerable <UserProfile> profiles = loadProfiles();
                return(loadClients(profiles));
            };


            var waitClue = new Waits.WaitClue(this);

            Action <Task> onErr = t =>
            {
                MessageBox.Show(t.Exception.InnerException.Message, Text);
                AppContext.LogManager.LogSysError("Chargement de la liste de tous les clients: " + t.Exception.InnerException.Message, true);
                waitClue.LeaveWaitMode();
            };

            Action <Task <TreeNode[]> > onSucces = t =>
            {
                m_tvClients.Nodes.Clear();

                m_tvClients.Nodes.AddRange(t.Result);
                m_tvClients.ExpandAll();

                waitClue.LeaveWaitMode();
            };


            var task = new Task <TreeNode[]>(load, TaskCreationOptions.LongRunning);

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

            waitClue.EnterWaitMode();
            task.Start();
        }
示例#6
0
        //handlers
        private void Next_Click(object sender, EventArgs e)
        {
            UseWaitCursor = true;

            try
            {
                if (m_previewPage.Visible)
                {
                    ImportData();

                    m_endPage.BadRows = ReadBadRows();

                    m_btnNext.Enabled     = m_btnPrevious.Enabled = false;
                    m_previewPage.Visible = false;
                    m_endPage.Visible     = true;

                    m_btnCancel.Text         = "Fermer";
                    m_btnCancel.DialogResult = DialogResult.OK;
                }
                else if (m_configPage.Visible)
                {
                    var wBox = new Waits.WaitClue(this);
                    wBox.EnterWaitMode();


                    Func <IDictionary <uint, List <IDataRow> > > runDriver = () =>
                    {
                        ImportInfo info = m_configPage.ImportData;

                        using (var driver = new ImportEngin(info.Data, info.ColumnsMapping))
                        {
                            driver.Run();
                            m_ndxBadRows = driver.IgnoredRows;
                            IDictionary <uint, List <IDataRow> > dic = driver.ImportedData;
                            var seq = from idTable in dic.Keys
                                      where dic[idTable].Count == 0
                                      select idTable;

                            foreach (uint idTable in seq.ToArray())
                            {
                                dic.Remove(idTable);
                            }

                            return(dic);
                        }
                    };


                    Action <Task> onErr = t =>
                    {
                        wBox.LeaveWaitMode();
                        this.ShowError(t.Exception.InnerException.Message);
                    };


                    Action <Task <IDictionary <uint, List <IDataRow> > > > onSuccess = t =>
                    {
                        m_importData = t.Result;
                        m_previewPage.SetPreviewData(m_importData, m_configPage.ImportData.Data.Length,
                                                     m_ndxBadRows.Count);

                        m_configPage.Visible  = false;
                        m_previewPage.Visible = true;
                        m_btnPrevious.Enabled = true;
                        wBox.LeaveWaitMode();
                    };


                    var task = new Task <IDictionary <uint, List <IDataRow> > >(runDriver,
                                                                                TaskCreationOptions.LongRunning);
                    task.OnError(onErr);
                    task.OnSuccess(onSuccess);
                    task.Start();
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex.Message);
            }
            finally
            {
                UseWaitCursor = false;
            }
        }