Click here to Skip to main content
15,883,705 members
Articles / Programming Languages / XML

Event Logging in Cx

Rate me:
Please Sign up or sign in to vote.
4.86/5 (8 votes)
30 Sep 2009CPOL7 min read 34.9K   284   16  
Adding an event logger to Cx.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Cx.Attributes;
using Cx.Common;
using Cx.EventArgs;
using Cx.Interfaces;

using Cx.Designer.Common;

namespace Cx.Designer
{
	[CxComponentName("EditProperties")]
	[CxExplicitEvent("GetPropertyList")]
	[CxExplicitEvent("UpdatePropertyValues")]
	[CxExplicitEvent("Save")]
	[CxExplicitEvent("RequestPropertyListUpdate")]
	[CxExplicitEvent("CloseDialog")]
	[CxExplicitEvent("UpdateItemList")]
	public class EditProperties : ICxBusinessComponentClass
	{
		protected List<PropertyValue> propVals;
		protected EventHelper updatePropertyValues;
		protected EventHelper updateItemList;
		protected EventHelper save;

		public EditProperties()
		{
			// gets the property list from the underlying model
			EventHelpers.CreateCommand(this, "GetPropertyList");
			EventHelpers.CreateCommand(this, "CloseDialog");
			// requests an update from the UI, since we aren't doing data binding.
			EventHelpers.CreateCommand(this, "RequestPropertyListUpdate");
			updatePropertyValues = EventHelpers.CreateEvent<IEnumerable>(this, "UpdatePropertyValues");
			updateItemList = EventHelpers.CreateEvent<IEnumerable>(this, "UpdateItemList");
			save = EventHelpers.CreateEvent<IEnumerable>(this, "Save");
		}

		[CxConsumer]
		public void OnInitialize(object sender, System.EventArgs args)
		{
			// gets the property list from the master model.
			EventHelpers.FireCommand(this, "GetPropertyList");
		}

		[CxConsumer]
		public void OnPropertyList(object sender, CxEventArgs<IEnumerable> args)
		{
			propVals = new List<PropertyValue>((IEnumerable<PropertyValue>)args.Data);
			updatePropertyValues.Fire(new List<PropertyValue>(propVals));
		}

		[CxConsumer]
		public void OnPropertySelected(object sender, CxEventArgs<object> args)
		{
			PropertyValue pv = (PropertyValue)args.Data;
			updateItemList.Fire(new List<ItemValue>(pv.ItemValues));
		}

		[CxConsumer]
		public void OnSave(object sender, System.EventArgs args)
		{
			EventHelpers.FireCommand(this, "RequestPropertyListUpdate");
			save.Fire(propVals);
			EventHelpers.FireCommand(this, "CloseDialog");
		}
	}
}							  

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions