void IScannerInteractionChannel.ResetState(string reason)
 {
     Logger.LogInfo(Message.SyncResetState, reason);
     lock (s_stateSync)
     {
         try
         {
             BackupCurrentState();
             var subsystemNames = new string[_stateDict.Keys.Count];
             _stateDict.Keys.CopyTo(subsystemNames, 0);
             foreach (var subsystemName in subsystemNames)
             {
                 var subsystem = (IStateSubsystem)Application.GetSubsystem(subsystemName);
                 subsystem.ResetState(false);
                 var state = subsystem.GetState();
                 _stateDict[subsystemName] = new StateItem(subsystemName)
                 {
                     Value = state
                 };
             }
             _isStateInitial = true;
             SaveState();
             Logger.LogInfo(Message.SyncResetStateSucceeded);
         }
         catch (Exception ex)
         {
             Logger.LogError(Message.SyncStateResetFailed, ex);
         }
     }
 }
        private void InitState()
        {
            var stateDirectory = _fileSystemManager.GetDataDirectoryPath(FileType.State);

            _stateFilePath = Path.Combine(
                stateDirectory,
                string.Format("{0}.{1}", STATE_FILE_NAME, STATE_FILE_EXT));
            var stateSubsystems = Application.GetSubsystems <IStateSubsystem>();

            _stateDict = new Dictionary <string, StateItem>(stateSubsystems.Count);
            foreach (var entry in stateSubsystems)
            {
                var subsystemName = entry.Key;
                var subsystem     = entry.Value;
                subsystem.ResetState(false);
                var subsystemState = subsystem.GetState();
                _stateDict[subsystemName] = new StateItem(subsystemName)
                {
                    Value = subsystemState
                };
                subsystem.StateChanged += StateSubsystem_StateChanged;
            }
        }
 private void InitState()
 {
     var stateDirectory = _fileSystemManager.GetDataDirectoryPath(FileType.State);
     _stateFilePath = Path.Combine(
         stateDirectory,
         string.Format("{0}.{1}", STATE_FILE_NAME, STATE_FILE_EXT));
     var stateSubsystems = Application.GetSubsystems<IStateSubsystem>();
     _stateDict = new Dictionary<string, StateItem>(stateSubsystems.Count);
     foreach (var entry in stateSubsystems)
     {
         var subsystemName = entry.Key;
         var subsystem = entry.Value;
         subsystem.ResetState(false);
         var subsystemState = subsystem.GetState();
         _stateDict[subsystemName] = new StateItem(subsystemName) { Value = subsystemState };
         subsystem.StateChanged += StateSubsystem_StateChanged;
     }
 }
 void IScannerInteractionChannel.ResetState(string reason)
 {
     Logger.LogInfo(Message.SyncResetState, reason);
     lock (s_stateSync)
     {
         try
         {
             BackupCurrentState();
             var subsystemNames = new string[_stateDict.Keys.Count];
             _stateDict.Keys.CopyTo(subsystemNames, 0);
             foreach (var subsystemName in subsystemNames)
             {
                 var subsystem = (IStateSubsystem)Application.GetSubsystem(subsystemName);
                 subsystem.ResetState(false);
                 var state = subsystem.GetState();
                 _stateDict[subsystemName] = new StateItem(subsystemName) { Value = state };
             }
             _isStateInitial = true;
             SaveState();
             Logger.LogInfo(Message.SyncResetStateSucceeded);
         }
         catch (Exception ex)
         {
             Logger.LogError(Message.SyncStateResetFailed, ex);
         }
     }
 }