Last active
March 1, 2019 07:58
-
-
Save merkle-sitecore-gists/0a87ae043e77067191655a44ea40f94e to your computer and use it in GitHub Desktop.
Bugfix for Sitecore 9 SocialConnect module adding bucket support for PostMessage and SocialMessages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
public void BindGrid() | |
{ | |
try | |
{ | |
if (Request.QueryString["id"] != null) | |
{ | |
var websitepageid = Request.QueryString["id"]; | |
var messageFolder = Sitecore.Configuration.Factory.GetDatabase("master").GetItem("/sitecore/system/Social/PostMessage"); | |
if (messageFolder != null && messageFolder.HasChildren) | |
{ | |
var index = ContentSearchManager.GetIndex("sitecore_master_index"); | |
using (var searchContext = index.CreateSearchContext()) | |
{ | |
List<PostMessageDetail> pastmessagelist = new List<PostMessageDetail>(); | |
var resultItems = searchContext.GetQueryable<SearchResultItem>().Where(x => x.Path.StartsWith("/sitecore/system/Social/PostMessage") && x.TemplateName.Contains("SocialMessages") && x["pageid_t"].Contains(websitepageid)).OrderByDescending(x => x.CreatedDate); | |
foreach (var result in resultItems) | |
{ | |
PostMessageDetail m = new PostMessageDetail(); | |
m.NetworkName = result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.Network].Value; | |
m.Domain = result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.Domain].Value; | |
m.Message = result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.Message].Value; | |
m.SendDate = DatetimeToString(result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.SendDate]); | |
m.PostDate = DatetimeToString(result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.PostDate]); | |
m.ApplicaitonID = result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.ApplicationID].Value; | |
m.PostID = result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.PostId].Value; | |
m.ItemId = result.GetItem().ID.ToString(); | |
m.Status = result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.Status].Value; | |
m.CampaignName = result.GetItem().Fields[SocialTemplates.SocialMessages.Fields.CampaignName].Value; | |
pastmessagelist.Add(m); | |
} | |
rptData.DataSource = pastmessagelist; | |
rptData.DataBind(); | |
} | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
Sitecore.Diagnostics.Log.Error( | |
(string.Format("Error at {0}:{1}", MethodBase.GetCurrentMethod().Name, ex.Message)), this); | |
} | |
} | |
... | |
protected void btnPostFb_Click(object sender, EventArgs e) | |
{ | |
... | |
ClearController(); | |
Thread.Sleep(1000); // new line of code, wait till index is registred | |
BindGrid(); | |
... | |
} | |
... | |
protected void btnTwitter_Click(object sender, EventArgs e) | |
{ | |
... | |
ClearController(); | |
Thread.Sleep(1000); // new line of code, wait till index is registred | |
BindGrid(); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment