private async void btnAllTasks_Click(object sender, RoutedEventArgs e) { string getTasksURL; if (Globals.ThisAddIn.myCredentials != null) { getTasksURL = Properties.Settings.Default.ServerURL + "DisplayAllTasks.displayalltasks?" + "access_token=" + Globals.ThisAddIn.myCredentials.AccessToken + "&instance_url=https://ap4.salesforce.com&rm_email=" + SelectedMailItem.SenderEmailAddress; string tasksResponse = await WebRequestHelper.getResponseAsync(getTasksURL); if (tasksResponse != "") { AllTasks = JsonConvert.DeserializeObject <Tasks>(tasksResponse); if (AllTasks.Number_of_records == 0) { //MessageBox.Show("No Tasks Found"); ShowNoTasksMessage = System.Windows.Visibility.Visible; HideTasksList = System.Windows.Visibility.Collapsed; } else { ShowNoTasksMessage = System.Windows.Visibility.Collapsed; HideTasksList = System.Windows.Visibility.Visible; } ShowTasksPane = System.Windows.Visibility.Visible; OnPropertyChanged("AllTasks"); OnPropertyChanged("ShowTasksPane"); } } }
private async Task <bool> HasLoginExpired() { try { string CaseBasedOnEmailURL = ""; if (myCredentials != null) { //Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.Address CaseBasedOnEmailURL = serverIP + "displayCase.allcase?rm_email=" + myCredentials.EmailID + "&type=all" + "&access_token=" + myCredentials.AccessToken + "&instance_url=" + myCredentials.InstanceURL; string CaseBasedOnEmailURLResponse = await WebRequestHelper.getResponseAsync(CaseBasedOnEmailURL); if (CaseBasedOnEmailURLResponse == "") { return(true); } else { return(false); } } return(true); } catch (Exception) { return(true); } }
//private static object _syncLock = new object(); private async void DisplayCaseBasedOnEmail(string currentUserEmailID, string selectedSenderMailID, string selectedMailSubject) { try { string CaseBasedOnEmailURL = ""; if (Globals.ThisAddIn.myCredentials != null) { CaseBasedOnEmailURL = serverURL + "displayCaseBasedOnEmail.displaycase?rm_email=" + currentUserEmailID + "&email=" + selectedSenderMailID + "&subject=" + selectedMailSubject + "&access_token=" + Globals.ThisAddIn.myCredentials.AccessToken + "&instance_url=" + Globals.ThisAddIn.myCredentials.InstanceURL; string CaseBasedOnEmailURLResponse = await WebRequestHelper.getResponseAsync(CaseBasedOnEmailURL); if (CaseBasedOnEmailURLResponse != "" && !CaseBasedOnEmailURLResponse.Contains("null")) { var details = JObject.Parse(CaseBasedOnEmailURLResponse); ClosedCaseCount = "Closed Case: " + details["totalClosedCaseEmail"].ToString(); OpenCaseCount = "Open Case: " + details["totalOpenCaseEmail"].ToString(); var escaletedcasesArray = details["escalated_cases"]; var opencasesArray = details["opencase"]; var autoRepliedCase = details["autoreplied_case"]; var currentCase = details["currentsubject"]; PositivePercentage = details["positive_percentage"].ToString(); NegativePercentage = details["nagative_percentage"].ToString(); NeutralPercentage = details["neutral_percentage"].ToString(); List <OpenCase> tempList = currentCase.ToObject <List <OpenCase> >(); tempList.AddRange(escaletedcasesArray.ToObject <List <OpenCase> >()); tempList.AddRange(opencasesArray.ToObject <List <OpenCase> >()); tempList.AddRange(autoRepliedCase.ToObject <List <OpenCase> >()); //lock (_syncLock) //{ // EmailBasedCases = escaletedcasesArray.ToObject<List<OpenCase>>(); // EmailBasedCases.AddRange(opencasesArray.ToObject<List<OpenCase>>()); //} int index = tempList.FindIndex(a => a.CaseSubject == SelectedMailItem.Subject); if (index >= 0) { OpenCase selectedCase = tempList[index]; selectedCase.IsSelectedCase = true; tempList.RemoveAt(index); tempList.Insert(0, selectedCase); } EmailBasedCases = tempList; emailListBox.Dispatcher.Invoke((System.Windows.Forms.MethodInvoker) delegate { emailListBox.Focus(); }); } } } catch (System.Exception ex) { MessageBox.Show("Exception Occured in displayCaseBasedOnEmail API." + ex.Message); } }
public async Task <string> GetTokens(string accessCode) { string tokenURL = serverURL + "getTokenRefreshToken.token?type=code&code=" + accessCode; string tokenResponse = await WebRequestHelper.getResponseAsync(tokenURL); var details = JObject.Parse(tokenResponse); AccessToken = details["access_token"].ToString(); RefreshToken = details["refresh_token"].ToString(); InstanceURL = details["instance_url"].ToString(); //EmailID = Globals.ThisAddIn.LoggedinUserID; return(""); }
//function for fetching LeadData and CaseData private async void CallLeadCaseDataBasedOnEmail(string emailId) { string MailDataURL = ""; if (Globals.ThisAddIn.myCredentials != null) { MailDataURL = serverURL + "MailDataBasedOnEmail.getdata?email=" + emailId + "&to=" + Globals.ThisAddIn.myCredentials.EmailID; string EmailDataResponse = await WebRequestHelper.getResponseAsync(MailDataURL); if (EmailDataResponse != "") { EmailBasedCaseData deserializedEmailBasedCaseData = JsonConvert.DeserializeObject <EmailBasedCaseData>(EmailDataResponse); EmailBasedLeads = deserializedEmailBasedCaseData.LeadDataCollection; } } }
public async void GetTokenViaRefreshToken(string refreshToken) { string tokenURL = serverURL + "getTokenRefreshToken.token?type=re_tkn&re_tkn=" + refreshToken; string tokenResponse = await WebRequestHelper.getResponseAsync(tokenURL); var details = JObject.Parse(tokenResponse); try { AccessToken = details["access_token"].ToString(); InstanceURL = details["instance_url"].ToString(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Failed while fetching accesstoken using refresh token. " + ex.Message); } }
private async void FireSentimentsRequest() { string emailID = Globals.ThisAddIn.myCredentials.EmailID; string SentimentsURL = ""; if (Globals.ThisAddIn.myCredentials != null) { SentimentsURL = serverURL + "SentimentServlet.getdata?email=" + emailID; //+ "&access_token=" + Globals.ThisAddIn.myCredentials.AccessToken; //string PostData = "{"rm_email":} string sentimentsResponse = await WebRequestHelper.getResponseAsync(SentimentsURL); if (sentimentsResponse != "") { formatJsonSentiments(sentimentsResponse); } } }
private async void GetTemplates(string email) { try { string TemplateURL = ""; if (Globals.ThisAddIn.myCredentials != null) { TemplateURL = serverURL + "SelectTemplates.getdata?email=" + email; string TemplateURLResponse = await WebRequestHelper.getResponseAsync(TemplateURL); if (TemplateURLResponse != "") { //EmailBasedCaseData deserializedEmailBasedCaseData = JsonConvert.DeserializeObject<EmailBasedCaseData>(CaseBasedOnEmailURLResponse); Templates = JsonConvert.DeserializeObject <Templates>(TemplateURLResponse); } } } catch (System.Exception ex) { MessageBox.Show("Exception Occured in SelectTemplates API. " + ex.Message); } }
private async void FireCaseRequest() { string emailID = Globals.ThisAddIn.myCredentials.EmailID; string OpenCasesURL = ""; if (Globals.ThisAddIn.myCredentials != null) { OpenCasesURL = serverURL + "displayCase.allcase?rm_email=" + emailID + "&type=all&access_token=" + Globals.ThisAddIn.myCredentials.AccessToken + "&instance_url=" + Globals.ThisAddIn.myCredentials.InstanceURL; string tokenResponse = await WebRequestHelper.getResponseAsync(OpenCasesURL); if (tokenResponse != "") { formatJsonCases(tokenResponse); } else { Globals.ThisAddIn.myCredentials.GetTokenViaRefreshToken(Globals.ThisAddIn.myCredentials.RefreshToken); Globals.ThisAddIn.myCredentials.serializeCredentials(Globals.ThisAddIn.myCredentials); tokenResponse = await WebRequestHelper.getResponseAsync(OpenCasesURL); if (tokenResponse != "") { formatJsonCases(tokenResponse); } else { ShowLoginWindow(); if (OpenCases == null) { FireCaseRequest(); } } } } }
private async void BtnOKClose_Click(object sender, RoutedEventArgs e) { BtnOKClose.IsEnabled = false; //Fire Case Close API and hide Popup string CaseCloseURL = ""; if (Globals.ThisAddIn.myCredentials != null) { CaseCloseURL = serverURL + "closeCaseServlet.caseclose?access_token=" + Globals.ThisAddIn.myCredentials.AccessToken + "&instance_url=" + Globals.ThisAddIn.myCredentials.InstanceURL + "&case_no=" + CloseCaseNumber + "&case_close_reason=" + CaseClosureReason.Text; string caseCloseResponse = await WebRequestHelper.getResponseAsync(CaseCloseURL); if (caseCloseResponse.Contains("Case closed and reason saved successfully")) { var itemToRemove = EmailBasedCases.Single(r => r.CaseNumber == CloseCaseNumber); EmailBasedCases.Remove(itemToRemove); emailListBox.Items.Refresh(); } } ShowPopup = false; BtnOKClose.IsEnabled = true; }
private async void CallGmailProfileAPI(string emailId) { string GmailURL = ""; if (Globals.ThisAddIn.myCredentials != null) { GmailURL = serverURL + "getGmailProfile.gmailprofile?p_email=" + emailId; string gmailProfileResponse = await WebRequestHelper.getResponseAsync(GmailURL); if (gmailProfileResponse != "") { var details = JObject.Parse(gmailProfileResponse); UserName = details["name"].ToString(); UserProfileImagePath = details["photo_link"].ToString(); UserEmail = details["email"].ToString(); } else { UserName = emailId.Substring(0, emailId.IndexOf('@')); UserProfileImagePath = "https://i.stack.imgur.com/34AD2.jpg"; UserEmail = emailId; } } }