コード例 #1
0
 internal static void EncodeToStream(ExtendedProperty attribute, Stream stream)
 {
     VarEnum interopTypeInfo;
     object data = attribute.Value;
     // NTRAID#T2-23063-2003/12/10-[....]: CODEQUALITY: Find better way to discover which properties should be persistable
     if (attribute.Id == KnownIds.DrawingFlags)
     {
         interopTypeInfo = VarEnum.VT_I4;
     }
     else if (attribute.Id == KnownIds.StylusTip)
     {
         interopTypeInfo = VarEnum.VT_I4;
     }
     else
     {
         // Find the type of the object if it's embedded in the stream
         if (UsesEmbeddedTypeInformation(attribute.Id))
         {
             interopTypeInfo = SerializationHelper.ConvertToVarEnum(attribute.Value.GetType(), true);
         }
         else // Otherwise treat this as byte array
         {
             interopTypeInfo = (VarEnum.VT_ARRAY | VarEnum.VT_UI1);
         }
     }
     EncodeAttribute(attribute.Id, data, interopTypeInfo, stream);
 }
コード例 #2
0
        /// <summary>
        /// Remove
        /// </summary>
        /// <param name="id">id</param>
        internal void Remove(Guid id)
        {
            if (!Contains(id))
            {
                throw new ArgumentException(SR.Get(SRID.EPGuidNotFound), "id");
            }

            ExtendedProperty propertyToRemove = GetExtendedPropertyById(id);

            System.Diagnostics.Debug.Assert(propertyToRemove != null);

            _extendedProperties.Remove(propertyToRemove);

            //
            // this value is bogus now
            //
            _optimisticIndex = -1;

            // fire notification event
            if (this.Changed != null)
            {
                ExtendedPropertiesChangedEventArgs eventArgs
                    = new ExtendedPropertiesChangedEventArgs(propertyToRemove, null);
                this.Changed(this, eventArgs);
            }
        }
コード例 #3
0
ファイル: Events.cs プロジェクト: beda2280/wpf-1
 /// <summary>Constructor</summary>
 internal ExtendedPropertiesChangedEventArgs(ExtendedProperty oldProperty,
                                             ExtendedProperty newProperty)
 {
     if (oldProperty == null && newProperty == null)
     {
         throw new ArgumentNullException("oldProperty");
     }
     _oldProperty = oldProperty;
     _newProperty = newProperty;
 }
コード例 #4
0
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="value">value</param>
        internal void Add(Guid id, object value)
        {
            if (this.Contains(id))
            {
                throw new ArgumentException(SR.Get(SRID.EPExists), "id");
            }

            ExtendedProperty extendedProperty = new ExtendedProperty(id, value);

            //this will raise change events
            this.Add(extendedProperty);
        }
コード例 #5
0
        /// <summary>
        /// private Add, we need to consider making this public in order to implement the generic ICollection
        /// </summary>
        private void Add(ExtendedProperty extendedProperty)
        {
            System.Diagnostics.Debug.Assert(!this.Contains(extendedProperty.Id), "ExtendedProperty already belongs to the collection");

            _extendedProperties.Add(extendedProperty);

            // fire notification event
            if (this.Changed != null)
            {
                ExtendedPropertiesChangedEventArgs eventArgs
                    = new ExtendedPropertiesChangedEventArgs(null, extendedProperty);
                this.Changed(this, eventArgs);
            }
        }
コード例 #6
0
        /// <summary>
        /// Generic accessor for the ExtendedPropertyCollection.
        /// </summary>
        /// <param name="attributeId">Attribue Id to find</param>
        /// <returns>Value for attribute specified by Id</returns>
        /// <exception cref="System.ArgumentException">Specified identifier was not found</exception>
        /// <remarks>
        /// Note that you can access extended properties via this indexer.
        /// </remarks>
        internal object this[Guid attributeId]
        {
            get
            {
                ExtendedProperty ep = GetExtendedPropertyById(attributeId);
                if (ep == null)
                {
                    throw new ArgumentException(SR.Get(SRID.EPNotFound), "attributeId");
                }
                return(ep.Value);
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                for (int i = 0; i < _extendedProperties.Count; i++)
                {
                    ExtendedProperty currentProperty = _extendedProperties[i];

                    if (currentProperty.Id == attributeId)
                    {
                        object oldValue = currentProperty.Value;
                        //this will raise events
                        currentProperty.Value = value;

                        //raise change if anyone is listening
                        if (this.Changed != null)
                        {
                            ExtendedPropertiesChangedEventArgs eventArgs
                                = new ExtendedPropertiesChangedEventArgs(
                                      new ExtendedProperty(currentProperty.Id, oldValue), //old prop
                                      currentProperty);                                   //new prop

                            this.Changed(this, eventArgs);
                        }
                        return;
                    }
                }

                //
                //  we didn't find the Id in the collection, we need to add it.
                //  this will raise change notifications
                //
                ExtendedProperty attributeToAdd = new ExtendedProperty(attributeId, value);
                this.Add(attributeToAdd);
            }
        }
コード例 #7
0
ファイル: ExtendedProperty.cs プロジェクト: beda2280/wpf-1
        /// <summary>Determine if two ExtendedProperty objects are equal</summary>
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType() != GetType())
            {
                return(false);
            }

            ExtendedProperty that = (ExtendedProperty)obj;

            if (that.Id == this.Id)
            {
                Type type1 = this.Value.GetType();
                Type type2 = that.Value.GetType();

                if (type1.IsArray && type2.IsArray)
                {
                    Type elementType1 = type1.GetElementType();
                    Type elementType2 = type2.GetElementType();
                    if (elementType1 == elementType2 &&
                        elementType1.IsValueType &&
                        type1.GetArrayRank() == 1 &&
                        elementType2.IsValueType &&
                        type2.GetArrayRank() == 1)
                    {
                        Array array1 = (Array)this.Value;
                        Array array2 = (Array)that.Value;
                        if (array1.Length == array2.Length)
                        {
                            for (int i = 0; i < array1.Length; i++)
                            {
                                if (!array1.GetValue(i).Equals(array2.GetValue(i)))
                                {
                                    return(false);
                                }
                            }
                            return(true);
                        }
                    }
                }
                else
                {
                    return(that.Value.Equals(this.Value));
                }
            }
            return(false);
        }
コード例 #8
0
        /// <summary>
        /// Whenever the base class fires the generic ExtendedPropertiesChanged
        /// event, we need to fire the DrawingAttributesChanged event also.
        /// </summary> 
        /// <param name="sender">Should be 'this' object</param>
        /// <param name="args">The custom attributes that changed</param> 
        private void ExtendedPropertiesChanged_EventForwarder(object sender, ExtendedPropertiesChangedEventArgs args) 
        {
            System.Diagnostics.Debug.Assert(sender != null); 
            System.Diagnostics.Debug.Assert(args != null);

            //see if the EP that changed is a drawingattribute
            if (args.NewProperty == null) 
            {
                //a property was removed, see if it is a drawing attribute property 
                object defaultValueIfDrawingAttribute 
                    = DrawingAttributes.GetDefaultDrawingAttributeValue(args.OldProperty.Id);
                if (defaultValueIfDrawingAttribute != null) 
                {
                    ExtendedProperty newProperty =
                        new ExtendedProperty(   args.OldProperty.Id,
                                                defaultValueIfDrawingAttribute); 
                    //this is a da guid
                    PropertyDataChangedEventArgs dargs = 
                        new PropertyDataChangedEventArgs(  args.OldProperty.Id, 
                                                                newProperty.Value,      //the property
                                                                args.OldProperty.Value);//previous value 

                    this.OnAttributeChanged(dargs);
                }
                else 
                {
                    PropertyDataChangedEventArgs dargs = 
                        new PropertyDataChangedEventArgs(  args.OldProperty.Id, 
                                                                null,      //the property
                                                                args.OldProperty.Value);//previous value 

                    this.OnPropertyDataChanged(dargs);

                } 
            }
            else if (args.OldProperty == null) 
            { 
                //a property was added, see if it is a drawing attribute property
                object defaultValueIfDrawingAttribute 
                    = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id);
                if (defaultValueIfDrawingAttribute != null)
                {
                    if (!defaultValueIfDrawingAttribute.Equals(args.NewProperty.Value)) 
                    {
                        //this is a da guid 
                        PropertyDataChangedEventArgs dargs = 
                            new PropertyDataChangedEventArgs(  args.NewProperty.Id,
                                                                    args.NewProperty.Value,   //the property 
                                                                    defaultValueIfDrawingAttribute);     //previous value

                        this.OnAttributeChanged(dargs);
                    } 
                }
                else 
                { 
                    PropertyDataChangedEventArgs dargs =
                        new PropertyDataChangedEventArgs(args.NewProperty.Id, 
                                                         args.NewProperty.Value,   //the property
                                                         null);     //previous value
                    this.OnPropertyDataChanged(dargs);
 
                }
            } 
            else 
            {
                //something was modified, see if it is a drawing attribute property 
                object defaultValueIfDrawingAttribute
                    = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id);
                if (defaultValueIfDrawingAttribute != null)
                { 
                    //
                    // we only raise DA changed when the value actually changes 
                    // 
                    if (!args.NewProperty.Value.Equals(args.OldProperty.Value))
                    { 
                        //this is a da guid
                        PropertyDataChangedEventArgs dargs =
                            new PropertyDataChangedEventArgs(  args.NewProperty.Id,
                                                                    args.NewProperty.Value,       //the da 
                                                                    args.OldProperty.Value);//old value
 
                        this.OnAttributeChanged(dargs); 
                    }
                } 
                else
                {
                    if (!args.NewProperty.Value.Equals(args.OldProperty.Value))
                    { 
                        PropertyDataChangedEventArgs dargs =
                            new PropertyDataChangedEventArgs(  args.NewProperty.Id, 
                                                                    args.NewProperty.Value, 
                                                                    args.OldProperty.Value);//old value
 
                        this.OnPropertyDataChanged(dargs);
                    }
                }
            } 
        }
コード例 #9
0
ファイル: Events.cs プロジェクト: sjyanxin/WPFSource
 /// <summary>Constructor</summary>
 internal ExtendedPropertiesChangedEventArgs(ExtendedProperty oldProperty, 
                                             ExtendedProperty newProperty)
 { 
     if ( oldProperty == null && newProperty == null ) 
     {
         throw new ArgumentNullException("oldProperty"); 
     }
     _oldProperty = oldProperty;
     _newProperty = newProperty;
 } 
コード例 #10
0
        /// <summary>
        /// private Add, we need to consider making this public in order to implement the generic ICollection
        /// </summary>
        private void Add(ExtendedProperty extendedProperty)
        {
            System.Diagnostics.Debug.Assert(!this.Contains(extendedProperty.Id), "ExtendedProperty already belongs to the collection");

            _extendedProperties.Add(extendedProperty);

            // fire notification event
            if (this.Changed != null)
            {
                ExtendedPropertiesChangedEventArgs eventArgs
                    = new ExtendedPropertiesChangedEventArgs(null, extendedProperty);
                this.Changed(this, eventArgs);
            }
        }
コード例 #11
0
        /// <summary>
        /// Generic accessor for the ExtendedPropertyCollection. 
        /// </summary>
        /// <param name="attributeId">Attribue Id to find</param>
        /// <returns>Value for attribute specified by Id</returns>
        /// <exception cref="System.ArgumentException">Specified identifier was not found</exception>
        /// <remarks>
        /// Note that you can access extended properties via this indexer.
        /// </remarks>
        internal object this[Guid attributeId]
        {
            get
            {
                ExtendedProperty ep = GetExtendedPropertyById(attributeId);
                if (ep == null)
                {
                    throw new ArgumentException(SR.Get(SRID.EPNotFound), "attributeId");
                }
                return ep.Value;
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                for (int i = 0; i < _extendedProperties.Count; i++)
                {
                    ExtendedProperty currentProperty = _extendedProperties[i];

                    if (currentProperty.Id == attributeId)
                    {
                        object oldValue = currentProperty.Value;
                        //this will raise events
                        currentProperty.Value = value;

                        //raise change if anyone is listening
                        if (this.Changed != null)
                        {
                            ExtendedPropertiesChangedEventArgs eventArgs
                                = new ExtendedPropertiesChangedEventArgs(
                                    new ExtendedProperty(currentProperty.Id, oldValue), //old prop
                                    currentProperty);                                   //new prop

                            this.Changed(this, eventArgs);
                        }
                        return;
                    }
                }

                //
                //  we didn't find the Id in the collection, we need to add it.
                //  this will raise change notifications
                //
                ExtendedProperty attributeToAdd = new ExtendedProperty(attributeId, value);
                this.Add(attributeToAdd);
            }
        }
コード例 #12
0
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="value">value</param>
        internal void Add(Guid id, object value)
        {
            if (this.Contains(id))
            {
                throw new ArgumentException(SR.Get(SRID.EPExists), "id");
            }

            ExtendedProperty extendedProperty = new ExtendedProperty(id, value);

            //this will raise change events
            this.Add(extendedProperty);
        }
コード例 #13
0
        /// <summary>
        /// Whenever the base class fires the generic ExtendedPropertiesChanged
        /// event, we need to fire the DrawingAttributesChanged event also.
        /// </summary>
        /// <param name="sender">Should be 'this' object</param>
        /// <param name="args">The custom attributes that changed</param>
        private void ExtendedPropertiesChanged_EventForwarder(object sender, ExtendedPropertiesChangedEventArgs args)
        {
            System.Diagnostics.Debug.Assert(sender != null);
            System.Diagnostics.Debug.Assert(args != null);

            //see if the EP that changed is a drawingattribute
            if (args.NewProperty == null)
            {
                //a property was removed, see if it is a drawing attribute property
                object defaultValueIfDrawingAttribute
                    = DrawingAttributes.GetDefaultDrawingAttributeValue(args.OldProperty.Id);
                if (defaultValueIfDrawingAttribute != null)
                {
                    ExtendedProperty newProperty =
                        new ExtendedProperty(args.OldProperty.Id,
                                             defaultValueIfDrawingAttribute);
                    //this is a da guid
                    PropertyDataChangedEventArgs dargs =
                        new PropertyDataChangedEventArgs(args.OldProperty.Id,
                                                         newProperty.Value,             //the property
                                                         args.OldProperty.Value);       //previous value

                    this.OnAttributeChanged(dargs);
                }
                else
                {
                    PropertyDataChangedEventArgs dargs =
                        new PropertyDataChangedEventArgs(args.OldProperty.Id,
                                                         null,                    //the property
                                                         args.OldProperty.Value); //previous value

                    this.OnPropertyDataChanged(dargs);
                }
            }
            else if (args.OldProperty == null)
            {
                //a property was added, see if it is a drawing attribute property
                object defaultValueIfDrawingAttribute
                    = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id);
                if (defaultValueIfDrawingAttribute != null)
                {
                    if (!defaultValueIfDrawingAttribute.Equals(args.NewProperty.Value))
                    {
                        //this is a da guid
                        PropertyDataChangedEventArgs dargs =
                            new PropertyDataChangedEventArgs(args.NewProperty.Id,
                                                             args.NewProperty.Value,          //the property
                                                             defaultValueIfDrawingAttribute); //previous value

                        this.OnAttributeChanged(dargs);
                    }
                }
                else
                {
                    PropertyDataChangedEventArgs dargs =
                        new PropertyDataChangedEventArgs(args.NewProperty.Id,
                                                         args.NewProperty.Value, //the property
                                                         null);                  //previous value
                    this.OnPropertyDataChanged(dargs);
                }
            }
            else
            {
                //something was modified, see if it is a drawing attribute property
                object defaultValueIfDrawingAttribute
                    = DrawingAttributes.GetDefaultDrawingAttributeValue(args.NewProperty.Id);
                if (defaultValueIfDrawingAttribute != null)
                {
                    //
                    // we only raise DA changed when the value actually changes
                    //
                    if (!args.NewProperty.Value.Equals(args.OldProperty.Value))
                    {
                        //this is a da guid
                        PropertyDataChangedEventArgs dargs =
                            new PropertyDataChangedEventArgs(args.NewProperty.Id,
                                                             args.NewProperty.Value,        //the da
                                                             args.OldProperty.Value);       //old value

                        this.OnAttributeChanged(dargs);
                    }
                }
                else
                {
                    if (!args.NewProperty.Value.Equals(args.OldProperty.Value))
                    {
                        PropertyDataChangedEventArgs dargs =
                            new PropertyDataChangedEventArgs(args.NewProperty.Id,
                                                             args.NewProperty.Value,
                                                             args.OldProperty.Value);       //old value

                        this.OnPropertyDataChanged(dargs);
                    }
                }
            }
        }