Example #1
0
        /// <summary>
        ///   Builds the sub nodes.
        /// </summary>
        /// <param name="parent">The parent ID.</param>
        /// <param name="process">Progress display</param>
        /// <returns></returns>
        private TreeNode[] BuildSubNodes([NotNull] TreeData parent, IProcessDisplay process)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            var treeNodes = new List <TreeNode>();

            foreach (var child in parent.Children)
            {
                process.CancellationToken.ThrowIfCancellationRequested();
                Extensions.ProcessUIElements();
                if (child.Visited)
                {
                    var treeNode = new TreeNode("Cycle -> " + child.Title)
                    {
                        Tag = child
                    };
                    treeNodes.Add(treeNode);
                }
                else
                {
                    child.Visited = true;
                    var treeNode = new TreeNode(child.NodeTitle, BuildSubNodes(child, process))
                    {
                        Tag = child
                    };
                    treeNodes.Add(treeNode);
                }
            }

            return(treeNodes.ToArray());
        }
        protected override void Append(log4net.Core.LoggingEvent loggingEvent)
        {
            string text = loggingEvent.MessageObject.ToString();

            if (AppenderTextBox != null && text.Length > 0 && !m_LastMessage.Equals(text, StringComparison.Ordinal))
            {
                AppenderTextBox.SafeBeginInvoke(() =>
                {
                    var appended = false;
                    var posSlash = text.IndexOf('–', 0);
                    if (posSlash != -1 && m_LastMessage.StartsWith(text.Substring(0, posSlash + 1), StringComparison.Ordinal))
                    {
                        // add to previous item,
                        AppendText(text.Substring(posSlash - 1), loggingEvent.Level);
                        appended = true;
                    }
                    m_LastMessage = text;
                    if (!appended)
                    {
                        if (AppenderTextBox.Text.Length > 0)
                        {
                            AppenderTextBox.AppendText(Environment.NewLine);
                        }
                        AppenderTextBox.AppendText($"{loggingEvent.TimeStamp:HH:mm:ss,fff}\t");
                        AppendText(text, loggingEvent.Level);
                    }
                });
                Extensions.ProcessUIElements();
            }
        }
 public void Clear()
 {
     AppenderTextBox.SafeBeginInvoke(() =>
     {
         AppenderTextBox.Text = string.Empty;
     });
     Extensions.ProcessUIElements();
 }
        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);
                });
            }
        }
 public override bool Flush(int timeout)
 {
     Extensions.ProcessUIElements();
     return(base.Flush(timeout));
 }
Example #6
0
 public new void Clear()
 {
     this.SafeBeginInvoke(() => { Text = string.Empty; });
     Extensions.ProcessUIElements();
 }
Example #7
0
        /// <summary>
        ///   Shows the tree.
        /// </summary>
        private void ShowTree(IProcessDisplay process)
        {
            m_TreeView.BeginUpdate();
            try
            {
                m_TreeView.Nodes.Clear();
                if (m_TreeData == null)
                {
                    return;
                }

                foreach (var treeData in m_TreeData)
                {
                    treeData.Visited = false;
                }
                process.SetProcess("Adding Tree with children", -1, false);
                foreach (var treeData in m_TreeData)
                {
                    process.CancellationToken.ThrowIfCancellationRequested();
                    Extensions.ProcessUIElements();
                    if (string.IsNullOrEmpty(treeData.ParentID))
                    {
                        AddTreeDataNodeWithChild(treeData, null, process);
                    }
                }

                process.SetProcess("Finding Cycles in Hierarchy", -1, true);
                var hasCycles = false;
                foreach (var treeData in m_TreeData)
                {
                    process.CancellationToken.ThrowIfCancellationRequested();
                    Extensions.ProcessUIElements();
                    if (!treeData.Visited)
                    {
                        hasCycles = true;
                        break;
                    }
                }

                if (!hasCycles)
                {
                    return;
                }

                process.SetProcess("Adding Cycles", -1, false);
                var rootNode = new TreeNode("Cycles in Hierarchy");
                m_TreeView.Nodes.Add(rootNode);

                foreach (var treeData in m_TreeData)
                {
                    process.CancellationToken.ThrowIfCancellationRequested();
                    Extensions.ProcessUIElements();
                    if (!treeData.Visited)
                    {
                        MarkInCycle(treeData, new HashSet <TreeData>());
                    }
                }

                foreach (var root in m_TreeData)
                {
                    process.CancellationToken.ThrowIfCancellationRequested();
                    Extensions.ProcessUIElements();
                    if (!root.Visited && root.InCycle)
                    {
                        AddTreeDataNodeWithChild(root, rootNode, process);
                    }
                }
            }
            catch
            {
                m_TreeView.Nodes.Clear();
            }
            finally
            {
                m_TreeView.EndUpdate();
            }
        }
Example #8
0
 public void BeginSection(string text)
 {
     AppendText($"\n{text}\n");
     Extensions.ProcessUIElements();
 }
Example #9
0
        /// <summary>
        ///   Copies the selected cells into the clipboard.
        /// </summary>
        /// <param name="addErrorInfo">if set to <c>true</c> [add error information].</param>
        /// <param name="cutLength">if set to <c>true</c> [cut length].</param>
        /// <param name="alternatingRows">if set to <c>true</c> [alternating rows].</param>
        /// <param name="columns">The columns.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="selectedCells">The selected cells.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        private void CopySelectedCellsIntoClipboard(
            bool addErrorInfo,
            bool cutLength,
            bool alternatingRows,
            [NotNull] DataGridViewColumnCollection columns,
            [NotNull] DataGridViewRowCollection rows,
            [NotNull] DataGridViewSelectedCellCollection selectedCells,
            CancellationToken cancellationToken)
        {
            var buffer     = new StringBuilder();
            var dataObject = new DataObject();

            // If there are multiple cells Add a header and a neat HTML table
            var sbHtml = new StringBuilder(m_HtmlStyle.TableOpen);

            var leftCol   = int.MaxValue;
            var rightCol  = int.MinValue;
            var topRow    = int.MaxValue;
            var bottomRow = int.MinValue;

            foreach (DataGridViewCell cell in selectedCells)
            {
                if (cell.OwningColumn.DisplayIndex < leftCol)
                {
                    leftCol = cell.OwningColumn.DisplayIndex;
                }
                if (cell.OwningColumn.DisplayIndex > rightCol)
                {
                    rightCol = cell.OwningColumn.DisplayIndex;
                }
                if (cell.RowIndex < topRow)
                {
                    topRow = cell.RowIndex;
                }
                if (cell.RowIndex > bottomRow)
                {
                    bottomRow = cell.RowIndex;
                }
            }

            var hasRowError    = HasRowErrors(topRow, bottomRow + 1, rows);
            var visibleColumns = new List <int>();

            sbHtml.Append(m_HtmlStyle.TROpenAlt);
            for (var col = leftCol; col <= rightCol; col++)
            {
                foreach (DataGridViewColumn diplayCol in columns)
                {
                    if (diplayCol.DisplayIndex == col && diplayCol.Visible && diplayCol.HeaderText != ReaderConstants.cErrorField)
                    {
                        visibleColumns.Add(col);
                        sbHtml.Append(HTMLStyle.AddTd(m_HtmlStyle.TH, diplayCol.HeaderText));
                        if (buffer.Length > 0)
                        {
                            buffer.Append('\t');
                        }

                        buffer.Append(EscapeTab(diplayCol.HeaderText));
                        break;
                    }
                }
            }

            if (hasRowError && addErrorInfo)
            {
                sbHtml.Append(HTMLStyle.AddTd(m_HtmlStyle.TH, c_ErrorInfo));
                buffer.Append('\t');
                buffer.Append(c_ErrorInfo);
            }

            sbHtml.AppendLine(m_HtmlStyle.TRClose);
            buffer.AppendLine();

            var trAlternate = false;
            var lastRefresh = DateTime.Now;

            for (var row = topRow; row <= bottomRow; row++)
            {
                if (rows[row].IsNewRow)
                {
                    continue;
                }
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                sbHtml.Append(trAlternate ? m_HtmlStyle.TROpenAlt : m_HtmlStyle.TROpen);
                if (alternatingRows)
                {
                    trAlternate = !trAlternate;
                }
                var written = false;
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                for (var col = leftCol; col <= rightCol; col++)
                {
                    if (!visibleColumns.Contains(col))
                    {
                        continue;
                    }
                    foreach (DataGridViewCell cell in selectedCells)
                    {
                        if (cell.RowIndex != row)
                        {
                            continue;
                        }
                        if (cell.OwningColumn.DisplayIndex != col)
                        {
                            continue;
                        }
                        AddCell(cell, buffer, sbHtml, col > leftCol, addErrorInfo, cutLength, m_HtmlStyle);
                        written = true;
                        break;
                    }

                    if (written)
                    {
                        continue;
                    }
                    buffer.Append('\t');
                    sbHtml.Append(m_HtmlStyle.TDEmpty);
                }

                AppendRowError(buffer, sbHtml, rows[row].ErrorText, addErrorInfo && hasRowError, m_HtmlStyle);

                sbHtml.AppendLine(m_HtmlStyle.TRClose);
                buffer.AppendLine();
                if (!((DateTime.Now - lastRefresh).TotalSeconds > 0.2))
                {
                    continue;
                }
                lastRefresh = DateTime.Now;
                Extensions.ProcessUIElements();
            }

            sbHtml.AppendLine(m_HtmlStyle.TableClose);
            dataObject.SetData(DataFormats.Html, true, m_HtmlStyle.ConvertToHtmlFragment(sbHtml.ToString()));
            dataObject.SetData(DataFormats.Text, true, buffer.ToString());
            dataObject.SetClipboard();
        }
Example #10
0
        /// <summary>
        ///   Copies all cells to the clipboard
        /// </summary>
        /// <param name="addErrorInfo">if set to <c>true</c> [add error information].</param>
        /// <param name="cutLength">if set to <c>true</c> [cut length].</param>
        /// <param name="alternatingRows">if set to <c>true</c> [alternating rows].</param>
        /// <param name="columns">The columns.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        private void CopyAllCellsIntoClipboard(
            bool addErrorInfo,
            bool cutLength,
            bool alternatingRows,
            [NotNull] DataGridViewColumnCollection columns,
            [NotNull] DataGridViewRowCollection rows,
            CancellationToken cancellationToken)
        {
            var buffer = new StringBuilder();
            var sbHtml = new StringBuilder(m_HtmlStyle.TableOpen);

            sbHtml.Append(m_HtmlStyle.TROpenAlt);
            var first = true;

            var visibleColumns = new SortedDictionary <int, DataGridViewColumn>();

            foreach (DataGridViewColumn c in columns)
            {
                // Do not include the error field it will be retrieved from the error collection with nice coloring
                if (c.Visible && c.HeaderText != ReaderConstants.cErrorField)
                {
                    visibleColumns.Add(c.DisplayIndex, c);
                }
            }
            var hasRowError = HasRowErrors(0, rows.Count, rows);

            foreach (var col in visibleColumns.Values)
            {
                var headerText = col.HeaderText;
                sbHtml.Append(HTMLStyle.AddTd(m_HtmlStyle.TH, headerText));
                if (!first)
                {
                    buffer.Append('\t');
                }
                else
                {
                    first = false;
                }

                buffer.Append(EscapeTab(headerText));
            }

            if (hasRowError && addErrorInfo)
            {
                sbHtml.Append(HTMLStyle.AddTd(m_HtmlStyle.TH, c_ErrorInfo));
                buffer.Append('\t');
                buffer.Append(c_ErrorInfo);
            }

            sbHtml.AppendLine(m_HtmlStyle.TRClose);
            buffer.AppendLine();

            var trAlternate = false;
            var lastRefresh = DateTime.Now;

            for (var row = 0; row < rows.Count; row++)
            {
                if (rows[row].IsNewRow)
                {
                    break;
                }
                sbHtml.Append(trAlternate ? m_HtmlStyle.TROpenAlt : m_HtmlStyle.TROpen);
                if (alternatingRows)
                {
                    trAlternate = !trAlternate;
                }
                first = true;
                foreach (var col in visibleColumns.Values)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    var cell = rows[row].Cells[col.Index];
                    AddCell(cell, buffer, sbHtml, !first, addErrorInfo, cutLength, m_HtmlStyle);
                    first = false;
                }

                AppendRowError(buffer, sbHtml, rows[row].ErrorText, addErrorInfo && hasRowError, m_HtmlStyle);
                sbHtml.AppendLine(m_HtmlStyle.TRClose);
                buffer.AppendLine();
                if (!((DateTime.Now - lastRefresh).TotalSeconds > 0.2))
                {
                    continue;
                }
                lastRefresh = DateTime.Now;
                Extensions.ProcessUIElements();
            }

            sbHtml.AppendLine(m_HtmlStyle.TableClose);

            var dataObject = new DataObject();

            dataObject.SetData(DataFormats.Html, true, m_HtmlStyle.ConvertToHtmlFragment(sbHtml.ToString()));
            dataObject.SetData(DataFormats.Text, true, buffer.ToString());
            dataObject.SetClipboard();
        }