public async Task <VkApiCommunity> DiscoverCommunityAsync(string groupId) { VkApiCommunity result = null; try { //"kate_kul" error 100 var groupInfo = await UserApi.Groups.GetByIdAsync(null, groupId, GroupsFields.All); if (groupInfo.Count == 1) { VkApiCommunity community = new VkApiCommunity(this, groupInfo[0]); if (Communities.FirstOrDefault(c => c.Id == community.Id) == null) { Communities.Add(community); } result = community; } } catch (ParameterMissingOrInvalidException) { Console.WriteLine("Error discovering community " + groupId + ": community not found."); } catch (Exception e) { Console.WriteLine("Error discovering community " + groupId + ": " + e); } return(result); }
public void AddUser(VkBrwUser user) { Users.Add(user); if (user.Communitites.Count > 0) { foreach (VkBrwCommunity community in user.Communitites) { VkBrwCommunity existingCommunity = Communities.FirstOrDefault(c => c.CommunityId == community.CommunityId); if (existingCommunity == null) { Communities.Add(community); } else { VkBrwUser existingUser = existingCommunity.Users.FirstOrDefault(u => u.ProfileLink == user.ProfileLink); if (existingUser == null) { existingCommunity.Users.Add(user); } } } } }
private Communities CreateCommunities() { var index = 0; var communities = new Communities(); var community = CreateCommunity(0); communities.Add(community, CreateMembers(ref index, community, 2)); community = CreateCommunity(1); communities.Add(community, CreateMembers(ref index, community, 3)); communities.NoCommunityMembers = CreateMembers(ref index, null, 4); return(communities); }
private void LoadDekalbCommunityData() { //Reading input files. string[] persons = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/p.txt"); string[] houses = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/r.txt"); string[] apartments = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/a.txt"); string[] schools = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/s.txt"); string[] business = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/b.txt"); //Iterating over each of the input files and type casting them to relevant class types. foreach (var item in persons) { string[] items = item.Split('\t'); Person p = new Person(items); lstDekalbPersons.Add(p); } lstDekalbPersons.Sort(new PersonComparer()); foreach (var item in houses) { string[] items = item.Split('\t'); House h = new House(items); lstDekalbHouses.Add(h); } lstDekalbHouses.Sort(new PropertyComparer()); foreach (var item in apartments) { string[] items = item.Split('\t'); Apartment a = new Apartment(items); lstDekalbApartments.Add(a); } lstDekalbApartments.Sort(new PropertyComparer()); foreach (var item in schools) { string[] items = item.Split('\t'); School s = new School(items); lstDekalbSchools.Add(s); } foreach (var item in business) { string[] items = item.Split('\t'); Business b = new Business(items); lstDekalbBusiness.Add(b); } Community community = new Community(lstDekalbPersons, lstDekalbHouses, lstDekalbApartments, lstDekalbSchools, lstDekalbBusiness); Communities.Add(community); }
private static void GenerateMissingPrimaryKeys() { int stateId = 0; int provinceId = 0; int communityId = 0; int placeId = 0; Countries .SelectMany(x => x.States, (country, state) => new { country, state }) .OrderBy(countryState => countryState.state.Name) .ToList() .ForEach(countryState => { countryState.state.Id = ++stateId; countryState.state.CountryId = countryState.country.Id; States.Add(countryState.state); countryState.state.Provinces .OrderBy(province => province.Name) .ToList() .ForEach(province => { province.Id = ++provinceId; province.StateId = countryState.state.Id; Provinces.Add(province); province.Communities .OrderBy(community => community.Name) .ToList() .ForEach(community => { community.Id = ++communityId; community.ProvinceId = province.Id; Communities.Add(community); community.Places .OrderBy(place => place.Name) .ToList() .ForEach(place => { place.Id = ++placeId; place.CommunityId = community.Id; Places.Add(place); }); }); }); }); }
public void SetCommunities(Dictionary <int, List <int> > dictCommunities) { foreach (KeyValuePair <int, List <int> > kvp in dictCommunities) { HashSet <Node <T> > communityNodes = new HashSet <Node <T> >(); foreach (int i in kvp.Value) { Node <T> node = GetNodeById(i); communityNodes.Add(GetNodeById(i)); node.CommunityId = kvp.Key; } Community <T> community = new Community <T> { Id = kvp.Key + 1, CommunityNodes = communityNodes }; foreach (Node <T> node in communityNodes) { node.Community = community; node.CommunityId = community.Id; } Communities.Add(community); } foreach (Node <T> node in Nodes) { List <Node <T> > node1 = Edges.Where(x => x.Node1.Id == node.Id && x.Node1.Community == null).Select(x => x.Node1).ToList(); foreach (Node <T> n in node1) { n.CommunityId = node.CommunityId; n.Community = node.Community; } List <Node <T> > node2 = Edges.Where(x => x.Node2.Id == node.Id && x.Node2.Community == null).Select(x => x.Node2).ToList(); foreach (Node <T> n in node2) { n.CommunityId = node.CommunityId; n.Community = node.Community; } } }
private void LoadDekalbCommunityData() { //Reading input files. string[] persons = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/p.txt"); string[] houses = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/r.txt"); string[] apartments = File.ReadAllLines(@"../../../DataLoader/InputFiles/Dekalb/a.txt"); //List<Person> lstPersons = new List<Person>(); //List<House> lstHouses = new List<House>(); //List<Apartment> lstApartments = new List<Apartment>(); //Iterating over each of the input files and type casting them to relevant class types. foreach (var item in persons) { string[] items = item.Split('\t'); Person p = new Person(items); lstDekalbPersons.Add(p); } lstDekalbPersons.Sort(new PersonComparer()); foreach (var item in houses) { string[] items = item.Split('\t'); House h = new House(items); lstDekalbHouses.Add(h); } lstDekalbHouses.Sort(new PropertyComparer()); foreach (var item in apartments) { string[] items = item.Split('\t'); Apartment a = new Apartment(items); lstDekalbApartments.Add(a); } lstDekalbApartments.Sort(new PropertyComparer()); Community community = new Community(lstDekalbPersons, lstDekalbHouses, lstDekalbApartments); Communities.Add(community); }
public static int Add(Community community) { return(Communities.Add(community)); }