cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
848
Views
0
Helpful
1
Replies

cupi .net api - ErrorEvents and cloning

stephan.steiner
Spotlight
Spotlight

Hi

So I wrote my logic to upload wave files to greetings. Works fine when I run it manually, yet when running as a service, it bombs out (the path returned by the conversion is empty). So, I figured I'd wire up ErrorEvents as this should return me the error - now I can't clone the rest objects anymore as it tries to serialize the class where the event handler resides (so my own class).

So, a typical case of needing to change the events, e.g. as described in c# - Serialization of a class with events - Stack Overflow

I quickly adapted this on code, now off to troubleshoot the conversion.

It would be useful to see this in the mainline code as well

Here's the logging and error events region from ConnectionServerRest containing my changes

        #region Logging and Error Events

        [NonSerialized]

        private LoggingEventHandler errorEvents;

        /// <summary>

        /// Event handle for external clients to register with so they can get logging events on errors and warnings that happen

        /// within this class.

        /// </summary>

        public event LoggingEventHandler ErrorEvents

        {

            add { errorEvents += value; }

            remove { errorEvents -= value; }

        }

        [NonSerialized]

        private LoggingEventHandler debugEvents;

        /// <summary>

        /// Debug events can be registered for and recieved to view raw send/response text

        /// </summary>

        public event LoggingEventHandler DebugEvents

        {

            add { debugEvents += value; }

            remove { debugEvents -= value; }

        }

        /// <summary>

        /// The RestTransportFunctions class sends errors and warnings encountered in the class as an event that's raised which

        /// clients can subscribe to for logging events if they wish.  A custom eventArg is used for this that contains

        /// just a simple string "Line" property.

        /// </summary>

        public class LogEventArgs : EventArgs

        {

            public string Line { get; set; }

            public LogEventArgs(string pLine)

            {

                Line = pLine;

            }

            public override string ToString()

            {

                return Line;

            }

        }

        /// <summary>

        /// Alternative event handler for logging events that includes the LogEventArgs that include the log string in the

        /// argument

        /// </summary>

        public delegate void LoggingEventHandler(object sender, LogEventArgs e);

        /// <summary>

        /// If there's one or more clients registered for the ErrorEvent event then issue it here.

        /// </summary>

        /// <param name="pLine">

        /// String to pass back to the receiving method

        /// </param>

        internal void RaiseErrorEvent(string pLine)

        {

            //notify registered clients

            LoggingEventHandler handler = errorEvents;

            if (handler != null)

            {

                LogEventArgs oArgs = new LogEventArgs(pLine);

                handler(null, oArgs);

            }

        }

        /// <summary>

        /// If there's one or more clients registerd for the DebugEvents event then issue it here.

        /// </summary>

        /// <param name="pLine">

        /// String to pass back to the receiving method

        /// </param>

        private void RaiseDebugEvent(string pLine)

        {

            if (DebugMode == false) return;

            //notify registered clients

            LoggingEventHandler handler = debugEvents;

            if (handler != null)

            {

                LogEventArgs oArgs = new LogEventArgs(pLine);

                handler(null, oArgs);

            }

        }

        /// <summary>

        /// register for events off the TranspfortFunctions interface and "pinwheel" the events up to clients

        /// who have registered for error events off the server class

        /// </summary>

        private void TransportFunctionsOnErrorEvents(object sender, RestTransportFunctions.LogEventArgs logEventArgs)

        {

            RaiseErrorEvent(logEventArgs.Line);

        }

        /// <summary>

        /// register for events off the TranspfortFunctions interface and "pinwheel" the events up to clients

        /// who have registered for debug events off the server class

        /// </summary>

        private void TransportFunctionsOnDebugEvents(object sender, RestTransportFunctions.LogEventArgs logEventArgs)

        {

            RaiseDebugEvent(logEventArgs.Line);

        }

        #endregion

1 Reply 1

lindborg
Cisco Employee
Cisco Employee

this (slightly modified) will be in the next release... thanks for the note.this (slightly modified) will be in the next release... thanks for the note.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: