Exemple #1
0
        public bool RemoveExcludeRule(ProtectedItemCategory category, string rule)
        {
            if (String.IsNullOrEmpty(rule))
            {
                _logger.Error("empty or undefined exclude rule not removed");
                return(false);
            }

            try
            {
                _fhMgr.AddRemoveExcludeRule(false, category, rule);
                _logger.Information("Removed exclude rule");
            }
            catch (Exception e)
            {
                var error = FileHistoryErrors.GetError(e);
                _logger.Error(error);

                return(false);
            }

            if (_rules == null)
            {
                _rules = new List <FileHistoryRule>();
            }

            var toRemove = _rules.FirstOrDefault(r => r.Rule.Equals(rule, StringComparison.OrdinalIgnoreCase));

            if (toRemove != null)
            {
                _rules.Remove(toRemove);
            }

            return(true);
        }
Exemple #2
0
        public bool AddExcludeRule(ProtectedItemCategory category, string rule)
        {
            if (String.IsNullOrEmpty(rule))
            {
                _logger.Error("empty or undefined exclude rule not added");
                return(false);
            }

            try
            {
                _fhMgr.AddRemoveExcludeRule(true, category, rule);
                _logger.Information("Added exclude rule");
            }
            catch (Exception e)
            {
                var error = FileHistoryErrors.GetError(e);
                _logger.Error(error);

                return(false);
            }

            if (_rules == null)
            {
                _rules = new List <FileHistoryRule>();
            }

            _rules.Add(new FileHistoryRule()
            {
                Category = category,
                Rule     = rule,
                Type     = RuleType.Exclude
            });

            return(true);
        }
        /// <summary>
        /// Creates an instance of the class, opening a connection to the Windows
        /// File History service.
        /// </summary>
        public FileHistoryService(IJ4JLogger <FileHistoryService> logger)
        {
            _logger = logger ?? throw new NullReferenceException(nameof(logger));

            try
            {
                FhServiceOpenPipe(true, ref _pipe);

                if (_pipe.Equals(IntPtr.Zero))
                {
                    _logger.Fatal(NoPipeError);
                    throw new NullReferenceException("failed to open pipe to File History Service");
                }

                _logger.Information("Opened pipe to File History Service");

                _svcCtrl = new ServiceController(ServiceName);
                _logger.Information("Created service controller");
            }
            catch (Exception e)
            {
                var error = FileHistoryErrors.GetError(e);
                _logger.Fatal(error);

                throw e;
            }
        }
Exemple #4
0
        public void SaveConfiguration()
        {
            try
            {
                _fhMgr.SaveConfiguration();
                _logger.Information("Saved configuration");
            }
            catch (Exception e)
            {
                var error = FileHistoryErrors.GetError(e);
                _logger.Error(error);
            }

            _rules = null; // force regeneration
            _logger.Information("Cleared list of rules");
        }
Exemple #5
0
        public void CreateConfiguration(bool overwrite)
        {
            try
            {
                _fhMgr.CreateDefaultConfiguration(overwrite);
                _logger.Information("Created default configuration");
            }
            catch (Exception e)
            {
                var error = FileHistoryErrors.GetError(e);
                _logger.Error(error);
            }

            _rules = null; // force regeneration
            _logger.Information("Cleared list of rules");
        }
Exemple #6
0
        public FileHistoryConfiguration(IJ4JLogger <FileHistoryConfiguration> histLogger, IJ4JLogger <FileHistoryService> svcLogger)
        {
            _logger = histLogger ?? throw new NullReferenceException(nameof(histLogger));

            if (svcLogger == null)
            {
                throw new NullReferenceException(nameof(svcLogger));
            }

            _fhMgr = new FHManager() as IFHManager;
            if (_fhMgr != null)
            {
                try
                {
                    _fhMgr.LoadConfiguration();

                    _logger.Information("Loaded File History configuration");
                    _logger.Information(
                        "Backing up to {TargetName} ({TargetUrl}) -- {TargetType}", TargetName, TargetUrl, propertyValue2: TargetType);
                }
                catch (Exception e)
                {
                    var error = FileHistoryErrors.GetError(e);
                    _logger.Fatal(error);

                    throw new NullReferenceException("Could not load File History configuration");
                }
            }
            else
            {
                _logger.Error(NoConfigError);
                throw new NullReferenceException("Could not load File History configuration");
            }

            _fhSvc = new FileHistoryService(svcLogger);
        }