Exemplo n.º 1
0
        public TextToolboxNode(string text)
        {
            Text = text;

            //TODO: Use additional filters to limit to a specific host
            ToolboxItemFilterAttribute[] filters  = new ToolboxItemFilterAttribute [1];
            filters[0] = new ToolboxItemFilterAttribute ("AspNetEdit.RawText", ToolboxItemFilterType.Require);
            base.ItemFilters = filters;
        }
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            ToolboxItemFilterAttribute attribute = obj as ToolboxItemFilterAttribute;

            return(((attribute != null) && attribute.FilterType.Equals(this.FilterType)) && attribute.FilterString.Equals(this.FilterString));
        }
        /// <include file='doc\ToolboxItemFilterAttribute.uex' path='docs/doc[@for="ToolboxItemFilterAttribute.Equals"]/*' />
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            ToolboxItemFilterAttribute other = obj as ToolboxItemFilterAttribute;

            return(other != null && other.FilterType.Equals(FilterType) && other.FilterString.Equals(FilterString));
        }
        public override bool Match(object obj)
        {
            ToolboxItemFilterAttribute attribute = obj as ToolboxItemFilterAttribute;

            if (attribute == null)
            {
                return(false);
            }
            if (!attribute.FilterString.Equals(this.FilterString))
            {
                return(false);
            }
            return(true);
        }
        /// <include file='doc\ToolboxItemFilterAttribute.uex' path='docs/doc[@for="ToolboxItemFilterAttribute.Match"]/*' />
        public override bool Match(object obj)
        {
            ToolboxItemFilterAttribute other = obj as ToolboxItemFilterAttribute;

            if (other == null)
            {
                return(false);
            }

            // different filter string kills a match immediately.
            //
            if (!other.FilterString.Equals(FilterString))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        //evaluate a filter attribute against a list, and check whther permitted
        private bool FilterPermitted(ToolboxItemFilterAttribute desFa, ICollection filterAgainst, object rootDesigner)
        {
            switch (desFa.FilterType) {
                case ToolboxItemFilterType.Allow:
                    //this is really for matching some other filter string against
                    return true;

                case ToolboxItemFilterType.Custom:
                    IToolboxUser tbUser = rootDesigner as IToolboxUser;
                    if (tbUser == null)
                        throw new ArgumentException ("Host's root designer does not support IToolboxUser interface.");
                    return EvaluateCustomFilter (tbUser);

                case ToolboxItemFilterType.Prevent:
                    //if host and toolboxitem have same filterstring, then not permitted
                    foreach (ToolboxItemFilterAttribute itemFa in filterAgainst)
                        if (desFa.Match (itemFa))
                            return false;
                    return true;

                case ToolboxItemFilterType.Require:
                    //if host and toolboxitem have same filterstring, then permitted, unless one is prevented
                    foreach (ToolboxItemFilterAttribute itemFa in filterAgainst)
                        if (desFa.Match (itemFa) && (desFa.FilterType != ToolboxItemFilterType.Prevent))
                            return true;
                    return false;
            }
            throw new InvalidOperationException ("Unexpected ToolboxItemFilterType value.");
        }
		//evaluate a filter attribute against a list, and check whether permitted
		private bool FilterPermitted (ItemToolboxNode node, ToolboxItemFilterAttribute desFa, 
		    ICollection<ToolboxItemFilterAttribute> filterAgainst, IToolboxConsumer consumer)
		{
			switch (desFa.FilterType) {
				case ToolboxItemFilterType.Allow:
					//this is really for matching some other filter string against
					return true;
				
				case ToolboxItemFilterType.Custom:
					return consumer.CustomFilterSupports (node);
					
				case ToolboxItemFilterType.Prevent:
					//if host and toolboxitem have same filterstring, then not permitted
					foreach (ToolboxItemFilterAttribute itemFa in filterAgainst)
						if (desFa.Match (itemFa))
							return false;
					return true;
				
				case ToolboxItemFilterType.Require:
					//if host and toolboxitem have same filterstring, then permitted, unless one is prevented
					foreach (ToolboxItemFilterAttribute itemFa in filterAgainst)
						if (desFa.Match (itemFa) && (desFa.FilterType != ToolboxItemFilterType.Prevent))
							return true;
					return false;
			}
			throw new InvalidOperationException ("Unexpected ToolboxItemFilterType value.");
		}
Exemplo n.º 8
0
        /// <include file='doc\ToolboxItem.uex' path='docs/doc[@for="ToolboxItem.ValidatePropertyValue"]/*' />
        /// <devdoc>
        ///    This is called whenever a value is set in the property dictionary.  It gives you a chance
        ///    to change the value of an object before comitting it, our reject it by throwing an 
        ///    exception.
        /// </devdoc>
        protected virtual object ValidatePropertyValue(string propertyName, object value) {
            switch (propertyName) {
                case "AssemblyName":
                    ValidatePropertyType(propertyName, value, typeof(AssemblyName), true);
                    break;

                case "Bitmap":
                    ValidatePropertyType(propertyName, value, typeof(Bitmap), true);
                    break;

                case "Company":
                case "Description":
                case "DisplayName":
                case "TypeName":
                    ValidatePropertyType(propertyName, value, typeof(string), true);
                    if (value == null) value = string.Empty;

                    break;

                case "Filter":
                    ValidatePropertyType(propertyName, value, typeof(ICollection), true);

                    int filterCount = 0;
                    ICollection col = (ICollection)value;

                    if (col != null) {
                        foreach (object f in col) {
                            if (f is ToolboxItemFilterAttribute) {
                                filterCount++;
                            }
                        }
                    }

                    ToolboxItemFilterAttribute[] filter = new ToolboxItemFilterAttribute[filterCount];

                    if (col != null) {
                        filterCount = 0;
                        foreach (object f in col) {
                            ToolboxItemFilterAttribute tfa = f as ToolboxItemFilterAttribute;
                            if (tfa != null) {
                                filter[filterCount++] = tfa;
                            }
                        }
                    }

                    value = filter;
                    break;

                case "IsTransient":
                    ValidatePropertyType(propertyName, value, typeof(bool), false);
                    break;
            }
            return value;
        }
Exemplo n.º 9
0
        /// <include file='doc\ToolboxItem.uex' path='docs/doc[@for="ToolboxItem.FilterPropertyValue"]/*' />
        /// <devdoc>
        ///    Filters a property value before returning it.  This allows a property to always clone values,
        ///    or to provide a default value when none exists.
        /// </devdoc>
        protected virtual object FilterPropertyValue(string propertyName, object value) {
            switch (propertyName) {
                case "AssemblyName":
                    if (value != null) value = ((AssemblyName)value).Clone();

                    break;

                case "DisplayName":
                case "TypeName":
                    if (value == null) value = string.Empty;

                    break;

                case "Filter":
                    if (value == null) value = new ToolboxItemFilterAttribute[0];

                    break;

                case "IsTransient":
                    if (value == null) value = false;

                    break;
            }
            return value;
        }
Exemplo n.º 10
0
		protected virtual object ValidatePropertyValue (string propertyName, object value)
		{
			switch (propertyName) {
			case "AssemblyName":
				ValidatePropertyType (propertyName, value, typeof (AssemblyName), true);
				break;
			case "Bitmap":
				ValidatePropertyType (propertyName, value, typeof (Bitmap), true);
				break;
			case "Company":
			case "Description":
			case "DisplayName":
			case "TypeName":
				ValidatePropertyType (propertyName, value, typeof (string), true);
				if (value == null)
					value = String.Empty;
				break;
			case "IsTransient":
				ValidatePropertyType (propertyName, value, typeof (bool), false);
				break;
			case "Filter":
				ValidatePropertyType (propertyName, value, typeof (ToolboxItemFilterAttribute[]), true);
				if (value == null)
					value = new ToolboxItemFilterAttribute [0];
				break;
			case "DependentAssemblies":
				ValidatePropertyType (propertyName, value, typeof (AssemblyName[]), true);
				break;
			default:
				break;
			}
			return value;
		}
Exemplo n.º 11
0
		/// <summary>
		/// Remove a filter from the specified <see cref="ModelingToolboxItem"/>
		/// </summary>
		/// <param name="items">A list of existing items</param>
		/// <param name="itemIndexDictionary">A dictionary mapping from the item identifier to an index in the
		/// <paramref name="items"/> list. The dictionary should be created with <see cref="CreateIdentifierToIndexMap"/></param>
		/// <param name="itemId">The identifer of the item to modify</param>
		/// <param name="filterString">The filter string for the filter to remove</param>
		public static void RemoveFilterAttribute(IList<ModelingToolboxItem> items, IDictionary<string, int> itemIndexDictionary, string itemId, string filterString)
		{
			int itemIndex;
			if (itemIndexDictionary.TryGetValue(itemId, out itemIndex))
			{
				ModelingToolboxItem itemBase = items[itemIndex];
				ICollection baseFilters = itemBase.Filter;
				int baseFilterCount = baseFilters.Count;
				if (baseFilterCount != 0)
				{
					int removeCount = 0;
					foreach (object filter in baseFilters)
					{
						ToolboxItemFilterAttribute filterAttribute = filter as ToolboxItemFilterAttribute;
						if (filterAttribute == null || filterAttribute.FilterString == filterString)
						{
							++removeCount;
						}
					}
					if (removeCount == baseFilterCount)
					{
						itemBase.Filter = null;
					}
					else
					{
						ToolboxItemFilterAttribute[] newFilters = new ToolboxItemFilterAttribute[baseFilterCount - removeCount];
						int nextIndex = 0;
						foreach (object filter in baseFilters)
						{
							ToolboxItemFilterAttribute filterAttribute = filter as ToolboxItemFilterAttribute;
							if (filterAttribute != null && filterAttribute.FilterString != filterString)
							{
								newFilters[nextIndex] = filterAttribute;
								++nextIndex;
							}
						}
						itemBase.Filter = newFilters;
					}
				}
			}
		}
Exemplo n.º 12
0
		/// <summary>
		/// Add a filter to the specified <see cref="ModelingToolboxItem"/>
		/// </summary>
		/// <param name="items">A list of existing items</param>
		/// <param name="itemIndexDictionary">A dictionary mapping from the item identifier to an index in the
		/// <paramref name="items"/> list. The dictionary should be created with <see cref="CreateIdentifierToIndexMap"/></param>
		/// <param name="itemId">The identifer of the item to modify</param>
		/// <param name="filterAttribute">The filter attribute to add</param>
		public static void AddFilterAttribute(IList<ModelingToolboxItem> items, IDictionary<string, int> itemIndexDictionary, string itemId, ToolboxItemFilterAttribute filterAttribute)
		{
			int itemIndex;
			if (itemIndexDictionary.TryGetValue(itemId, out itemIndex))
			{
				ModelingToolboxItem itemBase = items[itemIndex];
				ICollection baseFilters = itemBase.Filter;
				int baseFilterCount = (baseFilters != null) ? baseFilters.Count : 0;
				ToolboxItemFilterAttribute[] newFilters = new ToolboxItemFilterAttribute[baseFilterCount + 1];
				if (baseFilterCount != 0)
				{
					baseFilters.CopyTo(newFilters, 0);
				}
				newFilters[baseFilterCount] = filterAttribute;
				itemBase.Filter = newFilters;
			}
		}
        protected virtual object ValidatePropertyValue(string propertyName, object value)
        {
            switch (propertyName)
            {
                case "AssemblyName":
                    this.ValidatePropertyType(propertyName, value, typeof(System.Reflection.AssemblyName), true);
                    return value;

                case "Bitmap":
                    this.ValidatePropertyType(propertyName, value, typeof(System.Drawing.Bitmap), true);
                    return value;

                case "Company":
                case "Description":
                case "DisplayName":
                case "TypeName":
                    this.ValidatePropertyType(propertyName, value, typeof(string), true);
                    if (value == null)
                    {
                        value = string.Empty;
                    }
                    return value;

                case "Filter":
                {
                    this.ValidatePropertyType(propertyName, value, typeof(ICollection), true);
                    int num = 0;
                    ICollection is2 = (ICollection) value;
                    if (is2 != null)
                    {
                        foreach (object obj2 in is2)
                        {
                            if (obj2 is ToolboxItemFilterAttribute)
                            {
                                num++;
                            }
                        }
                    }
                    ToolboxItemFilterAttribute[] attributeArray = new ToolboxItemFilterAttribute[num];
                    if (is2 != null)
                    {
                        num = 0;
                        foreach (object obj3 in is2)
                        {
                            ToolboxItemFilterAttribute attribute = obj3 as ToolboxItemFilterAttribute;
                            if (attribute != null)
                            {
                                attributeArray[num++] = attribute;
                            }
                        }
                    }
                    value = attributeArray;
                    return value;
                }
                case "IsTransient":
                    this.ValidatePropertyType(propertyName, value, typeof(bool), false);
                    return value;
            }
            return value;
        }
 protected virtual object FilterPropertyValue(string propertyName, object value)
 {
     string str = propertyName;
     if (str != null)
     {
         if (!(str == "AssemblyName"))
         {
             if ((str == "DisplayName") || (str == "TypeName"))
             {
                 if (value == null)
                 {
                     value = string.Empty;
                 }
                 return value;
             }
             if (str == "Filter")
             {
                 if (value == null)
                 {
                     value = new ToolboxItemFilterAttribute[0];
                 }
                 return value;
             }
             if ((str == "IsTransient") && (value == null))
             {
                 value = false;
             }
             return value;
         }
         if (value != null)
         {
             value = ((System.Reflection.AssemblyName) value).Clone();
         }
     }
     return value;
 }
 private static ICollection MergeFilter(ToolboxItem item)
 {
     ICollection filter = item.Filter;
     ArrayList list = new ArrayList();
     foreach (Attribute attribute in TypeDescriptor.GetAttributes(item))
     {
         if (attribute is ToolboxItemFilterAttribute)
         {
             list.Add(attribute);
         }
     }
     if ((filter == null) || (filter.Count == 0))
     {
         return list;
     }
     if (list.Count > 0)
     {
         Hashtable hashtable = new Hashtable(list.Count + filter.Count);
         foreach (Attribute attribute2 in list)
         {
             hashtable[attribute2.TypeId] = attribute2;
         }
         foreach (Attribute attribute3 in filter)
         {
             hashtable[attribute3.TypeId] = attribute3;
         }
         ToolboxItemFilterAttribute[] array = new ToolboxItemFilterAttribute[hashtable.Values.Count];
         hashtable.Values.CopyTo(array, 0);
         return array;
     }
     return filter;
 }
 public virtual ICollection GetFilter(ICollection creators)
 {
     ICollection is2 = this._filter;
     if (this._filter == null)
     {
         if (this._dataObject.GetDataPresent("CF_TOOLBOXITEMCONTAINER"))
         {
             byte[] data = (byte[]) this._dataObject.GetData("CF_TOOLBOXITEMCONTAINER");
             if (data != null)
             {
                 BinaryReader reader = new BinaryReader(new MemoryStream(data));
                 if (reader.ReadInt16() != 1)
                 {
                     this._filter = new ToolboxItemFilterAttribute[0];
                 }
                 else
                 {
                     short num2 = reader.ReadInt16();
                     ToolboxItemFilterAttribute[] attributeArray = new ToolboxItemFilterAttribute[num2];
                     for (short i = 0; i < num2; i = (short) (i + 1))
                     {
                         string filterString = reader.ReadString();
                         short num4 = reader.ReadInt16();
                         attributeArray[i] = new ToolboxItemFilterAttribute(filterString, (ToolboxItemFilterType) num4);
                     }
                     this._filter = attributeArray;
                 }
             }
             else
             {
                 this._filter = new ToolboxItemFilterAttribute[0];
             }
             return this._filter;
         }
         if (creators != null)
         {
             foreach (ToolboxItemCreator creator in creators)
             {
                 if (this._dataObject.GetDataPresent(creator.Format))
                 {
                     ToolboxItem item = creator.Create(this._dataObject);
                     if (item != null)
                     {
                         return MergeFilter(item);
                     }
                 }
             }
         }
     }
     return is2;
 }