VS2010插件 - 错误1当前上下文中不存在名称“ExecutePostAccountUpdate”

时间:2021-02-08 07:24:01

I'm trying to make a plugin that grabs the revenue from opportunities and total up the revenue on the Account entity. I'm using Visual Studio 2010 Professional and using the MS Dynamics CRM 2013 SDK. I have been following two guides to help me get there, but they are for Dynamics CRM 2011. There aren't many guides out there for CRM 2013 so I was hoping to use this CRM 2011 guide to get a basic plugin going and modify it to my needs.

我正在尝试创建一个插件来抓住机会的收入,并总计帐户实体的收入。我正在使用Visual Studio 2010 Professional并使用MS Dynamics CRM 2013 SDK。我一直在关注两个指南来帮助我实现目标,但它们适用于Dynamics CRM 2011.对于CRM 2013没有很多指南,因此我希望使用此CRM 2011指南来获取基本插件并对其进行修改根据我的需要。

1: http://mscrmshop.blogspot.com.au/2012/02/plugin-to-update-children-records-when.html

2: http://mscrmshop.blogspot.com/2012/04/how-to-update-parent-record-when-child.html

Using those examples I got the plugin started on Visual Basic 2010, but when I go to build/deploy there are a few errors. Error 1 is the one I can't seem to get past.

使用这些示例我在Visual Basic 2010上启动了插件,但是当我进行构建/部署时,会出现一些错误。错误1是我似乎无法通过的那个。

1 - The type or namespace name 'FetchExpression' could not be found (are you missing a using directive or an assembly reference?) C:\VS2010\AccountRevenue\Plugins1\PostAccountUpdate.cs 114 95 Plugins1

1 - 找不到类型或命名空间名称'FetchExpression'(您是否缺少using指令或程序集引用?)C:\ VS2010 \ AccountRevenue \ Plugins1 \ PostAccountUpdate.cs 114 95 Plugins1

2 - The type or namespace name 'FetchExpression' could not be found (are you missing a using directive or an assembly reference?) C:\VS2010\AccountRevenue\Plugins1\PostAccountUpdate.cs 114 99 Plugins1

2 - 找不到类型或命名空间名称'FetchExpression'(您是否缺少using指令或程序集引用?)C:\ VS2010 \ AccountRevenue \ Plugins1 \ PostAccountUpdate.cs 114 99 Plugins1

3 - The name 'ExecutePostAccountUpdate' does not exist in the current context C:\VS2010\AccountRevenue\Plugins1\PostAccountUpdate.cs 51 154 Plugins1

3 - 当前上下文中不存在名称“ExecutePostAccountUpdate”C:\ VS2010 \ AccountRevenue \ Plugins1 \ PostAccountUpdate.cs 51 154插件1

    `// <copyright file="PostAccountUpdate.cs" company="">
// Copyright (c) 2014 All Rights Reserved
// </copyright>
// <author></author>
// <date>2/7/2014 2:53:23 PM</date>
// <summary>Implements the PostAccountUpdate Plugin.</summary>
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1
// </auto-generated>
using Microsoft.Xrm.Sdk.Client; // to get the OrganizationContext
using System.Linq; // to use linq queries with OrganizationContext
namespace AccountRevenue.Plugins1
{
    using System;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;

    /// <summary>
    /// PostAccountUpdate Plugin.
    /// Fires when the following attributes are updated:
    /// All Attributes
    /// </summary>    
    public class PostAccountUpdate: Plugin
    {
        /// <summary>
        /// Alias of the image registered for the snapshot of the 
        /// primary entity's attributes before the core platform operation executes.
        /// The image contains the following attributes:
        /// rrm_accountrevenue
        /// </summary>
        private readonly string preImageAlias = "PreImage";

        /// <summary>
        /// Alias of the image registered for the snapshot of the 
        /// primary entity's attributes after the core platform operation executes.
        /// The image contains the following attributes:
        /// rrm_accountrevenue
        /// 
        /// Note: Only synchronous post-event and asynchronous registered plug-ins 
        /// have PostEntityImages populated.
        /// </summary>
        private readonly string postImageAlias = "PostImage";

        /// <summary>
        /// Initializes a new instance of the <see cref="PostAccountUpdate"/> class.
        /// </summary>
        public PostAccountUpdate()
            : base(typeof(PostAccountUpdate))
        {
            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "account", new Action<LocalPluginContext>(ExecutePostAccountUpdate)));

            // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
            // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
        }

        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostOpportunityCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }


            IPluginExecutionContext context = localContext.PluginExecutionContext;

            //Get a IOrganizationService
            IOrganizationService service = localContext.OrganizationService;

            //create a service context
            var ServiceContext = new OrganizationServiceContext(service);
            //ITracingService tracingService = localContext.TracingService;

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
            context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parmameters.
                Entity entity = (Entity)context.InputParameters["Target"];

                //get the customerid
                EntityReference a = (EntityReference)entity.Attributes["customerid"];

                decimal totalAmount = 0;

                try
                {
                    //fetchxml to get the sum total of rrm_accountrevenue
                    string rrm_accountrevenue_sum = string.Format(@" 
            <fetch distinct='false' mapping='logical' aggregate='true'> 
                <entity name='opportunity'> 
                    <attribute name='rrm_accountrevenue' alias='rrm_accountrevenue_sum' aggregate='sum' /> 
                    <filter type='and'>
                        <condition attribute='statecode' operator='eq' value='Open' />
                            <condition attribute='customerid' operator='eq' value='{0}' uiname='' uitype='' />
                    </filter>
                </entity>
            </fetch>", a.Id);
                    EntityCollection rrm_accountrevenue_sum_result = service.RetrieveMultiple(new FetchExpression(rrm_accountrevenue_sum));

                    foreach (var c in rrm_accountrevenue_sum_result.Entities)
                    {
                        totalAmount = ((Money)((AliasedValue)c["rrm_accountrevenue_sum"]).Value).Value;
                    }

                    //updating the field on the account
                    Entity acc = new Entity("account");
                    acc.Id = a.Id;
                    acc.Attributes.Add("new_oppamount", new Money(totalAmount));
                    service.Update(acc);

                }
                catch (FaultException ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
                }
            }
        }
    }
}

    `

1 个解决方案

#1


0  

1,2 - You need add a references to microsoft.xrm.sdk.dll and microsoft.crm.sdk.proxy.dll. How to add reference You can find that dll's in SDK.

1,2 - 您需要添加对microsoft.xrm.sdk.dll和microsoft.crm.sdk.proxy.dll的引用。如何添加引用您可以在SDK中找到dll。

3- You can just overload "Execute" method.

3-你可以只重载“执行”方法。

public void Execute(IServiceProvider serviceProvider)
{
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
}

Good place to start write plugins

开始编写插件的好地方

#1


0  

1,2 - You need add a references to microsoft.xrm.sdk.dll and microsoft.crm.sdk.proxy.dll. How to add reference You can find that dll's in SDK.

1,2 - 您需要添加对microsoft.xrm.sdk.dll和microsoft.crm.sdk.proxy.dll的引用。如何添加引用您可以在SDK中找到dll。

3- You can just overload "Execute" method.

3-你可以只重载“执行”方法。

public void Execute(IServiceProvider serviceProvider)
{
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
}

Good place to start write plugins

开始编写插件的好地方