Example #1
0
        private void Add(string Type)
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;

            if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                ConcentratorClient.GetParametersForNewNode(FullJid, this.nodeInfo, Type, "en", string.Empty, string.Empty, string.Empty, (sender, Form) =>
                {
                    MainWindow.MouseDefault();

                    MainWindow.UpdateGui(() =>
                    {
                        ParameterDialog Dialog = new ParameterDialog(Form);
                        Dialog.ShowDialog();
                    });

                    return(Task.CompletedTask);
                }, (sender, e) =>
                {
                    if (e.Ok)
                    {
                        this.Add(new Node(this, e.NodeInformation));
                    }

                    return(Task.CompletedTask);
                }, null);
            }
        }
Example #2
0
        private void Add(string Type)
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;

            if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                ConcentratorClient.GetParametersForNewNode(FullJid, this.nodeInfo, Type, "en", string.Empty, string.Empty, string.Empty, (sender, Form) =>
                {
                    MainWindow.MouseDefault();

                    MainWindow.currentInstance.Dispatcher.BeginInvoke(new ThreadStart(() =>
                    {
                        ParameterDialog Dialog = new ParameterDialog(Form);
                        Dialog.ShowDialog();
                    }));
                }, (sender, e) =>
                {
                    if (e.Ok)
                    {
                        this.Add(new Node(this, e.NodeInformation));
                    }
                }, null);
            }
        }
Example #3
0
        private void Init(params ISniffer[] Sniffers)
        {
            if (!string.IsNullOrEmpty(this.passwordHash))
            {
                this.client = new XmppClient(this.host, this.port, this.account, this.passwordHash, this.passwordHashMethod, "en", typeof(App).Assembly);
            }
            else
            {
                this.client = new XmppClient(this.host, this.port, this.account, this.password, "en", typeof(App).Assembly);
            }

            if (Sniffers != null)
            {
                this.client.AddRange(Sniffers);
            }

            this.client.TrustServer            = this.trustCertificate;
            this.client.OnStateChanged        += new StateChangedEventHandler(Client_OnStateChanged);
            this.client.OnError               += new XmppExceptionEventHandler(Client_OnError);
            this.client.OnPresence            += new PresenceEventHandler(Client_OnPresence);
            this.client.OnPresenceSubscribe   += new PresenceEventHandler(Client_OnPresenceSubscribe);
            this.client.OnPresenceUnsubscribe += new PresenceEventHandler(Client_OnPresenceUnsubscribe);
            this.client.OnRosterItemAdded     += new RosterItemEventHandler(Client_OnRosterItemUpdated);
            this.client.OnRosterItemRemoved   += new RosterItemEventHandler(Client_OnRosterItemRemoved);
            this.client.OnRosterItemUpdated   += new RosterItemEventHandler(Client_OnRosterItemUpdated);
            this.connectionTimer               = new Timer(this.CheckConnection, null, 60000, 60000);

            this.client.SetPresence(Availability.Chat);

            this.sensorClient       = new SensorClient(this.client);
            this.controlClient      = new ControlClient(this.client);
            this.concentratorClient = new ConcentratorClient(this.client);

            this.client.Connect();
        }
Example #4
0
        public override void Dispose()
        {
            base.Dispose();

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

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

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

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

            if (this.client != null)
            {
                XmppClient Client = this.client;
                this.client = null;
                Client.Dispose();
            }
        }
Example #5
0
        public override void Delete(TreeNode Parent, EventHandler OnDeleted)
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;

            if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                ConcentratorClient.DestroyNode(FullJid, this.nodeInfo, "en", string.Empty, string.Empty, string.Empty, (sender, e) =>
                {
                    MainWindow.MouseDefault();

                    if (e.Ok)
                    {
                        try
                        {
                            base.Delete(Parent, OnDeleted);
                        }
                        catch (Exception ex)
                        {
                            Log.Critical(ex);
                        }
                    }
                }, null);
            }
        }
Example #6
0
        public override void AddSniffer(ISniffer Sniffer)
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;

            if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                this.ConcentratorClient.RegisterSniffer(FullJid, this.nodeInfo, DateTime.Now.AddHours(1), Sniffer,
                                                        string.Empty, string.Empty, string.Empty, (sender, e) =>
                {
                    MainWindow.MouseDefault();

                    if (e.Ok)
                    {
                        if (Sniffer is TabSniffer TabSniffer)
                        {
                            TabSniffer.SnifferId = e.SnifferrId;
                        }
                    }
                    else
                    {
                        MainWindow.ErrorBox(e.ErrorText);
                    }
                }, null);
            }
        }
Example #7
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);
        }
Example #8
0
        public override void Add()
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;

            if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                ConcentratorClient.GetAddableNodeTypes(FullJid, this.nodeInfo, "en", string.Empty, string.Empty, string.Empty, (sender, e) =>
                {
                    MainWindow.MouseDefault();

                    if (e.Ok)
                    {
                        switch (e.Result.Length)
                        {
                        case 0:
                            MainWindow.ErrorBox("No nodes can be added to this type of node.");
                            break;

                        case 1:
                            MainWindow.UpdateGui(() =>
                                                 this.Add(e.Result[0].Unlocalized));
                            break;

                        default:
                            MainWindow.UpdateGui(() =>
                            {
                                SelectItemDialog Form = new SelectItemDialog("Add node", "Select type of node to add:",
                                                                             "Add node of selected type.", "Type", "Class", e.Result)
                                {
                                    Owner = MainWindow.currentInstance
                                };

                                bool?Result = Form.ShowDialog();

                                if (Result.HasValue && Result.Value)
                                {
                                    LocalizedString?Item = Form.SelectedItem;
                                    if (Item.HasValue)
                                    {
                                        this.Add(Item.Value.Unlocalized);
                                    }
                                }
                            });
                            break;
                        }
                    }

                    return(Task.CompletedTask);
                }, null);
            }
        }
Example #9
0
        protected override void LoadChildren()
        {
            if (!this.loadingChildren && !this.IsLoaded)
            {
                string             FullJid            = this.Concentrator?.FullJid;
                ConcentratorClient ConcentratorClient = this.ConcentratorClient;

                if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
                {
                    if (this.nodeInfo.HasChildren)
                    {
                        Mouse.OverrideCursor = Cursors.Wait;

                        this.loadingChildren = true;
                        ConcentratorClient.GetChildNodes(FullJid, this.nodeInfo, true, true, "en", string.Empty, string.Empty, string.Empty, (sender, e) =>
                        {
                            this.loadingChildren = false;
                            MainWindow.MouseDefault();

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

                                foreach (NodeInformation Ref in e.NodesInformation)
                                {
                                    Children[Ref.NodeId] = new Node(this, Ref);
                                }

                                this.children = Children;

                                this.OnUpdated();
                                this.DataSource?.NodesAdded(Children.Values, this);
                            }

                            return(Task.CompletedTask);
                        }, null);
                    }
                    else
                    {
                        if (this.children != null)
                        {
                            this.DataSource?.NodesRemoved(this.children.Values, this);
                        }

                        this.children = null;

                        this.OnUpdated();
                    }
                }
            }

            base.LoadChildren();
        }
Example #10
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);
        }
Example #11
0
 /// <summary>
 /// Client-side Node Query object. It collects the results of the query.
 /// </summary>
 /// <param name="Client">Concentrator client.</param>
 /// <param name="To">Address of concentrator server.</param>
 /// <param name="NodeID">Node ID</param>
 /// <param name="SourceID">Optional Source ID</param>
 /// <param name="Partition">Optional Partition</param>
 /// <param name="Command">Command for which to get parameters.</param>
 /// <param name="Language">Code of desired language.</param>
 /// <param name="ServiceToken">Optional Service token.</param>
 /// <param name="DeviceToken">Optional Device token.</param>
 /// <param name="UserToken">Optional User token.</param>
 public NodeQuery(ConcentratorClient Client, string To, string NodeID, string SourceID, string Partition, string Command,
                  string Language, string ServiceToken, string DeviceToken, string UserToken)
 {
     this.queryId      = Guid.NewGuid().ToString().Replace("-", string.Empty);
     this.client       = Client;
     this.to           = To;
     this.nodeID       = NodeID;
     this.sourceID     = SourceID;
     this.partition    = Partition;
     this.command      = Command;
     this.language     = Language;
     this.serviceToken = ServiceToken;
     this.deviceToken  = DeviceToken;
     this.userToken    = UserToken;
 }
Example #12
0
        public override bool RemoveSniffer(ISniffer Sniffer)
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;

            if (Sniffer is TabSniffer TabSniffer && ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                return(this.ConcentratorClient.UnregisterSniffer(FullJid, this.nodeInfo, TabSniffer.SnifferId,
                                                                 string.Empty, string.Empty, string.Empty, (sender, e) =>
                {
                    MainWindow.MouseDefault();
                }, null));
            }
Example #13
0
        public async Task IsValueEqualAsync()
        {
            var uriB = new UriBuilder()
            {
                Port = 8000,
                Path = "/concentrator/ws"
            };

            var endpoint = new EndpointAddress(uriB.Uri);

            var client = new ConcentratorClient(GetBasicHttpBinding(), endpoint);

            var bla = await client.GetUnitsListAsync();

            Assert.Equal("234LKJ32KLJL3", bla.UnitsList[0].ID);
        }
Example #14
0
        /// <summary>
        /// Adds the extension to the client.
        /// </summary>
        /// <param name="Instance">Actor instance.</param>
        /// <param name="Client">XMPP Client</param>
        public override Task Add(IActor Instance, Waher.Networking.XMPP.XmppClient Client)
        {
            ConcentratorClient Extension = new ConcentratorClient(Client);

            Client.SetTag("ConcentratorClient", Extension);

            Extension.OnEvent += (Sender, e) =>
            {
                this.Model.ExternalEvent(Instance, "OnEvent",
                                         new KeyValuePair <string, object>("e", e),
                                         new KeyValuePair <string, object>("Client", Client));

                return(Task.CompletedTask);
            };

            return(Task.CompletedTask);
        }
Example #15
0
        private void Add(string Type)
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;

            if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                ConcentratorClient.GetParametersForNewNode(FullJid, this.nodeInfo, Type, "en", string.Empty, string.Empty, string.Empty, (sender, Form) =>
                {
                    MainWindow.MouseDefault();

                    MainWindow.currentInstance.Dispatcher.BeginInvoke(new ThreadStart(() =>
                    {
                        ParameterDialog Dialog = new ParameterDialog(Form);
                        Dialog.ShowDialog();
                    }));
                }, (sender, e) =>
                {
                    if (e.Ok)
                    {
                        if (!this.loadingChildren && (this.children == null || this.children.Count != 1 || !this.children.ContainsKey(string.Empty)))
                        {
                            SortedDictionary <string, TreeNode> Children = new SortedDictionary <string, TreeNode>();

                            if (this.children != null)
                            {
                                foreach (KeyValuePair <string, TreeNode> P in this.children)
                                {
                                    Children[P.Key] = P.Value;
                                }
                            }

                            Children[e.NodeInformation.NodeId] = new Node(this, e.NodeInformation);
                            this.children = Children;

                            this.OnUpdated();
                            this.Concentrator?.NodesAdded(Children.Values, this);
                        }
                    }
                }, null);
            }
        }
Example #16
0
        protected override void LoadChildren()
        {
            if (!this.loadingChildren && !this.IsLoaded)
            {
                string FullJid = this.FullJid;

                if (!string.IsNullOrEmpty(FullJid))
                {
                    Mouse.OverrideCursor = Cursors.Wait;

                    ConcentratorClient ConcentratorClient = this.XmppAccountNode.ConcentratorClient;

                    this.loadingChildren = true;
                    ConcentratorClient.GetRootDataSources(FullJid, (sender, e) =>
                    {
                        this.loadingChildren = false;
                        MainWindow.MouseDefault();

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

                            foreach (DataSourceReference Ref in e.DataSources)
                            {
                                DataSource DataSource  = new DataSource(this, Ref.SourceID, Ref.SourceID, Ref.HasChildren);
                                Children[Ref.SourceID] = DataSource;

                                DataSource.SubscribeToEvents();
                            }

                            this.children = Children;

                            this.OnUpdated();
                            this.NodesAdded(Children.Values, this);
                        }
                    }, null);
                }
            }

            base.LoadChildren();
        }
Example #17
0
        public override void Edit()
        {
            string             FullJid            = this.Concentrator?.FullJid;
            ConcentratorClient ConcentratorClient = this.ConcentratorClient;
            string             OldKey             = this.Key;

            if (ConcentratorClient != null && !string.IsNullOrEmpty(FullJid))
            {
                Mouse.OverrideCursor = Cursors.Wait;

                ConcentratorClient.GetNodeParametersForEdit(FullJid, this.nodeInfo, "en", string.Empty, string.Empty, string.Empty, (sender, Form) =>
                {
                    MainWindow.MouseDefault();

                    MainWindow.UpdateGui(() =>
                    {
                        ParameterDialog Dialog = new ParameterDialog(Form);
                        Dialog.ShowDialog();
                    });

                    return(Task.CompletedTask);
                }, (sender, e) =>
                {
                    if (e.Ok)
                    {
                        this.nodeInfo = e.NodeInformation;
                        this.OnUpdated();

                        string NewKey   = this.Key;
                        TreeNode Parent = this.Parent;

                        if (NewKey != OldKey && Parent != null)
                        {
                            Parent.RenameChild(OldKey, NewKey, this);
                        }
                    }

                    return(Task.CompletedTask);
                }, null);
            }
        }
Example #18
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(ConcentratorClient.GetEndpointAddress(EndpointConfiguration.ConcentratorPort));
 }
Example #19
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(ConcentratorClient.GetBindingForEndpoint(EndpointConfiguration.ConcentratorPort));
 }
Example #20
0
 public ConcentratorClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(ConcentratorClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #21
0
 public ConcentratorClient(EndpointConfiguration endpointConfiguration) :
     base(ConcentratorClient.GetBindingForEndpoint(endpointConfiguration), ConcentratorClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #22
0
 public ConcentratorClient() :
     base(ConcentratorClient.GetDefaultBinding(), ConcentratorClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.ConcentratorPort.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }