Exemplo n.º 1
0
 /// <summary>
 /// Makes this configuration binding being controlled by the specified button.
 /// Use this method if you want to use one ChooseStorageLocationButton to control
 /// multiple properties.
 /// </summary>
 public void RegisterLocationButton(ChooseStorageLocationButton btn)
 {
     this.storageLocationButton  = btn;
     btn.StorageLocationChanged += delegate(object sender, EventArgs e) {
         this.Location = ((ChooseStorageLocationButton)sender).StorageLocation;
     };
 }
Exemplo n.º 2
0
 public void SetProperty <T>(string propertyName, T value,
                             bool treatPropertyValueAsLiteral,
                             PropertyStorageLocations location)
 {
     project.SetProperty(configuration, platform, propertyName,
                         GenericConverter.ToString(value), location, treatPropertyValueAsLiteral);
 }
        static void OnLocationChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            StorageLocationPicker p = o as StorageLocationPicker;

            if (p != null)
            {
                PropertyStorageLocations location = (PropertyStorageLocations)e.NewValue;
                p.IsUserFile = (location & PropertyStorageLocations.UserFile) == PropertyStorageLocations.UserFile;
                switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific)
                {
                case PropertyStorageLocations.ConfigurationSpecific:
                    p.EllipseBackground = Brushes.Blue;
                    break;

                case PropertyStorageLocations.PlatformSpecific:
                    p.EllipseBackground = Brushes.Red;
                    break;

                case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
                    p.EllipseBackground = Brushes.Violet;
                    break;

                default:
                    p.EllipseBackground = Brushes.Black;
                    break;
                }
                if (p.contextMenu != null)
                {
                    p.SetIsCheckedOnMenu(location);
                }
            }
        }
Exemplo n.º 4
0
            public void Load(MSBuildBasedProject project, string configuration, string platform)
            {
                PropertyStorageLocations newLocation;
                string v;

                if (treatPropertyValueAsLiteral)
                {
                    v = project.GetProperty(configuration, platform, propertyName, out newLocation);
                }
                else
                {
                    v = project.GetUnevalatedProperty(configuration, platform, propertyName, out newLocation);
                }

                if (newLocation == PropertyStorageLocations.Unknown)
                {
                    newLocation = defaultLocation;
                }

                isLoading = true;
                try {
                    this.Value    = GenericConverter.FromString(v, defaultValue);
                    this.Location = newLocation;
                } finally {
                    isLoading = false;
                }
            }
Exemplo n.º 5
0
 public void Set <T>(T value)
 {
     if (location == PropertyStorageLocations.Unknown)
     {
         location = defaultLocation;
     }
     helper.SetProperty(property, value, treatPropertyValueAsLiteral, location);
 }
Exemplo n.º 6
0
			public ProjectProperty(string name, string value, string configuration, string platform, PropertyStorageLocations location)
			{
				this.Name = name;
				this.Value = value;
				this.Configuration = configuration;
				this.Platform = platform;
				this.Location = location;
			}
Exemplo n.º 7
0
 public ProjectProperty(string name, string value, string configuration, string platform, PropertyStorageLocations location)
 {
     this.Name          = name;
     this.Value         = value;
     this.Configuration = configuration;
     this.Platform      = platform;
     this.Location      = location;
 }
Exemplo n.º 8
0
            public ProjectProperty(ProjectOptionPanel parentPanel, string propertyName, T defaultValue, PropertyStorageLocations defaultLocation, bool treatPropertyValueAsLiteral)
            {
                this.parentPanel                 = parentPanel;
                this.propertyName                = propertyName;
                this.defaultValue                = defaultValue;
                this.defaultLocation             = defaultLocation;
                this.treatPropertyValueAsLiteral = treatPropertyValueAsLiteral;

                this.val      = defaultValue;
                this.location = defaultLocation;
            }
		ToolStripMenuItem CreateMenuItem(string text, PropertyStorageLocations location)
		{
			ToolStripMenuItem item = new ToolStripMenuItem(StringParser.Parse(text));
			item.CheckOnClick = true;
			item.CheckedChanged += delegate {
				if (item.Checked) {
					StorageLocation |= location;
				} else {
					StorageLocation &= ~location;
				}
			};
			return item;
		}
 static PropertyStorageLocations CoerceLocation(PropertyStorageLocations location)
 {
     if ((location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) != 0)
     {
         // remove 'Base' flag if any of the specific flags is set
         location &= ~PropertyStorageLocations.Base;
     }
     else
     {
         // otherwise, add 'Base' flag
         location |= PropertyStorageLocations.Base;
     }
     return(location);
 }
Exemplo n.º 11
0
        public ProjectProperty <T> GetProperty <T>(string propertyName, T defaultValue,
                                                   PropertyStorageLocations defaultLocation = PropertyStorageLocations.Base)
        {
            IProjectProperty existingProperty;

            if (projectProperties.TryGetValue(propertyName, out existingProperty))
            {
                return((ProjectProperty <T>)existingProperty);
            }

            ProjectProperty <T> newProperty = new ProjectProperty <T>(this, propertyName, defaultValue, defaultLocation, true);

            projectProperties.Add(propertyName, newProperty);
            return(newProperty);
        }
Exemplo n.º 12
0
        public T GetProperty <T>(string propertyName, T defaultValue,
                                 bool treatPropertyValueAsLiteral,
                                 out PropertyStorageLocations location)
        {
            string v;

            if (treatPropertyValueAsLiteral)
            {
                v = project.GetProperty(configuration, platform, propertyName, out location);
            }
            else
            {
                v = project.GetUnevalatedProperty(configuration, platform, propertyName, out location);
            }
            return(GenericConverter.FromString(v, defaultValue));
        }
Exemplo n.º 13
0
        static object CoerceLocation(DependencyObject d, object baseValue)
        {
            PropertyStorageLocations location = (PropertyStorageLocations)baseValue;

            if ((location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) != 0)
            {
                // remove 'Base' flag if any of the specific flags is set
                location &= ~PropertyStorageLocations.Base;
            }
            else
            {
                // otherwise, add 'Base' flag
                location |= PropertyStorageLocations.Base;
            }
            return(location);
        }
Exemplo n.º 14
0
        ToolStripMenuItem CreateMenuItem(string text, PropertyStorageLocations location)
        {
            ToolStripMenuItem item = new ToolStripMenuItem(StringParser.Parse(text));

            item.CheckOnClick    = true;
            item.CheckedChanged += delegate {
                if (item.Checked)
                {
                    StorageLocation |= location;
                }
                else
                {
                    StorageLocation &= ~location;
                }
            };
            return(item);
        }
Exemplo n.º 15
0
        public ProjectProperty <string> GetProperty(string propertyName, string defaultValue,
                                                    TextBoxEditMode textBoxEditMode          = TextBoxEditMode.EditEvaluatedProperty,
                                                    PropertyStorageLocations defaultLocation = PropertyStorageLocations.Base)
        {
            IProjectProperty existingProperty;

            if (projectProperties.TryGetValue(propertyName, out existingProperty))
            {
                return((ProjectProperty <string>)existingProperty);
            }

            bool treatAsLiteral = (textBoxEditMode == TextBoxEditMode.EditEvaluatedProperty);
            ProjectProperty <string> newProperty = new ProjectProperty <string>(this, propertyName, defaultValue, defaultLocation, treatAsLiteral);

            projectProperties.Add(propertyName, newProperty);
            return(newProperty);
        }
Exemplo n.º 16
0
        internal static PropertyStorageLocations GetLocationFromCondition(string condition)
        {
            if (string.IsNullOrEmpty(condition))
            {
                return(PropertyStorageLocations.Base);
            }
            PropertyStorageLocations location = 0;             // 0 is unknown

            if (condition.IndexOf("$(Configuration)", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                location |= PropertyStorageLocations.ConfigurationSpecific;
            }
            if (condition.IndexOf("$(Platform)", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                location |= PropertyStorageLocations.PlatformSpecific;
            }
            return(location);
        }
        MenuItem CreateMenuItem(string text, PropertyStorageLocations location)
        {
            MenuItem item = new MenuItem();

            item.SetValueToExtension(MenuItem.HeaderProperty, new StringParseExtension(text));
            item.Click += delegate(object sender, RoutedEventArgs e) {
                if ((this.Location & location) == 0)
                {
                    SetCurrentValue(LocationProperty, CoerceLocation(this.Location | location));
                }
                else
                {
                    SetCurrentValue(LocationProperty, CoerceLocation(this.Location & ~location));
                }
                e.Handled = true;
            };
            return(item);
        }
Exemplo n.º 18
0
        internal static PropertyStorageLocations GetLocationFromCondition(string condition)
        {
            if (string.IsNullOrEmpty(condition))
            {
                return(PropertyStorageLocations.Base);
            }
            PropertyStorageLocations location = 0;             // 0 is unknown

            if (condition.Contains("$(Configuration)"))
            {
                location |= PropertyStorageLocations.ConfigurationSpecific;
            }
            if (condition.Contains("$(Platform)"))
            {
                location |= PropertyStorageLocations.PlatformSpecific;
            }
            return(location);
        }
Exemplo n.º 19
0
        public ProjectProperty <T> GetProperty <T>(string propertyName, T defaultValue,
                                                   PropertyStorageLocations defaultLocation = PropertyStorageLocations.Base)
        {
            ILoadSaveCallback existingProperty;

            if (projectProperties.TryGetValue(propertyName, out existingProperty))
            {
                return((ProjectProperty <T>)existingProperty);
            }

            ProjectProperty <T> newProperty = new ProjectProperty <T>(this, propertyName, defaultValue, defaultLocation, true);

            projectProperties.Add(propertyName, newProperty);
            if (isLoaded)
            {
                newProperty.Load(project, activeConfiguration, activePlatform);
            }
            return(newProperty);
        }
Exemplo n.º 20
0
        public ProjectProperty <string> GetProperty(string propertyName, string defaultValue,
                                                    TextBoxEditMode textBoxEditMode          = TextBoxEditMode.EditEvaluatedProperty,
                                                    PropertyStorageLocations defaultLocation = PropertyStorageLocations.Base)
        {
            ILoadSaveCallback existingProperty;

            if (projectProperties.TryGetValue(propertyName, out existingProperty))
            {
                return((ProjectProperty <string>)existingProperty);
            }

            bool treatAsLiteral = (textBoxEditMode == TextBoxEditMode.EditEvaluatedProperty);
            ProjectProperty <string> newProperty = new ProjectProperty <string>(this, propertyName, defaultValue, defaultLocation, treatAsLiteral);

            projectProperties.Add(propertyName, newProperty);
            if (isLoaded)
            {
                newProperty.Load(project, activeConfiguration, activePlatform);
            }
            return(newProperty);
        }
Exemplo n.º 21
0
        public static Image CreateImage(PropertyStorageLocations location)
        {
            Bitmap bmp = new Bitmap(12, 12);

            using (Graphics g = Graphics.FromImage(bmp)) {
                g.Clear(Color.Transparent);
                Brush circleBrush;
                switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific)
                {
                case PropertyStorageLocations.ConfigurationSpecific:
                    circleBrush = Brushes.Blue;
                    break;

                case PropertyStorageLocations.PlatformSpecific:
                    circleBrush = Brushes.Red;
                    break;

                case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
                    circleBrush = Brushes.Violet;
                    break;

                default:
                    circleBrush = Brushes.Black;
                    break;
                }
                if ((location & PropertyStorageLocations.UserFile) == PropertyStorageLocations.UserFile)
                {
                    g.FillEllipse(circleBrush, 0, 0, 7, 7);
                    DrawU(g, 7, 5);
                }
                else
                {
                    g.FillEllipse(circleBrush, 2, 2, 8, 8);
                }
            }
            return(bmp);
        }
Exemplo n.º 22
0
		/// <summary>
		/// Retrieves the raw value of the property '<paramref name="propertyName"/>' from the
		/// specified configuration/platform.
		/// </summary>
		/// <param name="configuration">The configuration to use.</param>
		/// <param name="platform">The platform to use.</param>
		/// <param name="propertyName">The name of the MSBuild property to read.</param>
		/// <param name="location">[Out], the storage location where the property was found</param>
		/// <returns>The raw value of the property, or null if the property doesn't exist</returns>
		public string GetUnevalatedProperty(string configuration, string platform,
		                                    string propertyName,
		                                    out PropertyStorageLocations location)
		{
			using (var c = OpenConfiguration(configuration, platform)) {
				bool wasHiddenByImportedProperty;
				var prop = c.GetNonImportedProperty(propertyName, out wasHiddenByImportedProperty);
				if (prop != null) {
					location = c.GetLocation(prop);
					return prop.UnevaluatedValue;
				} else if (wasHiddenByImportedProperty) {
					return GetAnyUnevaluatedPropertyValue(configuration, platform, propertyName, out location);
				} else {
					location = PropertyStorageLocations.Unknown;
					return null;
				}
			}
		}
Exemplo n.º 23
0
		/// <summary>
		/// Finds the <c>BuildProperty</c> object used to store <paramref name="propertyName"/>
		/// in the specified configuration/platform.
		/// </summary>
		/// <param name="configuration">The configuration to use.</param>
		/// <param name="platform">The platform to use.</param>
		/// <param name="propertyName">The property to look for.</param>
		/// <param name="group">[Out], the property group in which the property was found</param>
		/// <param name="location">[Out], the storage location the condition of the property
		/// group was referring to</param>
		protected MSBuild.BuildProperty FindPropertyObject(string configuration, string platform,
		                                                   string propertyName,
		                                                   out MSBuild.BuildPropertyGroup group,
		                                                   out PropertyStorageLocations location)
		{
			if (string.IsNullOrEmpty(configuration)) configuration = ActiveConfiguration;
			if (string.IsNullOrEmpty(platform))      platform = ActivePlatform;
			
			// We need to use ToArray because EvaluateMSBuildCondition invalidates the list
			// of property groups.
			foreach (MSBuild.BuildPropertyGroup g
			         in Linq.ToList(Linq.CastTo<MSBuild.BuildPropertyGroup>(project.PropertyGroups)))
			{
				if (g.IsImported) {
					continue;
				}
				MSBuild.BuildProperty property = MSBuildInternals.GetProperty(g, propertyName);
				if (property == null)
					continue;
				if (EvaluateMSBuildCondition(configuration, platform, g.Condition)) {
					location = MSBuildInternals.GetLocationFromCondition(g.Condition);
					group = g;
					return property;
				}
			}
			location = PropertyStorageLocations.Unknown;
			group = null;
			return null;
		}
Exemplo n.º 24
0
		/// <summary>
		/// Retrieves the raw value of the property '<paramref name="propertyName"/>' from the
		/// specified configuration/platform.
		/// </summary>
		/// <param name="configuration">The configuration to use.</param>
		/// <param name="platform">The platform to use.</param>
		/// <param name="propertyName">The name of the MSBuild property to read.</param>
		/// <param name="location">[Out], the storage location where the property was found</param>
		/// <returns>The raw value of the property, or null if the property doesn't exist</returns>
		public string GetUnevalatedProperty(string configuration, string platform,
		                                    string propertyName,
		                                    out PropertyStorageLocations location)
		{
			lock (SyncRoot) {
				MSBuild.BuildPropertyGroup group;
				MSBuild.BuildProperty prop = FindPropertyObject(configuration, platform, propertyName,
				                                                out group, out location);
				if (prop == null)
					return null;
				else
					return prop.Value;
			}
		}
Exemplo n.º 25
0
		/// <summary>
		/// Retrieves the raw value of the property '<paramref name="propertyName"/>' from the
		/// specified configuration/platform.
		/// </summary>
		/// <param name="configuration">The configuration to use.</param>
		/// <param name="platform">The platform to use.</param>
		/// <param name="propertyName">The name of the MSBuild property to read.</param>
		/// <param name="location">[Out], the storage location where the property was found</param>
		/// <returns>The raw value of the property, or null if the property doesn't exist</returns>
		public string GetUnevalatedProperty(string configuration, string platform,
		                                    string propertyName,
		                                    out PropertyStorageLocations location)
		{
			using (var c = OpenConfiguration(configuration, platform)) {
				var prop = c.GetNonImportedProperty(propertyName);
				if (prop != null) {
					location = c.GetLocation(prop);
					return prop.UnevaluatedValue;
				} else {
					location = PropertyStorageLocations.Unknown;
					return null;
				}
			}
		}
Exemplo n.º 26
0
		MenuItem CreateMenuItem(string text, PropertyStorageLocations location)
		{
			MenuItem item = new MenuItem();
			item.SetValueToExtension(MenuItem.HeaderProperty, new StringParseExtension(text));
			item.Click += delegate(object sender, RoutedEventArgs e) {
				if ((this.Location & location) == 0) {
					this.Location |= location;
				} else {
					this.Location &= ~location;
				}
				e.Handled = true;
			};
			return item;
		}
Exemplo n.º 27
0
		ProjectPropertyChangedEventArgs SetPropertyInternal(string configuration, string platform,
		                                                    string propertyName, string newValue,
		                                                    PropertyStorageLocations location,
		                                                    bool treatPropertyValueAsLiteral)
		{
			PropertyStorageLocations oldLocation;
			ProjectPropertyGroupElement existingPropertyGroup;
			ProjectPropertyElement existingProperty = FindPropertyObject(configuration, platform,
			                                                             propertyName,
			                                                             out existingPropertyGroup,
			                                                             out oldLocation);
			// Try to get accurate oldLocation
			if (oldLocation == PropertyStorageLocations.Unknown) {
				oldLocation = FindExistingPropertyInAllConfigurations(propertyName);
				if (oldLocation == PropertyStorageLocations.Unknown) {
					oldLocation = PropertyStorageLocations.Base;
				}
			}
			// Set new location to old location if storage location should remain unchanged
			if (location == PropertyStorageLocations.Unchanged) {
				location = oldLocation;
			}
			// determine the insertion position for the property
			PropertyPosition propertyInsertionPosition;
			if (saveAfterImportsProperties.Contains(propertyName)) {
				propertyInsertionPosition = PropertyPosition.UseExistingOrCreateAfterLastImport;
			} else {
				propertyInsertionPosition = PropertyPosition.UseExistingOrCreateAfterLastPropertyGroup;
			}
			// get the project file where the property should be stored
			ProjectRootElement targetProject;
			if ((location & PropertyStorageLocations.UserFile) == PropertyStorageLocations.UserFile)
				targetProject = userProjectFile;
			else
				targetProject = projectFile;
			
			if (oldLocation != location) {
				// move existing properties to new location, then use the normal property
				// setting code at end of this method
				
				switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) {
					case 0:
						// Set base property - remove all previous copies of the property
						RemovePropertyCompletely(propertyName);
						break;
					case PropertyStorageLocations.ConfigurationSpecific:
						// Get any value usable as existing property value (once per configuration)
						Dictionary<string, string> oldValuesConf = new Dictionary<string, string>();
						foreach (string conf in this.ConfigurationNames) {
							oldValuesConf[conf] = GetAnyUnevaluatedPropertyValue(conf, null, propertyName);
						}
						
						// Remove the property
						RemovePropertyCompletely(propertyName);
						
						// Recreate the property using the saved value
						foreach (KeyValuePair<string, string> pair in oldValuesConf) {
							if (pair.Value != null) {
								MSBuildSetProperty(targetProject, propertyName, pair.Value,
								                   CreateCondition(pair.Key, null, location),
								                   propertyInsertionPosition,
								                   false);
							}
						}
						break;
					case PropertyStorageLocations.PlatformSpecific:
						// Get any value usable as existing property value (once per platform)
						Dictionary<string, string> oldValuesPlat = new Dictionary<string, string>();
						foreach (string plat in this.PlatformNames) {
							oldValuesPlat[plat] = GetAnyUnevaluatedPropertyValue(null, plat, propertyName);
						}
						
						// Remove the property
						RemovePropertyCompletely(propertyName);
						
						// Recreate the property using the saved value
						foreach (KeyValuePair<string, string> pair in oldValuesPlat) {
							if (pair.Value != null) {
								MSBuildSetProperty(targetProject, propertyName, pair.Value,
								                   CreateCondition(null, pair.Key, location),
								                   propertyInsertionPosition,
								                   false);
							}
						}
						break;
					case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
						// Get any value usable as existing property value (once per configuration+platform)
						Dictionary<StringPair, string> oldValues = new Dictionary<StringPair, string>();
						foreach (string conf in this.ConfigurationNames) {
							foreach (string plat in this.PlatformNames) {
								oldValues[new StringPair(conf, plat)] = GetAnyUnevaluatedPropertyValue(conf, plat, propertyName);
							}
						}
						
						// Remove the property
						RemovePropertyCompletely(propertyName);
						
						// Recreate the property using the saved value
						foreach (KeyValuePair<StringPair, string> pair in oldValues) {
							if (pair.Value != null) {
								MSBuildSetProperty(targetProject, propertyName, pair.Value,
								                   CreateCondition(pair.Key.Item1, pair.Key.Item2, location),
								                   propertyInsertionPosition,
								                   false);
							}
						}
						break;
					default:
						throw new NotSupportedException();
				}
				
				// update existingProperty and existingPropertyGroup after the move operation
				PropertyStorageLocations tmpLocation;
				existingProperty = FindPropertyObject(configuration,
				                                      platform,
				                                      propertyName,
				                                      out existingPropertyGroup,
				                                      out tmpLocation);
			}
			ProjectPropertyChangedEventArgs args;
			args = new ProjectPropertyChangedEventArgs(propertyName);
			args.Configuration = configuration;
			args.Platform = platform;
			args.NewLocation = location;
			args.OldLocation = oldLocation;
			if (newValue != null) {
				args.NewValue = treatPropertyValueAsLiteral ? MSBuildInternals.Escape(newValue) : newValue;
			}
			
			if (existingPropertyGroup != null && existingProperty != null) {
				// update or delete existing property
				args.OldValue = existingProperty.Value;
				MSBuildSetProperty(targetProject, propertyName, newValue ?? "",
				                   existingPropertyGroup.Condition,
				                   propertyInsertionPosition,
				                   treatPropertyValueAsLiteral);
				if (newValue == null) {
					// delete existing property
					existingPropertyGroup.RemoveChild(existingProperty);
					
					if (existingPropertyGroup.Count == 0) {
						targetProject.RemoveChild(existingPropertyGroup);
					}
				}
			} else if (newValue != null) {
				// create new property
				MSBuildSetProperty(targetProject, propertyName, newValue,
				                   CreateCondition(configuration, platform, location),
				                   propertyInsertionPosition,
				                   treatPropertyValueAsLiteral);
			}
			return args;
		}
 static PropertyStorageLocations CoerceLocation(PropertyStorageLocations location)
 {
     if ((location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) != 0) {
         // remove 'Base' flag if any of the specific flags is set
         location &= ~PropertyStorageLocations.Base;
     } else {
         // otherwise, add 'Base' flag
         location |= PropertyStorageLocations.Base;
     }
     return location;
 }
        /// <summary>
        /// Creates an MSBuild condition string.
        /// configuration and platform may be only <c>null</c> if they are not required (as specified by the
        /// storage location), otherwise an ArgumentNullException is thrown.
        /// </summary>
        internal static string CreateCondition(string configuration, string platform, PropertyStorageLocations location)
        {
            switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific)
            {
            case PropertyStorageLocations.ConfigurationSpecific:
                if (configuration == null)
                {
                    throw new ArgumentNullException("configuration");
                }
                return(" '$(Configuration)' == '" + configuration + "' ");

            case PropertyStorageLocations.PlatformSpecific:
                if (platform == null)
                {
                    throw new ArgumentNullException("platform");
                }
                return(" '$(Platform)' == '" + platform + "' ");

            case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
                if (platform == null)
                {
                    throw new ArgumentNullException("platform");
                }
                if (configuration == null)
                {
                    throw new ArgumentNullException("configuration");
                }
                return(" '$(Configuration)|$(Platform)' == '" + configuration + "|" + platform + "' ");

            default:
                return(null);
            }
        }
 public static Image CreateImage(PropertyStorageLocations location)
 {
     Bitmap bmp = new Bitmap(12, 12);
     using (Graphics g = Graphics.FromImage(bmp)) {
         g.Clear(Color.Transparent);
         Brush circleBrush;
         switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) {
             case PropertyStorageLocations.ConfigurationSpecific:
                 circleBrush = Brushes.Blue;
                 break;
             case PropertyStorageLocations.PlatformSpecific:
                 circleBrush = Brushes.Red;
                 break;
             case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
                 circleBrush = Brushes.Violet;
                 break;
             default:
                 circleBrush = Brushes.Black;
                 break;
         }
         if ((location & PropertyStorageLocations.UserFile) == PropertyStorageLocations.UserFile) {
             g.FillEllipse(circleBrush, 0, 0, 7, 7);
             DrawU(g, 7, 5);
         } else {
             g.FillEllipse(circleBrush, 2, 2, 8, 8);
         }
     }
     return bmp;
 }
Exemplo n.º 31
0
		/// <summary>
		/// Finds the <c>BuildProperty</c> object used to store <paramref name="propertyName"/>
		/// in the specified configuration/platform.
		/// </summary>
		/// 
		/// Warning: you need to lock(project.SyncRoot) around calls to GetAllProperties
		/// until you no longer need to access the BuildProperty objects!
		/// <param name="configuration">The configuration to use.</param>
		/// <param name="platform">The platform to use.</param>
		/// <param name="propertyName">The property to look for.</param>
		/// <param name="group">[Out], the property group in which the property was found</param>
		/// <param name="location">[Out], the storage location the condition of the property
		/// group was referring to</param>
		protected ProjectPropertyElement FindPropertyObject(string configuration, string platform,
		                                                    string propertyName,
		                                                    out ProjectPropertyGroupElement group,
		                                                    out PropertyStorageLocations location)
		{
			using (var c = OpenConfiguration(configuration, platform)) {
				bool wasHiddenByImportedProperty;
				var prop = c.GetNonImportedProperty(propertyName, out wasHiddenByImportedProperty);
				if (prop != null) {
					group = (ProjectPropertyGroupElement)prop.Xml.Parent;
					location = c.GetLocation(prop);
					return prop.Xml;
				} else {
					group = null;
					location = PropertyStorageLocations.Unknown;
					return null;
				}
			}
		}
Exemplo n.º 32
0
		void SetIsCheckedOnMenu(PropertyStorageLocations location)
		{
			((MenuItem)contextMenu.Items[0]).IsChecked = (location & PropertyStorageLocations.ConfigurationSpecific) != 0;
			((MenuItem)contextMenu.Items[1]).IsChecked = (location & PropertyStorageLocations.PlatformSpecific) != 0;
			((MenuItem)contextMenu.Items[2]).IsChecked = (location & PropertyStorageLocations.UserFile) != 0;
		}
Exemplo n.º 33
0
		string GetAnyUnevaluatedPropertyValue(string configuration, string platform, string propertyName, out PropertyStorageLocations location)
		{
			// first try main project file, then try user project file
			ProjectPropertyElement p = GetAnyUnevaluatedProperty(projectFile, configuration, platform, propertyName, out location);
			if (p == null) {
				p = GetAnyUnevaluatedProperty(userProjectFile, configuration, platform, propertyName, out location);
				if (p != null)
					location |= PropertyStorageLocations.UserFile;
			}
			return p != null ? p.Value : null;
		}
Exemplo n.º 34
0
		static ProjectPropertyElement GetAnyUnevaluatedProperty(ProjectRootElement project, string configuration, string platform, string propertyName, out PropertyStorageLocations location)
		{
			location = PropertyStorageLocations.Unknown;
			foreach (var g in project.PropertyGroups) {
				var property = g.Properties.FirstOrDefault(p => MSBuildInternals.PropertyNameComparer.Equals(p.Name, propertyName));
				if (property == null)
					continue;
				string gConfiguration, gPlatform;
				MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
				                                                          out gConfiguration,
				                                                          out gPlatform);
				if ((configuration == null || configuration == gConfiguration || gConfiguration == null)
				    && (platform == null || platform == gPlatform || gPlatform == null))
				{
					if (gConfiguration == null && gPlatform == null) {
						location = PropertyStorageLocations.Base;
					} else {
						location = 0;
						if (gConfiguration != null)
							location |= PropertyStorageLocations.ConfigurationSpecific;
						if (gPlatform != null)
							location |= PropertyStorageLocations.PlatformSpecific;
					};
					return property;
				}
			}
			return null;
		}
Exemplo n.º 35
0
		/// <summary>
		/// Sets an MSBuild property.
		/// </summary>
		/// <param name="configuration">The configuration to change the property in.</param>
		/// <param name="platform">The platform to change the property in.</param>
		/// <param name="propertyName">The name of the property to set.</param>
		/// <param name="newValue">The new value of the property.
		/// Use <c>null</c> to remove the property.</param>
		/// <param name="location">The location to save the property in.
		/// Use PropertyStorageLocations.Unchanged to keep the old location.</param>
		/// <param name="treatPropertyValueAsLiteral"><c>True</c> to treat the
		/// <paramref name="newValue"/> as literal (escape it before saving).
		/// </param>
		public void SetProperty(string configuration, string platform,
		                        string propertyName, string newValue,
		                        PropertyStorageLocations location,
		                        bool treatPropertyValueAsLiteral)
		{
			ProjectPropertyChangedEventArgs args;
			lock (SyncRoot) {
				args = SetPropertyInternal(configuration, platform, propertyName, newValue, location, treatPropertyValueAsLiteral);
			}
			if (args.NewValue != args.OldValue || args.NewLocation != args.OldLocation) {
				OnPropertyChanged(args);
			}
		}
 void SetIsCheckedOnMenu(PropertyStorageLocations location)
 {
     ((MenuItem)contextMenu.Items[0]).IsChecked = (location & PropertyStorageLocations.ConfigurationSpecific) != 0;
     ((MenuItem)contextMenu.Items[1]).IsChecked = (location & PropertyStorageLocations.PlatformSpecific) != 0;
     ((MenuItem)contextMenu.Items[2]).IsChecked = (location & PropertyStorageLocations.UserFile) != 0;
 }
Exemplo n.º 37
0
		/// <summary>
		/// Creates an MSBuild condition string.
		/// configuration and platform may be only <c>null</c> if they are not required (as specified by the
		/// storage location), otherwise an ArgumentNullException is thrown.
		/// </summary>
		internal static string CreateCondition(string configuration, string platform, PropertyStorageLocations location)
		{
			switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) {
				case PropertyStorageLocations.ConfigurationSpecific:
					if (configuration == null)
						throw new ArgumentNullException("configuration");
					return " '$(Configuration)' == '" + configuration + "' ";
				case PropertyStorageLocations.PlatformSpecific:
					if (platform == null)
						throw new ArgumentNullException("platform");
					return " '$(Platform)' == '" + platform + "' ";
				case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
					if (platform == null)
						throw new ArgumentNullException("platform");
					if (configuration == null)
						throw new ArgumentNullException("configuration");
					return " '$(Configuration)|$(Platform)' == '" + configuration + "|" + platform + "' ";
				default:
					return null;
			}
		}
		/// <summary>
		/// Finds the <c>BuildProperty</c> object used to store <paramref name="propertyName"/>
		/// in the specified configuration/platform.
		/// </summary>
		/// 
		/// Warning: you need to lock(project.SyncRoot) around calls to GetAllProperties
		/// until you no longer need to access the BuildProperty objects!
		/// <param name="configuration">The configuration to use.</param>
		/// <param name="platform">The platform to use.</param>
		/// <param name="propertyName">The property to look for.</param>
		/// <param name="group">[Out], the property group in which the property was found</param>
		/// <param name="location">[Out], the storage location the condition of the property
		/// group was referring to</param>
		protected MSBuild.BuildProperty FindPropertyObject(string configuration, string platform,
		                                                   string propertyName,
		                                                   out MSBuild.BuildPropertyGroup group,
		                                                   out PropertyStorageLocations location)
		{
			if (string.IsNullOrEmpty(configuration)) configuration = ActiveConfiguration;
			if (string.IsNullOrEmpty(platform))      platform = ActivePlatform;
			
			// First try main project file
			MSBuild.BuildProperty p = FindPropertyObjectInternal(project, configuration, platform, propertyName, out group);
			if (p != null) {
				location = MSBuildInternals.GetLocationFromCondition(group.Condition);
				return p;
			} else {
				// try user project file
				p = FindPropertyObjectInternal(userProject, configuration, platform, propertyName, out group);
				if (p != null) {
					location = PropertyStorageLocations.UserFile
						| MSBuildInternals.GetLocationFromCondition(group.Condition);
					return p;
				} else {
					location = PropertyStorageLocations.Unknown;
					group = null;
					return null;
				}
			}
		}