Feb 12, 2012 at 3:10 PM
Edited Feb 12, 2012 at 3:16 PM
|
Hi all,
today I little played with filters and I would like create own aspects [advices]. Something like Aspect library in Spring.NET
I created aspects for log input method parameters and output value.
public class LogInputParamsAttribute :
Attribute,
IPreProcessor
{
public int Priority
{
get { return 1; }
}
public bool Execute(IRoutedMessage message, IInteractionNode handlingNode,
object[] parameters)
{
var sb = new StringBuilder();
sb.AppendFormat("Action: {0}\n", message);
foreach (var parameter in parameters)
{
sb.AppendFormat("{0}\n",parameter);
}
//this is temporary ;)
MessageBox.Show(sb.ToString());
return true;
}
public bool AffectsTriggers
{
get { return true; }
}
}
and
public class LogOutputValueAttribute :
Attribute,
IPostProcessor
{
public int Priority
{
get { return 1; }
}
public void Execute(IRoutedMessage message, IInteractionNode handlingNode, MessageProcessingOutcome outcome)
{
var sb = new StringBuilder();
sb.AppendFormat("Action: {0}\n", message);
sb.AppendFormat("Output: {0}\n", outcome.Result);
//this is temporary ;)
MessageBox.Show(sb.ToString());
}
}
When my WPF app start up it call automatically method Execute in LogInputParamsAttribute but I don’t know why.
Because I used LogInputParamsAttribute on method LogParamsTest and this method is binded on button event Click.
Piece of code from VM:
[LogInputParams]
[LogOutputValue]
public string LogParamsTest(string username, string password)
{
return string.Format("Hello {0}", username);
}
View:
<Button Style="{StaticResource styleButton}"
Content="LogParamsTest"
cal:Message.Attach="[Event Click]=[Action LogParamsTest(UserName.Text,Password.Text)]"
Grid.Row="3"/>
And my second question is: It exist way how can I get parameters name in method Execute (LogInputParamsAttribute). For example in this case object[0]=>username, object[1]=>password.
Thank you for all answers...
|