예제 #1
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(this.provisioningClient, Message));
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(ex);
                    }
                }
            }
            else
            {
                this.provisioningClient = null;
            }
        }
예제 #2
0
        public void ConnectTo_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ConnectToForm Dialog = new ConnectToForm()
            {
                Owner = this.MainWindow
            };
            bool?Result = Dialog.ShowDialog();

            if (Result.HasValue && Result.Value)
            {
                string Host                        = Dialog.XmppServer.Text;
                int    Port                        = int.Parse(Dialog.XmppPort.Text);
                string Account                     = Dialog.AccountName.Text;
                string PasswordHash                = Dialog.PasswordHash;
                string PasswordHashMethod          = Dialog.PasswordHashMethod;
                bool   TrustCertificate            = Dialog.TrustServerCertificate.IsChecked.HasValue && Dialog.TrustServerCertificate.IsChecked.Value;
                bool   AllowInsecureAuthentication = Dialog.AllowInsecureAuthentication.IsChecked.HasValue && Dialog.AllowInsecureAuthentication.IsChecked.Value;

                XmppAccountNode Node = new XmppAccountNode(this.connections, null, Host, Port, Account, PasswordHash, PasswordHashMethod,
                                                           TrustCertificate, AllowInsecureAuthentication);

                this.connections.Add(Node);
                this.AddNode(Node);
            }
        }
예제 #3
0
        public void ConnectTo_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ConnectToForm Dialog = new ConnectToForm()
            {
                Owner = this.MainWindow
            };
            bool?Result = Dialog.ShowDialog();

            if (Result.HasValue && Result.Value)
            {
                if (!int.TryParse(Dialog.XmppPort.Text, out int Port))
                {
                    Port = XmppCredentials.DefaultPort;
                }

                XmppAccountNode Node = new XmppAccountNode(this.connections, null, Dialog.XmppServer.Text,
                                                           (TransportMethod)Dialog.ConnectionMethod.SelectedIndex, Port, Dialog.HttpEndpoint.Text,
                                                           Dialog.AccountName.Text, Dialog.PasswordHash, Dialog.PasswordHashMethod,
                                                           Dialog.TrustServerCertificate.IsChecked.HasValue && Dialog.TrustServerCertificate.IsChecked.Value,
                                                           Dialog.AllowInsecureAuthentication.IsChecked.HasValue && Dialog.AllowInsecureAuthentication.IsChecked.Value);

                this.connections.Add(Node);
                this.AddNode(Node);
            }
        }
예제 #4
0
        public QuestionView(XmppAccountNode Owner, ProvisioningClient ProvisioningClient)
        {
            this.owner = Owner;
            this.provisioningClient = ProvisioningClient;

            InitializeComponent();
        }
예제 #5
0
        public void UnsubscribeFromEvents()
        {
            this.unsubscribed = true;

            if (this.timer != null)
            {
                this.timer.Dispose();
                this.timer = null;
            }

            XmppConcentrator Concentrator = this.Concentrator;

            if (Concentrator is null)
            {
                return;
            }

            XmppAccountNode XmppAccountNode = Concentrator.XmppAccountNode;

            if (XmppAccountNode is null)
            {
                return;
            }

            string             FullJid            = Concentrator.FullJid;
            ConcentratorClient ConcentratorClient = XmppAccountNode?.ConcentratorClient;

            if (ConcentratorClient is null)
            {
                return;
            }

            XmppAccountNode.ConcentratorClient.Unsubscribe(FullJid, this.key, SourceEventType.All, "en",
                                                           string.Empty, string.Empty, string.Empty, null, null);
        }
예제 #6
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)
                {
                    ManagePresenceSubscriptionRequests = false
                };

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

                this.ProcessUnhandled();
            }
            else
            {
                this.provisioningClient = null;
            }
        }
예제 #7
0
        internal void NewQuestion(XmppAccountNode Owner, ProvisioningClient ProvisioningClient, Question Question)
        {
            QuestionView QuestionView = this.FindQuestionTab(Owner, ProvisioningClient);

            if (QuestionView != null && Question != null)
            {
                QuestionView.NewQuestion(Question);
                return;
            }

            Task.Run(async() =>
            {
                try
                {
                    LinkedList <Question> Questions = new LinkedList <Question>();
                    bool Found = Question == null;

                    foreach (Question Question2 in await Database.Find <Question>(new FilterAnd(new FilterFieldEqualTo("OwnerJID", Owner?.BareJID),
                                                                                                new FilterFieldEqualTo("ProvisioningJID", ProvisioningClient?.ProvisioningServerAddress)), "Created"))
                    {
                        Questions.AddLast(Question2);

                        if (!Found)
                        {
                            Found = Question2.ObjectId == Question.ObjectId;
                        }
                    }

                    if (!Found)
                    {
                        Questions.AddLast(Question);
                    }

                    if (Questions.First != null)
                    {
                        DispatcherOperation Op = MainWindow.currentInstance.Dispatcher.BeginInvoke(new ThreadStart(() =>
                        {
                            if (QuestionView == null)
                            {
                                QuestionView = this.CreateQuestionTab(Owner, ProvisioningClient);
                            }

                            foreach (Question Question2 in Questions)
                            {
                                QuestionView.NewQuestion(Question2);
                            }
                        }));
                    }
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            });
        }
예제 #8
0
        private QuestionView CreateQuestionTab(XmppAccountNode Owner, ProvisioningClient ProvisioningClient)
        {
            TabItem TabItem = MainWindow.NewTab("Questions (" + Owner.BareJID + ")");

            this.Tabs.Items.Add(TabItem);

            QuestionView QuestionView = new QuestionView(Owner, ProvisioningClient);

            TabItem.Content = QuestionView;

            return(QuestionView);
        }
예제 #9
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();
            }
        }
예제 #10
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);
            }
        }
예제 #11
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();
            }
        }
예제 #12
0
        public void SubscribeToEvents()
        {
            if (this.unsubscribed)
            {
                return;
            }

            XmppConcentrator Concentrator = this.Concentrator;

            if (Concentrator is null)
            {
                return;
            }

            XmppAccountNode XmppAccountNode = Concentrator.XmppAccountNode;

            if (XmppAccountNode is null)
            {
                return;
            }

            string             FullJid            = Concentrator.FullJid;
            ConcentratorClient ConcentratorClient = XmppAccountNode?.ConcentratorClient;

            if (ConcentratorClient is null)
            {
                return;
            }

            if (this.timer != null)
            {
                this.timer.Dispose();
                this.timer = null;
            }

            ConcentratorClient.Subscribe(FullJid, this.key, 600, SourceEventType.All, true, true, "en",
                                         string.Empty, string.Empty, string.Empty, (sender, e) =>
            {
                if (e.Ok)
                {
                    this.timer = new Timer((P) =>
                    {
                        this.SubscribeToEvents();
                    }, null, 300000, 300000);
                }

                return(Task.CompletedTask);
            }, null);
        }
예제 #13
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);
            }
        }
예제 #14
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.Partition));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
예제 #15
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.Partition) }, FieldType.All));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
예제 #16
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.Partition) },
                                              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);
            }
        }
예제 #17
0
        private QuestionView FindQuestionTab(XmppAccountNode Owner, ProvisioningClient ProvisioningClient)
        {
            QuestionView QuestionView = null;

            foreach (TabItem TabItem in this.Tabs.Items)
            {
                QuestionView = TabItem.Content as QuestionView;
                if (QuestionView != null &&
                    QuestionView.Owner == Owner &&
                    QuestionView.ProvisioningJid == ProvisioningClient.ProvisioningServerAddress)
                {
                    return(QuestionView);
                }
            }

            return(null);
        }
예제 #18
0
        public override SensorDataSubscriptionRequest SubscribeSensorDataMomentaryReadout(FieldSubscriptionRule[] Rules)
        {
            if (this.isSensor)
            {
                XmppAccountNode XmppAccountNode = this.XmppAccountNode;
                SensorClient    SensorClient;

                if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null)
                {
                    return(SensorClient.Subscribe(this.RosterItem.LastPresenceFullJid, FieldType.Momentary, Rules,
                                                  Duration.FromSeconds(1), Duration.FromMinutes(1), false));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
예제 #19
0
        private void ChatMessageReceived(object P)
        {
            MessageEventArgs e = (MessageEventArgs)P;
            ChatView         ChatView;

            string Message    = e.Body;
            bool   IsMarkdown = false;

            foreach (XmlNode N in e.Message.ChildNodes)
            {
                if (N.LocalName == "content" && N.NamespaceURI == "urn:xmpp:content")
                {
                    string Type = XML.Attribute((XmlElement)N, "type");
                    if (Type == "text/markdown")
                    {
                        IsMarkdown = true;

                        Type = N.InnerText;
                        if (!string.IsNullOrEmpty(Type))
                        {
                            Message = Type;
                        }

                        break;
                    }
                }
            }

            foreach (TabItem TabItem in this.Tabs.Items)
            {
                ChatView = TabItem.Content as ChatView;
                if (ChatView == null)
                {
                    continue;
                }

                XmppContact XmppContact = ChatView.Node as XmppContact;
                if (XmppContact == null)
                {
                    continue;
                }

                if (XmppContact.BareJID != e.FromBareJID)
                {
                    continue;
                }

                XmppAccountNode XmppAccountNode = XmppContact.XmppAccountNode;
                if (XmppAccountNode == null)
                {
                    continue;
                }

                if (XmppAccountNode.BareJID != XmppClient.GetBareJID(e.To))
                {
                    continue;
                }

                ChatView.ChatMessageReceived(Message, IsMarkdown, this);
                return;
            }

            foreach (TreeNode Node in this.MainView.ConnectionTree.Items)
            {
                XmppAccountNode XmppAccountNode = Node as XmppAccountNode;
                if (XmppAccountNode == null)
                {
                    continue;
                }

                if (XmppAccountNode.BareJID != XmppClient.GetBareJID(e.To))
                {
                    continue;
                }

                if (XmppAccountNode.TryGetChild(e.FromBareJID, out TreeNode ContactNode))
                {
                    TabItem TabItem2 = new TabItem();
                    this.Tabs.Items.Add(TabItem2);

                    ChatView = new ChatView(ContactNode);

                    TabItem2.Header  = e.FromBareJID;
                    TabItem2.Content = ChatView;

                    ChatView.ChatMessageReceived(Message, IsMarkdown, this);
                    return;
                }
            }
        }