Exemplo n.º 1
0
 private void OnLastActivityResponse(InfoQuery response)
 {
     if (response.LastActivity != null && response.LastActivity.SecondsSpecified)
     {
         this.LastActivity = response.LastActivity.Seconds;
     }
 }
Exemplo n.º 2
0
        private void OnDiscoverResponse(InfoQuery response)
        {
            this.info = response.ServiceInfo;
            this.capsChangedStream.OnNext(this);

#warning TODO: Update caps storage
        }
        private async Task GetLastBuildResult(IHubContext hubContext, string connectionId, string buildId)
        {
            try
            {
                Build lastBuildResult = await InfoQuery.GetLastBuildResult(buildId);

                IEnumerable <string> connIds = string.IsNullOrEmpty(connectionId)
                    ? ConnectionsManager.BuildsPerConnId.Where(b => b.Value.Contains(lastBuildResult.CiExternalId)).Select(d => d.Key)
                    : new List <string> {
                    connectionId
                };

                foreach (string connId in connIds)
                {
                    Logger.Debug(
                        "Sending build result for {buildId} to {connectionId}",
                        lastBuildResult.CiExternalId,
                        connId);
                    hubContext.Clients.Client(connId)
                    .SendBuildResult(lastBuildResult);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error getting last build result for {buildId}...", buildId);
            }
        }
Exemplo n.º 4
0
        public async Task SendAsync(InfoQuery request, Action <InfoQuery> onResponse = null, Action <InfoQuery> onError = null)
        {
            if (this.State != XmppTransportState.Open)
            {
                return;
            }

            IDisposable raction = null;
            IDisposable eaction = null;

            if (onResponse != null)
            {
                raction = this.InfoQueryStream
                          .Where(response => response.Id == request.Id && !response.IsError)
                          .Subscribe(onResponse);
            }

            if (eaction != null)
            {
                eaction = this.InfoQueryStream
                          .Where(response => response.Id == request.Id && response.IsError)
                          .Subscribe(onError);
            }

            var daction = this.InfoQueryStream
                          .Where(response => response.Id == request.Id)
                          .Subscribe(response => this.DisposeSubscription(response.Id));

            await this.SendAsync(request, raction, eaction, daction).ConfigureAwait(false);
        }
Exemplo n.º 5
0
        public async Task SendAsnwerTo(string messageId, XmppAddress to)
        {
            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Id            = messageId
                , Type        = InfoQueryType.Result
                , To          = to
                , ServiceInfo = new ServiceInfo
                {
                    Node = this.node
                }
            };

            foreach (var identity in this.Identities)
            {
                iq.ServiceInfo.Identities.Add(identity);
            }

            foreach (var feature in this.Features)
            {
                iq.ServiceInfo.Features.Add(feature);
            }

            await transport.SendAsync(iq).ConfigureAwait(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds the given contact to the roster
        /// </summary>
        /// <param name="address">Contact address</param>
        /// <param name="name">Contact name</param>
        public async Task AddContactAsync(XmppAddress address, string name)
        {
            var contact   = this[address];
            var transport = XmppTransportManager.GetTransport();

            if (contact != null)
            {
                throw new ArgumentException("The given address is already in the contact list");
            }

            var iq = new InfoQuery()
            {
                Type     = InfoQueryType.Set
                , From   = transport.UserAddress.BareAddress
                , To     = transport.UserAddress.BareAddress
                , Roster = new Roster
                {
                    Items =
                    {
                        new RosterItem
                        {
                            Subscription = RosterSubscriptionType.None
                            , Jid        = address.BareAddress
                            , Name       = name
                        }
                    }
                }
            };

            await transport.SendAsync(iq, r => this.OnAddContactResponse(r), e => this.OnAddContactError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 7
0
        private void OnDiscoverServices(InfoQuery response)
        {
            this.services.Clear();

            foreach (var itemDetail in response.ServiceItem.Items)
            {
                this.services.Add(new Service(itemDetail.Jid));
            }
        }
Exemplo n.º 8
0
        private void OnRemoveContactResponse(InfoQuery response)
        {
            if (response.Type == InfoQueryType.Set)
            {
                var item = response.Roster.Items.First();

                this.PublishContactListChanged(CollectionChangedAction.Reset, item.Jid);
            }
        }
Exemplo n.º 9
0
        public override T queryValue <T>(InfoQuery property, params object[] args)
        {
            if (mQueryDelegates.ContainsKey(property) == false)
            {
                throw new NotImplementedException();
            }

            return((T)mQueryDelegates[property](args));
        }
Exemplo n.º 10
0
        private void OnDiscoverSupport(InfoQuery response)
        {
            this.features.Clear();

            foreach (var details in response.ServiceItem.Items)
            {
                this.features.Add(details.Node);
            }
        }
Exemplo n.º 11
0
        private async Task OnPingPongAsync(InfoQuery ping)
        {
            if (ping.Type != InfoQueryType.Get)
            {
                return;
            }

            // Send the "pong" response
            await this.SendAsync(ping.AsResponse()).ConfigureAwait(false);
        }
Exemplo n.º 12
0
        private async Task OnBindedResourceAsync(InfoQuery iq)
        {
            // Update user ID
            this.userAddress = iq.Bind.Jid;

            // Update negotiated features
            this.serverFeatures = this.serverFeatures & (~ServerFeatures.ResourceBinding);

            // Continue feature negotiation
            await this.NegotiateStreamFeaturesAsync().ConfigureAwait(false);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Discover if we have personal eventing support enabled
        /// </summary>
        /// <returns></returns>
        internal async Task DiscoverSupportAsync()
        {
            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Type          = InfoQueryType.Get
                , From        = transport.UserAddress
                , To          = transport.UserAddress.BareAddress
                , ServiceItem = new ServiceItem()
            };

            await transport.SendAsync(iq, r => this.OnDiscoverSupport(r), e => this.OnDiscoverError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 14
0
        private async Task RequestAvatarAsync()
        {
            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                From        = transport.UserAddress
                , To        = this.Address
                , Type      = InfoQueryType.Get
                , VCardData = new VCardData()
            };

            await transport.SendAsync(iq, r => this.OnAvatarResponse(r), e => this.OnError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Request Roster list to the XMPP Server
        /// </summary>
        public async Task RequestRosterAsync()
        {
            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Type     = InfoQueryType.Get
                , From   = transport.UserAddress
                , To     = transport.UserAddress.BareAddress
                , Roster = new Roster()
            };

            await transport.SendAsync(iq, r => this.OnUpdateRoster(r), e => this.OnRosterError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Discover features.
        /// </summary>
        public async Task DiscoverFeaturesAsync()
        {
            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Type          = InfoQueryType.Get
                , From        = transport.UserAddress
                , To          = this.Node
                , ServiceInfo = new ServiceInfo()
            };

            await transport.SendAsync(iq, r => this.OnDiscoverFeatures(r), e => this.OnError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 17
0
        protected void ProcessInfoQuery(XmlStream xml, InfoQuery iq)
        {
            int id = InfoQueryID.NewId();

            xml.Write(
                new XElement(NamespaceClient + "iq",
                             new XAttribute("type", iq.Type),
                             iq.To == null ? null : new XAttribute("to", iq.To),
                             new XAttribute("id", id),
                             iq.Content
                             )
                );

            RunningQueries[id.ToString()] = iq;
        }
Exemplo n.º 18
0
        private async Task OnBindResourceAsync()
        {
            if (!this.Supports(ServerFeatures.ResourceBinding))
            {
                return;
            }

            var iq = new InfoQuery
            {
                Type   = InfoQueryType.Set
                , Bind = Bind.WithResource(this.connectionString.Resource)
            };

            await this.SendAsync(iq).ConfigureAwait(false);
        }
Exemplo n.º 19
0
        private void OnDiscoverFeatures(InfoQuery response)
        {
            this.features.Clear();
            this.identities.Clear();

            foreach (var identity in response.ServiceInfo.Identities)
            {
                this.AddIdentity(identity.Category, identity.Name, identity.Type);
            }

            foreach (var feature in response.ServiceInfo.Features)
            {
                this.AddFeature(feature.Name);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Performs the gateway unregistration process
        /// </summary>
        public async Task UnregisterAsync()
        {
            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Type       = InfoQueryType.Set
                , From     = transport.UserAddress
                , To       = this.Address
                , Register = new Register {
                    Remove = String.Empty
                }
            };

            await transport.SendAsync(iq).ConfigureAwait(false);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Performs the gateway registration process
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public async Task RegisterAsync(string username, string password)
        {
            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Type       = InfoQueryType.Set
                , From     = transport.UserAddress
                , To       = this.Address
                , Register = new Register {
                    UserName = username, Password = password
                }
            };

            await transport.SendAsync(iq).ConfigureAwait(false);
        }
Exemplo n.º 22
0
		protected MemberCollection (Type type, InfoQuery query, MemberComparer comparer, BindingFlags bindings)
		{
			if (query == null)
				throw new NullReferenceException ("Invalid query delegate.");

			if (comparer == null)
				throw new NullReferenceException ("Invalid comparer.");

			this.comparer = comparer;
			this.bindings = bindings;

			this.list = new SortedList ();

			MemberInfo [] data = query (type, bindings);
			foreach (MemberInfo info in data) {
				this.list [info.Name] = info;
			}
		}
Exemplo n.º 23
0
        public async Task DiscoverAsync()
        {
            var transport = XmppTransportManager.GetTransport();

#warning TODO: Grab Capabilities from storage or send the discovery request
            var iq = new InfoQuery
            {
                From          = transport.UserAddress
                , To          = this.Address
                , Type        = InfoQueryType.Get
                , ServiceInfo = new ServiceInfo {
                    Node = this.info.Node
                }
            };

            await transport.SendAsync(iq, r => this.OnDiscoverResponse(r), r => this.OnDiscoverError(r))
            .ConfigureAwait(false);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Refreshes the blocked contacts list
        /// </summary>
        /// <returns></returns>
        public async Task RefreshBlockedContactsAsync()
        {
#warning TODO: Change to use entity caps
            //if (!this.Client.ServiceDiscovery.SupportsBlocking)
            //{
            //    return;
            //}

            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Type        = InfoQueryType.Get
                , BlockList = new BlockList()
            };

            await transport.SendAsync(iq, r => this.OnBlockedContactsResponse(r), e => this.OnBlockedContactsError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Unblock contact.
        /// </summary>
        public async Task UnBlockAsync()
        {
            var transport = XmppTransportManager.GetTransport();

            if (!transport.ServerCapabilities.SupportsBlocking)
            {
                return;
            }

            var iq = new InfoQuery
            {
                From      = transport.UserAddress
                , Type    = InfoQueryType.Set
                , Unblock = new Unblock(this.Address.BareAddress)
            };

            await transport.SendAsync(iq, r => this.OnContactUnBlocked(r), e => this.OnBlockingError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Unblocks all blocked contacts
        /// </summary>
        public async Task UnBlockAllAsync()
        {
#warning TODO: Change to use entity caps
            //if (!this.Client.ServiceDiscovery.SupportsBlocking)
            //{
            //    return;
            //}

            var transport = XmppTransportManager.GetTransport();
            var iq        = new InfoQuery
            {
                Type      = InfoQueryType.Set
                , From    = transport.UserAddress
                , Unblock = new Unblock()
            };

            await transport.SendAsync(iq, r => this.OnUnBlockAllResponse(r), e => this.OnUnBlockAllError(e))
            .ConfigureAwait(false);
        }
Exemplo n.º 27
0
        private async Task OnInfoQueryAsync(InfoQuery iq)
        {
            if (iq.Bind != null)
            {
                await this.OnBindedResourceAsync(iq).ConfigureAwait(false);
            }
            else if (iq.Ping != null)
            {
                await this.OnPingPongAsync(iq).ConfigureAwait(false);
            }
            else
            {
                this.infoQueryStream.OnNext(iq);

                if (iq.Roster != null && iq.IsResult && this.Presence.IsOffline)
                {
                    await this.Presence.SetInitialPresenceAsync().ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 28
0
        private async void OnUpdateRoster(InfoQuery response)
        {
            var roster = response.Roster;

            // It's a roster management related message
            foreach (RosterItem item in roster.Items)
            {
                var contact = this.contacts.FirstOrDefault(c => c.Address.BareAddress == item.Jid);

                if (contact == null)
                {
                    // Create the new contact
                    contact = new Contact(item.Jid, item.Name, item.Subscription, item.Groups);

                    // Add the contact to the roster
                    this.contacts.Add(contact);
                }

                switch (item.Subscription)
                {
                case RosterSubscriptionType.Remove:
                    this.contacts.TryTake(out contact);
                    break;

                case RosterSubscriptionType.None:
                    // auto-accept pending subscription requests
                    if (item.IsPendingOut)
                    {
                        await contact.AcceptSubscriptionAsync().ConfigureAwait(false);
                    }
                    break;

                default:
                    // Update contact data
                    contact.Update(item.Name, item.Subscription, item.Groups);
                    break;
                }
            }

            this.PublishContactListChanged(CollectionChangedAction.Reset);
        }
Exemplo n.º 29
0
        private async Task OnRequestSessionAsync()
        {
            if (!this.Supports(ServerFeatures.Sessions))
            {
                return;
            }

            var iq = new InfoQuery
            {
                Type      = InfoQueryType.Set
                , Session = new Session()
            };

            await this.SendAsync(iq).ConfigureAwait(false);

            // Update negotiated features
            this.serverFeatures = this.serverFeatures & (~ServerFeatures.Sessions);

            // Continue feature negotiation
            await this.NegotiateStreamFeaturesAsync().ConfigureAwait(false);
        }
Exemplo n.º 30
0
        /// <summary>
        /// Updates the given contact information
        /// </summary>
        public async Task UpdateContactAsync(XmppAddress address)
        {
            var transport = XmppTransportManager.GetTransport();
            var contact   = this[address];

            if (contact == null)
            {
                throw new ArgumentException("The given address is not in the contact list");
            }

            var iq = new InfoQuery
            {
                Type     = InfoQueryType.Set
                , From   = transport.UserAddress.BareAddress
                , To     = transport.UserAddress.BareAddress
                , Roster = new Roster(new RosterItem(contact.Address.BareAddress
                                                     , contact.Name
                                                     , contact.Subscription
                                                     , contact.Groups))
            };

            await transport.SendAsync(iq).ConfigureAwait(false);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Adds to group.
        /// </summary>
        /// <param name="groupName">Name of the group.</param>
        public async Task AddContactToGroupAsync(XmppAddress address, string groupName)
        {
            var transport = XmppTransportManager.GetTransport();
            var contact   = this[address];

            if (contact == null)
            {
                throw new ArgumentException("The given address is not in the contact list");
            }

            if (contact.Groups.Contains(groupName))
            {
                return;
            }

            var iq = new InfoQuery
            {
                Type     = InfoQueryType.Set
                , Roster = new Roster(new RosterItem(contact.Address, contact.Name, contact.Subscription, groupName))
            };

            await transport.SendAsync(iq).ConfigureAwait(false);
        }
Exemplo n.º 32
0
        protected void ProcessInfoQuery(XmlStream xml, InfoQuery iq)
        {
            int id = InfoQueryID.NewId();
            xml.Write(
                new XElement(NamespaceClient + "iq",
                    new XAttribute("type", iq.Type),
                    iq.To == null ? null : new XAttribute("to", iq.To),
                    new XAttribute("id", id),
                    iq.Content
                )
            );

            RunningQueries[id.ToString()] = iq;
        }