示例#1
0
        private void PropertiesChannelOnMessagePublished(object sender, PublishMessageEventArgs e)
        {
            var props = JsonConvert.DeserializeObject <Properties>(e.Message);

            if (props != null)
            {
                this.Properties = props;

                if (e.Response.Headers.AllKeys.Contains("Set-RegistrationToken"))
                {
                    var registrationToken = e.Response.Headers["Set-RegistrationToken"];

                    if (!registrationToken.Equals(Credentials.RegistrationToken))
                    {
                        _logger.LogInformation("Received registrationToken: {registrationToken} (Length: {len})", registrationToken.Substring(0, 50) + "...", registrationToken.Length);
                        this.Credentials.RegistrationToken = registrationToken;
                    }
                }
            }

            if (this.Status != AppStatus.Connected)
            {
                this.UpdateStatus(AppStatus.Connected);
            }
        }
示例#2
0
        private void ConversationHistoryChannelOnMessagePublished(object sender, PublishMessageEventArgs e)
        {
            var frame = JsonConvert.DeserializeObject <ConversationsFrame>(e.Message);

            if (frame?.conversations != null)
            {
                _logger.LogInformation("Received {numberOfPastConversations} past conversations", frame.conversations.Length);
            }
        }
示例#3
0
        private void ContactsChannelOnMessagePublished(object sender, PublishMessageEventArgs e)
        {
            var contactsFrame = JsonConvert.DeserializeObject <ContactsFrame>(e.Message);

            if (contactsFrame.Contacts != null)
            {
                foreach (var contact in contactsFrame.Contacts)
                {
                    if (!this.Contacts.Exists(p => p.Id == contact.Mri))
                    {
                        var contactDisplayName = !string.IsNullOrWhiteSpace(contact.DisplayName) ? contact.DisplayName : contact.Profile.Name.First;
                        var profile            = new Profile(contact.Mri, contactDisplayName);

                        this.Contacts.Add(profile);
                        _logger.LogInformation("Found new contact: '{displayName}' ({id})", profile.DisplayName, profile.Id);
                    }
                }
            }
        }
示例#4
0
        private void ProfilesChannelOnMessagePublished(object sender, PublishMessageEventArgs e)
        {
            var profileFrame = JsonConvert.DeserializeObject <ProfileFrame>(e.Message);

            if (profileFrame == null)
            {
                return;
            }

            foreach (var item in profileFrame.Profiles)
            {
                var profile = new Profile(item.Key, item.Value.Profile.DisplayName);

                if (item.Value.Authorized)
                {
                    this.Me = profile;

                    if (this.Status != AppStatus.Ready)
                    {
                        _logger.LogInformation("Logged in as '{}', Id: {id}. Client is ready for interactions.", profile.DisplayName, profile.Id);
                        this.UpdateStatus(AppStatus.Ready);
                    }
                }
                else
                {
                    var existing = Contacts.SingleOrDefault(c => c.Id == profile.Id);
                    if (existing != null)
                    {
                        _logger.LogInformation("Updating existing contact '{displayName}' ({id})", existing.DisplayName, existing.Id);
                        existing.DisplayName = profile.DisplayName;
                    }
                    else
                    {
                        _logger.LogInformation("Found new contact: '{displayName}' ({id})", profile.DisplayName, profile.Id);
                        this.Contacts.Add(profile);
                    }
                }
            }
        }