Exemple #1
0
        /*
         * private void InsertNodeElementsTask(object parameters)
         * {
         *  TreeNode treenode = (TreeNode)((object[])parameters)[0];
         *  IExplorerObject exObject = (IExplorerObject)((object[])parameters)[1];
         *
         *  IStatusBar statusbar = (_app != null) ? _app.StatusBar : null;
         *  List<ExplorerObjectNode> treeNodes = new List<ExplorerObjectNode>();
         *
         *  List<IExplorerObject> childObjects = ((IExplorerParentObject)exObject).ChildObjects;
         *  if (childObjects == null) return;
         *  int pos = 0, count = childObjects.Count;
         *  if (statusbar != null) statusbar.ProgressVisible = true;
         *
         *  foreach (IExplorerObject exObj in childObjects)
         *  {
         *      if (exObj == null ||
         *          exObj is IExplorerObjectDoubleClick) continue;
         *
         *      if (statusbar != null)
         *      {
         *          statusbar.ProgressValue = (int)(((double)pos++ / (double)count) * 100.0);
         *          statusbar.Text = exObj.Name;
         *          statusbar.Refresh();
         *      }
         *
         *      if (_filter != null)
         *      {
         *          if (_filter.Match(exObj))
         *              continue;
         *          else if (!(exObj is IExplorerParentObject)) continue;
         *      }
         *      int imageIndex = FormExplorer.ImageIndex(exObj);
         *      treeNodes.Add(new ExplorerObjectNode(exObj, imageIndex));
         *
         *      if (exObj is IExplorerObjectDeletable)
         *          ((IExplorerObjectDeletable)exObj).ExplorerObjectDeleted += new ExplorerObjectDeletedEvent(CatalogTreeControl_ExplorerObjectDeleted);
         *      if (exObj is IExplorerObjectRenamable)
         *          ((IExplorerObjectRenamable)exObj).ExplorerObjectRenamed += new ExplorerObjectRenamedEvent(CatalogTreeControl_ExplorerObjectRenamed);
         *      if (exObj is IRefreshedEventHandler)
         *          ((IRefreshedEventHandler)exObj).Refreshed += new RefreshedEventHandler(CatalogTreeControl_Refreshed);
         *  }
         *
         *  if (treenode.Nodes.Count == 0)
         *  {
         *      treenode.Nodes.Add(new DummyNode());
         *      return;
         *  }
         * }
         *
         * private delegate void InsertNodeElementsCallback(TreeNode treeNode, List<ExplorerObjectNode> childNodes);
         * private void InsertNodeElements(TreeNode treeNode, List<ExplorerObjectNode> childNodes)
         * {
         *  if (this.InvokeRequired)
         *  {
         *      this.Invoke(new InsertNodeElementsCallback(InsertNodeElements), new object[] { treeNode, childNodes });
         *  }
         *  else
         *  {
         *      foreach (ExplorerObjectNode childNode in childNodes)
         *      {
         *          treeNode.Nodes.Add(childNode);
         *      }
         *  }
         * }
         */

        async private Task <bool> InsertNodeElements(TreeNode treenode)
        {
            if (!(treenode is ExplorerObjectNode))
            {
                return(true);
            }
            ExplorerObjectNode node     = (ExplorerObjectNode)treenode;
            IExplorerObject    exObject = node.ExplorerObject;

            if (exObject == null)
            {
                return(true);
            }

            try
            {
                Cursor = Cursors.WaitCursor;

                if (exObject is IExplorerParentObject)
                {
                    //System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(InsertNodeElementsTask));
                    //thread.Start(new object[] { treenode, exObject });

                    treenode.Nodes.Clear();
                    IStatusBar             statusbar    = (_app != null) ? _app.StatusBar : null;
                    List <IExplorerObject> childObjects = await((IExplorerParentObject)exObject).ChildObjects();
                    if (childObjects == null)
                    {
                        return(false);
                    }

                    int pos = 0, count = childObjects.Count;
                    if (statusbar != null)
                    {
                        statusbar.ProgressVisible = true;
                    }

                    foreach (IExplorerObject exObj in childObjects)
                    {
                        if (exObj == null ||
                            exObj is IExplorerObjectDoubleClick)
                        {
                            continue;
                        }

                        if (statusbar != null)
                        {
                            statusbar.ProgressValue = (int)((pos++ / (double)count) * 100.0);
                            statusbar.Text          = exObj.Name;
                            statusbar.Refresh();
                        }

                        if (_filter != null)
                        {
                            if (await _filter.Match(exObj))
                            {
                                continue;
                            }
                            else if (!(exObj is IExplorerParentObject))
                            {
                                continue;
                            }
                        }
                        int imageIndex = gView.Explorer.UI.Framework.UI.ExplorerIcons.ImageIndex(exObj);
                        treenode.Nodes.Add(new ExplorerObjectNode(exObj, imageIndex));

                        if (exObj is IExplorerObjectDeletable)
                        {
                            ((IExplorerObjectDeletable)exObj).ExplorerObjectDeleted += new ExplorerObjectDeletedEvent(CatalogTreeControl_ExplorerObjectDeleted);
                        }

                        if (exObj is IExplorerObjectRenamable)
                        {
                            ((IExplorerObjectRenamable)exObj).ExplorerObjectRenamed += new ExplorerObjectRenamedEvent(CatalogTreeControl_ExplorerObjectRenamed);
                        }

                        if (exObj is IRefreshedEventHandler)
                        {
                            ((IRefreshedEventHandler)exObj).Refreshed += new RefreshedEventHandler(CatalogTreeControl_Refreshed);
                        }
                    }

                    if (statusbar != null)
                    {
                        statusbar.ProgressVisible = false;
                        statusbar.Text            = String.Empty;
                        statusbar.Refresh();
                    }
                }

                if (treenode.Nodes.Count == 0)
                {
                    treenode.Nodes.Add(new DummyNode());
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;

                MessageBox.Show(ex.Message);
                treenode.Nodes.Add(new DummyNode());
                return(false);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private void BuildListThread(object chkTreeNodes)
        {
            bool checkTreeNodes = (bool)chkTreeNodes;

            ClearList();

            if (_exObject is IExplorerParentObject)
            {
                List <IExplorerObject> childs = ((IExplorerParentObject)_exObject).ChildObjects;
                if (childs != null)
                {
                    IStatusBar             statusbar    = (_app != null) ? _app.StatusBar : null;
                    List <IExplorerObject> childObjects = ((IExplorerParentObject)_exObject).ChildObjects;
                    if (childObjects == null)
                    {
                        return;
                    }
                    int pos = 0, count = childObjects.Count;
                    if (statusbar != null)
                    {
                        statusbar.ProgressVisible = true;
                    }

                    foreach (IExplorerObject exObject in childObjects)
                    {
                        if (exObject == null)
                        {
                            continue;
                        }
                        if (statusbar != null)
                        {
                            statusbar.ProgressValue = (int)(((double)pos++ / (double)count) * 100.0);
                            statusbar.Text          = exObject.Name;
                            statusbar.Refresh();
                        }

                        if (!_cancelTracker.Continue)
                        {
                            break;
                        }

                        if (_filter != null &&
                            !(exObject is IExplorerParentObject) &&
                            !(exObject is IExplorerObjectDoubleClick) &&
                            _open)
                        {
                            if (!_filter.Match(exObject))
                            {
                                continue;
                            }
                        }
                        int imageIndex = gView.Explorer.UI.Framework.UI.ExplorerIcons.ImageIndex(exObject);
                        if (imageIndex == -1)
                        {
                            continue;
                        }
                        string[] texts = null;
                        if (exObject is IExporerOjectSchema)
                        {
                            texts = new string[] { exObject.Name, exObject.Type, ((IExporerOjectSchema)exObject).Schema }
                        }
                        ;
                        else
                        {
                            texts = new string[] { exObject.Name, exObject.Type }
                        };
                        ListViewItem item = new ExplorerObjectListViewItem(texts, exObject);
                        item.ImageIndex = imageIndex;

                        AddListItem(item);
                        if (checkTreeNodes && _tree != null)
                        {
                            CheckTree(exObject);
                        }

                        if (exObject is IExplorerObjectDeletable)
                        {
                            ((IExplorerObjectDeletable)exObject).ExplorerObjectDeleted += new ExplorerObjectDeletedEvent(ContentsList_ExplorerObjectDeleted);
                        }
                        if (exObject is IExplorerObjectRenamable)
                        {
                            ((IExplorerObjectRenamable)exObject).ExplorerObjectRenamed += new ExplorerObjectRenamedEvent(ContentsList_ExplorerObjectRenamed);
                        }
                    }

                    if (statusbar != null)
                    {
                        statusbar.ProgressVisible = false;
                        statusbar.Text            = pos.ToString() + " Objects...";
                        statusbar.Refresh();
                    }
                }
            }

            _worker = null;
        }