/// <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;
            }
        }
Пример #2
0
        public StoreKeyApp(
            AppConfig config,
            IHostApplicationLifetime lifetime,
            IIndex <string, IConfigurationUpdater> configUpdaters,
            J4JHostInfo hostInfo,
            IJ4JProtection protection,
            IJ4JLogger?logger
            )
        {
            _config     = config;
            _lifetime   = lifetime;
            _hostInfo   = hostInfo;
            _protection = protection;

            _logger = logger;
            _logger?.SetLoggedType(GetType());

            if (!configUpdaters.TryGetValue(AutofacKey, out var updater) || !updater.Update(_config))
            {
                return;
            }

            _logger?.Fatal("Incomplete configuration, aborting");
            _lifetime.StopApplication();
        }
Пример #3
0
        public RouteApp(
            AppConfig config,
            IHostApplicationLifetime lifetime,
            IIndex <string, IConfigurationUpdater> configUpdaters,
            IIndex <ImportType, IImporter> importers,
            IIndex <ExportType, IExporter> exporters,
            IIndex <ProcessorType, IRouteProcessor> snapProcessors,
            IJ4JLogger logger
            )
        {
            _config    = config;
            _lifetime  = lifetime;
            _importers = importers;

            _exporter = exporters[config.ExportType];

            _distProc = snapProcessors[ProcessorType.Distance];
            _distProc.PointsProcessed += PointsProcessedHandler;

            _logger = logger;
            _logger.SetLoggedType(GetType());

            if (configUpdaters.TryGetValue(AutofacKey, out var updater) &&
                updater.Update(_config))
            {
                _routeProc = snapProcessors[config.ProcessorType];
                _routeProc.PointsProcessed += PointsProcessedHandler;

                return;
            }

            _logger.Fatal("Incomplete configuration, aborting");
            _lifetime.StopApplication();
        }
Пример #4
0
        public static Nodes <T> ToNodeList <T>(
            this IEnumerable <T> source,
            IEqualityComparer <T>?comparer = null,
            IJ4JLogger?logger = null)
            where T : class, IEquatable <T>
        {
            var retVal = new Nodes <T>(comparer);

            var idx      = 0;
            var nodeList = source.ToList();

            foreach (var node in nodeList)
            {
                var nodeType = node.GetType();

                var predAttr = nodeType.GetCustomAttribute <PredecessorAttribute>(false);
                if (predAttr == null)
                {
                    logger?.Error("Node type '{0}' (item {1}) is not decorated with a PredecessorAttribute", nodeType, idx);
                    continue;
                }

                if (predAttr.Predecessor == null)
                {
                    retVal.AddIndependentNode(node);
                }
                else
                {
                    var predecessor = nodeList.FirstOrDefault(x => x.GetType() == predAttr.Predecessor);
                    if (predecessor == null)
                    {
                        logger?.Fatal <string>("Couldn't find predecessor extractor {0}", predAttr.Predecessor.Name);
                        continue;
                    }

                    retVal.AddDependentNode(node, predecessor);
                }

                idx++;
            }

            return(retVal);
        }
Пример #5
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);
        }