Показать сообщение отдельно
Старый 13.02.2009, 12:05   #6  
Bondonello is offline
Bondonello
Kostya Afendikov
Аватар для Bondonello
MCBMSS
Лучший по профессии 2009
 
510 / 106 (5) +++++
Регистрация: 06.06.2008
Адрес: Украина
Да, бесконечный цикл был, да и вторая переменная оказалась лишняя, спасибо что указали. еще не набил руку.

Сделал Image на Post и событие и Зарегистрировал сборку на Update (Post)
исправленный метод Execute
X++:
public void Execute(IPluginExecutionContext context)
        {
            DynamicEntity entity = null;
           

            if (context.PostEntityImages.Properties.Contains("Image"))
            {
                entity = (DynamicEntity)context.PostEntityImages.Properties["Image"];
                if (entity.Properties.Contains("subject"))
                {
                    if (entity.Properties["subject"].ToString() == "test1")
                    {
                        return;
                    }
                }
            }
            else
            {
                throw new InvalidPluginExecutionException("Some sheet happened!");
            }

            if (context.InputParameters.Properties.Contains(ParameterName.Target) &&
               context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
            {

           
                entity = (DynamicEntity)context.InputParameters[ParameterName.Target];

            }
            else
            {
                return;
            }

            try
            {
                Key entityId = new Key();
             
                if (entity.Name == EntityName.task.ToString())
                {
                    if (entity.Properties.Contains("activityid"))
                    {


                        entityId = ((Key)entity.Properties["activityid"]);
                        //entity = (DynamicEntity)context.InputParameters[ParameterName.Target];

                        DynamicEntity task = new DynamicEntity();
                        task.Name = EntityName.task.ToString();

                        task.Properties = new PropertyCollection();


                        task.Properties.Add(new StringProperty("subject", "test1"));
                        task.Properties.Add(new KeyProperty("activityid", entityId));

                        ICrmService service = context.CreateCrmService(true);
                        service.Update(task);
                    }
                    else
                    {
                        throw new InvalidPluginExecutionException("Entity image do not contains activityid field!");
                    }
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw new InvalidPluginExecutionException(
                    String.Format("An error occurred in the {0} plug-in.",
                       this.GetType().ToString()),
                    ex);
            }
        }