更新Sitecore的社会知名度到外部系统 [英] Updating Sitecore Social Profile into an external system

查看:198
本文介绍了更新Sitecore的社会知名度到外部系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用的Sitecore的社会连接的模块3.0版与7.5 Sitecore的。一切工作正常,在我们登录的用户看到存储到MongoDB的配置文件信息的意识。然而,存在对简档信息还可以存储到一个单独的系统的要求。

We are using the Sitecore Social Connected Module version 3.0 with Sitecore 7.5. Everything is working fine, in the sense that we log the user in and see the profile information stored into MongoDb. However, there is a requirement to also store the profile information into a separate system.

我已经成功地已经能够做到这一点通过挖掘以下社会模块事件:

I've successfully been able to do this by tapping into the following social module events:

<event name="social:connector:user:loggedin">
</event>
<event name="social:connector:user:socialprofileattached">
</event>

在这些事件,我利用以下code阅读的MongoDB,并试图在我的外部系统,以更新的姿态:

In those events, I utilize the following code to read MongoDb and attempt to update the profile in my external system:

INetworkManager networkManager = ExecutingContext.Current.IoC.Get<INetworkManager>(new IParameter[0]);
ISocialProfileManager socialProfileManager = ExecutingContext.Current.IoC.Get<ISocialProfileManager>(new IParameter[0]);
string name = networkManager.GetNetwork(new IDIdentifier(ID.Parse(MembershipParameters.LinkedIn_NetworkId))).Name;
SocialProfile socialProfile = socialProfileManager.GetSocialProfile(Tracker.Current.Contact.ContactId.GetIdentifier(), name);

if (!socialProfile.IsEmpty && socialProfile.Fields.Any())
{
    MembershipUtil.UpdateLinkedInPofile(socialProfile);
}

问题是企图在二+日志这只作品。在第一次尝试中, socialProfile.Fields 计数始终为0。如此看来,code获取调用为时尚早。

The problem is that this only works on second+ log in attempts. On the first attempt, the socialProfile.Fields count is always 0. It seems that the code is getting called too early.

我真正需要的是蒙戈后一个事件或管道已被更新,这样我可以检索和更新外部系统。

What I really need is a event or pipeline AFTER mongo has been updated so that I can retrieve it and update the external system.

这是如何做到这一点显然会受到欢迎,以及任何其他建议。谢谢你。

Any other suggestions on how to accomplish this would obviously be welcome as well. Thanks.

推荐答案

原来我在得太多整个过程。随着反编译器的帮助下,我意识到,登录方法调用接受一个回调网址 sublayout参数。这是用户被重定向到登录后,让我重写登录按钮,并添加了返回URL的回调URL。然后在回调URL,我打电话给我的数据库更新方法。

Turns out I was overthinking the whole process. With the help of a decompiler, I realized that the login methods called accepts a Callback URL sublayout parameter. This is where the user gets redirected to after the login, so I overwrote the login button and added a return url to the Callback url. Then in the callback url, I called my database update method.

登录code从 Sitecore.Social.Client.Connector.Controls.LoginButtonBase.Login

protected void NewLogin(string networkName)
{
    var pageUrl = Request["pageUrl"];
    ILoginHelper loginHelper = ExecutingContext.Current.IoC.Get<ILoginHelper>(new IParameter[0]);
    Sublayout parent = this.Parent as Sublayout;
    NameValueCollection nameValueCollection = (parent != null ? WebUtil.ParseUrlParameters(parent.Parameters) : new NameValueCollection());
    Dictionary<string, object> dictionary = nameValueCollection.AllKeys.ToDictionary<string, string, object>((string key) => key, (string key) => nameValueCollection[key]);
    string callbackUrl = string.Empty;
    if (dictionary.ContainsKey("Callback URL") && !string.IsNullOrEmpty((string)dictionary["Callback URL"]))
    {
        try
        {
            try
            {
                callbackUrl = ExecutingContext.Current.IoC.Get<ILinkManager>(new IParameter[0]).GenerateLink(dictionary["Callback URL"].ToString(), string.Empty);
                if (string.IsNullOrEmpty(callbackUrl))
                {
                    ExecutingContext.Current.IoC.Get<ILogManager>(new IParameter[0]).LogMessage(string.Format("Could not parse the '{0}' link value. Context item ID: {1}", dictionary["Callback URL"], (Sitecore.Context.Item != null ? Sitecore.Context.Item.ID.ToString() : "null")), LogLevel.Error, this);
                }
                else if (!string.IsNullOrEmpty(callbackUrl) && !string.IsNullOrEmpty(pageUrl))
                {
                    callbackUrl += string.Format("?pageurl={0}", pageUrl);
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExecutingContext.Current.IoC.Get<ILogManager>(new IParameter[0]).LogMessage(string.Format("Could not parse the '{0}' link value. Context item ID: {1}", dictionary["Callback URL"], (Sitecore.Context.Item != null ? Sitecore.Context.Item.ID.ToString() : "null")), LogLevel.Error, this, exception);
            }
        }
        finally
        {
            dictionary.Remove("Callback URL");
        }
    }
    if (string.IsNullOrEmpty(callbackUrl))
    {
        callbackUrl = base.Request.Url.ToString();
    }
    loginHelper.Login(networkName, false, dictionary, callbackUrl);
}

在这里,一个重要的注意事项。在以下行的第二个参数指示是否配置文件应异步更新。如果设置为true,则该配置文件可能仍然不能当你到了回调URL提供给您。该设置为false,确保了创纪录的MongoDB的用户配置对象进行了更新,并提供给我的回调页面上。有自然涉及到一个费用。

An important note here. The second parameter in the following line indicates whether the profile should be updated asynchronously. If this is set to true, then the profile may still not be available to you when you hit the callback url. Setting that to false ensured that the UserProfile object in the MongoDB record was updated and available to me on the callback page. There is naturally a cost involved with that.

loginHelper.Login(networkName, false, dictionary, callbackUrl);

在回调网址登陆页面调用此:

Call this in the callback url landing page:

INetworkManager networkManager = ExecutingContext.Current.IoC.Get<INetworkManager>(new IParameter[0]);
ISocialProfileManager socialProfileManager = ExecutingContext.Current.IoC.Get<ISocialProfileManager>(new IParameter[0]);
string name = networkManager.GetNetwork(new IDIdentifier(Sitecore.Data.ID.Parse(MembershipParameters.LinkedIn_NetworkId))).Name;
if (Tracker.Current != null)
{
    SocialProfile socialProfile =
        socialProfileManager.GetSocialProfile(Tracker.Current.Contact.ContactId.GetIdentifier(),
            name);

    if (!socialProfile.IsEmpty && socialProfile.Fields.Any())
    {
        MembershipUtil.UpdateLinkedInPofile(socialProfile);
    }
}

这篇关于更新Sitecore的社会知名度到外部系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆