Exemplo n.º 1
0
        public override void SendChatMessage(string Message, MarkdownDocument Markdown)
        {
            XmppAccountNode XmppAccountNode = this.XmppAccountNode;

            if (XmppAccountNode != null)
            {
                string To = this.RosterItem?.LastPresenceFullJid;
                if (string.IsNullOrEmpty(To))
                {
                    To = this.bareJid;
                }

                if (Markdown is null)
                {
                    XmppAccountNode.Client.SendChatMessage(To, Message);
                }
                else
                {
                    string PlainText = Markdown.GeneratePlainText().Trim();

                    XmppAccountNode.Client.SendMessage(QoSLevel.Unacknowledged, MessageType.Chat, To,
                                                       "<content xmlns=\"urn:xmpp:content\" type=\"text/markdown\">" + XML.Encode(Message) + "</content>", PlainText,
                                                       string.Empty, string.Empty, string.Empty, string.Empty, null, null);
                }
            }
        }
Exemplo n.º 2
0
        public ThingRegistry(TreeNode Parent, string JID, string Name, string Node, Dictionary <string, bool> Features)
            : base(Parent, JID, Name, Node, Features)
        {
            this.supportsProvisioning = Features.ContainsKey(ProvisioningClient.NamespaceProvisioningOwner);
            this.registryClient       = new ThingRegistryClient(this.Account.Client, JID);

            if (this.supportsProvisioning)
            {
                XmppAccountNode Account = this.Account;
                XmppClient      Client  = Account.Client;

                this.provisioningClient = new ProvisioningClient(Client, JID);

                this.provisioningClient.IsFriendQuestion   += this.ProvisioningClient_IsFriendQuestion;
                this.provisioningClient.CanReadQuestion    += this.ProvisioningClient_CanReadQuestion;
                this.provisioningClient.CanControlQuestion += this.ProvisioningClient_CanControlQuestion;

                foreach (MessageEventArgs Message in Account.GetUnhandledMessages("isFriend", ProvisioningClient.NamespaceProvisioningOwner))
                {
                    try
                    {
                        this.ProvisioningClient_IsFriendQuestion(this, new IsFriendEventArgs(Client, Message));
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(ex);
                    }
                }
            }
            else
            {
                this.provisioningClient = null;
            }
        }
Exemplo n.º 3
0
        public override SensorDataClientRequest StartSensorDataFullReadout()
        {
            XmppAccountNode XmppAccountNode = this.XmppAccountNode;
            SensorClient    SensorClient;

            if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null)
            {
                return(SensorClient.RequestReadout(this.RosterItem.LastPresenceFullJid, FieldType.All));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Exemplo n.º 4
0
        public override void GetConfigurationForm(DataFormResultEventHandler Callback, object State)
        {
            XmppAccountNode XmppAccountNode = this.XmppAccountNode;
            ControlClient   ControlClient;

            if (XmppAccountNode != null && (ControlClient = XmppAccountNode.ControlClient) != null)
            {
                ControlClient.GetForm(this.RosterItem.LastPresenceFullJid, "en", Callback, State);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Exemplo n.º 5
0
        public override SensorDataClientRequest StartSensorDataMomentaryReadout()
        {
            XmppAccountNode XmppAccountNode = this.XmppAccountNode;
            SensorClient    SensorClient;

            if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null)
            {
                return(SensorClient.RequestReadout(this.RosterItem.LastPresenceFullJid, FieldType.Momentary));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        public override SensorDataSubscriptionRequest SubscribeSensorDataMomentaryReadout(FieldSubscriptionRule[] Rules)
        {
            XmppAccountNode XmppAccountNode = this.XmppAccountNode;
            SensorClient    SensorClient;

            if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null)
            {
                return(SensorClient.Subscribe(this.RosterItem.LastPresenceFullJid, FieldType.Momentary, Rules,
                                              new Duration(false, 0, 0, 0, 0, 0, 1), new Duration(false, 0, 0, 0, 0, 1, 0), false));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        public override void GetConfigurationForm(DataFormResultEventHandler Callback, object State)
        {
            XmppConcentrator Concentrator    = this.Concentrator;
            XmppAccountNode  XmppAccountNode = Concentrator.XmppAccountNode;
            ControlClient    ControlClient;

            if (XmppAccountNode != null && (ControlClient = XmppAccountNode.ControlClient) != null)
            {
                ControlClient.GetForm(Concentrator.RosterItem.LastPresenceFullJid, "en", Callback, State,
                                      new ThingReference(this.nodeInfo.NodeId, this.nodeInfo.SourceId, this.nodeInfo.ParentId));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Exemplo n.º 8
0
        public override SensorDataClientRequest StartSensorDataFullReadout()
        {
            XmppConcentrator Concentrator    = this.Concentrator;
            XmppAccountNode  XmppAccountNode = Concentrator.XmppAccountNode;
            SensorClient     SensorClient;

            if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null)
            {
                return(SensorClient.RequestReadout(Concentrator.RosterItem.LastPresenceFullJid,
                                                   new ThingReference[] { new ThingReference(this.nodeInfo.NodeId, this.nodeInfo.SourceId, this.nodeInfo.ParentId) }, FieldType.All));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Exemplo n.º 9
0
        public override SensorDataClientRequest StartSensorDataMomentaryReadout()
        {
            XmppConcentrator Concentrator    = this.Concentrator;
            XmppAccountNode  XmppAccountNode = Concentrator.XmppAccountNode;
            SensorClient     SensorClient;

            if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null)
            {
                return(SensorClient.RequestReadout(Concentrator.RosterItem.LastPresenceFullJid,
                                                   new ThingReference[] { new ThingReference(this.nodeInfo.NodeId, this.nodeInfo.SourceId, this.nodeInfo.Partition) }, FieldType.Momentary));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        public override SensorDataSubscriptionRequest SubscribeSensorDataMomentaryReadout(FieldSubscriptionRule[] Rules)
        {
            XmppConcentrator Concentrator    = this.Concentrator;
            XmppAccountNode  XmppAccountNode = Concentrator.XmppAccountNode;
            SensorClient     SensorClient;

            if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null)
            {
                return(SensorClient.Subscribe(Concentrator.RosterItem.LastPresenceFullJid,
                                              new ThingReference[] { new ThingReference(this.nodeInfo.NodeId, this.nodeInfo.SourceId, this.nodeInfo.ParentId) },
                                              FieldType.Momentary, Rules, new Duration(false, 0, 0, 0, 0, 0, 1), new Duration(false, 0, 0, 0, 0, 1, 0), false));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 11
0
        public void NodesRemoved(IEnumerable <TreeNode> Nodes, TreeNode Parent)
        {
            XmppAccountNode XmppAccountNode = this.Account;

            if (XmppAccountNode is null)
            {
                return;
            }

            Controls.ConnectionView View = XmppAccountNode.View;
            if (View is null)
            {
                return;
            }

            LinkedList <KeyValuePair <TreeNode, TreeNode> > ToRemove = new LinkedList <KeyValuePair <TreeNode, TreeNode> >();

            foreach (TreeNode Node in Nodes)
            {
                ToRemove.AddLast(new KeyValuePair <TreeNode, TreeNode>(Parent, Node));
            }

            while (ToRemove.First != null)
            {
                KeyValuePair <TreeNode, TreeNode> P = ToRemove.First.Value;
                ToRemove.RemoveFirst();

                Parent = P.Key;
                TreeNode Node = P.Value;

                if (Node.HasChildren.HasValue && Node.HasChildren.Value)
                {
                    foreach (TreeNode Child in Node.Children)
                    {
                        ToRemove.AddLast(new KeyValuePair <TreeNode, TreeNode>(Node, Child));
                    }
                }

                MainWindow.currentInstance.Dispatcher.BeginInvoke(new ThreadStart(() =>
                {
                    View.NodeRemoved(Parent, Node);
                }));
            }
        }
Exemplo n.º 12
0
        public void NodesAdded(IEnumerable <TreeNode> Nodes, TreeNode Parent)
        {
            XmppAccountNode XmppAccountNode = this.XmppAccountNode;

            if (XmppAccountNode == null)
            {
                return;
            }

            Controls.ConnectionView View = XmppAccountNode.View;
            if (View == null)
            {
                return;
            }

            foreach (TreeNode Node in Nodes)
            {
                View.NodeAdded(Parent, Node);
            }
        }
Exemplo n.º 13
0
        public void NodesRemoved(IEnumerable <TreeNode> Nodes, TreeNode Parent)
        {
            XmppAccountNode XmppAccountNode = this.Account;

            if (XmppAccountNode == null)
            {
                return;
            }

            Controls.ConnectionView View = XmppAccountNode.View;
            if (View == null)
            {
                return;
            }

            LinkedList <KeyValuePair <TreeNode, TreeNode> > ToRemove = new LinkedList <KeyValuePair <TreeNode, TreeNode> >();

            foreach (TreeNode Node in Nodes)
            {
                ToRemove.AddLast(new KeyValuePair <TreeNode, TreeNode>(Parent, Node));
            }

            while (ToRemove.First != null)
            {
                KeyValuePair <TreeNode, TreeNode> P = ToRemove.First.Value;
                ToRemove.RemoveFirst();

                Parent = P.Key;
                TreeNode Node = P.Value;

                if (Node.HasChildren.HasValue && Node.HasChildren.Value)
                {
                    foreach (TreeNode Child in Node.Children)
                    {
                        ToRemove.AddLast(new KeyValuePair <TreeNode, TreeNode>(Node, Child));
                    }
                }

                View.NodeRemoved(Parent, Node);
            }
        }
Exemplo n.º 14
0
        public override void SendChatMessage(string Message, string ThreadId, MarkdownDocument Markdown)
        {
            XmppAccountNode XmppAccountNode = this.XmppAccountNode;

            if (XmppAccountNode != null)
            {
                string To = this.RosterItem?.LastPresenceFullJid;
                if (string.IsNullOrEmpty(To))
                {
                    To = this.bareJid;
                }

                if (Markdown is null)
                {
                    XmppAccountNode.Client.SendChatMessage(To, Message, string.Empty, string.Empty, ThreadId);
                }
                else
                {
                    XmppAccountNode.Client.SendMessage(QoSLevel.Unacknowledged, MessageType.Chat, To,
                                                       MultiFormatMessage(Message, Markdown), string.Empty, string.Empty, string.Empty, ThreadId, string.Empty, null, null);
                }
            }
        }
Exemplo n.º 15
0
        public override void AddContexMenuItems(ref string CurrentGroup, ContextMenu Menu)
        {
            base.AddContexMenuItems(ref CurrentGroup, Menu);

            XmppAccountNode XmppAccountNode = this.XmppAccountNode;

            if (XmppAccountNode != null && XmppAccountNode.IsOnline)
            {
                SubscriptionState SubscriptionState = this.SubscriptionState;
                MenuItem          MenuItem;
                string            s;

                if (SubscriptionState == SubscriptionState.None || SubscriptionState == SubscriptionState.From)
                {
                    CurrentGroup = "Subscriptions";

                    if (SubscriptionState == SubscriptionState.None)
                    {
                        s = "../Graphics/To.png";
                    }
                    else
                    {
                        s = "../Graphics/Both.png";
                    }

                    Menu.Items.Add(MenuItem = new MenuItem()
                    {
                        Header    = "_Subscribe to",
                        IsEnabled = true,
                        Icon      = new Image()
                        {
                            Source = new BitmapImage(new Uri(s, UriKind.Relative)),
                            Width  = 16,
                            Height = 16
                        }
                    });

                    MenuItem.Click += Subscribe_Click;
                }

                if (SubscriptionState == SubscriptionState.To || SubscriptionState == SubscriptionState.Both)
                {
                    CurrentGroup = "Subscriptions";

                    if (SubscriptionState == SubscriptionState.To)
                    {
                        s = "../Graphics/None.png";
                    }
                    else
                    {
                        s = "../Graphics/From.png";
                    }

                    Menu.Items.Add(MenuItem = new MenuItem()
                    {
                        Header    = "_Unsubscribe from",
                        IsEnabled = true,
                        Icon      = new Image()
                        {
                            Source = new BitmapImage(new Uri(s, UriKind.Relative)),
                            Width  = 16,
                            Height = 16
                        }
                    });

                    MenuItem.Click += Unsubscribe_Click;
                }
            }
        }