예제 #1
0
        /// <summary>
        /// Factory
        /// </summary>
        public static SsmBasicLogger GetInstance(
            string configurationDirectory,
            Stream stream)
        {
            Trace.WriteLine("SsmBasicLogger.GetInstance");
            SsmBasicLogger instance = new SsmBasicLogger(configurationDirectory, stream);

            return(instance);
        }
예제 #2
0
        /// <summary>
        /// Stop logging, in response to "Suspend" power mode event.
        /// </summary>
        /// <remarks>
        /// For use by SsmLogger and test code only.
        /// </remarks>
        internal void Suspend()
        {
            Trace.WriteLine("### PowerModeChanged: Suspend");
            this.TryStateTransition(State.Closing);
            SsmBasicLogger localLogger = this.logger;

            if (localLogger != null)
            {
                Trace.WriteLine("SsmLogger.SystemEvents_PowerModeChanged: stopping logger");
                localLogger.BeginStopLogging(Logger_LoggingStoppedForSuspend, null);
            }
        }
예제 #3
0
        /// <summary>
        /// Complements BeginStopLogging
        /// </summary>
        public void EndStopLogging(IAsyncResult asyncResult)
        {
            Trace.WriteLine("SsmLogger.EndStopLogging");

            SsmBasicLogger localLogger = this.logger;

            if (localLogger != null)
            {
                Trace.WriteLine("SsmLogger.EndStopLogging: invoking SsmBasicLogger.EndStopLogging()");
                localLogger.EndStopLogging(asyncResult);
            }
        }
예제 #4
0
        private SsmLogger(
            string configurationDirectory,
            string ssmPortName)
        {
            this.configurationDirectory = configurationDirectory;
            this.ssmPortName            = ssmPortName;
            Stream stream = this.GetDataStream(true);

            this.logger = SsmBasicLogger.GetInstance(this.configurationDirectory, stream);
            this.TryStateTransition(State.Ready);
            this.logger.LogError += this.Logger_LogError;
#if !PocketPC
            this.powerModeChangedEventHandler              = new Microsoft.Win32.PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
            Microsoft.Win32.SystemEvents.PowerModeChanged += this.powerModeChangedEventHandler;
#endif
        }
예제 #5
0
        /// <summary>
        /// Stops logging
        /// </summary>
        public IAsyncResult BeginStopLogging(AsyncCallback callback, object asyncState)
        {
            Trace.WriteLine("SsmLogger.BeginStopLogging");
            this.TryStateTransition(State.Closing);

            StopLoggingAsyncResult asyncResult = new StopLoggingAsyncResult(callback, asyncState);
            SsmBasicLogger         localLogger = this.logger;

            if (localLogger != null)
            {
                Trace.WriteLine("SsmLogger.BeginStopLogging: stopping logger");
                return(localLogger.BeginStopLogging(Logger_LoggingStopped, asyncResult));
            }
            else
            {
                Trace.WriteLine("SsmLogger.BeginStopLogging: logger gone, returning trivial AsyncResult");
                AsyncResult result = new AsyncResult(callback, asyncState);
                result.Completed();
                //ThreadPool.QueueUserWorkItem(new WaitCallback(delegate { result.Completed(); }));
                return(result);
            }
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        private void ReopenStream()
        {
            if ((this.logger != null) && this.logger.IsLogging)
            {
                Trace.WriteLine("SsmLogger.TimerCallback: logger is already running.");
                return;
            }

            Trace.WriteLine("SsmLogger.TimerCallback: Attempting restart.");
            Stream stream = this.GetDataStream(false);

            if (stream == null)
            {
                Trace.WriteLine("SsmLogger.ReopenStream: Unable to open stream, will try again in one second.");

                if (!this.TryStateTransition(State.Resyncing))
                {
                    Trace.WriteLine("SsmLogger.ReopenStream: Going to reset the timer anyway...");
                }

                this.ScheduleRestart(TimeSpan.FromSeconds(1));
                return;
            }

            Trace.WriteLine("SsmLogger.ReopenStream: Stream opened.");
            this.logger.SetEcuStream(stream);
            this.StartLogging();

            if (!this.TryStateTransition(State.Ready))
            {
                Trace.WriteLine("SsmLogger.ReopenStream: Transition to Ready was illegal, stopping.");
                SsmBasicLogger localLogger = this.logger;
                if (localLogger != null)
                {
                    localLogger.BeginStopLogging(Logger_LoggingStopped, null);
                }
            }
        }