示例#1
0
        private Task Client_OnStateChanged(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.isOnline = true;

                if (this.credentials is null)
                {
                    this.credentials = new AccountCredentials()
                    {
                        Domain             = this.domain,
                        UserName           = this.userName,
                        PasswordHash       = this.client.PasswordHash,
                        PasswordHashMethod = this.client.PasswordHashMethod
                    };

                    Database.Insert(this.credentials);
                }
                break;

            case XmppState.Error:
            case XmppState.Offline:
                this.isOnline = false;
                break;
            }

            this.Model.ExternalEvent(this, "OnStateChanged",
                                     new KeyValuePair <string, object>("NewState", NewState),
                                     new KeyValuePair <string, object>("Client", this.client));

            return(Task.CompletedTask);
        }
        private async Task OnStateChanged(object Sender, XmppState State)
        {
            switch (State)
            {
            case XmppState.Connected:
                Console.WriteLine("Connected");
                this.formW.disableFormGroup();
                this.formW.setConnectionStatus(true);
                this.AddFeatures();
                await this.RegisterDevice();

                //this.formW.su
                //this.FindSensors();
                break;

            case XmppState.Error:
                this.formW.setConnectionStatus(false);
                Console.WriteLine("Connection Error");
                break;

            case XmppState.Offline:
                this.formW.setConnectionStatus(false);
                Console.WriteLine("Connection Error");
                break;
            }
        }
示例#3
0
        private static void XmppClient_OnStateChanged(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                connected = true;

                MarkdownToHtmlConverter.BareJID = xmppClient.BareJID;

                if (!registered && thingRegistryClient != null)
                {
                    Register();
                }

                if (!socksProxy.HasProxy)
                {
                    socksProxy.StartSearch(null);
                }
                break;

            case XmppState.Offline:
                immediateReconnect = connected;
                connected          = false;

                if (immediateReconnect && xmppClient != null)
                {
                    xmppClient.Reconnect();
                }
                break;
            }
        }
示例#4
0
        private Task XmppClient_OnStateChanged(object _, XmppState NewState)
        {
            this.state = NewState;

            if (NewState == XmppState.Connected)
            {
                this.CallCallbacks();
            }
            else if (NewState == XmppState.Error || NewState == XmppState.Offline)
            {
                if (!(this.parent is null))
                {
                    this.parent.PeerClosed(this);
                }

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

                this.CallCallbacks();
            }

            return(Task.CompletedTask);
        }
        private void DestroyContractsClient()
        {
            XmppState stateBefore = GetState();

            if (!(this.contractsClient is null))
            {
                this.contractsClient.IdentityUpdated                        -= ContractsClient_IdentityUpdated;
                this.contractsClient.PetitionForIdentityReceived            -= ContractsClient_PetitionForIdentityReceived;
                this.contractsClient.PetitionedIdentityResponseReceived     -= ContractsClient_PetitionedIdentityResponseReceived;
                this.contractsClient.PetitionForContractReceived            -= ContractsClient_PetitionForContractReceived;
                this.contractsClient.PetitionedContractResponseReceived     -= ContractsClient_PetitionedContractResponseReceived;
                this.contractsClient.PetitionForSignatureReceived           -= ContractsClient_PetitionForSignatureReceived;
                this.contractsClient.PetitionedSignatureResponseReceived    -= ContractsClient_PetitionedSignatureResponseReceived;
                this.contractsClient.PetitionForPeerReviewIDReceived        -= ContractsClient_PetitionForPeerReviewIdReceived;
                this.contractsClient.PetitionedPeerReviewIDResponseReceived -= ContractsClient_PetitionedPeerReviewIdResponseReceived;
                this.contractsClient.Dispose();
                this.contractsClient = null;
            }
            XmppState stateAfter = GetState();

            if (stateBefore != stateAfter)
            {
                this.OnConnectionStateChanged(new ConnectionStateChangedEventArgs(stateAfter, false));
            }
        }
示例#6
0
        private static string StateToString(XmppState State)
        {
            switch (State)
            {
            case XmppState.Offline: return("Offline");

            case XmppState.Connecting: return("Connecting");

            case XmppState.StreamNegotiation: return("Negotiating stream");

            case XmppState.StreamOpened: return("Opened stream");

            case XmppState.StartingEncryption: return("Starting encryption");

            case XmppState.Authenticating: return("Authenticating");

            case XmppState.Registering: return("Registering");

            case XmppState.Binding: return("Binding");

            case XmppState.RequestingSession: return("Requesting session");

            case XmppState.FetchingRoster: return("Fetching roster");

            case XmppState.SettingPresence: return("Setting presence");

            case XmppState.Connected: return("Connected");

            case XmppState.Error: return("In error");

            default: return("Unknown");
            }
        }
示例#7
0
        private void Client_OnStateChanged(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.connected = true;
                this.lastError = null;

                if (string.IsNullOrEmpty(this.passwordHash))
                {
                    this.passwordHash       = this.client.PasswordHash;
                    this.passwordHashMethod = this.client.PasswordHashMethod;
                }

                this.CheckRoster();
                break;

            case XmppState.Offline:
                bool ImmediateReconnect = this.connected;
                this.connected = false;

                if (ImmediateReconnect && this.client != null)
                {
                    this.client.Reconnect();
                }
                break;
            }

            this.OnUpdated();
        }
示例#8
0
        private async Task TestConnectionStateChanged(object Sender, XmppState State)
        {
            Log.Informational("Changing state: " + State.ToString());

            switch (State)
            {
            case XmppState.Connected:
                await RuntimeSettings.SetAsync("XmppHost", this.xmppClient.Host);

                await RuntimeSettings.SetAsync("XmppPort", this.xmppClient.Port);

                await RuntimeSettings.SetAsync("XmppUserName", this.xmppClient.UserName);

                await RuntimeSettings.SetAsync("XmppPasswordHash", this.xmppClient.PasswordHash);

                await RuntimeSettings.SetAsync("XmppPasswordHashMethod", this.xmppClient.PasswordHashMethod);

                this.xmppClient.OnStateChanged -= this.TestConnectionStateChanged;
                this.xmppClient.OnStateChanged += this.StateChanged;
                await this.SetVCard();

                await this.RegisterDevice();

                break;

            case XmppState.Error:
            case XmppState.Offline:
                if (!(this.xmppClient is null))
                {
                    await MainPage.Instance.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                async() => await this.ShowConnectionDialog(this.xmppClient.Host, this.xmppClient.Port, this.xmppClient.UserName));
                }
                break;
            }
        }
示例#9
0
        private void XmppStateChanged(object P)
        {
            XmppState NewState = (XmppState)P;

            switch (NewState)
            {
            case XmppState.Offline:
                this.ConnectionState.Content = "Offline.";
                break;

            case XmppState.Connecting:
                this.ConnectionState.Content = "Connecting.";
                break;

            case XmppState.StreamNegotiation:
                this.ConnectionState.Content = "Stream negotiation.";
                break;

            case XmppState.StreamOpened:
                this.ConnectionState.Content = "Stream opened.";
                break;

            case XmppState.StartingEncryption:
                this.ConnectionState.Content = "Starting encryption.";
                break;

            case XmppState.Authenticating:
                this.ConnectionState.Content = "Authenticating user.";
                break;

            case XmppState.Registering:
                this.ConnectionState.Content = "Registering account.";
                break;

            case XmppState.Binding:
                this.ConnectionState.Content = "Binding resource.";
                break;

            case XmppState.FetchingRoster:
                this.ConnectionState.Content = "Fetching roster.";
                break;

            case XmppState.SettingPresence:
                this.ConnectionState.Content = "Setting presence.";
                break;

            case XmppState.Connected:
                this.passwordHash            = this.client.PasswordHash;
                this.passwordHashMethod      = this.client.PasswordHashMethod;
                this.ConnectionState.Content = "Connected.";
                this.CloseClient();
                this.DialogResult = true;
                break;

            case XmppState.Error:
                this.ConnectionState.Content = "Error.";
                this.CloseClient();
                break;
            }
        }
示例#10
0
        private void ToError()
        {
            this.inputState = -1;
            this.state      = XmppState.Error;

            this.CallCallbacks();

            this.peer?.Dispose();
            this.peer = null;
        }
示例#11
0
        private void StateChanged(object Sender, XmppState State)
        {
            Log.Informational("Changing state: " + State.ToString());

            if (State == XmppState.Connected)
            {
                Log.Informational("Connected as " + this.xmppClient.FullJID);
                Task.Run(this.SetVCard);
                Task.Run(this.RegisterDevice);
            }
        }
示例#12
0
        private Task StateChanged(object _, XmppState State)
        {
            Log.Informational("Changing state: " + State.ToString());

            if (State == XmppState.Connected)
            {
                Log.Informational("Connected as " + this.xmppClient.FullJID);
                Task.Run(this.SetVCard);
                Task.Run(this.RegisterDevice);
            }

            return(Task.CompletedTask);
        }
示例#13
0
        private void XmppClient_OnStateChanged(object Sender, XmppState NewState)
        {
            if (NewState == XmppState.Offline || NewState == XmppState.Error || NewState == XmppState.Connected)
            {
                string[] TabIDs = this.GetTabIDs();
                if (TabIDs.Length > 0 && !(Gateway.XmppClient is null))
                {
                    string Json = JSON.Encode(new KeyValuePair <string, object>[]
                    {
                        new KeyValuePair <string, object>("html", this.RosterItemsHtml(Gateway.XmppClient.Roster, Gateway.XmppClient.SubscriptionRequests))
                    }, false);

                    ClientEvents.PushEvent(TabIDs, "UpdateRoster", Json, true, "User");
                }
            }
        }
示例#14
0
        private void Component_OnStateChanged(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.componentConnected.Set();
                break;

            case XmppState.Error:
                this.componentError.Set();
                break;

            case XmppState.Offline:
                this.componentOffline.Set();
                break;
            }
        }
示例#15
0
        /// <summary>
        /// Converts the state to a localized string.
        /// </summary>
        /// <param name="state">The state to convert.</param>
        /// <param name="domain">The domain, if any.</param>
        /// <returns></returns>
        public static string ToDisplayText(this XmppState state, string domain)
        {
            switch (state)
            {
            case XmppState.Authenticating:
                return(AppResources.XmppState_Authenticating);

            case XmppState.Binding:
                return(AppResources.XmppState_Binding);

            case XmppState.Connected:
                return(!string.IsNullOrWhiteSpace(domain)
                        ? string.Format(AppResources.XmppState_ConnectedTo, domain)
                        : AppResources.XmppState_Connected);

            case XmppState.Connecting:
                return(AppResources.XmppState_Connecting);

            case XmppState.Error:
                return(AppResources.XmppState_Error);

            case XmppState.FetchingRoster:
                return(AppResources.XmppState_FetchingRoster);

            case XmppState.Registering:
                return(AppResources.XmppState_Registering);

            case XmppState.RequestingSession:
                return(AppResources.XmppState_RequestingSession);

            case XmppState.SettingPresence:
                return(AppResources.XmppState_SettingPresence);

            case XmppState.StartingEncryption:
                return(AppResources.XmppState_StartingEncryption);

            case XmppState.StreamNegotiation:
                return(AppResources.XmppState_StreamNegotiation);

            case XmppState.StreamOpened:
                return(AppResources.XmppState_StreamOpened);

            default:
                return(AppResources.XmppState_Offline);
            }
        }
示例#16
0
        private void Client_OnStateChanged(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.BeginSearchSupport();
                break;

            case XmppState.Offline:
            case XmppState.Error:
                this.supportsBlocking    = false;
                this.supportsReporting   = false;
                this.supportsSpamReason  = false;
                this.supportsAbuseReason = false;
                break;
            }
        }
示例#17
0
        private Task Client_OnStateChanged(object _, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.BeginSearchSupport();
                break;

            case XmppState.Offline:
            case XmppState.Error:
                this.supportsBlocking    = false;
                this.supportsReporting   = false;
                this.supportsSpamReason  = false;
                this.supportsAbuseReason = false;
                break;
            }

            return(Task.CompletedTask);
        }
示例#18
0
        private Task Component_OnStateChanged(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.componentConnected.Set();
                break;

            case XmppState.Error:
                this.componentError.Set();
                break;

            case XmppState.Offline:
                this.componentOffline.Set();
                break;
            }

            return(Task.CompletedTask);
        }
示例#19
0
        private void Client_OnStateChanged1(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.connected1.Set();
                break;

            case XmppState.Error:
                this.error1.Set();
                break;

            case XmppState.Offline:
                this.offline1.Set();
                break;

            case XmppState.Connecting:
                break;
            }
        }
示例#20
0
        private async void TestConnectionStateChanged(object Sender, XmppState State)
        {
            try
            {
                this.StateChanged(Sender, State);

                switch (State)
                {
                case XmppState.Connected:
                    await RuntimeSettings.SetAsync("XmppHost", this.xmppClient.Host);

                    await RuntimeSettings.SetAsync("XmppPort", this.xmppClient.Port);

                    await RuntimeSettings.SetAsync("XmppUserName", this.xmppClient.UserName);

                    await RuntimeSettings.SetAsync("XmppPasswordHash", this.xmppClient.PasswordHash);

                    await RuntimeSettings.SetAsync("XmppPasswordHashMethod", this.xmppClient.PasswordHashMethod);

                    this.xmppClient.OnStateChanged -= this.TestConnectionStateChanged;
                    this.xmppClient.OnStateChanged += this.StateChanged;
                    this.AttachFeatures();
                    await this.SetVCard();

                    await this.RegisterDevice();

                    break;

                case XmppState.Error:
                case XmppState.Offline:
                    await MainPage.Instance.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                async() => await this.ShowConnectionDialog(this.xmppClient.Host, this.xmppClient.Port, this.xmppClient.UserName));

                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }
        }
示例#21
0
        private Task Client_OnStateChanged(object _, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                uint i;

                lock (this.synchObj)
                {
                    i = this.eventsLost;
                    this.eventsLost = 0;

                    this.connected = true;
                }

                if (i > 0)
                {
                    Log.Notice(i.ToString() + " events lost while XMPP connection was down.",
                               this.ObjectID, string.Empty, "EventsLost", new KeyValuePair <string, object>("Nr", i));
                }
                break;

            case XmppState.Offline:
                bool ImmediateReconnect;
                lock (this.synchObj)
                {
                    ImmediateReconnect = this.connected;
                    this.connected     = false;
                }

                if (ImmediateReconnect && this.timer != null)
                {
                    this.client.Reconnect();
                }
                break;
            }

            return(Task.CompletedTask);
        }
示例#22
0
        private Task Client_OnStateChanged2(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.connected2.Set();
                break;

            case XmppState.Error:
                this.error2.Set();
                break;

            case XmppState.Offline:
                this.offline2.Set();
                break;

            case XmppState.Connecting:
                break;
            }

            return(Task.CompletedTask);
        }
示例#23
0
        private void Client_OnStateChanged(object Sender, XmppState NewState)
        {
            switch (NewState)
            {
            case XmppState.Connected:
                this.connected = true;
                this.lastError = null;

                if (this.supportsHashes && string.IsNullOrEmpty(this.passwordHash))
                {
                    this.passwordHash         = this.client.PasswordHash;
                    this.passwordHashMethod   = this.client.PasswordHashMethod;
                    this.connections.Modified = true;
                }

                if (this.domain != this.client.Domain)
                {
                    this.domain = this.client.Domain;
                    this.connections.Modified = true;
                }

                this.CheckRoster();
                this.SearchComponents();
                break;

            case XmppState.Offline:
                bool ImmediateReconnect = this.connected;
                this.connected = false;

                if (ImmediateReconnect && this.client != null)
                {
                    this.client.Reconnect();
                }
                break;
            }

            this.OnUpdated();
        }
示例#24
0
        private async Task CreateContractsClient(bool CanCreateKeys)
        {
            if (!string.IsNullOrWhiteSpace(this.tagProfile.LegalJid))
            {
                DestroyContractsClient();
                XmppState stateBefore = GetState();
                this.contractsClient = await this.neuronService.CreateContractsClientAsync(CanCreateKeys);

                this.contractsClient.IdentityUpdated                        += ContractsClient_IdentityUpdated;
                this.contractsClient.PetitionForIdentityReceived            += ContractsClient_PetitionForIdentityReceived;
                this.contractsClient.PetitionedIdentityResponseReceived     += ContractsClient_PetitionedIdentityResponseReceived;
                this.contractsClient.PetitionForContractReceived            += ContractsClient_PetitionForContractReceived;
                this.contractsClient.PetitionedContractResponseReceived     += ContractsClient_PetitionedContractResponseReceived;
                this.contractsClient.PetitionForSignatureReceived           += ContractsClient_PetitionForSignatureReceived;
                this.contractsClient.PetitionedSignatureResponseReceived    += ContractsClient_PetitionedSignatureResponseReceived;
                this.contractsClient.PetitionForPeerReviewIDReceived        += ContractsClient_PetitionForPeerReviewIdReceived;
                this.contractsClient.PetitionedPeerReviewIDResponseReceived += ContractsClient_PetitionedPeerReviewIdResponseReceived;
                XmppState stateAfter = GetState();
                if (stateBefore != stateAfter)
                {
                    this.OnConnectionStateChanged(new ConnectionStateChangedEventArgs(stateAfter, false));
                }
            }
        }
示例#25
0
        private void XmppClient_OnStateChanged(object Sender, XmppState NewState)
        {
            this.state = NewState;

            if (NewState == XmppState.Connected)
            {
                this.CallCallbacks();
            }
            else if (NewState == XmppState.Error || NewState == XmppState.Offline)
            {
                if (this.parent != null)
                {
                    this.parent.PeerClosed(this);
                }

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

                this.CallCallbacks();
            }
        }
示例#26
0
        private void ProcessStream(string Xml)
        {
            try
            {
                int i = Xml.IndexOf("?>");
                if (i >= 0)
                {
                    Xml = Xml.Substring(i + 2).TrimStart();
                }

                this.streamHeader = Xml;

                i = Xml.IndexOf(":stream");
                if (i < 0)
                {
                    this.streamFooter = "</stream>";
                }
                else
                {
                    this.streamFooter = "</" + Xml.Substring(1, i - 1) + ":stream>";
                }

                XmlDocument Doc = new XmlDocument()
                {
                    PreserveWhitespace = true
                };
                Doc.LoadXml(Xml + this.streamFooter);

                if (Doc.DocumentElement.LocalName != "stream")
                {
                    throw new XmppException("Invalid stream.", Doc.DocumentElement);
                }

                XmlElement Stream = Doc.DocumentElement;

                this.version       = XML.Attribute(Stream, "version", 0.0);
                this.streamId      = XML.Attribute(Stream, "id");
                this.remoteFullJid = XML.Attribute(Stream, "from");

                if (this.version < 1.0)
                {
                    throw new XmppException("Version not supported.", Stream);
                }

                if (this.parentFullJid != XML.Attribute(Stream, "to"))
                {
                    throw new XmppException("Invalid destination JID.", Stream);
                }

                this.state = XmppState.Authenticating;

                string Header = "<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='" +
                                this.parentFullJid + "' to='" + this.remoteFullJid + "' version='1.0'>";

                try
                {
                    this.parent.AuthenticatePeer(this.peer, this.remoteFullJid);
                }
                catch (Exception ex)
                {
                    this.parent.Exception(ex);

                    Header += "<stream:error><invalid-from xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>" +
                              "<text xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" + XML.Encode(ex.Message) +
                              "</text></stream:error></stream:stream>";

                    this.headerSent = true;
                    this.SendAsync(Header, (sender, e) =>
                    {
                        this.ToError();
                    });

                    return;
                }

                if (!this.headerSent)
                {
                    this.headerSent = true;
                    this.SendAsync(Header);
                }

                this.state      = XmppState.Connected;
                this.xmppClient = new XmppClient(this, this.state, Header, "</stream:stream>", this.parentFullJid,
                                                 typeof(XmppServerlessMessaging).GetTypeInfo().Assembly)
                {
                    SendFromAddress = true
                };

                this.parent.PeerAuthenticated(this);
                this.parent.NewXmppClient(this.xmppClient, this.parentFullJid, this.remoteFullJid);

                this.xmppClient.OnStateChanged += this.XmppClient_OnStateChanged;

                this.CallCallbacks();
            }
            catch (Exception ex)
            {
                this.parent.Exception(ex);
                this.ToError();
            }
        }
示例#27
0
 private void Client_OnStateChanged(object Sender, XmppState NewState)
 {
     this.Dispatcher.BeginInvoke(new ParameterizedThreadStart(this.XmppStateChanged), NewState);
 }
 private Task Client_OnStateChanged(object Sender, XmppState NewState)
 {
     MainWindow.UpdateGui(this.XmppStateChanged, NewState);
     return(Task.CompletedTask);
 }
示例#29
0
 /// <inheritdoc/>
 protected override void SetConnectionStateAndText(XmppState state)
 {
     this.ConnectionStateText = state.ToDisplayText(this.tagProfile.Domain);
     this.IsConnected         = state == XmppState.Connected;
 }
 private void SetConnectionStateAndText(XmppState state)
 {
     IsConnected = state == XmppState.Connected;
     this.ConnectionStateText = state.ToDisplayText(null);
 }