private void SyncOrganizationInformation(Organization company) { Logs.WriteEvent(string.Format("Processing company {0}({1})", company.Name, company.OrganizationID)); if (!string.IsNullOrEmpty(company.Website)) { string responseText = string.Empty; string requestParameter = string.Format("{0}={1}", CompanyObjects.Lookup.domain.ToString(), company.Website); string requestUrl = string.Format("{0}company/lookup.json?{1}", _baseURI, requestParameter); responseText = CustomerInsightsUtilities.MakeHttpWebRequest(requestUrl, _securityToken, Logs, Settings, _currentCompanyApiCallsKey, ref _currentCompanyApiCalls); try { if (!string.IsNullOrEmpty(responseText)) { JObject jObject = JObject.Parse(responseText); CompanyObjects.RootObject companyInfo = JsonConvert.DeserializeObject <CompanyObjects.RootObject>(jObject.ToString()); UpdateCompanyInformation(companyInfo, company); } else { Logs.WriteEvent("CustomerInsights did not return information."); } } catch (Exception ex) { Logs.WriteException(ex); } } else { Logs.WriteEvent("This company does not have a website entered, can't get its CustomerInsights information."); } UpdateFullContactCompanyModified(company.OrganizationID); }
private bool UpdateCompanyInformation(CompanyObjects.RootObject customerInsightsOrganizationInfo, Organization currentCompanyInfo) { bool isUpdated = false; string useSocialProfile = CustomerInsightsUtilities.SocialProfiles.LinkedIn.ToString(); if (customerInsightsOrganizationInfo.socialProfiles != null && customerInsightsOrganizationInfo.socialProfiles.Count > 0) { //We will use LinkedIn for bio, if not found then use the first one of the others with that information if (!customerInsightsOrganizationInfo.socialProfiles.Exists(p => p.typeName.ToLower() == useSocialProfile.ToLower())) { useSocialProfile = string.Empty; useSocialProfile = customerInsightsOrganizationInfo.socialProfiles.Where(p => !string.IsNullOrEmpty(p.bio)).Select(p => p.typeName).FirstOrDefault(); } if (!string.IsNullOrEmpty(useSocialProfile)) { string bio = customerInsightsOrganizationInfo.socialProfiles.Where(p => p.typeName.ToLower() == useSocialProfile.ToLower() && !string.IsNullOrEmpty(p.bio)).Select(p => p.bio).FirstOrDefault(); if (CanUpdateCompanyBio(currentCompanyInfo, bio)) { currentCompanyInfo.Description = bio; isUpdated = true; } } else { Logs.WriteEvent("No bio found in any of the social profiles"); } } else { Logs.WriteEvent("No social profile found"); } if (!string.IsNullOrEmpty(customerInsightsOrganizationInfo.logo)) { string resultMessage = string.Empty; string logoPath = TeamSupport.Data.Quarantine.ServiceQ.GetAttachmentPath10(LoginUser, (int)currentCompanyInfo.ParentID); string logoFullPath = string.Format("{0}\\{1}.png", logoPath, currentCompanyInfo.OrganizationID); if (CustomerInsightsUtilities.DownloadImage(customerInsightsOrganizationInfo.logo, logoFullPath, currentCompanyInfo.OrganizationID, AttachmentProxy.References.Organizations, LoginUser, out resultMessage)) { string description = string.Format("TeamSupport System updated Logo for '{0}'", currentCompanyInfo.Name); ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.Organizations, currentCompanyInfo.OrganizationID, description); //delete cached image string cachePath = string.Empty; string pattern = string.Empty; try { cachePath = TeamSupport.Data.Quarantine.ServiceQ.GetAttachmentPath11(LoginUser, currentCompanyInfo.ParentID.ToString()); if (System.IO.Directory.Exists(cachePath)) { pattern = currentCompanyInfo.OrganizationID.ToString() + "-*.*"; string[] files = System.IO.Directory.GetFiles(cachePath, pattern, System.IO.SearchOption.TopDirectoryOnly); foreach (String file in files) { System.IO.File.Delete(file); Logs.WriteEvent(string.Format("Cached file {0} deleted.", file)); } } } catch (Exception ex) { Logs.WriteEvent("Exception deleting cached images for company."); Logs.WriteEventFormat("CachePath: {0}", cachePath.ToString()); Logs.WriteEventFormat("Pattern: {0}", pattern.ToString()); Logs.WriteEventFormat("Exception Message: {0}", ex.Message.ToString()); Logs.WriteEventFormat("Exception StackTrace: {0}", ex.StackTrace.ToString()); } } if (!string.IsNullOrEmpty(resultMessage)) { Logs.WriteEvent(resultMessage); } } else { Logs.WriteEvent("No logo found"); } if (isUpdated) { currentCompanyInfo.Collection.Save(); Logs.WriteEvent(string.Format("Bio pulled from {0}", useSocialProfile)); string description = "TeamSupport System changed description for organization '" + currentCompanyInfo.Name + "'"; ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.Organizations, currentCompanyInfo.OrganizationID, description); } return(isUpdated); }