private void btnGetFriends_Click(object sender, EventArgs e) { lblStep2.Visible = false; if (getLimit() == 0) { MessageBox.Show("Please enter a valid number for the Limit field.", "Limit is invalid"); return; } lbFriends.DisplayMember = "Name"; lbFriends.Items.Clear(); Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("limit", getLimit()); if (getOffset() > 0) { parms.Add("offset", getOffset()); } var result = app.Get("me/friends", parms); JObject jobject = JObject.Parse(result.ToString()); JArray friends = (JArray)jobject["data"]; foreach (JObject friend in friends) { System.Diagnostics.Debug.WriteLine(friend.ToString()); FbFriend fbFriend = new FbFriend() { Name = (string)friend["name"], UserID = (string)friend["id"] }; Friends.Add(fbFriend.UserID, fbFriend); lbFriends.Items.Add(fbFriend); } btnGetDetails.Enabled = true; btnGetStatus.Enabled = true; btnAreFriends.Enabled = true; lblStep2.Visible = true; tsStatusMessage.Text = string.Format("Collected {0} friends.", Friends.Count); }
private void btnGetDetails_Click(object sender, EventArgs e) { lblStep3.Visible = false; tsProgressBar.Visible = true; tsProgressBar.Minimum = 0; tsProgressBar.Value = 0; tsProgressBar.Maximum = Friends.Count; tsStatusMessage.Text = "Collecting details for each friend..."; foreach (FbFriend f in Friends.Values) { try { app.GetAsync(f.UserID, (val) => { BeginInvoke(new MethodInvoker( delegate() { if (val != null && val.Result != null) { JObject jobject = JObject.Parse(val.Result.ToString()); FbFriend fb = Friends[(string)jobject["id"]]; fb.FirstName = (string)jobject["first_name"]; fb.LastName = (string)jobject["last_name"]; fb.Gender = (string)jobject["gender"]; fb.Link = (string)jobject["link"]; fb.RelationshipStatus = (string)jobject["relationship_status"]; // get birthday if available string bdayString = (string)jobject["birthday"]; if (bdayString != null) { string[] bday = bdayString.Split(new char[] { '/' }); if (bday.Length == 3) { fb.BirthdayYear = bday[2]; } if (bday.Length >= 2) { fb.BirthdayMonth = bday[0]; fb.BirthdayDay = bday[1]; } } JArray schools = (JArray)jobject["education"]; if (schools != null) { Schools.AddRange(parseEducation(schools, fb.UserID)); } } if (tsProgressBar.Value++ == tsProgressBar.Maximum - 1) { tsProgressBar.Visible = false; tsStatusMessage.Text = string.Format("Details retrieved for {0} friends", Friends.Values.Count); lblStep3.Visible = true; } } )); System.Diagnostics.Debug.WriteLine(val.Result.ToString()); }); } catch { tsProgressBar.Value++; } } }
private void btnGetFriends_Click(object sender, EventArgs e) { lblStep2.Visible = false; if (getLimit() == 0) { MessageBox.Show("Please enter a valid number for the Limit field.", "Limit is invalid"); return; } lbFriends.DisplayMember = "Name"; lbFriends.Items.Clear(); Dictionary<string, object> parms = new Dictionary<string, object>(); parms.Add("limit", getLimit()); if (getOffset() > 0) { parms.Add("offset", getOffset()); } var result = app.Get("me/friends",parms); JObject jobject = JObject.Parse(result.ToString()); JArray friends = (JArray)jobject["data"]; foreach (JObject friend in friends) { System.Diagnostics.Debug.WriteLine(friend.ToString()); FbFriend fbFriend = new FbFriend() { Name = (string)friend["name"], UserID=(string)friend["id"] }; Friends.Add(fbFriend.UserID, fbFriend); lbFriends.Items.Add(fbFriend); } btnGetDetails.Enabled = true; btnGetStatus.Enabled = true; btnAreFriends.Enabled = true; lblStep2.Visible = true; tsStatusMessage.Text = string.Format("Collected {0} friends.", Friends.Count); }
public static string GetSasProgram(FbFriend me, Dictionary<string, FbFriend> friends, List<FbSchool> schools, List<FbStatus> statuses, List<string> friendPairs, bool preserveEncoding) { StringBuilder sb = new StringBuilder(); sb.AppendLine(sasOdsPaths); sb.AppendFormat("%let myFacebookName = {0};\n", me.Name); sb.Append(sasFriends); foreach (string key in friends.Keys) { sb.AppendLine(string.Format("\"{0}\",\"{1}\"", friends[key].UserID, FixUpDatalinesString(friends[key].Name))); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); sb.AppendLine(); sb.Append(sasFriendDetails); foreach (string key in friends.Keys) { sb.AppendLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",{6},{7},{8}", friends[key].UserID, FixUpDatalinesString(friends[key].LastName), FixUpDatalinesString(friends[key].FirstName), friends[key].Gender, FixUpDatalinesString(friends[key].Link), friends[key].RelationshipStatus, friends[key].BirthdayYear, friends[key].BirthdayMonth, friends[key].BirthdayDay )); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); sb.AppendLine(); sb.Append(sasStatus); foreach (FbStatus s in statuses) { sb.AppendLine(buildStatusRecord(s)); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); sb.AppendLine(); sb.Append(sasSchools); foreach (FbSchool s in schools) { sb.AppendLine(buildSchoolRecord(s)); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); if (friendPairs.Count>0) { sb.Append(buildFriendMatrix(friendPairs)); } sb.Append(FacebookToSas.ReadFileFromAssembly("SAS.FbFriends.FbReport.sas")); if (!preserveEncoding) { Encoding enc = Encoding.ASCII; byte[] encoded = enc.GetBytes(sb.ToString()); return enc.GetString(encoded); } else return sb.ToString(); }
static public string GetSasProgram(FbFriend me, Dictionary <string, FbFriend> friends, List <FbSchool> schools, List <FbStatus> statuses, List <string> friendPairs, bool preserveEncoding) { StringBuilder sb = new StringBuilder(); sb.AppendLine(sasOdsPaths); sb.AppendFormat("%let myFacebookName = {0};\n", me.Name); sb.Append(sasFriends); foreach (string key in friends.Keys) { sb.AppendLine(string.Format("\"{0}\",\"{1}\"", friends[key].UserID, FixUpDatalinesString(friends[key].Name))); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); sb.AppendLine(); sb.Append(sasFriendDetails); foreach (string key in friends.Keys) { sb.AppendLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",{6},{7},{8}", friends[key].UserID, FixUpDatalinesString(friends[key].LastName), FixUpDatalinesString(friends[key].FirstName), friends[key].Gender, FixUpDatalinesString(friends[key].Link), friends[key].RelationshipStatus, friends[key].BirthdayYear, friends[key].BirthdayMonth, friends[key].BirthdayDay )); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); sb.AppendLine(); sb.Append(sasStatus); foreach (FbStatus s in statuses) { sb.AppendLine(buildStatusRecord(s)); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); sb.AppendLine(); sb.Append(sasSchools); foreach (FbSchool s in schools) { sb.AppendLine(buildSchoolRecord(s)); } sb.AppendLine(";;;;"); sb.AppendLine("run;"); if (friendPairs.Count > 0) { sb.Append(buildFriendMatrix(friendPairs)); } sb.Append(FacebookToSas.ReadFileFromAssembly("SAS.FbFriends.FbReport.sas")); if (!preserveEncoding) { Encoding enc = Encoding.ASCII; byte[] encoded = enc.GetBytes(sb.ToString()); return(enc.GetString(encoded)); } else { return(sb.ToString()); } }