/// <inheritdoc /> public async Task <GetContactsResponse> ExecuteAsync(GetContactsRequest request) { try { var requestedContacts = await this.LoadContactsOnAddressAsync(request.RequestAddress, request.KeyPair); var localApprovedContacts = await this.ContactRepository.LoadContactsAsync(request.PublicKeyAddress.Value); var addressComparer = new ContactComparer(); var approvedContacts = requestedContacts.Intersect(localApprovedContacts, addressComparer).ToList(); approvedContacts.ForEach(c => c.Request = false); var pendingContactRequests = requestedContacts.Union(localApprovedContacts, addressComparer).ToList() .Except(localApprovedContacts, addressComparer).ToList(); if (request.DoCrossCheck) { return(await this.CrossCheckAsync(request.KeyPair, request.PublicKeyAddress, approvedContacts, pendingContactRequests)); } return(new GetContactsResponse { ApprovedContacts = approvedContacts, PendingContactRequests = pendingContactRequests, Code = ResponseCode.Success }); } catch (Exception) { return(new GetContactsResponse { Code = ResponseCode.ContactsUnavailable }); } }
private static int CompareContactListsAlphabetically(IContactList contactListA, IContactList contactListB) { int comparisons = Math.Min(contactListA.Count, contactListB.Count); for (int contactIndex = 0; contactIndex < comparisons; contactIndex++) { int contactCompare = ContactComparer.CompareAlphabetically(contactListA[contactIndex], contactListB[contactIndex]); if (contactCompare != 0) { return(contactCompare); } } return(contactListA.Count - contactListB.Count); }
public void GetAllContactsTest() { var contactController = new ContactController(_contactService) { Request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri(ServiceBaseURL + "v1/Contacts/Contact/all") } }; contactController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); _response = contactController.Get(); var responseResult = JsonConvert.DeserializeObject <List <Contact> >(_response.Content.ReadAsStringAsync().Result); Assert.AreEqual(_response.StatusCode, HttpStatusCode.OK); Assert.AreEqual(responseResult.Any(), true); var comparer = new ContactComparer(); CollectionAssert.AreEqual( responseResult.OrderBy(contact => contact, comparer), _contacts.OrderBy(contact => contact, comparer), comparer); }
public ContactFilter() { Include = true; comparer = new ContactComparer(); Contacts = new ObservableCollection<IContact>(); }
void Awake() { solver = GetComponent <ObiSolver>(); comparer = new ContactComparer(solver); prevData = new Oni.Contact[0]; }