public void getContacts_Click(object sender, EventArgs e) { checkAccessToken(Operation.GetContactsOperation); var qs = "search=" + searchVal.Text; if (!addressbook.getContacts(qs)) { this.contact_error = this.addressbook.errorResponse; } else { try { this.qContactResult = serializer.Deserialize <QuickContactJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.contact_error = ex.Message; } } }
/// <summary> /// Initial set up for the application. We read the config file and create the instance of Oauth and addressbook object. /// If it's post back from getting Auth code then perform operations. /// </summary> protected void Page_Load(object sender, EventArgs e) { ReadConfigFile(); oauth = new OAuth(endPoint, scope, apiKey, secretKey, authorizeRedirectUri, refreshTokenExpiresIn, bypassSSL); this.serializer = new JavaScriptSerializer(); if (Session["cs_rest_AccessToken"] != null && this.addressbook == null) { this.addressbook = new AddressBook(this.endPoint, Session["cs_rest_AccessToken"].ToString()); } if ((string)Session["cs_rest_appState"] == "GetToken" && Request["Code"] != null) { this.oauth.authCode = Request["code"].ToString(); if (oauth.GetAccessToken(OAuth.AccessTokenType.Authorization_Code) == true) { StoreAccessTokenToSession(oauth.access_token_json); this.addressbook = new AddressBook(this.endPoint, this.accessToken); Operation operation = (Operation)Session["cs_rest_ServiceRequest"]; switch (operation) { case Operation.CreateContactOperation: if (!addressbook.createContact(Session["JSONstring"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { this.create_contact = new Success(); this.create_contact.location = this.addressbook.location; } break; case Operation.UpdateContactOperation: if (!addressbook.updateContact(Session["contactid"].ToString(), Session["JSONstring"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { this.success_contact = new Success(); this.success_contact.last_modified = this.addressbook.last_mod; } break; case Operation.DeleteContactOperation: if (!addressbook.deleteContact(Session["contactid"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { this.success_contact = new Success(); this.success_contact.last_modified = this.addressbook.last_mod; } break; case Operation.GetContactsOperation: if (!addressbook.getContacts(Session["querystring"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { try { this.qContactResult = serializer.Deserialize<QuickContactJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.contact_error = ex.Message; } } break; case Operation.UpdateMyInfoOperation: if (!addressbook.updateMyInfo(Session["JSONstring"].ToString())) { this.myinfo_error = this.addressbook.errorResponse; } else { this.update_myinfo = new Success(); this.update_myinfo.last_modified = this.addressbook.last_mod; } break; case Operation.GetMyInfoOperation: if (!addressbook.getMyInfo()) { this.myinfo_error = this.addressbook.errorResponse; } else { try { this.myInfoResult = serializer.Deserialize<ContactJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.myinfo_error = ex.Message; } } break; case Operation.CreateGroupOperation: if (!addressbook.createGroup(Session["JSONstring"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { this.create_group = new Success(); this.create_group.location = this.addressbook.location; } break; case Operation.UpdateGroupOperation: if (!addressbook.updateGroup(Session["groupid"].ToString(), Session["JSONstring"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { this.success_group = new Success(); this.success_group.last_modified = this.addressbook.last_mod; } break; case Operation.DeleteGroupOperation: if (!addressbook.deleteGroup(Session["groupid"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { this.success_group = new Success(); this.success_group.last_modified = this.addressbook.last_mod; } break; case Operation.GetGroupsOperation: if (!addressbook.getGroups(Session["querystring"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { try { this.groupResult = serializer.Deserialize<GroupJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.group_error = ex.Message; } } break; case Operation.GetGroupContactsOperation: if (!addressbook.getGroupContacts(Session["groupid"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { try { this.contactIdResult = serializer.Deserialize<ContactIdJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.manage_groups_error = ex.Message; } } break; case Operation.AddContctsToGroupOperation: if(!addressbook.addContactToGroup(Session["groupid"].ToString(), Session["contactids"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { this.manage_groups = new Success(); this.manage_groups.last_modified = this.addressbook.last_mod; } break; case Operation.RemoveContactsFromGroupOperation: if (!addressbook.removeContactsFromGroup(Session["groupid"].ToString(), Session["contactids"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { this.manage_groups = new Success(); this.manage_groups.last_modified = this.addressbook.last_mod; } break; case Operation.GetContactGroupsOperation: if (addressbook.getContactGroups(Session["contactid"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { try { this.contactGroupResult = serializer.Deserialize<GroupJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.manage_groups_error = ex.Message; } } break; } ResetRequestSessionVariables(operation); } else { if (oauth.getAuthCodeError != null) { this.oauth_error = "GetAuthCodeError: " + oauth.getAuthCodeError; } if (oauth.GetAccessTokenError != null) { this.oauth_error = "GetAccessTokenError: " + oauth.GetAccessTokenError; } this.ResetTokenSessionVariables(); return; } } }
public void getContacts_Click(object sender, EventArgs e) { checkAccessToken(Operation.GetContactsOperation); var qs = "search=" + searchVal.Text; if (!addressbook.getContacts(qs)) { this.contact_error = this.addressbook.errorResponse; } else { try { this.qContactResult = serializer.Deserialize<QuickContactJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.contact_error = ex.Message; } } }
/// <summary> /// Initial set up for the application. We read the config file and create the instance of Oauth and addressbook object. /// If it's post back from getting Auth code then perform operations. /// </summary> protected void Page_Load(object sender, EventArgs e) { ReadConfigFile(); oauth = new OAuth(endPoint, scope, apiKey, secretKey, authorizeRedirectUri, refreshTokenExpiresIn, bypassSSL); this.serializer = new JavaScriptSerializer(); if (Session["cs_rest_AccessToken"] != null && this.addressbook == null) { this.addressbook = new AddressBook(this.endPoint, Session["cs_rest_AccessToken"].ToString()); } if ((string)Session["cs_rest_appState"] == "GetToken" && Request["Code"] != null) { this.oauth.authCode = Request["code"].ToString(); if (oauth.GetAccessToken(OAuth.AccessTokenType.Authorization_Code) == true) { StoreAccessTokenToSession(oauth.access_token_json); this.addressbook = new AddressBook(this.endPoint, this.accessToken); Operation operation = (Operation)Session["cs_rest_ServiceRequest"]; switch (operation) { case Operation.CreateContactOperation: if (!addressbook.createContact(Session["JSONstring"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { this.create_contact = new Success(); this.create_contact.location = this.addressbook.location; } break; case Operation.UpdateContactOperation: if (!addressbook.updateContact(Session["contactid"].ToString(), Session["JSONstring"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { this.success_contact = new Success(); this.success_contact.last_modified = this.addressbook.last_mod; } break; case Operation.DeleteContactOperation: if (!addressbook.deleteContact(Session["contactid"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { this.success_contact = new Success(); this.success_contact.last_modified = this.addressbook.last_mod; } break; case Operation.GetContactsOperation: if (!addressbook.getContacts(Session["querystring"].ToString())) { this.contact_error = this.addressbook.errorResponse; } else { try { this.qContactResult = serializer.Deserialize <QuickContactJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.contact_error = ex.Message; } } break; case Operation.UpdateMyInfoOperation: if (!addressbook.updateMyInfo(Session["JSONstring"].ToString())) { this.myinfo_error = this.addressbook.errorResponse; } else { this.update_myinfo = new Success(); this.update_myinfo.last_modified = this.addressbook.last_mod; } break; case Operation.GetMyInfoOperation: if (!addressbook.getMyInfo()) { this.myinfo_error = this.addressbook.errorResponse; } else { try { this.myInfoResult = serializer.Deserialize <ContactJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.myinfo_error = ex.Message; } } break; case Operation.CreateGroupOperation: if (!addressbook.createGroup(Session["JSONstring"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { this.create_group = new Success(); this.create_group.location = this.addressbook.location; } break; case Operation.UpdateGroupOperation: if (!addressbook.updateGroup(Session["groupid"].ToString(), Session["JSONstring"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { this.success_group = new Success(); this.success_group.last_modified = this.addressbook.last_mod; } break; case Operation.DeleteGroupOperation: if (!addressbook.deleteGroup(Session["groupid"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { this.success_group = new Success(); this.success_group.last_modified = this.addressbook.last_mod; } break; case Operation.GetGroupsOperation: if (!addressbook.getGroups(Session["querystring"].ToString())) { this.group_error = this.addressbook.errorResponse; } else { try { this.groupResult = serializer.Deserialize <GroupJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.group_error = ex.Message; } } break; case Operation.GetGroupContactsOperation: if (!addressbook.getGroupContacts(Session["groupid"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { try { this.contactIdResult = serializer.Deserialize <ContactIdJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.manage_groups_error = ex.Message; } } break; case Operation.AddContctsToGroupOperation: if (!addressbook.addContactToGroup(Session["groupid"].ToString(), Session["contactids"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { this.manage_groups = new Success(); this.manage_groups.last_modified = this.addressbook.last_mod; } break; case Operation.RemoveContactsFromGroupOperation: if (!addressbook.removeContactsFromGroup(Session["groupid"].ToString(), Session["contactids"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { this.manage_groups = new Success(); this.manage_groups.last_modified = this.addressbook.last_mod; } break; case Operation.GetContactGroupsOperation: if (addressbook.getContactGroups(Session["contactid"].ToString())) { this.manage_groups_error = this.addressbook.errorResponse; } else { try { this.contactGroupResult = serializer.Deserialize <GroupJSON.RootObject>(addressbook.JSONstring); } catch (Exception ex) { this.manage_groups_error = ex.Message; } } break; } ResetRequestSessionVariables(operation); } else { if (oauth.getAuthCodeError != null) { this.oauth_error = "GetAuthCodeError: " + oauth.getAuthCodeError; } if (oauth.GetAccessTokenError != null) { this.oauth_error = "GetAccessTokenError: " + oauth.GetAccessTokenError; } this.ResetTokenSessionVariables(); return; } } }