public void SetUp()
 {
     this.activityBuilder = new WriteToLogActivityBuilder(new XslBuilder(new XpathBuilder()));
     this.activity = new WriteToLogActivity( "My Activity Name",ActivityType.writeToLogActivityType);
     this.activity.Role = "Error";
     var xml =
         @"
     <ns:ActivityInput xmlns:xsl=""http://w3.org/1999/XSL/Transform"" xmlns:ns=""http://www.tibco.com/pe/WriteToLogActivitySchema"">
     <message>
     <xsl:value-of select=""'testvalue'""/>
     </message>
     <msgCode>
     <xsl:value-of select=""'EVL'""/>
     </msgCode>
     </ns:ActivityInput>
     ";
     XElement doc = XElement.Parse(xml);
     this.activity.InputBindings = doc.Nodes();
     this.activity.Parameters = new List<ClassParameter>{
         new ClassParameter{
             Name = "message",
             Type= "String"},
         new ClassParameter{
             Name = "msgCode",
             Type= "String"}
     };
 }
        public CodeStatementCollection GenerateCodeInvocation(WriteToLogActivity activity)
        {
            var invocationCodeCollection = new CodeStatementCollection();

            // add log
            invocationCodeCollection.AddRange(DefaultActivityBuilder.LogActivity(activity));
            //add the input
            invocationCodeCollection.AddRange(this.xslBuilder.Build(activity.InputBindings));

            //Add the logger call
            invocationCodeCollection.Add(this.GenerateLoggerCodeInvocation(activity));

            return invocationCodeCollection;
        }
        public Activity Parse(XElement inputElement)
        {
            var activity = new WriteToLogActivity();

            activity.Name = inputElement.Attribute ("name").Value;
            activity.Type = (ActivityType) inputElement.Element (XmlnsConstant.tibcoProcessNameSpace + "type").Value;
            var configElement = inputElement.Element ("config");

            activity.Role = XElementParserUtils.GetStringValue(configElement.Element("role"));

            if (inputElement.Element(XmlnsConstant.tibcoProcessNameSpace + "inputBindings") != null && inputElement.Element(XmlnsConstant.tibcoProcessNameSpace + "inputBindings").Element(XmlnsConstant.writeToLogActivityNameSpace + "ActivityInput") != null)
            {
                activity.InputBindings = inputElement.Element(XmlnsConstant.tibcoProcessNameSpace + "inputBindings").Element(XmlnsConstant.writeToLogActivityNameSpace + "ActivityInput").Nodes();
                activity.Parameters = new XslParser().Build(activity.InputBindings);
            }

            return activity;
        }
        private CodeMethodInvokeExpression GenerateLoggerCodeInvocation(WriteToLogActivity activity)
        {
            var parameters = DefaultActivityBuilder.GenerateParameters(new List<string> {
                @"""Message : {0}\nMessage code : {1} """
            }, activity);

            CodeMethodInvokeExpression stringFormatCall = new CodeMethodInvokeExpression();
            stringFormatCall.Parameters.AddRange(parameters);

            CodeMethodReferenceExpression formatMethod = new CodeMethodReferenceExpression();
            formatMethod.MethodName = "Format";
            CodeVariableReferenceExpression stringObject = new CodeVariableReferenceExpression();
            stringObject.VariableName = "String";
            formatMethod.TargetObject = stringObject;
            stringFormatCall.Method = formatMethod;

            var loggerReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), VariableHelper.ToVariableName("logger"));
            var methodInvocation = new CodeMethodInvokeExpression(loggerReference, activity.Role, stringFormatCall);
            return methodInvocation;
        }