Показать сообщение отдельно
Старый 13.03.2013, 10:55   #1  
probka is offline
probka
Участник
Аватар для probka
 
98 / 11 (1) +
Регистрация: 20.02.2012
Адрес: Ростов-на-Дону
CRM 4.0 Выполнение плагина
Добрый день!
Есть плагин, который выполняется после создания экземпляра кастомной сущности new_grmember, у которой есть атрибут new_groupid. При запуске двух параллельных процессов создания двух различных экземпляров этой сущности с двух разных компьютеров одновременно в алгоритме плагина, запущенного для первого экземпляра, почему-то появляется значение new_groupid из PostImage второго экземпляра. Почему такое может быть? Это какой-то баг или ошибка алгоритма? Текст алгоритма привожу ниже.

X++:
Guid groupId = ((Lookup)GetEntityProperty("new_groupid")).Value;

//------------------//

       protected object GetEntityProperty(string propertyName)
        {
            if (_currentContext.Stage == MessageProcessingStage.AfterMainOperationOutsideTransaction)
            {
                if (_postEntityImage == null)
                    _postEntityImage = GetPostEntityImage(_currentContext, TargetEntity.Name);

                if (_postEntityImage == null)
                {
                    if (_entity.Properties.Contains(propertyName))
                    {
                        return _entity[propertyName];
                    }


                }
                else if (_postEntityImage.Properties.Contains(propertyName))
                {
                    return _postEntityImage[propertyName];
                }

                return null;
            }

            else // (_currentContext.Stage == MessageProcessingStage.BeforeMainOperationOutsideTransaction)
            {
                if (!_entity.Properties.Contains(propertyName))
                {
                    if (_preEntityImage == null)
                        _preEntityImage = GetPreEntityImage(_currentContext, TargetEntity.Name);

                    if (_preEntityImage == null)
                        return null;

                    else if (_preEntityImage.Properties.Contains(propertyName))
                    {
                        return _preEntityImage[propertyName];
                    }

                    return null;

                }

                return _entity[propertyName];
            }
            
        }

        protected static DynamicEntity GetPostEntityImage(IPluginExecutionContext _currentContext, string _EntityName)
        {
            DynamicEntity postImageEntity = null;

            if (_currentContext.PostEntityImages.Contains(_EntityName))
                postImageEntity = _currentContext.PostEntityImages[_EntityName] as DynamicEntity;

            return postImageEntity;
        }
__________________
Так победим!