예제 #1
0
        /// <summary>
        ///   Builds the tree.
        /// </summary>
        public void BuildTree(string parent, string id, string display1 = null, string display2 = null)
        {
            var oldCursor = Cursor.Current == Cursors.WaitCursor ? Cursors.WaitCursor : Cursors.Default;

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                m_BuildProcess = new FormProcessDisplay("Building Tree", false, m_CancellationTokenSource.Token);
                m_BuildProcess.Show(this);
                m_BuildProcess.Maximum = m_DataRow.GetLength(0) * 2;

                BuildTreeData(parent, id, display1, display2, m_BuildProcess);

                m_BuildProcess.Maximum = 0;
                ShowTree(m_BuildProcess);
            }
            catch (Exception ex)
            {
                Logger.Warning(ex, ex.Message);
            }
            finally
            {
                m_BuildProcess.Dispose();
                m_BuildProcess = null;
                Cursor.Current = oldCursor;
            }
        }
예제 #2
0
 private void ButtonSkipLine_ClickAsync(object sender, EventArgs e)
 {
     using (var frm = new FormProcessDisplay("Check", true, CancellationToken.None))
     {
         frm.Show();
         frm.Maximum = 0;
         using (var streamReader = new ImprovedTextReader(m_Stream, fileSetting.CodePageId))
         {
             streamReader.ToBeginning();
             fileSetting.SkipRows = streamReader.GuessStartRow(textBoxDelimiter.Text, m_TextBoxQuote.Text, textBoxComment.Text, frm.CancellationToken);
         }
         HighlightVisibleRange(fileSetting.SkipRows);
     }
 }
예제 #3
0
        public static IProcessDisplay GetProcessDisplay(
            [NotNull] this IFileSetting fileSetting,
            [CanBeNull] Form owner,
            bool withLogger,
            CancellationToken cancellationToken)
        {
            if (!fileSetting.ShowProgress)
            {
                return(new CustomProcessDisplay(cancellationToken));
            }

            var processDisplay = new FormProcessDisplay(fileSetting.ToString(), withLogger, cancellationToken);

            processDisplay.Show(owner);
            return(processDisplay);
        }
예제 #4
0
 private void FilterValueChangedElapsed(object sender, ElapsedEventArgs e)
 {
     // go to UI Main thread
     m_TextBoxValue.Invoke((MethodInvoker) delegate
     {
         try
         {
             using (var proc = new FormProcessDisplay("Searching", m_CancellationTokenSource.Token))
             {
                 proc.Show(this);
                 Search(m_TextBoxValue.Text, m_TreeView.Nodes, proc.CancellationToken);
             }
         }
         catch (Exception ex)
         {
             this.ShowError(ex);
         }
     });
 }
예제 #5
0
        /// <summary>
        ///   Gets the process display.
        /// </summary>
        /// <param name="fileSetting">The setting.</param>
        /// <param name="cancellationToken">A Cancellation token</param>
        /// <param name="owner">
        ///   The owner form, in case the owner is minimized or closed this progress will do the same
        /// </param>
        /// <returns>A process display, if the stetting want a process</returns>
        public static IProcessDisplay GetProcessDisplay(this IFileSetting fileSetting, Form owner, bool withLogger, CancellationToken cancellationToken)
        {
            if (!fileSetting.ShowProgress)
            {
                return(new DummyProcessDisplay(cancellationToken));
            }

            if (withLogger)
            {
                var processDisplay = new FormProcessDisplayLogger(fileSetting.GetProcessDisplayTitle(), cancellationToken);
                processDisplay.Show(owner);
                return(processDisplay);
            }
            else
            {
                var processDisplay = new FormProcessDisplay(fileSetting.GetProcessDisplayTitle(), cancellationToken);
                processDisplay.Show(owner);
                return(processDisplay);
            }
        }
예제 #6
0
        private void Work(string dataColumnName, bool ignoreNull)
        {
            if (string.IsNullOrEmpty(dataColumnName))
            {
                return;
            }
            if (dataColumnName.Equals(m_LastDataColumnName, StringComparison.Ordinal) && m_LastIgnoreNull == ignoreNull)
            {
                return;
            }

            m_LastDataColumnName = dataColumnName;
            m_LastIgnoreNull     = ignoreNull;

            this.SafeInvoke(() =>
            {
                detailControl.Visible = false;
                detailControl.SuspendLayout();
            });
            Extensions.ProcessUIElements();
            try
            {
                this.SafeBeginInvoke(() =>
                                     Text = $"Unique Values Display - {dataColumnName} ");

                var dataColumnID   = m_DataTable.Columns[dataColumnName];
                var dictIDToRow    = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);
                var intervalAction = new IntervalAction();

                using (var display = new FormProcessDisplay($"Processing {dataColumnName}", m_CancellationTokenSource.Token))
                {
                    display.Maximum = m_DataRow.Length;
                    display.Show(this);

                    for (var rowIdex = 0; rowIdex < m_DataRow.Length; rowIdex++)
                    {
                        if (display.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        intervalAction.Invoke(delegate
                        {
                            display.SetProcess("Getting Unique values", rowIdex);
                        });
                        var id = m_DataRow[rowIdex][dataColumnID.Ordinal].ToString().Trim();
                        if (ignoreNull && string.IsNullOrEmpty(id))
                        {
                            continue;
                        }
                        if (!dictIDToRow.ContainsKey(id))
                        {
                            dictIDToRow.Add(id, rowIdex);
                        }
                    }

                    this.SafeInvoke(() => Text =
                                        $"Unique Values Display - {dataColumnName} - Rows {dictIDToRow.Count}/{m_DataRow.Length}");

                    m_DataTable.BeginLoadData();
                    m_DataTable.Clear();
                    display.Maximum = dictIDToRow.Count;

                    var counter = 0;
                    foreach (var rowIdex in dictIDToRow.Values)
                    {
                        if (display.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        counter++;
                        if (counter % 100 == 0)
                        {
                            intervalAction.Invoke(delegate
                            {
                                display.SetProcess("Importing Rows to Grid", counter);
                            });
                        }
                        m_DataTable.ImportRow(m_DataRow[rowIdex]);
                    }

                    m_DataTable.EndLoadData();
                    detailControl.CancellationToken = m_CancellationTokenSource.Token;
                    display.Maximum = 0;
                    display.SetProcess("Sorting");
                    detailControl.SafeInvoke(() =>
                    {
                        try
                        {
                            foreach (DataGridViewColumn col in detailControl.DataGridView.Columns)
                            {
                                if (col.DataPropertyName == dataColumnName)
                                {
                                    detailControl.DataGridView.Sort(col, ListSortDirection.Ascending);
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.InnerExceptionMessages());
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex);
            }
            finally
            {
                this.SafeInvoke(() =>
                {
                    detailControl.Visible = true;
                    detailControl.ResumeLayout(true);
                });
            }
        }
예제 #7
0
        /// <summary>
        ///   Builds the tree data.
        /// </summary>
        private void BuildTreeData()
        {
            Contract.Requires(m_DataTable != null);
            var intervalAction = new IntervalAction();

            using (var process = new FormProcessDisplay("Building Tree", m_CancellationTokenSource.Token))
            {
                process.Show(this);
                process.Maximum = m_DataRow.GetLength(0);

                var dataColumnParent   = m_DataTable.Columns[m_ComboBoxParentID.SelectedItem.ToString()];
                var dataColumnID       = m_DataTable.Columns[m_ComboBoxID.SelectedItem.ToString()];
                var dataColumnDisplay1 = m_ComboBoxDisplay1.SelectedItem != null
          ? m_DataTable.Columns[m_ComboBoxDisplay1.SelectedItem.ToString()]
          : null;
                var dataColumnDisplay2 = m_ComboBoxDisplay2.SelectedItem != null
          ? m_DataTable.Columns[m_ComboBoxDisplay2.SelectedItem.ToString()]
          : null;

                // Using a dictionary here to speed up lookups
                var treeDataDictionary  = new Dictionary <string, TreeData>();
                var rootDataParentFound = new TreeData
                {
                    ID    = "{R}",
                    Title = "Parent found / No Parent"
                };

                treeDataDictionary.Add(rootDataParentFound.ID, rootDataParentFound);

                var counter = 0;
                foreach (var dataRow in m_DataRow)
                {
                    process.CancellationToken.ThrowIfCancellationRequested();
                    counter++;
                    intervalAction.Invoke(delegate
                    {
                        process.SetProcess($"Parent found {counter}/{process.Maximum} ", counter);
                    });
                    var id = dataRow[dataColumnID.Ordinal].ToString();
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }
                    var treeData = new TreeData
                    {
                        ID    = id,
                        Title = dataColumnDisplay1 != null
              ? dataColumnDisplay2 != null
                ? dataRow[dataColumnDisplay1.Ordinal] + " - " + dataRow[dataColumnDisplay2.Ordinal]
                : dataRow[
                            dataColumnDisplay1.Ordinal].ToString()
              : id,
                        ParentID = dataRow[dataColumnParent.Ordinal].ToString()
                    };
                    if (dataColumnDisplay1 != null)
                    {
                        treeData.Tag = dataRow[dataColumnDisplay1.Ordinal].ToString();
                    }
                    // Store the display
                    if (!treeDataDictionary.ContainsKey(id))
                    {
                        treeDataDictionary.Add(id, treeData);
                    }
                }

                // Generate a list of missing parents
                var additionalRootNodes = new HashSet <string>();
                foreach (var child in treeDataDictionary.Values)
                {
                    if (!string.IsNullOrEmpty(child.ParentID) && !treeDataDictionary.ContainsKey(child.ParentID))
                    {
                        additionalRootNodes.Add(child.ParentID);
                    }
                }

                var rootDataParentNotFound = new TreeData
                {
                    ID    = "{M}",
                    Title = "Parent not found"
                };

                if (additionalRootNodes.Count > 0)
                {
                    treeDataDictionary.Add(rootDataParentNotFound.ID, rootDataParentNotFound);
                    counter         = 0;
                    process.Maximum = additionalRootNodes.Count;
                    // Create new entries
                    foreach (var parentID in additionalRootNodes)
                    {
                        process.CancellationToken.ThrowIfCancellationRequested();
                        counter++;
                        intervalAction.Invoke(delegate
                        {
                            process.SetProcess($"Parent not found (Step 1) {counter}/{process.Maximum} ", counter);
                        });
                        var childData = new TreeData
                        {
                            ParentID = rootDataParentNotFound.ID,
                            ID       = parentID,
                            Title    = $"{m_ComboBoxID.SelectedItem} - {parentID}"
                        };
                        treeDataDictionary.Add(parentID, childData);
                    }
                }

                process.Maximum = treeDataDictionary.Values.Count;
                counter         = 0;
                foreach (var child in treeDataDictionary.Values)
                {
                    process.CancellationToken.ThrowIfCancellationRequested();
                    counter++;
                    intervalAction.Invoke(delegate
                    {
                        process.SetProcess($"Parent not found (Step 2) {counter}/{process.Maximum} ", counter);
                    });
                    if (string.IsNullOrEmpty(child.ParentID) && child.ID != rootDataParentFound.ID &&
                        child.ID != rootDataParentNotFound.ID)
                    {
                        child.ParentID = rootDataParentFound.ID;
                    }
                }

                process.Maximum = treeDataDictionary.Values.Count;
                counter         = 0;
                // Fill m_Children for the new nodes
                foreach (var child in treeDataDictionary.Values)
                {
                    process.CancellationToken.ThrowIfCancellationRequested();
                    counter++;
                    intervalAction.Invoke(delegate
                    {
                        process.SetProcess($"Set children {counter}/{process.Maximum} ", counter);
                    });
                    if (!string.IsNullOrEmpty(child.ParentID))
                    {
                        treeDataDictionary[child.ParentID].Children.Add(child);
                    }
                }

                m_TreeData = treeDataDictionary.Values;
            }
        }
예제 #8
0
        private void Work(string dataColumnName, bool ignoreNull)
        {
            if (string.IsNullOrEmpty(dataColumnName))
            {
                return;
            }
            if (dataColumnName.Equals(m_LastDataColumnName, StringComparison.OrdinalIgnoreCase) &&
                m_LastIgnoreNull == ignoreNull)
            {
                return;
            }

            m_LastDataColumnName = dataColumnName;
            m_LastIgnoreNull     = ignoreNull;
            this.SafeInvoke(
                () =>
            {
                detailControl.Visible = false;
                detailControl.SuspendLayout();
            });
            try
            {
                var dupliacteList     = new List <int>();
                var dictIDToRow       = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);
                var dictFirstIDStored = new HashSet <int>();
                var dataColumnID      = m_DataTable.Columns[dataColumnName];
                this.SafeInvoke(() => Text = $@"Duplicate Display - {dataColumnName}");

                var intervalAction = new IntervalAction();
                using (var display = new FormProcessDisplay(
                           $"Processing {dataColumnName}",
                           false,
                           m_CancellationTokenSource.Token))
                {
                    display.Maximum = m_DataRow.Length;
                    display.Show(this);
                    for (var rowIndex = 0; rowIndex < m_DataRow.Length; rowIndex++)
                    {
                        if (display.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        // ReSharper disable once AccessToDisposedClosure
                        intervalAction.Invoke(row => display.SetProcess("Getting duplicate values", row, false), rowIndex);

                        var id = m_DataRow[rowIndex][dataColumnID.Ordinal].ToString().Trim();

                        // if (id != null) id = id.Trim();
                        if (ignoreNull && string.IsNullOrEmpty(id))
                        {
                            continue;
                        }
                        if (dictIDToRow.TryGetValue(id, out var duplicateRowIndex))
                        {
                            if (!dictFirstIDStored.Contains(duplicateRowIndex))
                            {
                                dupliacteList.Add(duplicateRowIndex);
                                dictFirstIDStored.Add(duplicateRowIndex);
                            }

                            dupliacteList.Add(rowIndex);
                        }
                        else
                        {
                            dictIDToRow.Add(id, rowIndex);
                        }
                    }

                    dictFirstIDStored.Clear();
                    dictIDToRow.Clear();

                    this.SafeInvoke(
                        () => Text = $@"Duplicate Display - {dataColumnName} - Rows {dupliacteList.Count} / {m_DataRow.Length}");

                    m_DataTable.BeginLoadData();
                    m_DataTable.Clear();
                    var counter = 0;

                    display.Maximum = dupliacteList.Count;

                    foreach (var rowIndex in dupliacteList)
                    {
                        if (display.CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                        intervalAction.Invoke(row => display.SetProcess("Importing Rows to Grid", row, false), counter++);
                        m_DataTable.ImportRow(m_DataRow[rowIndex]);
                    }

                    m_DataTable.EndLoadData();
                    display.Maximum = 0;
                    display.SetProcess("Sorting");

                    detailControl.SafeInvoke(
                        () =>
                    {
                        try
                        {
                            foreach (DataGridViewColumn col in detailControl.FilteredDataGridView.Columns)
                            {
                                if (col.DataPropertyName == dataColumnName)
                                {
                                    detailControl.FilteredDataGridView.Sort(col, ListSortDirection.Ascending);
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Warning(ex, "Sorting duplicate list {exception}", ex.SourceExceptionMessage());
                        }
                    });
                }
            }
            finally
            {
                this.SafeInvoke(
                    () =>
                {
                    detailControl.Visible = true;
                    detailControl.ResumeLayout(true);
                });
            }
        }