Beispiel #1
0
        /// <summary>
        /// Reads in the nodes of the xml file one by one and builds the data structure of all existing properties
        /// </summary>
        private bool ParseParameterGroupOrParameter(XamlTypes.BaseProperty baseProperty, LinkedList <Property> propertyList, Property property, Dictionary <string, Property> argumentDependencyLookup)
        {
            // node is a property
            if (!ParseParameter(baseProperty, propertyList, property, argumentDependencyLookup))
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
 public PropertyWrapper(Type newType, BaseProperty newProperty)
 {
     PropertyType = newType;
     Property = newProperty;
 }
Beispiel #3
0
 private void GenerateArgumentBool(CommandLineBuilder builder, BaseProperty property, string value)
 {
     if (value == "true")
     {
         builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPrefix, property.Switch);
     }
     else if (value == "false" && ((BoolProperty)property).ReverseSwitch != null)
     {
         builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPrefix, ((BoolProperty)property).ReverseSwitch);
     }
 }
Beispiel #4
0
 private void GenerateArgumentInt(CommandLineBuilder builder, BaseProperty property, string value)
 {
     // Currently we only have one Int property and it doesn't correspond to a
     // command line arguemnt (ProcessorNumber) so we ignore it here.
 }
Beispiel #5
0
 private void GenerateArgumentString(CommandLineBuilder builder, BaseProperty property, string value)
 {
     // could cache this SubType test off in property wrapper or somewhere if performance were an issue
     StringProperty casted = (StringProperty)property;
     AppendStringValue(builder, property, casted.Subtype, value);
 }
Beispiel #6
0
        private void GenerateArgumentStringList(CommandLineBuilder builder, BaseProperty property, string value)
        {
            string[] arguments = value.Split(';');

            foreach (string argument in arguments)
            {
                if (argument.Length > 0)
                {
                    StringListProperty casted = (StringListProperty)property;
                    AppendStringValue(builder, property, casted.Subtype, argument);
                }
            }
        }
 private bool ParseParameterGroupOrParameter(BaseProperty baseProperty, LinkedList<Property> propertyList, Property property)
 {
     if (!this.ParseParameter(baseProperty, propertyList, property))
     {
         return false;
     }
     return true;
 }
Beispiel #8
0
        /// <summary>
        /// Fills in the property data structure
        /// </summary>
        private bool ParseParameter(XamlTypes.BaseProperty baseProperty, LinkedList <Property> propertyList, Property property, Dictionary <string, Property> argumentDependencyLookup)
        {
            Property propertyToAdd = ObtainAttributes(baseProperty, property);

            if (String.IsNullOrEmpty(propertyToAdd.Name))
            {
                propertyToAdd.Name = "AlwaysAppend";
            }

            // generate the list of parameters in order
            if (!_switchOrderList.Contains(propertyToAdd.Name))
            {
                _switchOrderList.Add(propertyToAdd.Name);
            }
            else
            {
                throw new XamlParseException(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("Xaml.DuplicatePropertyName", propertyToAdd.Name));
            }

            // Inherit the Prefix from the Tool
            if (String.IsNullOrEmpty(propertyToAdd.Prefix))
            {
                propertyToAdd.Prefix = DefaultPrefix;
            }

            // If the property is an enum type, parse that.
            XamlTypes.EnumProperty enumProperty = baseProperty as XamlTypes.EnumProperty;
            if (enumProperty != null)
            {
                foreach (XamlTypes.EnumValue enumValue in enumProperty.AdmissibleValues)
                {
                    var value = new Value
                    {
                        Name       = enumValue.Name,
                        SwitchName = enumValue.Switch
                    };

                    if (value.SwitchName == null)
                    {
                        value.SwitchName = String.Empty;
                    }

                    value.DisplayName = enumValue.DisplayName;
                    value.Description = enumValue.Description;
                    value.Prefix      = enumValue.SwitchPrefix;
                    if (String.IsNullOrEmpty(value.Prefix))
                    {
                        value.Prefix = enumProperty.SwitchPrefix;
                    }

                    if (String.IsNullOrEmpty(value.Prefix))
                    {
                        value.Prefix = DefaultPrefix;
                    }

                    if (enumValue.Arguments.Count > 0)
                    {
                        value.Arguments = new List <Argument>();
                        foreach (XamlTypes.Argument argument in enumValue.Arguments)
                        {
                            var arg = new Argument
                            {
                                Parameter = argument.Property,
                                Separator = argument.Separator,
                                Required  = argument.IsRequired
                            };
                            value.Arguments.Add(arg);
                        }
                    }

                    if (value.Prefix == null)
                    {
                        value.Prefix = propertyToAdd.Prefix;
                    }

                    propertyToAdd.Values.Add(value);
                }
            }

            // build the dependencies and the values for a parameter
            foreach (XamlTypes.Argument argument in baseProperty.Arguments)
            {
                // To refactor into a separate func
                if (propertyToAdd.Arguments == null)
                {
                    propertyToAdd.Arguments = new List <Argument>();
                }

                var arg = new Argument
                {
                    Parameter = argument.Property,
                    Separator = argument.Separator,
                    Required  = argument.IsRequired
                };
                propertyToAdd.Arguments.Add(arg);
            }

            if (argumentDependencyLookup != null && !argumentDependencyLookup.ContainsKey(propertyToAdd.Name))
            {
                argumentDependencyLookup.Add(propertyToAdd.Name, propertyToAdd);
            }

            // We've read any enumerated values and any dependencies, so we just
            // have to add the property
            propertyList.AddLast(propertyToAdd);
            return(true);
        }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void GenerateArgumentString (CommandLineBuilder builder, BaseProperty property, string value)
    {
      StringProperty casted = (StringProperty)property;

      AppendStringValue (builder, property, casted.Subtype, value.Trim (new char [] { ' ', '\"' }));
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void GenerateArgumentStringList (CommandLineBuilder builder, BaseProperty property, string value)
    {
      string [] arguments = value.Split (new char [] { ';' }, StringSplitOptions.RemoveEmptyEntries);

      if (arguments.Length > 0)
      {
        StringListProperty casted = (StringListProperty)property;

        if (casted.CommandLineValueSeparator != null)
        {
          List<string> sanitised = new List<string> ();

          foreach (string argument in arguments)
          {
            if (argument.Length > 0)
            {
              sanitised.Add (argument.Trim (new char [] { ' ', '\"' }));
            }
          }

          if (sanitised.Count > 0)
          {
            AppendStringListValue (builder, property, casted.Subtype, sanitised.ToArray (), casted.CommandLineValueSeparator);
          }
        }
        else
        {
          foreach (string argument in arguments)
          {
            if (argument.Length > 0)
            {
              AppendStringValue (builder, property, casted.Subtype, argument.Trim (new char [] { ' ', '\"' }));
            }
          }
        }
      }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void AppendIntValue (CommandLineBuilder builder, BaseProperty property, string value)
    {
      value = value.Trim ();

      string switchName = m_parsedBuildRule.SwitchPrefix + property.Switch;

      switchName += property.Separator;

      builder.AppendSwitchUnquotedIfNotNull (switchName, value);
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void AppendStringListValue (CommandLineBuilder builder, BaseProperty property, string subtype, string [] value, string delimiter)
    {
      string switchName = m_parsedBuildRule.SwitchPrefix + property.Switch;

      switchName += property.Separator;

      if (subtype == "file" || subtype == "folder")
      {
        builder.AppendSwitchUnquotedIfNotNull (switchName, value, delimiter);
      }
      else if (!string.IsNullOrEmpty (property.Switch))
      {
        builder.AppendSwitchUnquotedIfNotNull (switchName, value, delimiter);
      }
      else if (value.Length > 0)
      {
        foreach (string entry in value)
        {
          builder.AppendTextUnquoted (entry + delimiter);
        }
      }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void AppendStringValue (CommandLineBuilder builder, BaseProperty property, string subtype, string value)
    {
      string switchName = property.SwitchPrefix;

      if (string.IsNullOrEmpty (property.SwitchPrefix))
      {
        switchName = m_parsedBuildRule.SwitchPrefix;
      }

      switchName += property.Switch + property.Separator;

      if (subtype == "file" || subtype == "folder")
      {
        if (!string.IsNullOrWhiteSpace (switchName))
        {
          builder.AppendSwitchIfNotNull (switchName, value);
        }
        else
        {
          builder.AppendTextUnquoted (" " + PathUtils.QuoteIfNeeded (value));
        }
      }
      else if (!string.IsNullOrEmpty (property.Switch))
      {
        builder.AppendSwitchUnquotedIfNotNull (switchName, value);
      }
      else if (!string.IsNullOrEmpty (value))
      {
        builder.AppendTextUnquoted (" " + value);
      }
    }
 private Property ObtainAttributes(BaseProperty baseProperty, Property parameterGroup)
 {
     Property property;
     if (parameterGroup != null)
     {
         property = parameterGroup.Clone();
     }
     else
     {
         property = new Property();
     }
     BoolProperty property2 = baseProperty as BoolProperty;
     DynamicEnumProperty property3 = baseProperty as DynamicEnumProperty;
     EnumProperty property4 = baseProperty as EnumProperty;
     IntProperty property5 = baseProperty as IntProperty;
     StringProperty property6 = baseProperty as StringProperty;
     StringListProperty property7 = baseProperty as StringListProperty;
     if (baseProperty.Name != null)
     {
         property.Name = baseProperty.Name;
     }
     if ((property2 != null) && !string.IsNullOrEmpty(property2.ReverseSwitch))
     {
         property.Reversible = "true";
     }
     if (property2 != null)
     {
         property.Type = PropertyType.Boolean;
     }
     else if (property4 != null)
     {
         property.Type = PropertyType.String;
     }
     else if (property3 != null)
     {
         property.Type = PropertyType.String;
     }
     else if (property5 != null)
     {
         property.Type = PropertyType.Integer;
     }
     else if (property6 != null)
     {
         property.Type = PropertyType.String;
     }
     else if (property7 != null)
     {
         property.Type = PropertyType.StringArray;
     }
     if (((baseProperty.DataSource != null) && !string.IsNullOrEmpty(baseProperty.DataSource.SourceType)) && baseProperty.DataSource.SourceType.Equals("Item", StringComparison.OrdinalIgnoreCase))
     {
         property.Type = PropertyType.ItemArray;
     }
     if (property5 != null)
     {
         property.Max = property5.MaxValue.HasValue ? property5.MaxValue.ToString() : null;
         property.Min = property5.MinValue.HasValue ? property5.MinValue.ToString() : null;
     }
     if (property2 != null)
     {
         property.ReverseSwitchName = property2.ReverseSwitch;
     }
     if (baseProperty.Switch != null)
     {
         property.SwitchName = baseProperty.Switch;
     }
     if (property7 != null)
     {
         property.Separator = property7.Separator;
     }
     if (baseProperty.Default != null)
     {
         property.DefaultValue = baseProperty.Default;
     }
     property.Required = baseProperty.IsRequired.ToString().ToLower(CultureInfo.InvariantCulture);
     if (baseProperty.Category != null)
     {
         property.Category = baseProperty.Category;
     }
     if (baseProperty.DisplayName != null)
     {
         property.DisplayName = baseProperty.DisplayName;
     }
     if (baseProperty.Description != null)
     {
         property.Description = baseProperty.Description;
     }
     if (baseProperty.SwitchPrefix != null)
     {
         property.Prefix = baseProperty.SwitchPrefix;
     }
     return property;
 }
Beispiel #15
0
 private void GenerateArgumentEnum(CommandLineBuilder builder, BaseProperty property, string value)
 {
     var result = ((EnumProperty)property).AdmissibleValues.Find(x => (x.Name == value));
     if (result != null)
     {
         builder.AppendSwitchUnquotedIfNotNull(m_parsedBuildRule.SwitchPrefix, result.Switch);
     }
 }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void GenerateArgumentInt (CommandLineBuilder builder, BaseProperty property, string value)
    {
      AppendIntValue (builder, property, value);
    }
Beispiel #17
0
        // helper for string-based properties
        private void AppendStringValue(CommandLineBuilder builder, BaseProperty property, string subtype, string value)
        {
            value = value.Trim();

            // could cache this SubType test off in property wrapper or somewhere if performance were an issue
            string switchName = m_parsedBuildRule.SwitchPrefix + property.Switch;
            switchName += property.Separator;
            if (subtype == "file" || subtype == "folder")
            {
                // for switches that contains files or folders we need quoting
                builder.AppendSwitchIfNotNull(switchName, value);
            }
            else if (!string.IsNullOrEmpty(property.Switch))
            {
                builder.AppendSwitchUnquotedIfNotNull(switchName, value);
            }
            else if (!string.IsNullOrEmpty(value))
            {
                // for non-switches such as AdditionalOptions we just append the value
                builder.AppendTextUnquoted(" " + value);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Gets all the attributes assigned in the xml file for this parameter or all of the nested switches for
        /// this parameter group
        /// </summary>
        private static Property ObtainAttributes(XamlTypes.BaseProperty baseProperty, Property parameterGroup)
        {
            Property parameter;

            if (parameterGroup != null)
            {
                parameter = parameterGroup.Clone();
            }
            else
            {
                parameter = new Property();
            }

            XamlTypes.BoolProperty        boolProperty        = baseProperty as XamlTypes.BoolProperty;
            XamlTypes.DynamicEnumProperty dynamicEnumProperty = baseProperty as XamlTypes.DynamicEnumProperty;
            XamlTypes.EnumProperty        enumProperty        = baseProperty as XamlTypes.EnumProperty;
            XamlTypes.IntProperty         intProperty         = baseProperty as XamlTypes.IntProperty;
            XamlTypes.StringProperty      stringProperty      = baseProperty as XamlTypes.StringProperty;
            XamlTypes.StringListProperty  stringListProperty  = baseProperty as XamlTypes.StringListProperty;

            parameter.IncludeInCommandLine = baseProperty.IncludeInCommandLine;

            if (baseProperty.Name != null)
            {
                parameter.Name = baseProperty.Name;
            }

            if (boolProperty != null && !String.IsNullOrEmpty(boolProperty.ReverseSwitch))
            {
                parameter.Reversible = "true";
            }

            // Determine the type for this property.
            if (boolProperty != null)
            {
                parameter.Type = PropertyType.Boolean;
            }
            else if (enumProperty != null)
            {
                parameter.Type = PropertyType.String;
            }
            else if (dynamicEnumProperty != null)
            {
                parameter.Type = PropertyType.String;
            }
            else if (intProperty != null)
            {
                parameter.Type = PropertyType.Integer;
            }
            else if (stringProperty != null)
            {
                parameter.Type = PropertyType.String;
            }
            else if (stringListProperty != null)
            {
                parameter.Type = PropertyType.StringArray;
            }

            // We might need to override this type based on the data source, if it specifies a source type of 'Item'.
            if (baseProperty.DataSource != null)
            {
                if (!String.IsNullOrEmpty(baseProperty.DataSource.SourceType))
                {
                    if (baseProperty.DataSource.SourceType.Equals("Item", StringComparison.OrdinalIgnoreCase))
                    {
                        parameter.Type = PropertyType.ItemArray;
                    }
                }
            }

            if (intProperty != null)
            {
                parameter.Max = intProperty.MaxValue != null?intProperty.MaxValue.ToString() : null;

                parameter.Min = intProperty.MinValue != null?intProperty.MinValue.ToString() : null;
            }

            if (boolProperty != null)
            {
                parameter.ReverseSwitchName = boolProperty.ReverseSwitch;
            }

            if (baseProperty.Switch != null)
            {
                parameter.SwitchName = baseProperty.Switch;
            }

            if (stringListProperty != null)
            {
                parameter.Separator = stringListProperty.Separator;
            }

            if (baseProperty.Default != null)
            {
                parameter.DefaultValue = baseProperty.Default;
            }

            parameter.Required = baseProperty.IsRequired.ToString().ToLower(CultureInfo.InvariantCulture);

            if (baseProperty.Category != null)
            {
                parameter.Category = baseProperty.Category;
            }

            if (baseProperty.DisplayName != null)
            {
                parameter.DisplayName = baseProperty.DisplayName;
            }

            if (baseProperty.Description != null)
            {
                parameter.Description = baseProperty.Description;
            }

            if (baseProperty.SwitchPrefix != null)
            {
                parameter.Prefix = baseProperty.SwitchPrefix;
            }

            return(parameter);
        }
 private bool ParseParameter(BaseProperty baseProperty, LinkedList<Property> propertyList, Property property)
 {
     Property property2 = this.ObtainAttributes(baseProperty, property);
     if (string.IsNullOrEmpty(property2.Name))
     {
         property2.Name = "AlwaysAppend";
     }
     if (!this.switchesAdded.Contains(property2.Name))
     {
         this.switchOrderList.Add(property2.Name);
     }
     if (string.IsNullOrEmpty(property2.Prefix))
     {
         property2.Prefix = this.DefaultPrefix;
     }
     EnumProperty property3 = baseProperty as EnumProperty;
     if (property3 != null)
     {
         foreach (EnumValue value2 in property3.AdmissibleValues)
         {
             Value value3 = new Value {
                 Name = value2.Name,
                 SwitchName = value2.Switch
             };
             if (value3.SwitchName == null)
             {
                 value3.SwitchName = string.Empty;
             }
             value3.DisplayName = value2.DisplayName;
             value3.Description = value2.Description;
             value3.Prefix = value2.SwitchPrefix;
             if (string.IsNullOrEmpty(value3.Prefix))
             {
                 value3.Prefix = property3.SwitchPrefix;
             }
             if (string.IsNullOrEmpty(value3.Prefix))
             {
                 value3.Prefix = this.DefaultPrefix;
             }
             if (value2.Arguments.Count > 0)
             {
                 value3.Arguments = new ArrayList();
                 foreach (Microsoft.Build.Framework.XamlTypes.Argument argument in value2.Arguments)
                 {
                     Microsoft.Build.Tasks.Xaml.Argument argument2 = new Microsoft.Build.Tasks.Xaml.Argument {
                         Parameter = argument.Property,
                         Separator = argument.Separator,
                         Required = argument.IsRequired
                     };
                     value3.Arguments.Add(argument2);
                 }
             }
             if (value3.Prefix == null)
             {
                 value3.Prefix = property2.Prefix;
             }
             property2.Values.Add(value3);
         }
     }
     foreach (Microsoft.Build.Framework.XamlTypes.Argument argument3 in baseProperty.Arguments)
     {
         if (property2.Arguments == null)
         {
             property2.Arguments = new ArrayList();
         }
         Microsoft.Build.Tasks.Xaml.Argument argument4 = new Microsoft.Build.Tasks.Xaml.Argument {
             Parameter = argument3.Property,
             Separator = argument3.Separator,
             Required = argument3.IsRequired
         };
         property2.Arguments.Add(argument4);
     }
     propertyList.AddLast(property2);
     return true;
 }