private void AddProfileScore(IXdbContext client, Contact contact) { if (string.IsNullOrWhiteSpace(tbProfileScore.Text) || string.IsNullOrWhiteSpace(tbProfileKeyId.Text) || string.IsNullOrWhiteSpace(tbProfileId.Text)) { return; } Guid profileId = Guid.Parse(tbProfileId.Text); Guid profileKeyId = Guid.Parse(tbProfileKeyId.Text); int score = int.Parse(tbProfileScore.Text, CultureInfo.CurrentCulture); var interaction = new Interaction(contact, InteractionInitiator.Brand, SystemChannelId, UserAgent); var engagementValueEvent = new Event(ProfileScoreChangeEventDefinitionId, DateTime.UtcNow); interaction.Events.Add(engagementValueEvent); client.AddInteraction(interaction); var profileScores = new ProfileScores(); var profileScore = new ProfileScore { Values = { [profileKeyId] = score } }; profileScores.Scores.Add(profileId, profileScore); client.SetProfileScores(interaction, profileScores); }
private void ApplyPatternCard(Contact contact, TwitterStatus tweet, PatternCard patternCard) { using (var client = XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { try { // Get updated contact with ContactBehaviorProfile facet var updatedContact = client.Get(new IdentifiedContactReference("twitter", tweet.User.ScreenName), new ContactExpandOptions(ContactBehaviorProfile.DefaultFacetKey)); if (updatedContact == null) { return; } // Retrieve facet or create new var isNewFacet = false; var facet = updatedContact.GetFacet <ContactBehaviorProfile>(ContactBehaviorProfile.DefaultFacetKey); if (facet == null) { isNewFacet = true; facet = new ContactBehaviorProfile(); } // Change facet properties var score = new ProfileScore { ProfileDefinitionId = patternCard.GetProfile().ID.ToGuid() }; if (score.Values == null) { score.Values = new Dictionary <Guid, double>(); } var patterns = patternCard.GetPatterns(); foreach (var pair in patterns) { score.Values.Add(pair.Key, pair.Value); } if (facet.Scores.ContainsKey(patternCard.GetProfile().ID.Guid)) { facet.Scores[patternCard.GetProfile().ID.Guid] = score; } else { facet.Scores.Add(patternCard.GetProfile().ID.Guid, score); } // Save the facet if (isNewFacet) { client.SetFacet <ContactBehaviorProfile>(updatedContact, ContactBehaviorProfile.DefaultFacetKey, facet); } else { client.SetFacet(updatedContact, ContactBehaviorProfile.DefaultFacetKey, facet); } client.Submit(); } catch (XdbExecutionException ex) { Diagnostics.Log.Error( $"[HashTagMonitor] Error applying Patter Card to Contact '{contact.Personal().Nickname}'", ex, GetType()); } } }
public ContactViewModel GetContact(string source, string identifier) { ContactViewModel result = new ContactViewModel(); using (XConnectClient client = GetClient()) { try { IdentifiedContactReference reference = new IdentifiedContactReference(source, identifier); Contact existingContact = client.Get <Contact>( reference, new ContactExpandOptions(PersonalInformation.DefaultFacetKey, CvPersonFacet.DefaultFacetKey, Avatar.DefaultFacetKey, ContactBehaviorProfile.DefaultFacetKey)); if (existingContact == null) { return(null); } PersonalInformation personalInformation = existingContact.GetFacet <PersonalInformation>(PersonalInformation.DefaultFacetKey); if (personalInformation == null) { return(null); } result.FirstName = personalInformation.FirstName; result.LastName = personalInformation.LastName; result.Gender = personalInformation.Gender; result.Id = identifier; Avatar avatar = existingContact.GetFacet <Avatar>(Avatar.DefaultFacetKey); if (avatar?.Picture != null) { result.AvatarImage = Convert.ToBase64String(avatar.Picture); } CvPersonFacet cvPerson = existingContact.GetFacet <CvPersonFacet>(CvPersonFacet.DefaultFacetKey); if (cvPerson != null) { result.LastName = cvPerson.LastName; result.FirstName = cvPerson.FirstName; result.Id = cvPerson.Id; result.Age = cvPerson.Age; result.Gender = cvPerson.Gender; } ContactBehaviorProfile behaviorProfile = existingContact.ContactBehaviorProfile(); if (behaviorProfile?.Scores != null) { if (behaviorProfile.Scores.ContainsKey(Settings.RelationshipProfileId)) { ProfileScore behaviorProfileScore = behaviorProfile.Scores[Settings.RelationshipProfileId]; result.ClientScore = behaviorProfileScore.Values.ContainsKey(Settings.ClientBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.ClientBehaviorProfileId] : 0; result.PartnerScore = behaviorProfileScore.Values.ContainsKey(Settings.PartnerBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.PartnerBehaviorProfileId] : 0; result.SitecoreScore = behaviorProfileScore.Values.ContainsKey(Settings.SitecoreBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.SitecoreBehaviorProfileId] : 0; } if (behaviorProfile.Scores.ContainsKey(Settings.RoleProfileId)) { var behaviorProfileScore = behaviorProfile.Scores[Settings.RoleProfileId]; result.DevelopmentScore = behaviorProfileScore.Values.ContainsKey(Settings.DevelopmentBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.DevelopmentBehaviorProfileId] : 0; result.BusinessDevelopmentScore = behaviorProfileScore.Values.ContainsKey(Settings.BusinessDevelopmentBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.BusinessDevelopmentBehaviorProfileId] : 0; result.MarketingScore = behaviorProfileScore.Values.ContainsKey(Settings.MarketingBehaviorProfileId) ? (int)behaviorProfileScore.Values[Settings.MarketingBehaviorProfileId] : 0; } } return(result); } catch (XdbExecutionException ex) { } } return(null); }
public void getInfos(string username) { string link_github; if (username == null) { string mail = Session["UserMail"].ToString(); Account user = db.Account.FirstOrDefault(m => m.AccountMail == mail); Profil githubProfile = db.Profil.FirstOrDefault(m => m.AccountId == user.AccountId && m.SourceId == 1); link_github = githubUrl + githubProfile.ProfileUsername; } else { link_github = githubUrl + username; } Uri url = new Uri(link_github); WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; string html = client.DownloadString(url); HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(html); var githubilkbar = @"//span[@class='Counter hide-lg hide-md hide-sm']"; var githubName = @"//span[@class='p-name vcard-fullname d-block overflow-hidden']"; List <string> githubilkbarList = new List <string>(); StringBuilder firstInfos = new StringBuilder(); StringBuilder languages = new StringBuilder(); var githubilkbarHtml = document.DocumentNode.SelectNodes(githubilkbar); var githubNameHtml = document.DocumentNode.SelectNodes(githubName); foreach (var items in githubilkbarHtml) { if (items.InnerText.Trim().Last() == 'k') { githubilkbarList.Add(items.InnerText.Trim().Remove(items.InnerText.Trim().Length - 1).Replace(".", string.Empty) + "000"); } else { githubilkbarList.Add(items.InnerText.Trim()); } } foreach (var items in githubNameHtml) { strgithubName = items.InnerText.Trim(); } //github dilleri gizlemis farklı bir yol izlemek gerekiyor. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Uri url_ = new Uri("http://ionicabizau.github.io/github-profile-languages/?user=hakanbakacak"); //WebClient client_ = new WebClient(); //client_.Encoding = Encoding.UTF8; //string html_ = client_.DownloadString(url_); //HtmlAgilityPack.HtmlDocument document_ = new HtmlAgilityPack.HtmlDocument(); //document_.LoadHtml(html_); //var githubls = @"//div[@class='content mrg-xl pad-xl']"; //string githublsNames=""; //var githublsHtml = document_.DocumentNode.SelectNodes(githubls); //foreach (var items in githublsHtml) //{ // githublsNames += items.InnerText.Trim(); //} //HtmlDocument doc = new HtmlDocument(); //doc.LoadHtml(html_); //foreach (HtmlNode node in doc.DocumentNode.SelectNodes(githubls)) //{ // Console.WriteLine("text=" + node.InnerText); //} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string mail2 = Session["UserMail"].ToString(); Account user2 = db.Account.FirstOrDefault(m => m.AccountMail == mail2); Profil githubProfile2 = db.Profil.FirstOrDefault(m => m.AccountId == user2.AccountId && m.SourceId == 1); var scannedProfile = db.Profil.FirstOrDefault(m => m.ProfileUsername == githubProfile2.ProfileUsername); githubRepositories = githubilkbarList[0];//repo count ProfileScore repoCount = new ProfileScore(); repoCount.ProfileId = scannedProfile.ProfileId; repoCount.ProfileScoreFlag = true; repoCount.SourceDataTypeId = 8; repoCount.ScoreValue = Convert.ToInt32(githubRepositories); db.ProfileScore.Add(repoCount);//repo count githubProjects = githubilkbarList[1]; githubStars = githubilkbarList[2];//Star Count ProfileScore starCount = new ProfileScore(); starCount.ProfileId = scannedProfile.ProfileId; starCount.ProfileScoreFlag = true; starCount.SourceDataTypeId = 9; starCount.ScoreValue = Convert.ToInt32(githubStars); db.ProfileScore.Add(starCount);//star count githubFollowers = githubilkbarList[3]; ProfileScore FollowersCount = new ProfileScore();//Followers Count FollowersCount.ProfileId = scannedProfile.ProfileId; FollowersCount.ProfileScoreFlag = true; FollowersCount.SourceDataTypeId = 12; FollowersCount.ScoreValue = Convert.ToInt32(githubFollowers); db.ProfileScore.Add(FollowersCount);//Followers Count githubFollowing = githubilkbarList[4]; ProfileScore FollowingCount = new ProfileScore();//Following Count FollowingCount.ProfileId = scannedProfile.ProfileId; FollowingCount.ProfileScoreFlag = true; FollowingCount.SourceDataTypeId = 12; FollowingCount.ScoreValue = Convert.ToInt32(githubFollowing); db.ProfileScore.Add(FollowingCount);//Following Count db.SaveChanges(); //MPR:.Trim() string languagesLink = link_github.Trim() + "?tab=repositories"; Uri url_repo = new Uri(languagesLink); WebClient client_repo = new WebClient(); client_repo.Encoding = Encoding.UTF8; string html_repo = client_repo.DownloadString(url_repo); HtmlAgilityPack.HtmlDocument document_repo = new HtmlAgilityPack.HtmlDocument(); document_repo.LoadHtml(html_repo); var githubLanguages = @"//span[@class='text-normal']"; List <string> githubLanguageListTemp = new List <string>(); var githubLanguageHtml = document_repo.DocumentNode.SelectNodes(githubLanguages); foreach (var items in githubLanguageHtml) { githubLanguageListTemp.Add(items.InnerText.Trim()); } for (int i = 6; i < githubLanguageListTemp.Count; i++) { githubLanguageList.Add(githubLanguageListTemp[i]); } foreach (var i in githubLanguageList) { string dilUrl = languagesLink + "&q=&type=&language=" + i; Uri url_repo_count = new Uri(dilUrl); WebClient client_repo_count = new WebClient(); client_repo_count.Encoding = Encoding.UTF8; string html_repo_count = client_repo_count.DownloadString(url_repo_count); HtmlAgilityPack.HtmlDocument document_repo_count = new HtmlAgilityPack.HtmlDocument(); document_repo_count.LoadHtml(html_repo_count); var githubcount = @"//div[@class='user-repo-search-results-summary TableObject-item TableObject-item--primary v-align-top']//strong"; var githubcountHtml = document_repo_count.DocumentNode.SelectNodes(githubcount); for (int k = 0; k < githubcountHtml.Count; k = k + 2) { githubLanguageListCount.Add(githubcountHtml[k].InnerText.Trim()); } foreach (var item in githubLanguageListCount) { githubLanguageListCountInt.Add(Convert.ToInt32(item)); } } }
private static void UpdateContactBehaviorProfile(Dictionary <Guid, ProfileScore> profileScores, IEnumerable <BehaviorProfileValue> behaviorProfileValues) { foreach (var profile in profileScores) { Log.Debug("profileScores.Key = " + profile.Key); Log.Debug("profileScores.Value = " + profile.Value); } foreach (var behaviorProfile in behaviorProfileValues) { Log.Debug("behavior profile id = " + behaviorProfile.ProfileId); foreach (var kv in behaviorProfile.KeyValues) { Log.Debug("behavior kv Key = " + kv.Key); Log.Debug("behavior kv Value = " + kv.Value); } } foreach (BehaviorProfileValue behaviorProfileValue in behaviorProfileValues) { if ((behaviorProfileValue != null ? behaviorProfileValue.KeyValues : (IDictionary <Guid, double>)null) != null) { ProfileScore profileScore1; if (!profileScores.TryGetValue(behaviorProfileValue.ProfileId, out profileScore1)) { Dictionary <Guid, ProfileScore> dictionary1 = profileScores; Guid profileId = behaviorProfileValue.ProfileId; ProfileScore profileScore2 = new ProfileScore(); profileScore2.ProfileDefinitionId = behaviorProfileValue.ProfileId; IDictionary <Guid, double> keyValues = behaviorProfileValue.KeyValues; //Func<KeyValuePair<Guid, double>, Guid> func = (Func<KeyValuePair<Guid, double>, Guid>)(kv => kv.Key); //Func<KeyValuePair<Guid, double>, Guid> keySelector; Dictionary <Guid, double> dictionary2 = keyValues.ToDictionary(kv => kv.Key, kv => kv.Value); profileScore2.Values = dictionary2; dictionary1[profileId] = profileScore2; } else if (profileScore1.Values == null) { ProfileScore profileScore2 = profileScore1; IDictionary <Guid, double> keyValues = behaviorProfileValue.KeyValues; //Func<KeyValuePair<Guid, double>, Guid> func = (Func<KeyValuePair<Guid, double>, Guid>)(kv => kv.Key); //Func<KeyValuePair<Guid, double>, Guid> keySelector; Dictionary <Guid, double> dictionary = keyValues.ToDictionary(kv => kv.Key, kv => kv.Value); profileScore2.Values = dictionary; } else { foreach (KeyValuePair <Guid, double> keyValuePair in (IEnumerable <KeyValuePair <Guid, double> >)behaviorProfileValue.KeyValues) { double num; if (profileScore1.Values.TryGetValue(keyValuePair.Key, out num)) { Dictionary <Guid, double> values = profileScore1.Values; Guid key = keyValuePair.Key; values[key] = values[key] + keyValuePair.Value; } else { profileScore1.Values.Add(keyValuePair.Key, keyValuePair.Value); } } } } } }
/// <summary> /// Parses the configuration. /// </summary> /// <param name="profiles">The profiles.</param> /// <param name="startupProjects">The startup projects.</param> /// <param name="currentStartupProjects">The current startup projects.</param> /// <returns>The parsed configuration.</returns> private ParsedConfiguration ParseConfiguration(IEnumerable <Profile> profiles, IEnumerable <string> startupProjects, ICollection <string> currentStartupProjects) { var parsedConfiguration = new ParsedConfiguration(); // List all projects foreach (var startupProject in startupProjects) { var profile = new Profile(); profile.DisplayName = startupProject; var projectItem = new Project(); projectItem.Name = startupProject; profile.Projects.Add(projectItem); parsedConfiguration.Profiles.Add(profile); } var currentProfile = new Profile(); foreach (var startupProject in currentStartupProjects) { var projectName = Path.GetFileNameWithoutExtension(startupProject); if (!_projectCache.TryGetProjectByName(projectName, out var projectProxy)) { continue; } var projectItem = new Project(); projectItem.Name = projectProxy.Name; foreach (EnvDTE.Configuration configuration in projectProxy.Source.ConfigurationManager) { if (configuration?.Properties == null) { continue; } foreach (var property in configuration.Properties.Cast <Property>()) { if (property == null) { continue; } switch (property.Name) { case "StartArguments": projectItem.CommandLineArgs = Convert.ToString(property.Value); break; case "StartWorkingDirectory": projectItem.WorkingDirectory = Convert.ToString(property.Value); break; case "StartProgram": projectItem.StartExternalProgram = Convert.ToString(property.Value); break; case "StartURL": projectItem.StartBrowserUrl = Convert.ToString(property.Value); break; case "RemoteDebugEnabled": projectItem.IsRemoteDebuggingEnabled = Convert.ToBoolean(property.Value); break; case "RemoteDebugMachine": projectItem.RemoteDebuggingMachine = Convert.ToString(property.Value); break; } } } currentProfile.Projects.Add(projectItem); } // List custom configuration foreach (var profile in profiles) { parsedConfiguration.Profiles.Add(profile); } // Identify current configuration var profileScores = ProfileScore.Generate(parsedConfiguration.Profiles, currentProfile); var bestMatch = profileScores.OrderByDescending(s => s.Score).FirstOrDefault(); parsedConfiguration.CurrentProfile = bestMatch?.Configuration; return(parsedConfiguration); }