Exemple #1
0
        /// <summary>
        /// Configure our logging as requested by the user
        /// </summary>
        /// <param name="commandLine">Options selected by the user (if any).</param>
        private static void ConfigureLogging(CommandLineBase commandLine)
        {
            var logSetup = new LoggerSetup();

            var consoleLevel = TryParse(commandLine.LogLevel, "console", LogLevel.Information);
            var actualLevel  = consoleLevel.HasValue ? consoleLevel.Value : LogLevel.Information;

            logSetup.SendToConsole(actualLevel);

            var fileLevel = TryParse(commandLine.LogFileLevel, "file", actualLevel);

            if (!string.IsNullOrEmpty(commandLine.LogFile))
            {
                if (fileLevel.HasValue)
                {
                    var file = new FileInfo(commandLine.LogFile);
                    logSetup.SendToFile(file, fileLevel.Value);
                }
            }

            var logger = logSetup.Logger;

            logger.LogHeader("Software Entitlement Service Test Utility");
            logger.LogErrors(consoleLevel.Errors);
            logger.LogErrors(fileLevel.Errors);

            if (!consoleLevel.HasValue || !fileLevel.HasValue)
            {
                // A problem during setup, don't share our config
                return;
            }

            _logger   = logger;
            _provider = logSetup.Provider;
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            var configuration    = ApplicationConfiguration.Read <UlearnConfiguration>();
            var logsSubdirectory = configuration.GraphiteServiceName + (configuration.Environment == "staging" ? "-dev" : null);

            LoggerSetup.Setup(configuration.HostLog, logsSubdirectory);
            DirectoryInfo сompilerDirectory = null;

            if (args.Any(x => x.StartsWith("-p:")))
            {
                var path = args.FirstOrDefault(x => x.StartsWith("-p:"))?.Substring(3);
                if (path != null)
                {
                    сompilerDirectory = new DirectoryInfo(path);
                }
            }

            var isSelfCheck = args.Contains("--selfcheck");

            var program = new Program(сompilerDirectory);

            if (isSelfCheck)
            {
                program.SelfCheck();
            }
            else
            {
                program.Run();
            }
        }
Exemple #3
0
        private static void SetupLog(IVostokCompositeLogBuilder logBuilder, UlearnConfiguration ulearnConfiguration)
        {
            var log = LoggerSetup.Setup(ulearnConfiguration.HostLog, ulearnConfiguration.GraphiteServiceName, false);

            logBuilder.AddLog(log);
            logBuilder.CustomizeLog(logCustomization => logCustomization.WithMinimumLevel(LogLevel.Debug));

            const LogLevel minimumLevel         = LogLevel.Info;
            var            dbMinimumLevelString = ulearnConfiguration.HostLog.DbMinimumLevel ?? "";

            if (!LoggerSetup.TryParseLogLevel(dbMinimumLevelString, out var dbMinimumLevel))
            {
                dbMinimumLevel = minimumLevel;
            }
            var min = dbMinimumLevel > minimumLevel ? minimumLevel : dbMinimumLevel;

            logBuilder.SetupHerculesLog(herculesLogBuilder =>
            {
                herculesLogBuilder.SetStream(ulearnConfiguration.Hercules.Stream);
                herculesLogBuilder.SetApiKeyProvider(() => ulearnConfiguration.Hercules.ApiKey);
                herculesLogBuilder.CustomizeLog(lb =>
                                                lb
                                                .WithMinimumLevelForSourceContext("ULearnDb", dbMinimumLevel) // Database
                                                .WithMinimumLevel(min)
                                                );
            });
        }
Exemple #4
0
 private void BuildGenericManager<T>(){
 
 if (systemLogger == null)
             {
                 LoggerSetup.Configure(Constants.ModuleNameForLogging);
                 systemLogger = new Log4NetLoggingAdapter(LogManager.GetLogger(typeof(RequestManager)));
             }
             proxy = WcfClientProxy.Create<T>(c =>
             {
                 c.SetEndpoint("BasicHttpBinding_IRequestService");
 
                 c.OnCallBegin += (sender, args) => { };
 
                 c.OnBeforeInvoke += (sender, args) =>
                 {
                     systemLogger.Write(string.Format("{0}.{1} called with parameters: {2}", args.ServiceType.Name, args.InvokeInfo.MethodName, string.Join(", ", args.InvokeInfo.Parameters)), Core.EventSeverity.Verbose);
                 };
 
                 c.OnAfterInvoke += (sender, args) =>
                 {
                     systemLogger.Write(string.Format("{0}.{1} returned value: {2}", args.ServiceType.Name, args.InvokeInfo.MethodName, args.InvokeInfo.ReturnValue), Core.EventSeverity.Verbose);
                 };
 
                 c.OnCallSuccess += (sender, args) =>
                 {
                     systemLogger.Write(string.Format("{0}.{1} completed successfully", args.ServiceType.Name, args.InvokeInfo.MethodName));
                 };
 
                 c.OnException += (sender, args) =>
                 {
                     systemLogger.Write(string.Format("Exception during service call to {0}.{1}: {2}", args.ServiceType.Name, args.InvokeInfo.MethodName, args.Exception.Message), args.Exception, Core.EventSeverity.Error);
                 };
             });
         }
        public static void Execute(StorageEnvironmentOptions srcOptions,
                                   StorageEnvironmentOptions.DirectoryStorageEnvironmentOptions compactOptions,
                                   LoggerSetup loggerSetup,
                                   Action <CompactionProgress> progressReport = null)
        {
            if (srcOptions.IncrementalBackupEnabled)
            {
                throw new InvalidOperationException(CannotCompactBecauseOfIncrementalBackup);
            }

            long minimalCompactedDataFileSize;

            srcOptions.ManualFlushing     = true; // prevent from flushing during compaction - we shouldn't touch any source files
            compactOptions.ManualFlushing = true; // let us flush manually during data copy

            using (var existingEnv = new StorageEnvironment(srcOptions, loggerSetup))
                using (var compactedEnv = new StorageEnvironment(compactOptions, loggerSetup))
                {
                    CopyTrees(existingEnv, compactedEnv, progressReport);

                    compactedEnv.FlushLogToDataFile(allowToFlushOverwrittenPages: true);

                    compactedEnv.Journal.Applicator.SyncDataFile(compactedEnv.OldestTransaction);
                    compactedEnv.Journal.Applicator.DeleteCurrentAlreadyFlushedJournal();

                    minimalCompactedDataFileSize = compactedEnv.NextPageNumber * existingEnv.Options.PageSize;
                }

            using (var compactedDataFile = new FileStream(Path.Combine(compactOptions.BasePath, Constants.DatabaseFilename), FileMode.Open, FileAccess.ReadWrite))
            {
                compactedDataFile.SetLength(minimalCompactedDataFileSize);
            }
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            Process p = Process.GetCurrentProcess();

            p.PriorityClass = ProcessPriorityClass.High;

            LoggerSetup.Initialize();

            Language.Instance.SetLanguage("Swedish");

            Recellection game      = new Recellection();
            Initializer  logic     = new Initializer(game.Window.Handle);
            Thread       gameLogic = new Thread(logic.Run);

            game.LogicThread        = gameLogic;
            Recellection.textureMap = new SpriteTextureMap(game.Content);

            FullScreen(game.Window.Handle);


            game.Run();
            gameLogic.Abort();
            Environment.Exit(0);
            // MOAR EXITS! MOAR!!! DEATH TO ALL APPLICATION!
        }
Exemple #7
0
        private async Task MainAsync()
        {
            LoggerSetup.SetupLog();

            _client   = new DiscordSocketClient();
            _commands = new CommandService();

            var configBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", false, true);
            var configuration = configBuilder.Build();

            await InstallCommandsAsync(configuration);

            _logger = LogManager.GetCurrentClassLogger();

            _client.Log += Log;

            var discordSettings = new DiscordSettings();

            configuration.Bind("Discord", discordSettings);

            await _client.LoginAsync(Discord.TokenType.Bot, discordSettings.Token);

            await _client.StartAsync();

            var chronoGgService = _services.GetService <ChronoGgService>();
            await chronoGgService.StartService();

            var mehService = _services.GetRequiredService <MehService>();
            await mehService.StartService();

            _logger.Debug("Bot running at {0}", DateTime.Now);

            await Task.Delay(-1);
        }
Exemple #8
0
 /// <summary>
 /// Creates an empty graph controller.
 /// Nothing to it, really.
 /// </summary>
 protected GraphController()
 {
     components = new List <Graph>();
     logger.SetThreshold(LogLevel.ERROR);
     logger.SetTarget(LoggerSetup.GetLogFileTarget("graphcontrol.log"));
     logger.Info("Constructed a new GraphController.");
 }
Exemple #9
0
        public static async Task Main(string[] args)
        {
            var configuration = ApplicationConfiguration.Read <UlearnConfiguration>();

            LoggerSetup.Setup(configuration.HostLog, configuration.GraphiteServiceName);
            var optionsBuilder = new DbContextOptionsBuilder <UlearnDb>()
                                 .UseLazyLoadingProxies()
                                 .UseSqlServer(configuration.Database);
            var db = new UlearnDb(optionsBuilder.Options);
            var aOptionsBuilder = new DbContextOptionsBuilder <AntiPlagiarismDb>()
                                  .UseLazyLoadingProxies()
                                  .UseSqlServer(configuration.Database);
            var adb = new AntiPlagiarismDb(aOptionsBuilder.Options);

            //await ResendLti(db);
            //await FindExternalSolutionsPlagiarism.UploadSolutions();
            //await FindExternalSolutionsPlagiarism.GetRawResults();
            //await FindExternalSolutionsPlagiarism.PrepareResults();
            //await UpdateExerciseVisits(db, "fpIntroduction");

            //Users.PrintCourseAdmins(db);
            //await ScoresUpdater.UpdateTests(db, "java-rtf");
            //GetMostSimilarSubmission(adb);
            //ParsePairWeightsFromLogs();
            //GetBlackAndWhiteLabels(db, adb);
            //ParseTaskWeightsFromLogs();
            //CampusRegistration();
            //GetIps(db);
            //FillAntiplagFields.FillClientSubmissionId(adb);
            //await XQueueRunAutomaticChecking(db);
        }
Exemple #10
0
        public static void Main(string[] args)
        {
            var configuration    = ApplicationConfiguration.Read <UlearnConfiguration>();
            var logsSubdirectory = configuration.GraphiteServiceName + (configuration.Environment == "staging" ? "-dev" : null);

            LoggerSetup.Setup(configuration.HostLog, logsSubdirectory);
            try
            {
                var selfCheckIndex = args.FindIndex("--selfcheck");

                var program    = new Program(configuration.GraphiteServiceName);
                var hasNextArg = args.Length > selfCheckIndex + 1;
                if (selfCheckIndex >= 0 && hasNextArg)
                {
                    program.SelfCheck(args[selfCheckIndex + 1]);
                }
                else
                {
                    program.Run();
                }
            }
            finally
            {
                FileLog.FlushAll();
            }
        }
        public StorageEnvironment(StorageEnvironmentOptions options, LoggerSetup loggerSetup)
        {
            try
            {
                _loggerSetup       = loggerSetup;
                _options           = options;
                _dataPager         = options.DataPager;
                _freeSpaceHandling = new FreeSpaceHandling();
                _headerAccessor    = new HeaderAccessor(this);
                var isNew = _headerAccessor.Initialize();

                _scratchBufferPool = new ScratchBufferPool(this);

                _journal = new WriteAheadJournal(this);

                if (isNew)
                {
                    CreateNewDatabase();
                }
                else // existing db, let us load it
                {
                    LoadExistingDatabase();
                }

                if (_options.ManualFlushing == false)
                {
                    Task.Run(IdleFlushTimer);
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
        }
Exemple #12
0
        private static void RunZFile(string zFile)
        {
            var progId = Path.GetFileNameWithoutExtension(zFile);

            new ZMachine2(
                new UserIo(progId),
                new ConsoleFileIo(progId),
                LoggerSetup.Create <ZMachine2>()
                ).RunFile(zFile);
        }
        static void Main(string[] args)
        {
            Title      = "Seed Node 1";
            Log.Logger = LoggerSetup.LogToConsoleAndSeq("http://localhost:5341");

            Log.Information("Seed Node 1 has started");

            ReadKey();
            Log.Information("Seed Node 1 has stopped");
        }
Exemple #14
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureLogging((hostingContext, logging) =>
 {
     logging.ClearProviders();
     LoggerSetup.Configure(hostingContext);
     logging.AddSerilog(Log.Logger);
 })
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder.UseStartup <Startup>();
 });
Exemple #15
0
        public static void ConfigureLogging()
        {
            var configuration = ApplicationConfiguration.Read <UlearnConfiguration>();
            var log           = LoggerSetup.Setup(configuration.HostLog, configuration.GraphiteServiceName, false)
                                .WithProperty("user", () => new HttpContextUserNameProvider().ToString())
                                .WithProperty("address", () => new HttpContextAddressProvider().ToString());

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Sink(new VostokSink(log))
                         .CreateLogger();
            SerilogWebClassic.Configure(cfg => cfg.UseLogger(Log.Logger));
            LogProvider.Configure(log);
        }
        static void Main(string[] args)
        {
            Title           = "Remote Node";
            BackgroundColor = ConsoleColor.DarkBlue;
            Log.Logger      = LoggerSetup.LogToConsoleAndSeq("http://localhost:5341");

            using (var actorSystem = ActorSystem.Create("RemoteNode"))
            {
                Log.Information("remote Node up");

                ReadKey();
            }
        }
Exemple #17
0
        static void Main(string[] args)
        {
            var configuration = ApplicationConfiguration.Read <UlearnConfiguration>();

            LoggerSetup.Setup(configuration.HostLog, configuration.GraphiteServiceName);
            /* Pass first argument 'send' to send emails to addresses from `emails.txt` with content from `content.txt` (notifications daemon is not started in this case)*/
            if (args.Length > 0 && args[0] == "send")
            {
                var sender = new OneTimeEmailSender();
                sender.SendEmailsAsync().Wait();
                return;
            }

            new Program().MainLoop().Wait();
        }
Exemple #18
0
        static void Main(string[] args)
        {
            Title = "Parent node - remoting";

            Log.Logger = LoggerSetup.LogToConsoleAndSeq("http://localhost:5341");
            Log.Information("Start parent node");
            using (var actorSystem = ActorSystem.Create("remoteExample"))
            {
                var logProcessedActor = actorSystem.ActorOf(Props.Create <LogProcessedDataActor>(), "LogProcessed");
                var processActor      = actorSystem.ActorOf(Props.Create(() => new SampleProcessActor(logProcessedActor)), "ProcessActor");
                var remoteManager     = actorSystem.ActorOf(Props.Create(() => new RemoteManagerActor(processActor)), "RemoteManager");

                ReadKey();
            }
        }
Exemple #19
0
        private static LogLevel GetDbMinimumLevelFromConfig()
        {
            var configuration        = ApplicationConfiguration.Read <UlearnConfiguration>();
            var minimumLevelString   = configuration.HostLog.MinimumLevel ?? "debug";
            var dbMinimumLevelString = configuration.HostLog.DbMinimumLevel ?? "";

            if (!LoggerSetup.TryParseLogLevel(minimumLevelString, out var minimumLevel))
            {
                minimumLevel = LogLevel.Debug;
            }
            if (!LoggerSetup.TryParseLogLevel(dbMinimumLevelString, out var dbMinimumLevel))
            {
                dbMinimumLevel = minimumLevel;
            }
            return(dbMinimumLevel);
        }
Exemple #20
0
        private static void Main(string[] args)
        {
            var settings            = JObject.Parse(File.ReadAllText("appsettings.json"));
            var hostLog             = settings["hostLog"].ToObject <HostLogConfiguration>();
            var graphiteServiceName = settings["graphiteServiceName"].Value <string>();

            LoggerSetup.Setup(hostLog, graphiteServiceName);
            try
            {
                var staff = new StaffClient(settings["staff"]["clientAuth"].Value <string>());
                if (args.Contains("-r"))
                {
                    Console.WriteLine("Username (example: KONTUR\\pe):");
                    var username = Console.ReadLine();
                    Console.WriteLine($"Password for {username}:");
                    var password     = GetConsolePassword();
                    var refreshToken = staff.GetRefreshToken(username, password);
                    Console.WriteLine($"RefreshToken: {refreshToken}");
                    return;
                }

                var telegramBot = new GiftsTelegramBot();
                try
                {
                    staff.UseRefreshToken(settings["staff"]["refreshToken"].Value <string>());
                    var maxGiftsPerRun = args.Length > 0 ? int.Parse(args[0]) : settings["maxGiftsPerRun"].Value <int>();
                    log.Info("UseGiftGrantsLimitPerRun\t" + maxGiftsPerRun);
                    var db      = new ULearnDb();
                    var repo    = new VisitsRepo(db);
                    var courses = settings["courses"].Values <string>();
                    var program = new Program(repo, staff, maxGiftsPerRun, settings, telegramBot);
                    foreach (var courseId in courses)
                    {
                        program.GrantGiftsForCourse(courseId);
                    }
                }
                catch (Exception e)
                {
                    telegramBot.PostToChannel($"Error while grant staff gifts.\n\n{e}");
                    log.Error(e, "UnhandledException");
                }
            }
            finally
            {
                FileLog.FlushAll();
            }
        }
Exemple #21
0
        /// <summary>
        /// Simple test for the non-interrupt version
        /// </summary>
        /// <param name="zFile"></param>
        // ReSharper disable once UnusedMember.Local
        private static void RunZFileWithoutInterrupts(string zFile)
        {
            var progId = Path.GetFileNameWithoutExtension(zFile);

            _zMachine2 = new ZMachine2(
                new UserIo(progId),
                new ConsoleFileIo(progId),
                LoggerSetup.Create <ZMachine2>()
                );
            _zMachine2.RunFile(File.OpenRead(zFile), false);

            do
            {
                var input = Console.ReadLine();
                _zMachine2.ContinueTillNextRead(input);
            } while (_zMachine2.Running);
        }
Exemple #22
0
        public static async Task Main(string[] args)
        {
            var configuration = ApplicationConfiguration.Read <UlearnConfiguration>();

            LoggerSetup.Setup(configuration.HostLog, configuration.GraphiteServiceName);
            try
            {
                var optionsBuilder = new DbContextOptionsBuilder <UlearnDb>()
                                     .UseLazyLoadingProxies()
                                     .UseNpgsql(configuration.Database, o => o.SetPostgresVersion(13, 2));
                var db = new UlearnDb(optionsBuilder.Options);
                var aOptionsBuilder = new DbContextOptionsBuilder <AntiPlagiarismDb>()
                                      .UseLazyLoadingProxies()
                                      .UseNpgsql(configuration.Database, o => o.SetPostgresVersion(13, 2));
                var adb             = new AntiPlagiarismDb(aOptionsBuilder.Options);
                var serviceProvider = ConfigureDI(adb, db);
                await Run(adb, db, serviceProvider);
            }
            finally
            {
                await FileLog.FlushAllAsync();
            }
        }
Exemple #23
0
		private static void SetupLog(IVostokCompositeLogBuilder logBuilder, UlearnConfiguration ulearnConfiguration)
		{
			var log = LoggerSetup.Setup(ulearnConfiguration.HostLog, ulearnConfiguration.GraphiteServiceName, false);
			logBuilder.AddLog(log);
			logBuilder.CustomizeLog(logCustomization => logCustomization.WithMinimumLevel(LogLevel.Debug));

			const LogLevel minimumLevel = LogLevel.Info;
			var dbMinimumLevelString = ulearnConfiguration.HostLog.DbMinimumLevel ?? "";
			if (!LoggerSetup.TryParseLogLevel(dbMinimumLevelString, out var dbMinimumLevel))
				dbMinimumLevel = minimumLevel;
			var min = dbMinimumLevel > minimumLevel ? minimumLevel : dbMinimumLevel;
			logBuilder.SetupHerculesLog(herculesLogBuilder =>
			{
				herculesLogBuilder.SetStream(ulearnConfiguration.Hercules.Stream);
				herculesLogBuilder.SetApiKeyProvider(() => ulearnConfiguration.Hercules.ApiKey);
				herculesLogBuilder.CustomizeLog(lb =>
					lb
						.DropEvents(LoggerSetup.FilterLogs)
						.SelectEvents(le => le.Level >= (LoggerSetup.IsDbSource(le) ? dbMinimumLevel : minimumLevel))
						.WithMinimumLevel(min)
				);
			});
		}
Exemple #24
0
        private ServiceProvider GetServiceProvider()
        {
            var configuration = ApplicationConfiguration.Read <AntiPlagiarismUpdateDbConfiguration>();

            var services = new ServiceCollection();

            services.AddOptions();

            services.Configure <AntiPlagiarismUpdateDbConfiguration>(ApplicationConfiguration.GetConfiguration());
            services.Configure <AntiPlagiarismConfiguration>(ApplicationConfiguration.GetConfiguration());

            LoggerSetup.Setup(configuration.HostLog, configuration.GraphiteServiceName);
            services.AddScoped(_ => GetDatabase(configuration));
            services.AddScoped <AntiPlagiarismSnippetsUpdater>();
            services.AddScoped <ISnippetsRepo, SnippetsRepo>();
            services.AddScoped <ISubmissionsRepo, SubmissionsRepo>();
            services.AddSingleton <CSharpCodeUnitsExtractor>();
            services.AddSingleton <CodeUnitsExtractor>();
            services.AddSingleton <TokensExtractor>();
            services.AddSingleton <SnippetsExtractor>();
            services.AddSingleton <SubmissionSnippetsExtractor>();

            return(services.BuildServiceProvider());
        }
Exemple #25
0
 public void GlobalSetup()
 {
     LoggerSetup.SetupForTests();
 }
Exemple #26
0
        public void Restore(StorageEnvironmentOptions options, IEnumerable <string> backupPaths, LoggerSetup loggerSetup)
        {
            var ownsPagers = options.OwnsPagers;

            options.OwnsPagers = false;
            using (var env = new StorageEnvironment(options, loggerSetup))
            {
                foreach (var backupPath in backupPaths)
                {
                    Restore(env, backupPath);
                }
            }
            options.OwnsPagers = ownsPagers;
        }