Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                // See  https://issues.bloomlibrary.org/youtrack/issue/BL-8475.
                Console.WriteLine("Harvester cannot run on Linux until we verify that phash computations always yield the same result on both Windows and Linux!");
                return;
            }

            // See https://github.com/commandlineparser/commandline for documentation about CommandLine.Parser
            var parser = new CommandLine.Parser((settings) =>
            {
                settings.CaseInsensitiveEnumValues = true;
                settings.CaseSensitive             = false;
                settings.HelpWriter = Console.Error;
            });

            try
            {
                parser.ParseArguments <HarvesterOptions, UpdateStateInParseOptions, BatchUpdateStateInParseOptions, GenerateProcessedFilesTSVOptions>(args)
                .WithParsed <HarvesterOptions>(options =>
                {
                    options.ValidateOptions();
                    Harvester.RunHarvest(options);
                })
                .WithParsed <UpdateStateInParseOptions>(options =>
                {
                    HarvestStateUpdater.UpdateState(options.ParseDBEnvironment, options.ObjectId, options.NewState);
                })
                .WithParsed <BatchUpdateStateInParseOptions>(options =>
                {
                    HarvestStateBatchUpdater.RunBatchUpdateStates(options);
                })
                .WithParsed <GenerateProcessedFilesTSVOptions>(options =>
                {
                    ProcessedFilesInfoGenerator.GenerateTSV(options);
                })
                .WithNotParsed(errors =>
                {
                    Console.Out.WriteLine("Error parsing command line arguments.");
                    Environment.Exit(1);
                });
            }
            catch (Exception e)
            {
                YouTrackIssueConnector.GetInstance(EnvironmentSetting.Unknown).ReportException(e, "An exception was thrown which was not handled by the program.", null);
                throw;
            }
        }
 public void InitializeYouTrackConnector()
 {
     _connector = YouTrackIssueConnector.GetInstance(EnvironmentSetting.Test, "SB");
 }
Ejemplo n.º 3
0
        public AzureMonitorLogger(EnvironmentSetting environment, string harvesterId)
        {
            _issueReporter = YouTrackIssueConnector.GetInstance(environment);

            // Get the Instrumentation Key for Azure from an environment variable.
            string environmentVarName = "BloomHarvesterAzureAppInsightsKeyDev";

            if (environment == EnvironmentSetting.Test)
            {
                environmentVarName = "BloomHarvesterAzureAppInsightsKeyTest";
            }
            else if (environment == EnvironmentSetting.Prod)
            {
                environmentVarName = "BloomHarvesterAzureAppInsightsKeyProd";
            }

            string instrumentationKey = Environment.GetEnvironmentVariable(environmentVarName);

            Debug.Assert(!String.IsNullOrWhiteSpace(instrumentationKey), "Azure Instrumentation Key is invalid. Azure logging probably won't work.");

            try
            {
                Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
            }
            catch (ArgumentNullException e)
            {
                _issueReporter.ReportException(e, $"InstrumentationKey: {instrumentationKey ?? "null"}.\nenvironmentVarName: {environmentVarName}", null);
            }

            _telemetry.Context.User.Id                = "BloomHarvester " + harvesterId;
            _telemetry.Context.Session.Id             = Guid.NewGuid().ToString();
            _telemetry.Context.Device.OperatingSystem = Environment.OSVersion.ToString();

            string logFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "BloomHarvester", "log.txt");

            Console.Out.WriteLine("Creating log file at: " + logFilePath);
            try
            {
                if (File.Exists(logFilePath))
                {
                    // Check if the file is too big (~10 MB)
                    if (new FileInfo(logFilePath).Length > 10000000)
                    {
                        var oldPath = logFilePath + "-OLD";
                        // Preserve one previous log file for debugging help, and start over with
                        // an empty log file.
                        // (The data is in Azure too anyway, but having it local may speed things up.)
                        if (RobustFile.Exists(oldPath))
                        {
                            RobustFile.Delete(oldPath);
                        }
                        RobustFile.Move(logFilePath, oldPath);
                    }
                }
            }
            catch
            {
                // Doesn't matter if there are any errors
            }

            try
            {
                _fileLogger = new FileLogger(logFilePath);
            }
            catch
            {
                // That's unfortunate that creating the logger failed, but I don't really want to throw an exception since the file logger isn't even the main purpose of this calss.
                // Let's just replace it with something to get it to be quiet.
                _fileLogger = new NullLogger();
            }
        }