Beispiel #1
0
        /// <summary>
        /// Initializes an instance of an actor.
        /// </summary>
        public override async Task InitializeInstance()
        {
            this.credentials = await Database.FindFirstIgnoreRest <AccountCredentials>(new FilterAnd(
                                                                                           new FilterFieldEqualTo("Host", this.host),
                                                                                           new FilterFieldEqualTo("UserName", this.userName)));

            if (this.credentials is null)
            {
                this.credentials = new AccountCredentials()
                {
                    Host     = this.host,
                    UserName = this.userName,
                    Password = string.IsNullOrEmpty(this.password) ? string.Empty : await this.Model.GetKey(this.password, this.userName)
                };
            }

            this.sniffer = this.Model.GetSniffer(this.InstanceId);

            if (this.sniffer is null)
            {
                this.client = new MqClient(this.queueManager, this.channel, this.cipher, this.cipherSuite, this.certificateStore, this.host, this.port);
            }
            else
            {
                this.client = new MqClient(this.queueManager, this.channel, this.cipher, this.cipherSuite, this.certificateStore, this.host, this.port, this.sniffer);
            }

            this.connectionTask = this.client.ConnectAsync(this.credentials.UserName, this.credentials.Password);
        }
Beispiel #2
0
        /// <summary>
        /// Finalizes an instance of an actor.
        /// </summary>
        public override async Task FinalizeInstance()
        {
            foreach (SubscriptionState State in this.subscriptions)
            {
                State.Dispose();
            }

            foreach (SubscriptionState State in this.subscriptions)
            {
                await State.Stopped.Task;
            }

            this.client?.Dispose();
            this.client = null;

            if (!(this.sniffer is null))
            {
                if (this.sniffer is IDisposable Disposable)
                {
                    Disposable.Dispose();
                }

                this.sniffer = null;
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes an instance of an actor.
        /// </summary>
        public override async Task InitializeInstance()
        {
            this.xmppCredentials = await this.GetInstanceCredentials();

            this.sniffer = this.Model.GetSniffer(this.userName);

            if (this.sniffer is null)
            {
                this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly);
            }
            else
            {
                this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly, this.sniffer);
            }

            this.client.OnStateChanged      += this.Client_OnStateChanged;
            this.client.OnChatMessage       += Client_OnChatMessage;
            this.client.OnConnectionError   += Client_OnConnectionError;
            this.client.OnError             += Client_OnError;
            this.client.OnErrorMessage      += Client_OnErrorMessage;
            this.client.OnGroupChatMessage  += Client_OnGroupChatMessage;
            this.client.OnHeadlineMessage   += Client_OnHeadlineMessage;
            this.client.OnNormalMessage     += Client_OnNormalMessage;
            this.client.OnPresence          += Client_OnPresence;
            this.client.OnPresenceSubscribe += Client_OnPresenceSubscribe;
            this.client.OnRosterItemAdded   += Client_OnRosterItemAdded;
            this.client.OnRosterItemRemoved += Client_OnRosterItemRemoved;
            this.client.OnRosterItemUpdated += Client_OnRosterItemUpdated;
            this.client.CustomPresenceXml   += Client_CustomPresenceXml;

            if (this.Parent is IActor ParentActor)
            {
                foreach (ISimulationNode Node in ParentActor.Children)
                {
                    if (Node is HandlerNode HandlerNode)
                    {
                        HandlerNode.RegisterHandlers(this, this.client);
                    }

                    if (Node is Extensions.IXmppExtension Extension)
                    {
                        await Extension.Add(this, Client);
                    }
                }
            }

            this.connected = new TaskCompletionSource <bool>();

            if (this.alwaysConnected)
            {
                this.client.Connect(this.domain);

                if (this.xmppCredentials.AllowRegistration && !(await this.connected.Task))
                {
                    throw new Exception("Unable to create account for " + this.userName + "@" + this.domain);
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// <see cref="ISniffable.Add"/>
 /// </summary>
 public void Add(ISniffer Sniffer)
 {
     lock (this.sniffers)
     {
         this.sniffers.Add(Sniffer);
         this.staticList  = this.sniffers.ToArray();
         this.hasSniffers = this.staticList.Length > 0;
     }
 }
Beispiel #6
0
 public override bool RemoveSniffer(ISniffer Sniffer)
 {
     if (this.client == null)
     {
         return(false);
     }
     else
     {
         return(this.client.Remove(Sniffer));
     }
 }
Beispiel #7
0
        /// <summary>
        /// <see cref="ISniffable.Remove"/>
        /// </summary>
        public bool Remove(ISniffer Sniffer)
        {
            lock (this.sniffers)
            {
                if (this.sniffers.Remove(Sniffer))
                {
                    this.staticList  = this.sniffers.ToArray();
                    this.hasSniffers = this.staticList.Length > 0;
                    return(true);
                }
            }

            return(false);
        }
Beispiel #8
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));
            }
Beispiel #9
0
        /// <summary>
        /// Finalizes an instance of an actor.
        /// </summary>
        public override Task FinalizeInstance()
        {
            this.client?.Dispose();
            this.client = null;

            if (!(this.sniffer is null))
            {
                if (this.sniffer is IDisposable Disposable)
                {
                    Disposable.Dispose();
                }

                this.sniffer = null;
            }

            return(Task.CompletedTask);
        }
Beispiel #10
0
        /// <summary>
        /// Initializes an instance of an actor.
        /// </summary>
        public override async Task InitializeInstance()
        {
            this.credentials = await Database.FindFirstIgnoreRest <AccountCredentials>(new FilterAnd(
                                                                                           new FilterFieldEqualTo("Domain", this.domain),
                                                                                           new FilterFieldEqualTo("UserName", this.userName)));

            if (this.credentials is null)
            {
                this.credentials = new AccountCredentials()
                {
                    Domain   = this.domain,
                    UserName = this.userName,
                    Password = string.IsNullOrEmpty(this.password) ? string.Empty : await this.Model.GetKey(this.password, this.userName)
                };
            }

            this.sniffer = this.Model.GetSniffer(this.userName);

            if (this.sniffer is null)
            {
                this.client = new MqttClient(this.domain, this.port, this.encrypted, this.userName, this.credentials.Password);
            }
            else
            {
                this.client = new MqttClient(this.domain, this.port, this.encrypted, this.userName, this.credentials.Password, this.sniffer);
            }

            this.client.TrustServer = this.trustServer;

            this.client.OnStateChanged    += this.Client_OnStateChanged;
            this.client.OnConnectionError += Client_OnConnectionError;
            this.client.OnError           += Client_OnError;
            this.client.OnContentReceived += Client_OnContentReceived;
            this.client.OnPing            += Client_OnPing;
            this.client.OnPingResponse    += Client_OnPingResponse;
            this.client.OnPublished       += Client_OnPublished;
            this.client.OnSubscribed      += Client_OnSubscribed;
            this.client.OnUnsubscribed    += Client_OnUnsubscribed;

            this.connected = new TaskCompletionSource <bool>();
        }
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.Information(this.Text);
 }
Beispiel #12
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.TransmitText(this.Text);
 }
 protected void EvaluateOnReceive(ISniffer sniffer, IInformationState state)
 {
     textBoxReceive.AppendText("Reception Detected:");
     textBoxReceive.AppendText("\r\n");
     textBoxReceive.AppendText(state.generateDebugger().FullDebug);
     textBoxReceive.AppendText("\r\n");
     textBoxReceive.AppendText("\r\n");
 }
Beispiel #14
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.TransmitBinary(this.Data);
 }
Beispiel #15
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.ReceiveText(this.Text);
 }
Beispiel #16
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.Error(this.Text);
 }
 protected void EvaluateOnTransmit(ISniffer sniffer, IInformationState state)
 {
     textBoxTransmit.AppendText("Transmission Detected:");
     textBoxTransmit.AppendText("\r\n");
     textBoxTransmit.AppendText(state.generateDebugger().FullDebug);
     textBoxTransmit.AppendText("\r\n");
     textBoxTransmit.AppendText("\r\n");
 }
 protected void EvaluateOnReceive(ISniffer sniffer, IState state)
 {
     if (InvokeRequired)
     {
         SniferStateDelegate methodDelegate = new SniferStateDelegate(EvaluateOnReceive);
         BeginInvoke(methodDelegate, new object[] { sniffer, state });
     }
     else
     {
         textBoxReceive.AppendText("Reception Detected");
         textBoxReceive.AppendText("\r\n");
         if (state is IQuantumState)
         { textBoxReceive.AppendText(((IQuantumState)state).Debugger.FullDebug); }
         if (state is IClassicState)
         { textBoxReceive.AppendText(((IClassicState)state).Debugger.FullDebug); }
         textBoxReceive.AppendText("\r\n");
         textBoxReceive.AppendText("\r\n");
     }
 }
Beispiel #19
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.Exception(this.Text);
 }
Beispiel #20
0
 /// <summary>
 /// Adds a sniffer to the node.
 /// </summary>
 /// <param name="Sniffer">Sniffer object.</param>
 /// <exception cref="NotSupportedException">If the feature is not supported by the node.</exception>
 public virtual void AddSniffer(ISniffer Sniffer)
 {
     throw new NotSupportedException();
 }
 protected void EvaluateOnTransmit(ISniffer sniffer, IState state)
 {
     try
     {
         if (InvokeRequired)
         {
             SniferStateDelegate methodDelegate = new SniferStateDelegate(EvaluateOnTransmit);
             BeginInvoke(methodDelegate, new object[] { sniffer, state });
         }
         else
         {
             textBoxTransmit.AppendText("Transmission Detected");
             textBoxTransmit.AppendText("\r\n");
             if (state is IQuantumState)
             { textBoxTransmit.AppendText(((IQuantumState)state).Debugger.FullDebug); }
             if (state is IClassicState)
             { textBoxTransmit.AppendText(((IClassicState)state).Debugger.FullDebug); }
             textBoxTransmit.AppendText("\r\n");
             textBoxTransmit.AppendText("\r\n");
         }
     }
     catch
     { }
 }
Beispiel #22
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.ReceiveBinary(this.Data);
 }
Beispiel #23
0
        /// <summary>
        /// Initializes an instance of an actor.
        /// </summary>
        public override async Task InitializeInstance()
        {
            this.xmppCredentials = await this.GetInstanceCredentials();

            this.sniffer = this.Model.GetSniffer(this.userName);

            if (this.sniffer is null)
            {
                this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly);
            }
            else
            {
                this.client = new XmppClient(this.xmppCredentials, "en", typeof(XmppActor).GetTypeInfo().Assembly, this.sniffer);
            }

            this.client.OnStateChanged      += this.Client_OnStateChanged;
            this.client.OnChatMessage       += Client_OnChatMessage;
            this.client.OnConnectionError   += Client_OnConnectionError;
            this.client.OnError             += Client_OnError;
            this.client.OnErrorMessage      += Client_OnErrorMessage;
            this.client.OnGroupChatMessage  += Client_OnGroupChatMessage;
            this.client.OnHeadlineMessage   += Client_OnHeadlineMessage;
            this.client.OnNormalMessage     += Client_OnNormalMessage;
            this.client.OnPresence          += Client_OnPresence;
            this.client.OnPresenceSubscribe += Client_OnPresenceSubscribe;
            this.client.OnRosterItemAdded   += Client_OnRosterItemAdded;
            this.client.OnRosterItemRemoved += Client_OnRosterItemRemoved;
            this.client.OnRosterItemUpdated += Client_OnRosterItemUpdated;
            this.client.CustomPresenceXml   += Client_CustomPresenceXml;

            string InstanceIndexSuffix = this.InstanceIndex.ToString();
            int    c   = this.N.ToString().Length;
            int    Nr0 = c - InstanceIndexSuffix.Length;

            if (Nr0 > 0)
            {
                InstanceIndexSuffix = new string('0', Nr0) + InstanceIndexSuffix;
            }

            if (this.Parent is IActor ParentActor)
            {
                foreach (ISimulationNode Node in ParentActor.Children)
                {
                    if (Node is HandlerNode HandlerNode)
                    {
                        HandlerNode.RegisterHandlers(this, this.client);
                    }

                    if (Node is Extensions.IXmppExtension Extension)
                    {
                        object ExtensionObj = await Extension.Add(this, Client);

                        if (!string.IsNullOrEmpty(Extension.Id))
                        {
                            this.Model.Variables[Extension.Id + InstanceIndexSuffix] = ExtensionObj;
                        }
                    }
                }
            }

            if (this.alwaysConnected)
            {
                this.client.Connect(this.domain);

                if (this.xmppCredentials.AllowRegistration)
                {
                    switch (await this.client.WaitStateAsync(30000, XmppState.Connected, XmppState.Error, XmppState.Offline))
                    {
                    case 0:                             // Connected
                        break;

                    case 1:                             // Error
                    case 2:                             // Offline
                    default:
                        throw new Exception("Unable to create account for " + this.userName + "@" + this.domain);
                    }
                }
            }
        }
Beispiel #24
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public abstract void Replay(ISniffer Sniffer);
Beispiel #25
0
 /// <summary>
 /// Replays the event to a given sniffer.
 /// </summary>
 /// <param name="Sniffer">Sniffer.</param>
 public override void Replay(ISniffer Sniffer)
 {
     Sniffer.Warning(this.Timestamp, this.Text);
 }
Beispiel #26
0
 public DelegateSniffer(ISniffer socketWrapper, ITeraServerList serverList)
 {
     socketWrapper.Start();
     _serversByIp = serverList.Servers.ToDictionary(x => x.Ip.Replace("\n", "").Trim());
     socketWrapper.NewConnection += HandleNewConnection;
 }
Beispiel #27
0
 /// <summary>
 /// Removes a sniffer from the node.
 /// </summary>
 /// <param name="Sniffer">Sniffer object.</param>
 /// <returns>If the sniffer was found and removed.</returns>
 /// <exception cref="NotSupportedException">If the feature is not supported by the node.</exception>
 public virtual bool RemoveSniffer(ISniffer Sniffer)
 {
     throw new NotSupportedException();
 }
Beispiel #28
0
 public HomeController(ILogger <HomeController> logger, ISniffer sniffer)
 {
     _logger  = logger;
     _sniffer = sniffer;
 }