locked
Get Process Parameters Value - problems, how to do it? RRS feed

  • Question

  • Hi, I have the following code;

    private static TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://myserver.com:8080/tfs/defaultcollection"));
    private static VersionControlServer vcServer = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
    IBuildServer buildServer = tfs.GetService<IBuildServer>();
    private void button1_Click(object sender, EventArgs e)
    {
         Activity myActivity = ActivityXamlServices.Load(@"C:\dev\CI_Testing\BuildProcessTemplates\TestMasterTemplate.xaml");
         var allParameters = WorkflowHelpers.GetCombinedMetadata(myActivity);
         foreach (var p in allParameters)
         {
               listBox1.Items.AddRange(new object[] { p.ParameterName  });
               var param = WorkflowHelpers.GetProcessParameterValue(myActivity, p.ParameterName, "null");
               listBox2.Items.AddRange(new object[] { param });
         }
    } 

    When I run the program I get the results below. In the build template, everything below exists and has values. I understand from the code that 'null' gets output if the parameter doesn't exit, but they do. So why does null show up? How do I get all the values to display? I'm going crazy! Please help.

    Thank you!

    Sunday, June 17, 2012 8:12 PM

Answers

  • Hi,

    As your pictures shows, build definition parameters' type vary. So you see only value types printed.  I've tried below code, which could list parameter value. Note that a number of parameter could not be printed.  Hope this gets you started.

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private static TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://vm-tfs-forrestg:8080/tfs/defaultcollection"));
            private static VersionControlServer vcServer = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
            static IBuildServer buildServer = tfs.GetService<IBuildServer>();
    
            IBuildDefinition myBuildDefinition = buildServer.GetBuildDefinition("Contoso", "BuildDefinition_EnterpriseLib");
    
            private void GetPropertyParameters()
            {
                StringReader sr = new StringReader(myBuildDefinition.Process.Parameters);
                DynamicActivity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(sr) as DynamicActivity;
    
                foreach (var prop in activity.Properties)
                {
                    object defaultValue;
                    if (prop.Value == null)
                    {
                        defaultValue = null;
                    }
                    else
                    {
                        try
                        {
                            Type genericTypeDefinition = prop.Type.GetGenericTypeDefinition();
                            if (genericTypeDefinition == typeof(InArgument<>) || genericTypeDefinition == typeof(InOutArgument<>))
                            {
                                // use reflection to get the values
                                var valueProp = prop.Value.GetType().GetProperty("Expression", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly);
                                var expression = valueProp.GetValue(prop.Value, null);
                                try
                                {
                                    var expressionValueProp = expression.GetType().GetProperty("ExpressionText");
    
                                    defaultValue = expressionValueProp.GetValue(expression, null);
    
                                    listBox1.Items.Add(prop.Name + ": Value =  " + defaultValue.ToString());
                                }
                                catch (NullReferenceException)
                                {
                                    listBox1.Items.Add("Error, fail to retrieve property value.  Property Name: " + prop.Name);
                                }
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            listBox1.Items.Add("Property type doesn't support retrieve value, not generic type. Property Name: " + prop.Name);
                        }
                    }
                }
    
            }
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.GetPropertyParameters();
            }
        }


    Forrest Guo | MSDN Community Support | Feedback to manager

    Wednesday, June 27, 2012 3:50 AM
    Moderator

All replies

  • Hi AndrejsM,

    Thank you for your question.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
     
    Thank you for your understanding and support.


    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 19, 2012 6:16 AM
    Moderator
  • Hi Andrejs

    The process parameter values supposed to be filled in a build definition, instead of a build template.  Take TestSpecs in end of above list as example, in build definitions, we specify test assembly spec, etc.

    You will want to turn to build definition.

    thanks,


    Forrest Guo | MSDN Community Support | Feedback to manager

    • Marked as answer by AndrejsM Tuesday, June 19, 2012 1:57 PM
    • Unmarked as answer by AndrejsM Wednesday, June 20, 2012 9:20 PM
    Tuesday, June 19, 2012 8:24 AM
    Moderator
  • Hi. Still trying to get paramater values from a build definition. I have this;

    IBuildDefinition myBuildDefinition = buildServer.GetBuildDefinition("CI_Testing", "Module_1_BUILD");
    private void GetPropertyParameters()
    {
        StringReader sr = new StringReader(myBuildDefinition.Process.Parameters);
        DynamicActivity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(sr) as DynamicActivity;
        var propertyQuery = from dap in activity.Properties select dap;
        var pList = propertyQuery.ToList<DynamicActivityProperty>();
        foreach (var p in pList)
        {
            if (p.Value == null)
            {
                listBox1.Items.Add("** IS NULL **");
            }
                else
            {
                listBox1.Items.Add(p.Value);
            }
        }
    }

    and the result is this;

    How can I get the actual values? Please help. Thank you very much.

    Tuesday, June 19, 2012 9:45 PM
  • Hi, I understand about getting the information from the definition and not the template. I have an issue with that. I can get the names of the parameters from the definition, but not the values. Please see..

    http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/148485c9-a004-430b-bd1f-73f5991d57ac

    Can you please help? Thanks.

    Wednesday, June 20, 2012 9:24 PM
  • Hi,

    As your pictures shows, build definition parameters' type vary. So you see only value types printed.  I've tried below code, which could list parameter value. Note that a number of parameter could not be printed.  Hope this gets you started.

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private static TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://vm-tfs-forrestg:8080/tfs/defaultcollection"));
            private static VersionControlServer vcServer = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
            static IBuildServer buildServer = tfs.GetService<IBuildServer>();
    
            IBuildDefinition myBuildDefinition = buildServer.GetBuildDefinition("Contoso", "BuildDefinition_EnterpriseLib");
    
            private void GetPropertyParameters()
            {
                StringReader sr = new StringReader(myBuildDefinition.Process.Parameters);
                DynamicActivity activity = System.Activities.XamlIntegration.ActivityXamlServices.Load(sr) as DynamicActivity;
    
                foreach (var prop in activity.Properties)
                {
                    object defaultValue;
                    if (prop.Value == null)
                    {
                        defaultValue = null;
                    }
                    else
                    {
                        try
                        {
                            Type genericTypeDefinition = prop.Type.GetGenericTypeDefinition();
                            if (genericTypeDefinition == typeof(InArgument<>) || genericTypeDefinition == typeof(InOutArgument<>))
                            {
                                // use reflection to get the values
                                var valueProp = prop.Value.GetType().GetProperty("Expression", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly);
                                var expression = valueProp.GetValue(prop.Value, null);
                                try
                                {
                                    var expressionValueProp = expression.GetType().GetProperty("ExpressionText");
    
                                    defaultValue = expressionValueProp.GetValue(expression, null);
    
                                    listBox1.Items.Add(prop.Name + ": Value =  " + defaultValue.ToString());
                                }
                                catch (NullReferenceException)
                                {
                                    listBox1.Items.Add("Error, fail to retrieve property value.  Property Name: " + prop.Name);
                                }
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            listBox1.Items.Add("Property type doesn't support retrieve value, not generic type. Property Name: " + prop.Name);
                        }
                    }
                }
    
            }
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.GetPropertyParameters();
            }
        }


    Forrest Guo | MSDN Community Support | Feedback to manager

    Wednesday, June 27, 2012 3:50 AM
    Moderator