Exemple #1
0
        /// <summary>
        /// Adds a AddressBookItem to the list
        /// </summary>
        /// <param name="item"></param>
        public void Add(AddressBookItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("AddressBookItem", "A null reference to a AddressBookItem cannot be added to the list.");
            }

            if (this.Contains(item))
            {
                throw new NameNotUniqueException(item.Name);
            }

            // bind to the end point's events
            item.Changed           += new AddressingEventHandler(this.OnChanged);
            item.BeforeNameChanged += new NameChangeEventHandler(this.OnBeforeAddressNameAddressChanged);

            // add the item
            base.InnerList.Add(item);

            // set the item's parent
            item.Parent = _parent;

            /*
             * raise the event
             *
             * starting it at the object level, which will trickle all the way up through the object heirarchies
             * normally, the "this" pointer would be the context of the call, but because we want the object
             * to get the add and remove events as well, we start the call with it
             * */
            AddressBookItemEventArgs e = new AddressBookItemEventArgs(item, AddressingActions.Added);

            item.OnChanged(this, e);
            //this.OnChanged(this, e);
        }
Exemple #2
0
        /// <summary>
        /// Removes a AddressBookItem from the list
        /// </summary>
        /// <param name="item"></param>
        public void Remove(AddressBookItem item)
        {
            if (this.Contains(item))
            {
                /*
                 * raise the event
                 *
                 * starting it at the object level, which will trickle all the way up through the object heirarchies
                 * normally, the "this" pointer would be the context of the call, but because we want the object
                 * to get the add and remove events as well, we start the call with it
                 * */
                AddressBookItemEventArgs e = new AddressBookItemEventArgs(item, AddressingActions.Removed);
                item.OnChanged(this, e);
//				this.OnChanged(this, e);

                item.Changed           -= new AddressingEventHandler(this.OnChanged);
                item.BeforeNameChanged -= new NameChangeEventHandler(this.OnBeforeAddressNameAddressChanged);

                // remove the item
                base.InnerList.Remove(item);

                // orphan the item
                item.Parent = null;
            }
        }
Exemple #3
0
        public void Add(AddressBookItem item, bool overwrite)
        {
            // if we're not overwriting, just add it like normal
            if (!overwrite)
            {
                this.Add(item);
                return;
            }

            // again we can't add null references
            if (item == null)
            {
                throw new ArgumentNullException("AddressBookItem", "A null reference to an AddressBookItem cannot be added to the list.");
            }

            // if there is a collision, go ahead and overwrite the existing one
            if (this.Contains(item))
            {
                // find the existing one
                AddressBookItem existingItem = this[item.Name];

                // write the properties from the one coming in, to the existing one
                item.WriteProperties(existingItem);
                return;
            }
            else
            {
                // try and find it by id
                AddressBookItem existingItem = this.FindById(item.Id);

                // if we have a hit, that means this is the same object, just renamed
                if (existingItem != null)
                {
                    // so give it a new id
                    item.GetNewId();
                }
            }

            // bind to the end point's events
            item.Changed           += new AddressingEventHandler(this.OnChanged);
            item.BeforeNameChanged += new NameChangeEventHandler(this.OnBeforeAddressNameAddressChanged);

            // add the item
            base.InnerList.Add(item);

            // set the item's parent
            item.Parent = _parent;

            /*
             * raise the event
             *
             * starting it at the object level, which will trickle all the way up through the object heirarchies
             * normally, the "this" pointer would be the context of the call, but because we want the object
             * to get the add and remove events as well, we start the call with it
             * */
            AddressBookItemEventArgs e = new AddressBookItemEventArgs(item, AddressingActions.Added);

            item.OnChanged(this, e);
//			this.OnChanged(this, e);
        }
 /// <summary>
 /// Raises the AddressBookItemChanged event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnAddressBookItemChanged(object sender, AddressBookItemEventArgs e)
 {
     try
     {
         if (this.AddressBookItemChanged != null)
         {
             this.AddressBookItemChanged(sender, e);
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
     }
 }
		/// <summary>
		/// Raises the AddressBookItemChanged event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected virtual void OnAddressBookItemChanged(object sender, AddressBookItemEventArgs e)
		{
			try
			{
				if (this.AddressBookItemChanged != null)
					this.AddressBookItemChanged(sender, e);
			}
			catch(Exception ex)
			{
				Trace.WriteLine(ex);
			}
		}
		/// <summary>
		/// Adds a AddressBookItem to the list
		/// </summary>
		/// <param name="item"></param>
		public void Add(AddressBookItem item)
		{
			if (item == null)
				throw new ArgumentNullException("AddressBookItem", "A null reference to a AddressBookItem cannot be added to the list.");
			
			if (this.Contains(item))
				throw new NameNotUniqueException(item.Name);

			// bind to the end point's events
			item.Changed += new AddressingEventHandler(this.OnChanged);
            item.BeforeNameChanged += new NameChangeEventHandler(this.OnBeforeAddressNameAddressChanged);

			// add the item
			base.InnerList.Add(item);			
			
			// set the item's parent
			item.Parent = _parent;

			/*
			 * raise the event
			 * 
			 * starting it at the object level, which will trickle all the way up through the object heirarchies
			 * normally, the "this" pointer would be the context of the call, but because we want the object
			 * to get the add and remove events as well, we start the call with it
			 * */
			AddressBookItemEventArgs e = new AddressBookItemEventArgs(item, AddressingActions.Added);
			item.OnChanged(this, e); 
			//this.OnChanged(this, e);
		}
		/// <summary>
		/// Removes a AddressBookItem from the list
		/// </summary>
		/// <param name="item"></param>
		public void Remove(AddressBookItem item)
		{
			if (this.Contains(item))
			{				
				/*
				 * raise the event
				 * 
				 * starting it at the object level, which will trickle all the way up through the object heirarchies
				 * normally, the "this" pointer would be the context of the call, but because we want the object
				 * to get the add and remove events as well, we start the call with it
				 * */
				AddressBookItemEventArgs e = new AddressBookItemEventArgs(item, AddressingActions.Removed);				
				item.OnChanged(this, e);
//				this.OnChanged(this, e);

				item.Changed -= new AddressingEventHandler(this.OnChanged);
				item.BeforeNameChanged -= new NameChangeEventHandler(this.OnBeforeAddressNameAddressChanged);

				// remove the item 
				base.InnerList.Remove(item);			

				// orphan the item
				item.Parent = null;
			}
		}
		public void Add(AddressBookItem item, bool overwrite)
		{
			// if we're not overwriting, just add it like normal
			if (!overwrite)
			{
				this.Add(item);
				return;
			}

			// again we can't add null references
			if (item == null)
				throw new ArgumentNullException("AddressBookItem", "A null reference to an AddressBookItem cannot be added to the list.");

			// if there is a collision, go ahead and overwrite the existing one
			if (this.Contains(item))
			{
				// find the existing one
				AddressBookItem existingItem = this[item.Name];				

				// write the properties from the one coming in, to the existing one
				item.WriteProperties(existingItem);
				return;
			}
			else
			{
				// try and find it by id
				AddressBookItem existingItem = this.FindById(item.Id);

				// if we have a hit, that means this is the same object, just renamed
				if (existingItem != null)
					// so give it a new id
					item.GetNewId();	
			}

			// bind to the end point's events
			item.Changed += new AddressingEventHandler(this.OnChanged);
			item.BeforeNameChanged += new NameChangeEventHandler(this.OnBeforeAddressNameAddressChanged);

			// add the item
			base.InnerList.Add(item);			
			
			// set the item's parent
			item.Parent = _parent;

			/*
			 * raise the event
			 * 
			 * starting it at the object level, which will trickle all the way up through the object heirarchies
			 * normally, the "this" pointer would be the context of the call, but because we want the object
			 * to get the add and remove events as well, we start the call with it
			 * */
			AddressBookItemEventArgs e = new AddressBookItemEventArgs(item, AddressingActions.Added);
			item.OnChanged(this, e);
//			this.OnChanged(this, e);
		}