예제 #1
0
        void GeneralHelper_ApplicationClosingEvent()
        {
            GeneralHelper.ApplicationClosingEvent -= new GeneralHelper.DefaultDelegate(GeneralHelper_ApplicationClosingEvent);
            Dispose();

            TracerHelper.TraceSimple(TracerItem.TypeEnum.Report, "Thread pool fast GeneralHelper_ApplicationClosingEvent");
        }
예제 #2
0
        /// <summary>
        /// Allows the user of this interface to force an update to an object.
        /// Also the object itself can raise an request to be updated (saved).
        /// </summary>
        public bool RestoreObjectState(IPersistentEx persistent)
        {
            TracerHelper.Trace("[" + ActualPersistentId(persistent) + "] invoked by :" + ReflectionHelper.GetFullCallingMethodName(3));

            lock (this)
            {
                string persistentName = ActualPersistentId(persistent);
                SystemMonitor.CheckThrow(_verificationObjects.ContainsKey(persistentName) == false || _verificationObjects[persistentName] == persistent);

                if (_restoredObjects.ContainsKey(persistentName) == false
                    /*|| _restoredObjects[persistentName].Values.Count == 0*/)
                {// Object restoration infromation not found.
                    return(false);
                }

                PersistentData dataCopy = _restoredObjects[persistentName].Clone();
                bool           result   = persistent.OnRestoreState(this, dataCopy);

                if (result)
                {// Object restored successfully, remove pending restoration information.
                    _restoredObjects.Remove(persistentName);
                }

                return(result);
            }
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 public static void OperationWarning(string warningMessage, TracerItem.PriorityEnum priority)
 {
     TracerHelper.TraceOperationWarning(warningMessage);
     if (GlobalDiagnosticsMode && priority > TracerItem.PriorityEnum.Medium)
     {
         Debug.Fail(warningMessage);
     }
 }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="errorMessage"></param>
 public static void Error(string errorMessage, TracerItem.PriorityEnum priority)
 {
     TracerHelper.Trace(TracerHelper.Tracer, TracerItem.TypeEnum.Error, errorMessage, priority);
     if (GlobalDiagnosticsMode)
     {
         Debug.Fail(errorMessage);
     }
 }
예제 #5
0
 /// <summary>
 /// Report an serious error. Those errors are usually a sign something in the work
 /// of the application has gone seriously wrong, and operation can not continue
 /// properly (for ex. unexpected exception, access to critical resources etc.)
 /// </summary>
 /// <param name="errorMessage"></param>
 public static void Error(string errorMessage)
 {
     TracerHelper.TraceError(errorMessage);
     if (GlobalDiagnosticsMode)
     {
         Debug.Fail(errorMessage);
     }
 }
예제 #6
0
 /// <summary>
 /// Report operation warning; it is a normal occurence in the work of the system. It can be caused
 /// for example by the lack of access to a resource or some error in a data stream.
 /// </summary>
 /// <param name="warningMessage"></param>
 public static void OperationWarning(string warningMessage)
 {
     TracerHelper.TraceWarning(warningMessage);
     //if (GlobalDiagnosticsMode)
     //{
     //    Debug.Fail(warningMessage);
     //}
 }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="errorMessage"></param>
 public static void OperationError(string errorMessage, TracerItem.PriorityEnum priority)
 {
     TracerHelper.TraceOperationError(errorMessage);
     if ((GlobalDiagnosticsMode && priority > TracerItem.PriorityEnum.Medium) ||
         priority == TracerItem.PriorityEnum.Critical)
     {
         Debug.Fail(errorMessage);
     }
 }
예제 #8
0
        /// <summary>
        /// A Warning notifies that in some part of the systems operation a recovarable error has occured.
        /// </summary>
        /// <param name="warningMessage"></param>
        public static void Warning(string warningMessage)
        {
            TracerHelper.TraceWarning(warningMessage);

            if (GlobalDiagnosticsMode)
            {
                Debug.Fail(warningMessage);
            }
        }
예제 #9
0
        /// <summary>
        /// Helper, redefine with exception consumption.
        /// </summary>
        /// <param name="errorMessage"></param>
        /// <param name="exception"></param>
        public static void Error(string errorMessage, Exception exception)
        {
            errorMessage = ProcessExceptionMessage(errorMessage, exception);

            TracerHelper.TraceError(errorMessage);
            if (GlobalDiagnosticsMode)
            {
                Debug.Fail(errorMessage);
            }
        }
예제 #10
0
 /// <summary>
 /// Follow synchrnozation source status.
 /// </summary>
 void _statusSynchronizationSource_OperationalStatusChangedEvent(IOperational parameter1, OperationalStateEnum parameter2)
 {
     if (StatusSynchronizationEnabled)
     {
         TracerHelper.Trace(this.GetType().Name + " is following its source " + parameter1.GetType().Name + " to state " + parameter1.OperationalState.ToString());
         this.ChangeOperationalState(parameter1.OperationalState);
     }
     else
     {
         TracerHelper.Trace(this.GetType().Name + " is not following its source " + parameter1.GetType().Name + " to new state because synchronization is disabled.");
     }
 }
예제 #11
0
 /// <summary>
 /// Report a simplme message to the report management system.
 /// </summary>
 /// <param name="reportMessage"></param>
 public static void Report(string reportMessage, TracerItem.PriorityEnum priority)
 {
     // TODO: Implement tracer item priority properly.
     if (priority == TracerItem.PriorityEnum.High ||
         priority == TracerItem.PriorityEnum.Critical)
     {
         TracerHelper.Trace("***Report*** " + reportMessage);
     }
     else
     {
         TracerHelper.Trace("Report: " + reportMessage);
     }
 }
예제 #12
0
        /// <summary>
        /// Allows the user of this interface to force an update to an object.
        /// Also the object itself can raise an request to be updated (saved).
        /// </summary>
        public bool SaveObjectState(IPersistentEx persistent)
        {
            TracerHelper.Trace("[" + ActualPersistentId(persistent) + "] invoked by: " + ReflectionHelper.GetFullCallingMethodName(2));

            lock (this)
            {
                RegisterObject(persistent);
                PersistentData data = _pendingSaveObjects[ActualPersistentId(persistent)];
                if (persistent.OnSaveState(this, data) == false)
                {
                    return(false);
                }

                // Only if the receiver has confirmed the saving operation, replace the current data.
                _pendingSaveObjects[ActualPersistentId(persistent)] = data;
            }

            return(true);
        }
예제 #13
0
        public void SaveToFile()
        {
            TracerHelper.Trace("[" + _fullFileName + "] invoked by: " + ReflectionHelper.GetFullCallingMethodName(2));

            lock (this)
            {
                if (File.Exists(_fullFileName))
                {// Rename the old file - keep it as archive.
                    TimeSpan span            = DateTime.Now - new DateTime(DateTime.Now.Year, 1, 1);
                    string   customTimeValue = "." + DateTime.Now.Year + "." + (int)span.TotalSeconds;
                    string   newFileName     = _fullFileName.ToLower().Replace("." + FileExtension, customTimeValue) + "." + FileExtension;

                    while (File.Exists(newFileName))
                    {
                        newFileName = newFileName.Replace("." + FileExtension, "X" + "." + FileExtension);
                    }

                    File.Move(_fullFileName, newFileName);
                }

                try
                {
                    FileInfo fi = new FileInfo(_fullFileName);
                    if (fi.Directory.Exists == false)
                    {
                        fi.Directory.Create();
                    }

                    using (FileStream stream = new FileStream(_fullFileName, FileMode.Create, FileAccess.Write))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        formatter.Serialize(stream, _pendingSaveObjects);
                        stream.Close();
                    }
                }
                catch (Exception exception)
                {
                    System.Diagnostics.Debug.Fail("Stream error.");
                    TracerHelper.TraceError("Error occured while creating file stream [" + exception.Message + "].");
                }
            }
        }
예제 #14
0
        public bool RestoreFromFile()
        {
            TracerHelper.Trace("[" + _fullFileName + "] invoked by: " + ReflectionHelper.GetFullCallingMethodName(2));

            lock (this)
            {
                _restoredObjects.Clear();

                if (File.Exists(_fullFileName) == false)
                {
                    return(false);
                }

                try
                {
                    using (FileStream stream = new FileStream(_fullFileName, FileMode.Open, FileAccess.Read))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        _restoredObjects = (Dictionary <string, PersistentData>)formatter.Deserialize(stream);
                        stream.Close();
                    }

                    // Transfer the restored info in the pending info places, where no info exists at all, to persist objects
                    // that are not currently active and will be restorable in the furure.
                    foreach (string id in _restoredObjects.Keys)
                    {
                        if (_pendingSaveObjects.ContainsKey(id) == false)
                        {
                            _pendingSaveObjects.Add(id, _restoredObjects[id]);
                        }
                    }

                    return(true);
                }
                catch (Exception exception)
                {
                    System.Diagnostics.Debug.Fail("Stream error.");
                    TracerHelper.TraceError("Error occured while parsing file stream [" + exception.Message + "].");
                }
            }
            return(false);
        }
예제 #15
0
        /// <summary>
        /// Change the component operational state.
        /// </summary>
        /// <param name="operationalState"></param>
        public virtual void ChangeOperationalState(OperationalStateEnum operationalState)
        {
            OperationalStateEnum previousState;

            lock (this)
            {
                if (operationalState == _operationalState)
                {
                    return;
                }

                previousState = _operationalState;
            }

            TracerHelper.Trace(this.GetType().Name + " was " + previousState.ToString() + " is now " + operationalState.ToString());

            _operationalState = operationalState;
            if (OperationalStateChangedEvent != null)
            {
                OperationalStateChangedEvent(this, previousState);
            }
        }
예제 #16
0
        public void RegisterObject(IPersistentEx persistent)
        {
            lock (this)
            {
                if (persistent.PersistencyIsInitialzed == false)
                {
                    TracerHelper.Trace("[" + ActualPersistentId(persistent) + "] invoked by: " + ReflectionHelper.GetFullCallingMethodName(2));

                    persistent.InitializePersistency(this);

                    if (_pendingSaveObjects.ContainsKey(ActualPersistentId(persistent)) == false)
                    {
                        _pendingSaveObjects.Add(ActualPersistentId(persistent), new PersistentData());
                    }

                    SystemMonitor.CheckThrow(_verificationObjects.ContainsKey(ActualPersistentId(persistent)) == false);
                    _verificationObjects.Add(ActualPersistentId(persistent), persistent);
                }

                System.Diagnostics.Debug.Assert(_verificationObjects.ContainsKey(ActualPersistentId(persistent)));
            }
        }
 void GeneralHelper_ApplicationClosingEvent()
 {
     TracerHelper.TraceSimple(TracerItem.TypeEnum.Report, "Background message operator GeneralHelper_ApplicationClosingEvent");
     Stop();
 }
예제 #18
0
 /// <summary>
 /// Report a simplme message to the report management system.
 /// </summary>
 /// <param name="reportMessage"></param>
 public static void Report(string reportMessage, TracerItem.PriorityEnum priority)
 {
     TracerHelper.Trace(TracerItem.TypeEnum.Report, reportMessage, priority);
 }