Click here to Skip to main content
15,881,600 members
Articles / Programming Languages / C#

Persistent .NET Events in Stateless Remoting Server

Rate me:
Please Sign up or sign in to vote.
4.76/5 (18 votes)
5 Jan 20037 min read 93.7K   1K   43  
This article demonstrates usage of .NET events in the stateless remoting server, thus allowing to use .NET event mechanism in highly available and scalable distributed applications.
//------------------------------------------------------------------------------
// <autogenerated>
//     This code was generated by a tool.
//     Runtime Version: 1.0.3705.288
//
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

namespace DataAccess {
    using System;
    using System.Data;
    using System.Xml;
    using System.Runtime.Serialization;
    
    
    [Serializable()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Diagnostics.DebuggerStepThrough()]
    [System.ComponentModel.ToolboxItem(true)]
    public class EventSinksDataSet : DataSet {
        
        private tb_sinksDataTable tabletb_sinks;
        
        public EventSinksDataSet() {
            this.InitClass();
            System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
            this.Tables.CollectionChanged += schemaChangedHandler;
            this.Relations.CollectionChanged += schemaChangedHandler;
        }
        
        protected EventSinksDataSet(SerializationInfo info, StreamingContext context) {
            string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string))));
            if ((strSchema != null)) {
                DataSet ds = new DataSet();
                ds.ReadXmlSchema(new XmlTextReader(new System.IO.StringReader(strSchema)));
                if ((ds.Tables["tb_sinks"] != null)) {
                    this.Tables.Add(new tb_sinksDataTable(ds.Tables["tb_sinks"]));
                }
                this.DataSetName = ds.DataSetName;
                this.Prefix = ds.Prefix;
                this.Namespace = ds.Namespace;
                this.Locale = ds.Locale;
                this.CaseSensitive = ds.CaseSensitive;
                this.EnforceConstraints = ds.EnforceConstraints;
                this.Merge(ds, false, System.Data.MissingSchemaAction.Add);
                this.InitVars();
            }
            else {
                this.InitClass();
            }
            this.GetSerializationData(info, context);
            System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
            this.Tables.CollectionChanged += schemaChangedHandler;
            this.Relations.CollectionChanged += schemaChangedHandler;
        }
        
        [System.ComponentModel.Browsable(false)]
        [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)]
        public tb_sinksDataTable tb_sinks {
            get {
                return this.tabletb_sinks;
            }
        }
        
        public override DataSet Clone() {
            EventSinksDataSet cln = ((EventSinksDataSet)(base.Clone()));
            cln.InitVars();
            return cln;
        }
        
        protected override bool ShouldSerializeTables() {
            return false;
        }
        
        protected override bool ShouldSerializeRelations() {
            return false;
        }
        
        protected override void ReadXmlSerializable(XmlReader reader) {
            this.Reset();
            DataSet ds = new DataSet();
            ds.ReadXml(reader);
            if ((ds.Tables["tb_sinks"] != null)) {
                this.Tables.Add(new tb_sinksDataTable(ds.Tables["tb_sinks"]));
            }
            this.DataSetName = ds.DataSetName;
            this.Prefix = ds.Prefix;
            this.Namespace = ds.Namespace;
            this.Locale = ds.Locale;
            this.CaseSensitive = ds.CaseSensitive;
            this.EnforceConstraints = ds.EnforceConstraints;
            this.Merge(ds, false, System.Data.MissingSchemaAction.Add);
            this.InitVars();
        }
        
        protected override System.Xml.Schema.XmlSchema GetSchemaSerializable() {
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            this.WriteXmlSchema(new XmlTextWriter(stream, null));
            stream.Position = 0;
            return System.Xml.Schema.XmlSchema.Read(new XmlTextReader(stream), null);
        }
        
        internal void InitVars() {
            this.tabletb_sinks = ((tb_sinksDataTable)(this.Tables["tb_sinks"]));
            if ((this.tabletb_sinks != null)) {
                this.tabletb_sinks.InitVars();
            }
        }
        
        private void InitClass() {
            this.DataSetName = "EventSinksDataSet";
            this.Prefix = "";
            this.Namespace = "http://www.tempuri.org/EventSinksDataSet.xsd";
            this.Locale = new System.Globalization.CultureInfo("en-US");
            this.CaseSensitive = false;
            this.EnforceConstraints = true;
            this.tabletb_sinks = new tb_sinksDataTable();
            this.Tables.Add(this.tabletb_sinks);
        }
        
        private bool ShouldSerializetb_sinks() {
            return false;
        }
        
        private void SchemaChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e) {
            if ((e.Action == System.ComponentModel.CollectionChangeAction.Remove)) {
                this.InitVars();
            }
        }
        
        public delegate void tb_sinksRowChangeEventHandler(object sender, tb_sinksRowChangeEvent e);
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class tb_sinksDataTable : DataTable, System.Collections.IEnumerable {
            
            private DataColumn columnID;
            
            private DataColumn columnObjRefStream;
            
            private DataColumn columnCreationTime;
            
            private DataColumn columnEventType;
            
            internal tb_sinksDataTable() : 
                    base("tb_sinks") {
                this.InitClass();
            }
            
            internal tb_sinksDataTable(DataTable table) : 
                    base(table.TableName) {
                if ((table.CaseSensitive != table.DataSet.CaseSensitive)) {
                    this.CaseSensitive = table.CaseSensitive;
                }
                if ((table.Locale.ToString() != table.DataSet.Locale.ToString())) {
                    this.Locale = table.Locale;
                }
                if ((table.Namespace != table.DataSet.Namespace)) {
                    this.Namespace = table.Namespace;
                }
                this.Prefix = table.Prefix;
                this.MinimumCapacity = table.MinimumCapacity;
                this.DisplayExpression = table.DisplayExpression;
            }
            
            [System.ComponentModel.Browsable(false)]
            public int Count {
                get {
                    return this.Rows.Count;
                }
            }
            
            internal DataColumn IDColumn {
                get {
                    return this.columnID;
                }
            }
            
            internal DataColumn ObjRefStreamColumn {
                get {
                    return this.columnObjRefStream;
                }
            }
            
            internal DataColumn CreationTimeColumn {
                get {
                    return this.columnCreationTime;
                }
            }
            
            internal DataColumn EventTypeColumn {
                get {
                    return this.columnEventType;
                }
            }
            
            public tb_sinksRow this[int index] {
                get {
                    return ((tb_sinksRow)(this.Rows[index]));
                }
            }
            
            public event tb_sinksRowChangeEventHandler tb_sinksRowChanged;
            
            public event tb_sinksRowChangeEventHandler tb_sinksRowChanging;
            
            public event tb_sinksRowChangeEventHandler tb_sinksRowDeleted;
            
            public event tb_sinksRowChangeEventHandler tb_sinksRowDeleting;
            
            public void Addtb_sinksRow(tb_sinksRow row) {
                this.Rows.Add(row);
            }
            
            public tb_sinksRow Addtb_sinksRow(System.Byte[] ObjRefStream, System.DateTime CreationTime, string EventType) {
                tb_sinksRow rowtb_sinksRow = ((tb_sinksRow)(this.NewRow()));
                rowtb_sinksRow.ItemArray = new object[] {
                        null,
                        ObjRefStream,
                        CreationTime,
                        EventType};
                this.Rows.Add(rowtb_sinksRow);
                return rowtb_sinksRow;
            }
            
            public tb_sinksRow FindByID(int ID) {
                return ((tb_sinksRow)(this.Rows.Find(new object[] {
                            ID})));
            }
            
            public System.Collections.IEnumerator GetEnumerator() {
                return this.Rows.GetEnumerator();
            }
            
            public override DataTable Clone() {
                tb_sinksDataTable cln = ((tb_sinksDataTable)(base.Clone()));
                cln.InitVars();
                return cln;
            }
            
            protected override DataTable CreateInstance() {
                return new tb_sinksDataTable();
            }
            
            internal void InitVars() {
                this.columnID = this.Columns["ID"];
                this.columnObjRefStream = this.Columns["ObjRefStream"];
                this.columnCreationTime = this.Columns["CreationTime"];
                this.columnEventType = this.Columns["EventType"];
            }
            
            private void InitClass() {
                this.columnID = new DataColumn("ID", typeof(int), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnID);
                this.columnObjRefStream = new DataColumn("ObjRefStream", typeof(System.Byte[]), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnObjRefStream);
                this.columnCreationTime = new DataColumn("CreationTime", typeof(System.DateTime), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnCreationTime);
                this.columnEventType = new DataColumn("EventType", typeof(string), null, System.Data.MappingType.Element);
                this.Columns.Add(this.columnEventType);
                this.Constraints.Add(new UniqueConstraint("Constraint1", new DataColumn[] {
                                this.columnID}, true));
                this.columnID.AutoIncrement = true;
                this.columnID.AllowDBNull = false;
                this.columnID.ReadOnly = true;
                this.columnID.Unique = true;
            }
            
            public tb_sinksRow Newtb_sinksRow() {
                return ((tb_sinksRow)(this.NewRow()));
            }
            
            protected override DataRow NewRowFromBuilder(DataRowBuilder builder) {
                return new tb_sinksRow(builder);
            }
            
            protected override System.Type GetRowType() {
                return typeof(tb_sinksRow);
            }
            
            protected override void OnRowChanged(DataRowChangeEventArgs e) {
                base.OnRowChanged(e);
                if ((this.tb_sinksRowChanged != null)) {
                    this.tb_sinksRowChanged(this, new tb_sinksRowChangeEvent(((tb_sinksRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowChanging(DataRowChangeEventArgs e) {
                base.OnRowChanging(e);
                if ((this.tb_sinksRowChanging != null)) {
                    this.tb_sinksRowChanging(this, new tb_sinksRowChangeEvent(((tb_sinksRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleted(DataRowChangeEventArgs e) {
                base.OnRowDeleted(e);
                if ((this.tb_sinksRowDeleted != null)) {
                    this.tb_sinksRowDeleted(this, new tb_sinksRowChangeEvent(((tb_sinksRow)(e.Row)), e.Action));
                }
            }
            
            protected override void OnRowDeleting(DataRowChangeEventArgs e) {
                base.OnRowDeleting(e);
                if ((this.tb_sinksRowDeleting != null)) {
                    this.tb_sinksRowDeleting(this, new tb_sinksRowChangeEvent(((tb_sinksRow)(e.Row)), e.Action));
                }
            }
            
            public void Removetb_sinksRow(tb_sinksRow row) {
                this.Rows.Remove(row);
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class tb_sinksRow : DataRow {
            
            private tb_sinksDataTable tabletb_sinks;
            
            internal tb_sinksRow(DataRowBuilder rb) : 
                    base(rb) {
                this.tabletb_sinks = ((tb_sinksDataTable)(this.Table));
            }
            
            public int ID {
                get {
                    return ((int)(this[this.tabletb_sinks.IDColumn]));
                }
                set {
                    this[this.tabletb_sinks.IDColumn] = value;
                }
            }
            
            public System.Byte[] ObjRefStream {
                get {
                    try {
                        return ((System.Byte[])(this[this.tabletb_sinks.ObjRefStreamColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tabletb_sinks.ObjRefStreamColumn] = value;
                }
            }
            
            public System.DateTime CreationTime {
                get {
                    try {
                        return ((System.DateTime)(this[this.tabletb_sinks.CreationTimeColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tabletb_sinks.CreationTimeColumn] = value;
                }
            }
            
            public string EventType {
                get {
                    try {
                        return ((string)(this[this.tabletb_sinks.EventTypeColumn]));
                    }
                    catch (InvalidCastException e) {
                        throw new StrongTypingException("Cannot get value because it is DBNull.", e);
                    }
                }
                set {
                    this[this.tabletb_sinks.EventTypeColumn] = value;
                }
            }
            
            public bool IsObjRefStreamNull() {
                return this.IsNull(this.tabletb_sinks.ObjRefStreamColumn);
            }
            
            public void SetObjRefStreamNull() {
                this[this.tabletb_sinks.ObjRefStreamColumn] = System.Convert.DBNull;
            }
            
            public bool IsCreationTimeNull() {
                return this.IsNull(this.tabletb_sinks.CreationTimeColumn);
            }
            
            public void SetCreationTimeNull() {
                this[this.tabletb_sinks.CreationTimeColumn] = System.Convert.DBNull;
            }
            
            public bool IsEventTypeNull() {
                return this.IsNull(this.tabletb_sinks.EventTypeColumn);
            }
            
            public void SetEventTypeNull() {
                this[this.tabletb_sinks.EventTypeColumn] = System.Convert.DBNull;
            }
        }
        
        [System.Diagnostics.DebuggerStepThrough()]
        public class tb_sinksRowChangeEvent : EventArgs {
            
            private tb_sinksRow eventRow;
            
            private DataRowAction eventAction;
            
            public tb_sinksRowChangeEvent(tb_sinksRow row, DataRowAction action) {
                this.eventRow = row;
                this.eventAction = action;
            }
            
            public tb_sinksRow Row {
                get {
                    return this.eventRow;
                }
            }
            
            public DataRowAction Action {
                get {
                    return this.eventAction;
                }
            }
        }
    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect mPrest Systems
Israel Israel
I am working with various Microsoft technologies since 1994 (remember Windows 3.1 ?Smile | :) ). Language of choice - C++/C#. I am mainly interested in software engineering and "generic solutions", so frequently I find myself designing / implementing frameworks and application skeletons, although sometimes I do various stuff from DB to Kernel Mode device drivers. I also love to understand why things are in the way they are, not just how to use them.
Currently I am Chief Software Architect and CTO of the software outsourcing company mPrest Ltd , Israel.

Comments and Discussions