Example #1
0
        public static string DescribeElementEnteringEdit(XmlConfigurationElementCancelEventArgs e)
        {
            try
            {
                string elementType = null;
                XmlConfigurationElementTypes et = e.Element.GetElementType();
                switch (et)
                {
                case XmlConfigurationElementTypes.XmlConfiguration:                             elementType = "configuration"; break;

                case XmlConfigurationElementTypes.XmlConfigurationCategory:             elementType = "category"; break;

                case XmlConfigurationElementTypes.XmlConfigurationElement:              elementType = "element"; break;

                case XmlConfigurationElementTypes.XmlConfigurationOption:               elementType = "option"; break;
                }
                ;

                return(string.Format("The {0} '{1}' is entering edit mode at {2} on {3}. The current user is {4}.", elementType, e.Element.Fullpath, DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString(), System.Environment.UserName));
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
            return(null);
        }
        public virtual bool BeginEdit()
        {
            try
            {
                if (!_isBeingEdited)
                {
                    /// Raise BeforeEdit event and provide a means of cancellation
                    XmlConfigurationElementCancelEventArgs e = new XmlConfigurationElementCancelEventArgs(this, false);
                    this.OnBeforeEdit(this, e);
                    if (e.Cancel)
                    {
                        return(false);
                    }

                    /// place the element in edit mode and clone ourself so that future changes will be redirected to the clone and not to ourself
                    _editableProxy = this.GetElementToEdit();
                    if (_editableProxy != null)
                    {
                        _editableProxy.Changed         += new XmlConfigurationElementEventHandler(this.OnChanged);
                        _editableProxy._isEditableProxy = true;
                        _isBeingEdited = true;
                        return(true);
                    }
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
            return(false);
        }
        public void OnBeforeEdit(object sender, XmlConfigurationElementCancelEventArgs e)
        {
            try
            {
                EventTracing.TraceMethodAndDelegate(this, this.BeforeEdit);

                if (this.BeforeEdit != null)
                {
                    this.BeforeEdit(sender, e);
                }
            }
            catch (System.Exception systemException)
            {
                System.Diagnostics.Trace.WriteLine(systemException);
            }
        }
		public void OnBeforeEdit(object sender, XmlConfigurationElementCancelEventArgs e)
		{
			try
			{
				EventTracing.TraceMethodAndDelegate(this, this.BeforeEdit);

				if (this.BeforeEdit != null)
					this.BeforeEdit(sender, e);
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
		}
		public static string DescribeElementEnteringEdit(XmlConfigurationElementCancelEventArgs e)
		{
			try
			{
				string elementType = null;
				XmlConfigurationElementTypes et = e.Element.GetElementType();
				switch(et)
				{
				case XmlConfigurationElementTypes.XmlConfiguration:				elementType = "configuration"; break;
				case XmlConfigurationElementTypes.XmlConfigurationCategory:		elementType = "category"; break;		
				case XmlConfigurationElementTypes.XmlConfigurationElement:		elementType = "element"; break;
				case XmlConfigurationElementTypes.XmlConfigurationOption:		elementType = "option"; break;
				};
				
				return string.Format("The {0} '{1}' is entering edit mode at {2} on {3}. The current user is {4}.", elementType, e.Element.Fullpath, DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString(), System.Environment.UserName);				
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
			return null;
		}
		public virtual bool BeginEdit()
		{
			try
			{
				if (!_isBeingEdited)
				{
					/// Raise BeforeEdit event and provide a means of cancellation
					XmlConfigurationElementCancelEventArgs e = new XmlConfigurationElementCancelEventArgs(this, false);
					this.OnBeforeEdit(this, e);
					if (e.Cancel)
						return false;
					
					/// place the element in edit mode and clone ourself so that future changes will be redirected to the clone and not to ourself					
					_editableProxy = this.GetElementToEdit();		
					if (_editableProxy != null)
					{
						_editableProxy.Changed += new XmlConfigurationElementEventHandler(this.OnChanged);
						_editableProxy._isEditableProxy = true;
						_isBeingEdited = true;
						return true;
					}					
				}
			}
			catch(System.Exception systemException)
			{
				System.Diagnostics.Trace.WriteLine(systemException);
			}
			return false;
		}