Example #1
0
        protected override void LoadChildren()
        {
            if (!this.loadingChildren && !this.IsLoaded)
            {
                Mouse.OverrideCursor = Cursors.Wait;

                this.loadingChildren = true;
                this.Account.Client.SendServiceItemsDiscoveryRequest(this.pubSubClient.ComponentAddress, (sender, e) =>
                {
                    this.loadingChildren = false;
                    MainWindow.MouseDefault();

                    if (e.Ok)
                    {
                        SortedDictionary <string, TreeNode> Children = new SortedDictionary <string, TreeNode>();

                        this.NodesRemoved(this.children.Values, this);

                        foreach (Item Item in e.Items)
                        {
                            this.Account.Client.SendServiceDiscoveryRequest(this.PubSubClient.ComponentAddress, Item.Node, (sender2, e2) =>
                            {
                                if (e2.Ok)
                                {
                                    Item Item2        = (Item)e2.State;
                                    string Jid        = Item2.JID;
                                    string Node       = Item2.Node;
                                    string Name       = Item2.Name;
                                    NodeType NodeType = NodeType.leaf;
                                    PubSubNode NewNode;

                                    foreach (Identity Identity in e2.Identities)
                                    {
                                        if (Identity.Category == "pubsub")
                                        {
                                            if (!Enum.TryParse <NodeType>(Identity.Type, out NodeType))
                                            {
                                                NodeType = NodeType.leaf;
                                            }

                                            if (!string.IsNullOrEmpty(Identity.Name))
                                            {
                                                Name = Identity.Name;
                                            }
                                        }
                                    }

                                    lock (Children)
                                    {
                                        Children[Item2.Node] = NewNode = new PubSubNode(this, Jid, Node, Name, NodeType);
                                        this.children        = new SortedDictionary <string, TreeNode>(Children);
                                    }

                                    this.OnUpdated();
                                    this.NodesAdded(new TreeNode[] { NewNode }, this);
                                }
                            }, Item);
                        }
                    }
                    else
                    {
                        MainWindow.ErrorBox(string.IsNullOrEmpty(e.ErrorText) ? "Unable to get root nodes." : e.ErrorText);
                    }
                }, null);
            }

            base.LoadChildren();
        }
Example #2
0
        public override void Add()
        {
            Mouse.OverrideCursor = Cursors.Wait;

            this.pubSubClient.GetDefaultNodeConfiguration((sender, e) =>
            {
                MainWindow.MouseDefault();

                if (e.Ok)
                {
                    int c          = e.Form.Fields.Length;
                    Field[] Fields = new Field[c + 1];
                    DataForm Form  = null;

                    Array.Copy(e.Form.Fields, 0, Fields, 1, c);
                    Fields[0] = new TextSingleField(null, "Node", "Node Name:", true, new string[] { string.Empty }, null, "Name of the node to create.",
                                                    StringDataType.Instance, null, string.Empty, false, false, false);

                    Form = new DataForm(this.pubSubClient.Client,
                                        (sender2, e2) =>
                    {
                        string NodeName = Form["Node"].ValueString;
                        string Title    = Form["pubsub#title"]?.ValueString ?? string.Empty;

                        if (!Enum.TryParse <NodeType>(Form["pubsub#node_type"]?.ValueString ?? string.Empty, out NodeType Type))
                        {
                            Type = NodeType.leaf;
                        }

                        Mouse.OverrideCursor = Cursors.Wait;

                        this.pubSubClient.CreateNode(NodeName, e.Form, (sender3, e3) =>
                        {
                            MainWindow.MouseDefault();

                            if (e3.Ok)
                            {
                                if (this.IsLoaded)
                                {
                                    PubSubNode Node = new PubSubNode(this, this.pubSubClient.ComponentAddress, NodeName, Title, Type);

                                    if (this.children is null)
                                    {
                                        this.children = new SortedDictionary <string, TreeNode>()
                                        {
                                            { Node.Key, Node }
                                        }
                                    }
                                    ;
                                    else
                                    {
                                        lock (this.children)
                                        {
                                            this.children[Node.Key] = Node;
                                        }
                                    }

                                    MainWindow.UpdateGui(() =>
                                    {
                                        this.Account?.View?.NodeAdded(this, Node);
                                        this.OnUpdated();
                                    });
                                }
                            }
                            else
                            {
                                MainWindow.ErrorBox("Unable to create node: " + e3.ErrorText);
                            }
                        }, null);
                    },
                                        (sender2, e2) =>
                    {
                        // Do nothing.
                    }, string.Empty, string.Empty, Fields);

                    ParameterDialog Dialog = new ParameterDialog(Form);

                    MainWindow.UpdateGui(() =>
                    {
                        Dialog.ShowDialog();
                    });
                }
                else
                {
                    MainWindow.ErrorBox("Unable to get default node properties: " + e.ErrorText);
                }
            }, null);
        }
Example #3
0
        protected override void LoadChildren()
        {
            if (!this.loadingChildren && !this.IsLoaded)
            {
                SortedDictionary <string, TreeNode> Children = new SortedDictionary <string, TreeNode>();

                Mouse.OverrideCursor = Cursors.Wait;
                this.loadingChildren = true;

                if (this.nodeType == NodeType.leaf && this.Service.SupportsLastPublished)
                {
                    this.Service.PubSubClient.GetLatestItems(this.node, 50, (sender, e) =>
                    {
                        this.loadingChildren = false;
                        MainWindow.MouseDefault();

                        if (e.Ok)
                        {
                            foreach (Networking.XMPP.PubSub.PubSubItem Item in e.Items)
                            {
                                Children[Item.ItemId] = new PubSubItem(this, this.jid, Item.Node, Item.ItemId, Item.Payload, Item.Publisher);
                            }

                            this.children = Children;

                            this.OnUpdated();
                            this.Service.NodesAdded(this.children.Values, this);

                            this.Service.PubSubClient.Subscribe(this.node, (sender2, e2) =>
                            {
                                if (!e2.Ok)
                                {
                                    MainWindow.ErrorBox("Unable to subscribe to new items: " + e.ErrorText);
                                }

                                return(Task.CompletedTask);
                            }, null);
                        }
                        else
                        {
                            MainWindow.ErrorBox(string.IsNullOrEmpty(e.ErrorText) ? "Unable to get latest items." : e.ErrorText);
                        }

                        return(Task.CompletedTask);
                    }, null);
                }
                else
                {
                    this.Service.Account.Client.SendServiceItemsDiscoveryRequest(this.PubSubClient.ComponentAddress, this.node, (sender, e) =>
                    {
                        this.loadingChildren = false;
                        MainWindow.MouseDefault();

                        if (e.Ok)
                        {
                            this.Service.NodesRemoved(this.children.Values, this);

                            if (this.nodeType == NodeType.leaf)
                            {
                                List <string> ItemIds = new List <string>();

                                foreach (Item Item in e.Items)
                                {
                                    ItemIds.Add(Item.Name);
                                }

                                this.Service.PubSubClient.GetItems(this.node, ItemIds.ToArray(), (sender2, e2) =>
                                {
                                    if (e2.Ok)
                                    {
                                        if (e2.Items.Length == ItemIds.Count)
                                        {
                                            foreach (Networking.XMPP.PubSub.PubSubItem Item in e2.Items)
                                            {
                                                Children[Item.ItemId] = new PubSubItem(this, this.jid, Item.Node, Item.ItemId, Item.Payload, Item.Publisher);
                                            }

                                            this.children = Children;

                                            this.OnUpdated();
                                            this.Service.NodesAdded(this.children.Values, this);
                                        }
                                        else
                                        {
                                            foreach (Item Item in e.Items)
                                            {
                                                this.Service.PubSubClient.GetItems(this.node, new string[] { Item.Name }, (sender3, e3) =>
                                                {
                                                    if (e3.Ok)
                                                    {
                                                        if (e3.Items.Length == 1)
                                                        {
                                                            Networking.XMPP.PubSub.PubSubItem Item2 = e3.Items[0];
                                                            TreeNode NewNode;

                                                            lock (Children)
                                                            {
                                                                NewNode = new PubSubItem(this, this.jid, Item2.Node, Item2.ItemId, Item2.Payload, Item2.Publisher);
                                                                Children[Item2.ItemId] = NewNode;
                                                                this.children          = new SortedDictionary <string, TreeNode>(Children);
                                                            }

                                                            this.OnUpdated();
                                                            this.Service.NodesAdded(new TreeNode[] { NewNode }, this);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to get item." : e3.ErrorText);
                                                    }

                                                    return(Task.CompletedTask);
                                                }, Item);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to get items." : e2.ErrorText);
                                    }

                                    return(Task.CompletedTask);
                                }, null);
                            }
                            else
                            {
                                foreach (Item Item in e.Items)
                                {
                                    this.Service.Account.Client.SendServiceDiscoveryRequest(this.PubSubClient.ComponentAddress, Item.Node, (sender2, e2) =>
                                    {
                                        if (e2.Ok)
                                        {
                                            Item Item2        = (Item)e2.State;
                                            string Jid        = Item2.JID;
                                            string Node       = Item2.Node;
                                            string Name       = Item2.Name;
                                            NodeType NodeType = NodeType.leaf;
                                            TreeNode NewNode;

                                            foreach (Identity Identity in e2.Identities)
                                            {
                                                if (Identity.Category == "pubsub")
                                                {
                                                    if (!Enum.TryParse <NodeType>(Identity.Type, out NodeType))
                                                    {
                                                        NodeType = NodeType.leaf;
                                                    }

                                                    if (!string.IsNullOrEmpty(Identity.Name))
                                                    {
                                                        Name = Identity.Name;
                                                    }
                                                }
                                            }

                                            lock (Children)
                                            {
                                                NewNode = new PubSubNode(this, Jid, Node, Name, NodeType);
                                                Children[Item2.Node] = NewNode;
                                                this.children        = new SortedDictionary <string, TreeNode>(Children);
                                            }

                                            this.OnUpdated();
                                            this.Service.NodesAdded(new TreeNode[] { NewNode }, this);
                                        }
                                        else
                                        {
                                            MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to get information." : e2.ErrorText);
                                        }

                                        return(Task.CompletedTask);
                                    }, Item);
                                }
                            }
                        }
                        else
                        {
                            MainWindow.ErrorBox(string.IsNullOrEmpty(e.ErrorText) ? "Unable to get information." : e.ErrorText);
                        }

                        return(Task.CompletedTask);
                    }, null);
                }
            }

            base.LoadChildren();
        }