public void SetUp()
 {
     this.activityBuilder = new GenerateErrorActivityBuilder(new XslBuilder(new XpathBuilder()));
     this.activity = new GenerateErrorActivity( "My Activity Name",ActivityType.generateErrorActivity);
     this.activity.FaultName = "";
     var xml =
         @"
     <ns:ActivityInput xmlns:xsl=""http://w3.org/1999/XSL/Transform"" xmlns:ns=""http://www.tibco.com/pe/GenerateErrorActivitySchema"">
     <message>
     <xsl:value-of select=""'testvalue'""/>
     </message>
     <messageCode>
     <xsl:value-of select=""'EVL'""/>
     </messageCode>
     </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 = "messageCode",
             Type= "String"}
     };
 }
        public CodeStatementCollection GenerateCodeInvocation(GenerateErrorActivity activity)
        {
            var invocationCodeCollection = new CodeStatementCollection();

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

            // Add the exception Call
            invocationCodeCollection.Add(this.GenerateExceptionStatement(activity));

            return invocationCodeCollection;
        }
        private CodeThrowExceptionStatement GenerateExceptionStatement(GenerateErrorActivity 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;
            CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement(new CodeObjectCreateExpression(new CodeTypeReference(typeof(System.Exception)), stringFormatCall));
            return throwException;
        }
        public Activity Parse(XElement inputElement)
        {
            var activity = new GenerateErrorActivity();

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

            activity.FaultName = XElementParserUtils.GetStringValue(configElement.Element("faultName"));

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

            return activity;
        }