none
您好,关于附加plug-in的问题 RRS feed

  • 问题

  • 大家好,我看了SDK2011的“Walkthrough: Register a Plug-in using the Plug-in Registration Tool”的教程,教我怎么创建并附加plug-in(建立出程序集,进行签名,并且使用SDK自带的那个附加程序集的工具进行的附加(工具在SDK的地址\tools\pluginregistration))。

    接着我又按教程上说,进行测试

    Test the Plug-in

     

    1. Open the Microsoft Dynamics CRM Web application for the same organization that you registered the plug-in assembly under.

    2. Move to the workplace, select Accounts, and then click New.

    3. In the Account Name box, type an account name, for example, Adventure Works Cycle, and then click Save & Close.

    4. Double-click the form name in the Accounts grid to open the form.

    5. Click Activities to display a list of related activities for the account. You should see the activity named “Send e-mail to the new customer“ that the plug-in created.

     

    结果是,我在活动列表中并没有我创建的plug-in,请问应如何解决?

    对了,以下是我的程序集代码,照着SDK写的。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;

    using Microsoft.Xrm.Sdk;

    namespace FollowupPlugin3
    {
        public class FollowupPlugin4 : IPlugin
        {

            public void Execute(IServiceProvider serviceProvider)
            {
                //提取跟踪服务以供沙盒插件使用
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

                //获取执行上下文权限
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                //InputParameters收集包含所有数据传输的请求
                if (context.InputParameters.Contains("Target") &&
                    context.InputParameters["Target"] is Entity)
                {
                    //从输入参数获取目标实体
                    Entity entity = (Entity)context.InputParameters["Target"];

                    //判断目标实体是否为帐户实体
                    //如果不是帐户,这个插件未登记正确
                    if (entity.LogicalName != "account")
                    {
                        return;
                    }

                    try
                    {
                        //创建一个跟踪帐户七天的活动任务
                        Entity followup = new Entity("task");
                        followup["subject"] = "Send e-mail to the new customer";
                        followup["description"] = "Follow up with the customer.Check if there are any new issues that need resolution.";
                        followup["scheduledstart"] = DateTime.Now.AddDays(7);
                        followup["scheduledend"] = DateTime.Now.AddDays(7);
                        followup["category"] = context.PrimaryEntityName;

                        //当前帐户的任务活动
                        if (context.OutputParameters.Contains("id"))
                        {
                            Guid regardingobjectid = new Guid(context.OutputParameters["id"].ToString());
                            string regardingobjectidTye = "account";
                            followup["regardingobjectid"] = new EntityReference(regardingobjectidTye, regardingobjectid);
                        }

                        //获取组织服务的引用
                        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                        IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

                        //创建CRM任务
                        tracingService.Trace("FollowupPlugin:Creating the task activity.");
                        service.Create(followup);
                    }
                    catch (Exception ex)
                    {
                        tracingService.Trace("FollowupPlugin: {0}", ex.ToString());
                        throw;
                    }


                }
            }
        }
    }

    谢谢各位前辈…鞠躬

    2011年5月18日 7:11

全部回复

  • 你需要使用 Plugin Registration 的工具来登记 你所创建的 Plugin.
    Darren Liu (MSFT) | 刘嘉鸿 | Blog: http://liudarren.spaces.live.com
    2011年5月18日 21:58
    版主
  • 有呀,使用pluginregistration进行附加了。

    附加的流程是:

    1、使用该工具连上我的ORM

    2、点击Register New Plugin

      值得提的是,我按SDK文档所述,Step #3:Specify the Isolation Mode选的是Sandbox

    3、选中程序集,点击Register New Step

      值得提的是,我按SDK文档所述,Eventing Pipeline Stage of 选的是Post-operation,Execution选的是异步(Asynchronous)

    2011年5月19日 2:17
  • 把它改为同步 (Synchronous), 异步就跟 workflow 一样了。
    Darren Liu (MSFT) | 刘嘉鸿 | Blog: http://liudarren.spaces.live.com
    2011年5月23日 16:31
    版主
  • 如果使用异步模式进行运行,那么需要等待一段时间,才能够在活动列表中显示Plugin创建的活动记录
    daemon lin
    2011年5月26日 12:09