コード例 #1
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);
            }
        }
コード例 #2
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);
     }
 }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        public static void OperationWarning(string warningMessage, TracerItem.PriorityEnum priority)
        {
            TracerHelper.Trace(TracerItem.TypeEnum.Warning | TracerItem.TypeEnum.Operation, warningMessage, priority);

            if (GlobalDiagnosticsMode && priority > TracerItem.PriorityEnum.Medium)
            {
                Debug.Fail(warningMessage);
            }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        public static void OperationError(string errorMessage, TracerItem.PriorityEnum priority)
        {
            TracerHelper.Trace(TracerItem.TypeEnum.Operation | TracerItem.TypeEnum.Error, errorMessage, priority);

            if ((GlobalDiagnosticsMode && priority > TracerItem.PriorityEnum.Medium) ||
                priority == TracerItem.PriorityEnum.Critical)
            {
                Debug.Fail(errorMessage);
            }
        }
コード例 #5
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.");
     }
 }
コード例 #6
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);
     }
 }
コード例 #7
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);
        }
コード例 #8
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 + "].");
                }
            }
        }
コード例 #9
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);
        }
コード例 #10
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);
            }
        }
コード例 #11
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)));
            }
        }
コード例 #12
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);
 }