예제 #1
0
파일: Client.cs 프로젝트: jaydcarlson/WTalk
        public void GetEntityById(params string[] chat_ids)
        {
            GetEntityByIdRequest request = new GetEntityByIdRequest()
            {
                request_header    = RequestHeaderBody,
                batch_lookup_spec = chat_ids.Select(c => new EntityLookupSpec()
                {
                    gaia_id = c
                }).ToList(),
                field_mask = new List <FieldMask>()
                {
                    FieldMask.FIELD_MASK_AVAILABLE, FieldMask.FIELD_MASK_DEVICE, FieldMask.FIELD_MASK_REACHABLE
                }
            };

            HttpResponseMessage message = _client.PostProtoJson(_api_key, "contacts/getentitybyid", request);

            if (ContactInformationReceived != null)
            {
                GetEntityByIdResponse response = message.Content.ReadAsProtoJson <GetEntityByIdResponse>();

                foreach (var contact in response.entity.Where(c => c.id != null))
                {
                    _contact_ids.Add(contact.id.chat_id);
                    ContactInformationReceived(this, contact);
                }

                QueryPresences();
            }
        }
예제 #2
0
파일: Client.cs 프로젝트: kbmanikanta/WTalk
        public async Task GetEntityByIdAsync(params string[] ids)
        {
            if (ids.Length == 0)
            {
                return;
            }

            GetEntityByIdRequest request = new GetEntityByIdRequest()
            {
                request_header    = RequestHeaderBody,
                batch_lookup_spec = ids.Select(c => new EntityLookupSpec()
                {
                    gaia_id = c
                }).ToList()
                                    //field_mask = new List<FieldMask>() { FieldMask.FIELD_MASK_AVAILABLE, FieldMask.FIELD_MASK_DEVICE, FieldMask.FIELD_MASK_REACHABLE }
            };

            using (HttpResponseMessage message = await _client.PostProtoJson("contacts/getentitybyid", _api_key, request))
            {
                GetEntityByIdResponse response = await message.Content.ReadAsProtoJson <GetEntityByIdResponse>();

                if (_contacts.Count == 0)
                {
                    _contacts = response.entity.Where(c => c.id != null).ToDictionary(c => c.id.gaia_id, c => c);
                    if (OnContactListReceived != null)
                    {
                        OnContactListReceived(this, _contacts.Values.ToList());
                    }
                }
                else
                {
                    response.entity.Where(c => c.id != null).ToList().ForEach((contact) =>
                    {
                        if (_contacts.ContainsKey(contact.id.gaia_id))
                        {
                            _contacts[contact.id.gaia_id] = contact;
                        }
                        else
                        {
                            _contacts.Add(contact.id.gaia_id, contact);
                        }

                        if (OnContactInformationReceived != null)
                        {
                            OnContactInformationReceived(this, _contacts[contact.id.gaia_id]);
                        }
                    });
                }
                QueryPresencesAsync();
            }
        }
예제 #3
0
파일: Client.cs 프로젝트: itainteasy/WTalk
        public void GetEntityById(params string[] ids)
        {
            GetEntityByIdRequest request = new GetEntityByIdRequest()
            {
                request_header    = RequestHeaderBody,
                batch_lookup_spec = ids.Select(c => new EntityLookupSpec()
                {
                    gaia_id = c
                }).ToList()
                                    //field_mask = new List<FieldMask>() { FieldMask.FIELD_MASK_AVAILABLE, FieldMask.FIELD_MASK_DEVICE, FieldMask.FIELD_MASK_REACHABLE }
            };

            using (HttpResponseMessage message = _client.PostProtoJson("contacts/getentitybyid", request))
            {
                GetEntityByIdResponse response = message.Content.ReadAsProtoJson <GetEntityByIdResponse>();
                if (_contacts.Count == 0)
                {
                    _contacts = response.entity.Where(c => c.id != null).ToDictionary(c => c.id.gaia_id, c => new User(c));
                    if (ContactListLoaded != null)
                    {
                        ContactListLoaded(this, _contacts.Values.ToList());
                    }
                }
                else
                {
                    foreach (var contact in response.entity.Where(c => c.id != null))
                    {
                        if (_contacts.ContainsKey(contact.id.gaia_id))
                        {
                            _contacts[contact.id.gaia_id] = new User(contact);
                        }
                        else
                        {
                            _contacts.Add(contact.id.gaia_id, new User(contact));
                        }

                        if (ContactInformationReceived != null)
                        {
                            ContactInformationReceived(this, _contacts[contact.id.gaia_id]);
                        }
                    }
                }
                QueryPresences();
            }
        }