public List <Activity> GetActivities(HashSet <string> ids, string appId, HashSet <String> fields, CollectionOptions options) { var activities = db.activities .OrderByDescending(x => x.id) .Where(x => ids.AsEnumerable().Contains(x.person_id.ToString()) && (string.IsNullOrEmpty(appId)?true:x.app_id.ToString() == appId)); int first = options.getFirst(); int max = options.getMax(); if (first != 0) { activities = activities.Skip(first); } if (max != 0) { activities = activities.Take(max); } List <Activity> actList = new List <Activity>(); foreach (var row in activities) { var act = new Activity(row.id.ToString(), row.person_id.ToString()); act.streamTitle = "activities"; act.title = row.title; act.body = row.body; act.postedTime = row.created; act.mediaItems = GetMediaItems(row.id.ToString()); actList.Add(act); } return(actList); }
override public RestfulCollection <Person> getPeople(HashSet <UserId> userId, GroupId groupId, CollectionOptions options, HashSet <String> fields, ISecurityToken token) { int first = options.getFirst(); int max = options.getMax(); Dictionary <string, Person> allPeople; HashSet <String> ids = GetIdSet(userId, groupId, token); #if AZURE using (var db = new AzureDbFetcher()) #else using (var db = new RayaDbFetcher()) #endif { allPeople = db.GetPeople(ids, fields, options); } var totalSize = allPeople.Count; var result = new List <Person>(); if (first < totalSize) { foreach (var id in ids) { if (!allPeople.ContainsKey(id)) { continue; } Person person = allPeople[id]; if (!token.isAnonymous() && id == token.getViewerId()) { person.isViewer = true; } if (!token.isAnonymous() && id == token.getOwnerId()) { person.isOwner = true; } result.Add(person); } // We can pretend that by default the people are in top friends order if (options.getSortBy().Equals(Person.Field.NAME.ToDescriptionString())) { result.Sort(new NameComparator()); } if (options.getSortOrder().Equals(SortOrder.descending)) { result.Reverse(); } result = result.GetRange(first, Math.Min(max, totalSize - first > 0 ? totalSize - first : 1)); } return(new RestfulCollection <Person>(result, options.getFirst(), totalSize)); }
public override RestfulCollection <Person> getPeople(HashSet <UserId> userIds, GroupId groupId, CollectionOptions options, HashSet <String> fields, ISecurityToken token) { List <Person> result = new List <Person>(); try { JsonArray people = db[PEOPLE_TABLE] as JsonArray; HashSet <String> idSet = GetIdSet(userIds, groupId, token); if (people != null) { for (int i = 0; i < people.Length; i++) { JsonObject person = people[i] as JsonObject; if (person != null && !idSet.Contains(person[Person.Field.ID.ToDescriptionString()] as string)) { continue; } // Add group support later result.Add(ConvertToPerson(person, fields)); } } // We can pretend that by default the people are in top friends order if (options.getSortBy().Equals(Person.Field.NAME.ToDescriptionString())) { result.Sort(new NameComparator()); } if (options.getSortOrder().Equals(SortOrder.descending)) { result.Reverse(); } // TODO: The samplecontainer doesn't really have the concept of HAS_APP so // we can't support any filters yet. We should fix this. int totalSize = result.Count; int last = options.getFirst() + options.getMax(); result = result.GetRange(options.getFirst(), Math.Min(last, totalSize) - options.getFirst()); return(new RestfulCollection <Person>(result, options.getFirst(), totalSize)); } catch (Exception je) { throw new ProtocolException(ResponseError.INTERNAL_ERROR, je.Message); } }
public List <Activity> GetActivities(HashSet <string> ids, string appId, HashSet <String> fields, CollectionOptions options) { var activityList = new List <ActivityRow>(); using (var db = new AzureRayaDataContext()) { foreach (var id in ids) { if (string.IsNullOrEmpty(appId)) { var activities = db.activities .Where(x => x.PartitionKey == id); foreach (var row in activities) { activityList.Add(row); } } else { var activities = db.activities .Where(x => x.PartitionKey == id && x.app_id == appId); foreach (var row in activities) { activityList.Add(row); } } } } IEnumerable <ActivityRow> ordered = activityList.OrderByDescending(x => x.id); int first = options.getFirst(); int max = options.getMax(); if (first != 0) { ordered = ordered.Skip(first); } if (max != 0) { ordered = ordered.Take(max); } List <Activity> actList = new List <Activity>(); foreach (var row in ordered) { actList.Add(ConvertToActivity(row)); } return(actList); }