Показать сообщение отдельно
Старый 08.10.2008, 23:26   #4  
ZooY is offline
ZooY
Участник
Аватар для ZooY
 
379 / 46 (2) +++
Регистрация: 24.06.2008
Адрес: Россия, Москва
Некий универсальный код...
Некий универсальный код...

Код:
_message = context.MessageName;
switch(_message)
{
    case MessageName.Create:
    case MessageName.DeliverIncoming:
        if (context.InputParameters.Contains(ParameterName.Target) && context.InputParameters[ParameterName.Target] is DynamicEntity)
        {
            DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
            _entityName = entity.Name.ToLower();
        }
        if (context.Stage == MessageProcessingStage.BeforeMainOperationOutsideTransaction)
        {
            // EntityId is not available in Pre-stage
        }
        else
        {
            if(context.OutputParameters.Contains(ParameterName.Id))
                _entityId = (Guid)context.OutputParameters[ParameterName.Id];
            else if (context.OutputParameters.Contains(ParameterName.EmailId))
                _entityId = (Guid)context.OutputParameters[ParameterName.EmailId];
        }
        break;
    case MessageName.Update:
        if (context.InputParameters.Contains(ParameterName.Target) && context.InputParameters[ParameterName.Target] is DynamicEntity)
        {
            DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
            _entityName = entity.Name.ToLower();
            _entityId = ((Key)entity.Properties[_entityName + "id"]).Value;
        }
        break;
    case MessageName.Delete:
	case MessageName.Assign:
	case MessageName.GrantAccess:
	case MessageName.Handle:
		if (context.InputParameters.Contains(ParameterName.Target) && context.InputParameters[ParameterName.Target] is Moniker)
		{
			Moniker moniker = (Moniker)context.InputParameters[ParameterName.Target];
            _entityName = moniker.Name.ToLower();
			_entityId = moniker.Id;
		}
		break;
    case MessageName.SetState:
	case MessageName.SetStateDynamicEntity:
        if (context.InputParameters.Contains(ParameterName.EntityMoniker) && context.InputParameters[ParameterName.EntityMoniker] is Moniker)
        {
            Moniker moniker = (Moniker)context.InputParameters[ParameterName.EntityMoniker];
            _entityName = moniker.Name.ToLower();
            _entityId = moniker.Id;
        }
        break;
}
_entityId - идентификатор записи, для которой сработал плагин
_entityName - имя сущности записи