コード例 #1
0
ファイル: RepositoryWindow.cs プロジェクト: Adel-dz/Hub
        //private:
        void ConnectTableAsync(IDataTable table)
        {
            var waitClue = new Waits.WaitClue(this);


            Action connect = () =>
            {
                if (!table.IsConnected)
                {
                    table.Connect();
                }

                var fuzzyTable = table as IFuzzyDataTable;

                IDatumProvider dp = (fuzzyTable?.RowProvider) ?? table.DataProvider;
                dp.Connect();

                lock (m_dpCache)
                    m_dpCache[table.ID] = dp;
            };

            Action onSuccess = () =>
            {
                waitClue.LeaveWaitMode();
                SetInfo(table);
            };

            Action <Task> onError = t =>
            {
                waitClue.LeaveWaitMode();

                Exception ex = t.Exception.InnerException;
                MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);

                m_lvTables.SelectedItems.Clear();
            };



            waitClue.EnterWaitMode();

            var connecting = new Task(connect, TaskCreationOptions.LongRunning);

            connecting.OnError(onError);
            connecting.OnSuccess(onSuccess);

            connecting.Start();
        }
コード例 #2
0
ファイル: DatumView.cs プロジェクト: Adel-dz/Hub
        void InsertColumns()
        {
            Assert(!InvokeRequired);

            IDataColumn[]  colHeader = m_dataProvider.DataSource.Columns;
            ColumnHeader[] columns   = new ColumnHeader[colHeader.Length];

            for (int i = 0; i < columns.Length; ++i)
            {
                columns[i] = new ColumnHeader()
                {
                    Text      = colHeader[i].Caption,
                    TextAlign = HorizontalAlignment.Center,
                    Tag       = colHeader[i].DataType,
                }
            }
            ;

            m_lvData.Columns.AddRange(columns);
        }

        void InsertItems(ListViewEntry[] items)
        {
            Assert(!InvokeRequired);

            m_lvData.Items.AddRange(items);

            TextLogger.Info("\nNbre d'enregistrements {0}.", m_dataProvider.Count);
        }

        void LoadDataAsync()
        {
            Func <ListViewEntry[]> loadData = () =>
            {
                ConnectProvider();
                return(LoadItems());
            };


            var waitClue = new Waits.WaitClue(this);

            Action <Task <ListViewEntry[]> > onError = t =>
            {
                Exception ex = t.Exception.InnerException;
                TextLogger.Error(ex.Message);

                waitClue.LeaveWaitMode();


                if (ex is CorruptedStreamException == false)
                {
                    ex = new CorruptedStreamException(innerException: ex);
                }

                throw ex;
            };


            Action <Task <ListViewEntry[]> > onSuccess = t =>
            {
                InsertColumns();

                ListViewEntry[] items = t.Result;
                InsertItems(items);
                waitClue.LeaveWaitMode();

                m_tslblStatus.Text = $"Nombre d'neregistrements: {m_lvData.Items.Count}";
            };


            waitClue.EnterWaitMode();

            var loading = new Task <ListViewEntry[]>(loadData, TaskCreationOptions.LongRunning);

            loading.ContinueWith(onSuccess,
                                 CancellationToken.None,
                                 TaskContinuationOptions.OnlyOnRanToCompletion,
                                 TaskScheduler.FromCurrentSynchronizationContext());

            loading.ContinueWith(onError, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted,
                                 TaskScheduler.FromCurrentSynchronizationContext());

            loading.Start();
        }

        IColumnSorter SorterFactory(int ndxColumn)
        {
            var           dataType = (ColumnDataType_t)m_lvData.Columns[ndxColumn].Tag;
            IColumnSorter sorter   = null;

            switch (dataType)
            {
            case ColumnDataType_t.Text:
                sorter = new TextColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Integer:
                sorter = new IntegerColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Float:
                sorter = new FloatColumnSorter(ndxColumn);
                break;

            case ColumnDataType_t.Time:
                sorter = new TimeColumnSorter(ndxColumn);
                break;
            }

            Assert(sorter != null);

            return(sorter);
        }