public void CompanyRequestByIDTest() { int id = 57644826; CompanyRequest request = new CompanyRequest(m_highriseURL, m_highriseAuthToken); Company company = request.GetByID(id); Assert.AreEqual(id, company.ID, "The ID of the company record did not match the ID that was requested."); Assert.AreEqual("Acme Washing Machines", company.Name, "The name of the company was not as expected."); }
public void CompanyRequestByIDTest() { int id = 57644826; CompanyRequest request = new CompanyRequest(m_highriseURL, m_highriseAuthToken); Company company = request.GetByID(id); Assert.AreEqual(id, company.ID, "The ID of the company record did not match the ID that was requested."); Assert.AreEqual("Acme Washing Machines", company.Name, "The name of the company was not as expected."); }
/// <summary> /// Looks up a person contact in the 37 Signals Highrise application. /// </summary> /// <param name="url">The URL of the Highrise account to attempt the lookup on.</param> /// <param name="authToken">The auth token for the Highrise account to attempt the lookup with.</param> /// <param name="name">The name of the person to attempt a match on.</param> /// <param name="addCallNote">If true it indicates a Highrise note should be created if a matching contact is found.</param> //public CRMHeaders LookupHighriseContact(string url, string authToken, string name, bool addCallNote, bool async) //{ // LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Looking up Highrise contact on " + url + " for " + name + ".", m_context.Owner)); // if (async) // { // m_context.SetCallerDetails(new CRMHeaders() { Pending = true }); // ThreadPool.QueueUserWorkItem(delegate { DoLookup(url, authToken, name, addCallNote, (result) => { m_context.SetCallerDetails(result); }); }); // return null; // } // else // { // return DoLookup(url, authToken, name, addCallNote, null); // } //} private CRMHeaders DoLookup(string url, string authToken, SIPFromHeader from, bool addCallNote, Action <CRMHeaders> callback) { try { string searchString = null; string lookupType = null; if (from.FromName != null && Regex.Match(from.FromName, @"\D").Success) { // The From display name has a non-digit character do a name lookup. lookupType = "name"; searchString = from.FromName.Trim(); } else if (from.FromName != null) { // The From display name is all digits do a phone number lookup. lookupType = "phonenumber"; searchString = from.FromName.Trim(); } else if (!Regex.Match(from.FromURI.User, @"\D").Success) { // The From URI user is all digits do a phone number lookup. lookupType = "phonenumber"; searchString = from.FromURI.User.Trim(); } else { // Last resort is to do a SIP URI lookup. lookupType = "sipaddress"; searchString = from.FromURI.ToAOR(); } LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Highrise contact lookup type " + lookupType + " commencing for " + searchString + ".", m_context.Owner)); CRMHeaders result = null; DateTime startLookup = DateTime.Now; PersonRequest personRequest = new PersonRequest(url, authToken); People people = null; if (lookupType == "name") { people = personRequest.GetByName(searchString); } else if (lookupType == "phonenumber") { people = personRequest.GetByPhoneNumber(searchString); } else if (lookupType == "sipaddress") { people = personRequest.GetByCustomField("sip_address", searchString); } if (people != null && people.PersonList != null && people.PersonList.Count > 0) { Person person = people.PersonList[0]; string companyName = null; if (person.CompanyID != null) { CompanyRequest companyRequest = new CompanyRequest(url, authToken); Company company = companyRequest.GetByID(person.CompanyID.Value); if (company != null) { companyName = company.Name; } } double secondsDuration = DateTime.Now.Subtract(startLookup).TotalSeconds; if (companyName != null) { LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Highrise contact match " + person.FirstName + " " + person.LastName + " of " + companyName + ", time taken " + secondsDuration.ToString("0.##") + "s.", m_context.Owner)); } else { LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Highrise contact match " + person.FirstName + " " + person.LastName + ", time taken " + secondsDuration.ToString("0.##") + "s.", m_context.Owner)); } //m_context.SetCallerDetails(new CRMHeaders(person.FirstName + " " + person.LastName, companyName, person.AvatarURL)); string personName = (!person.LastName.IsNullOrBlank()) ? person.FirstName + " " + person.LastName : person.FirstName; result = new CRMHeaders(personName, companyName, person.AvatarURL); if (addCallNote) { ThreadPool.QueueUserWorkItem(delegate { AddHighriseCallNote(url, authToken, from, person); }); } } else { double secondsDuration = DateTime.Now.Subtract(startLookup).TotalSeconds; LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "No Highrise contact match, time taken " + secondsDuration.ToString("0.##") + "s.", m_context.Owner)); result = new CRMHeaders() { Pending = false, LookupError = "No Highrise contact match." }; } if (callback != null) { callback(result); } return(result); } catch (Exception excp) { logger.Error("Exception LookupHighriseContact. " + excp.Message); LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Error looking up Highrise contact.", m_context.Owner)); var errorResult = new CRMHeaders() { Pending = false, LookupError = "Error looking up Highrise contact." }; if (callback != null) { callback(errorResult); } return(errorResult); } }
/// <summary> /// Looks up a person contact in the 37 Signals Highrise application. /// </summary> /// <param name="url">The URL of the Highrise account to attempt the lookup on.</param> /// <param name="authToken">The auth token for the Highrise account to attempt the lookup with.</param> /// <param name="name">The name of the person to attempt a match on.</param> /// <param name="addCallNote">If true it indicates a Highrise note should be created if a matching contact is found.</param> //public CRMHeaders LookupHighriseContact(string url, string authToken, string name, bool addCallNote, bool async) //{ // LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Looking up Highrise contact on " + url + " for " + name + ".", m_context.Owner)); // if (async) // { // m_context.SetCallerDetails(new CRMHeaders() { Pending = true }); // ThreadPool.QueueUserWorkItem(delegate { DoLookup(url, authToken, name, addCallNote, (result) => { m_context.SetCallerDetails(result); }); }); // return null; // } // else // { // return DoLookup(url, authToken, name, addCallNote, null); // } //} private CRMHeaders DoLookup(string url, string authToken, SIPFromHeader from, bool addCallNote, Action<CRMHeaders> callback) { try { string searchString = null; string lookupType = null; if (from.FromName != null && Regex.Match(from.FromName, @"\D").Success) { // The From display name has a non-digit character do a name lookup. lookupType = "name"; searchString = from.FromName.Trim(); } else if (from.FromName != null) { // The From display name is all digits do a phone number lookup. lookupType = "phonenumber"; searchString = from.FromName.Trim(); } else if (!Regex.Match(from.FromURI.User, @"\D").Success) { // The From URI user is all digits do a phone number lookup. lookupType = "phonenumber"; searchString = from.FromURI.User.Trim(); } else { // Last resort is to do a SIP URI lookup. lookupType = "sipaddress"; searchString = from.FromURI.ToAOR(); } LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Highrise contact lookup type " + lookupType + " commencing for " + searchString + ".", m_context.Owner)); CRMHeaders result = null; DateTime startLookup = DateTime.Now; PersonRequest personRequest = new PersonRequest(url, authToken); People people = null; if (lookupType == "name") { people = personRequest.GetByName(searchString); } else if (lookupType == "phonenumber") { people = personRequest.GetByPhoneNumber(searchString); } else if (lookupType == "sipaddress") { people = personRequest.GetByCustomField("sip_address", searchString); } if (people != null && people.PersonList != null && people.PersonList.Count > 0) { Person person = people.PersonList[0]; string companyName = null; if (person.CompanyID != null) { CompanyRequest companyRequest = new CompanyRequest(url, authToken); Company company = companyRequest.GetByID(person.CompanyID.Value); if (company != null) { companyName = company.Name; } } double secondsDuration = DateTime.Now.Subtract(startLookup).TotalSeconds; if (companyName != null) { LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Highrise contact match " + person.FirstName + " " + person.LastName + " of " + companyName + ", time taken " + secondsDuration.ToString("0.##") + "s.", m_context.Owner)); } else { LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Highrise contact match " + person.FirstName + " " + person.LastName + ", time taken " + secondsDuration.ToString("0.##") + "s.", m_context.Owner)); } //m_context.SetCallerDetails(new CRMHeaders(person.FirstName + " " + person.LastName, companyName, person.AvatarURL)); string personName = (!person.LastName.IsNullOrBlank()) ? person.FirstName + " " + person.LastName : person.FirstName; result = new CRMHeaders(personName, companyName, person.AvatarURL); if (addCallNote) { ThreadPool.QueueUserWorkItem(delegate { AddHighriseCallNote(url, authToken, from, person); }); } } else { double secondsDuration = DateTime.Now.Subtract(startLookup).TotalSeconds; LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "No Highrise contact match, time taken " + secondsDuration.ToString("0.##") + "s.", m_context.Owner)); result = new CRMHeaders() { Pending = false, LookupError = "No Highrise contact match." }; } if (callback != null) { callback(result); } return result; } catch (Exception excp) { logger.Error("Exception LookupHighriseContact. " + excp.Message); LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Error looking up Highrise contact.", m_context.Owner)); var errorResult = new CRMHeaders() { Pending = false, LookupError = "Error looking up Highrise contact." }; if (callback != null) { callback(errorResult); } return errorResult; } }
private void DoLookup(string url, string authToken, string name, bool addCallNote) { try { PersonRequest personRequest = new PersonRequest(url, authToken); People people = personRequest.GetByName(name); if (people != null && people.PersonList != null && people.PersonList.Count > 0) { Person person = people.PersonList[0]; string companyName = null; if (person.CompanyID != null) { CompanyRequest companyRequest = new CompanyRequest(url, authToken); Company company = companyRequest.GetByID(person.CompanyID.Value); if (company != null) { companyName = company.Name; } } LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Highrise contact match " + person.FirstName + " " + person.LastName + " of " + companyName + ".", m_context.Owner)); m_context.SetCallerDetails(new CRMHeaders(person.FirstName + " " + person.LastName, companyName, person.AvatarURL)); if (addCallNote) { ThreadPool.QueueUserWorkItem(delegate { AddHighriseCallNote(url, authToken, person); }); } } else { LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "No Highrise contact match.", m_context.Owner)); m_context.SetCallerDetails(new CRMHeaders() { Pending = false, LookupError = "No Highrise contact match." }); } } catch (Exception excp) { logger.Error("Exception LookupHighriseContact. " + excp.Message); LogToMonitor(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Error looking up Highrise contact.", m_context.Owner)); m_context.SetCallerDetails(new CRMHeaders() { Pending = false, LookupError = "Error looking up Highrise contact." }); } }