Example #1
0
        static void Main(string[] args)
        {
            // Print MOTD
            Console.WriteLine(File.ReadAllText("./etc/motd"));

            // Check if folder system is intact
            _logger.LogInformation("Checking folder system...");

            // Make sure 'etc' folder exists
            if (!Directory.Exists("./etc"))
            {
                _logger.LogInformation("'etc' folder not found...creating a new one.");

                Directory.CreateDirectory("./etc");
                // Add methos to generate config file.
                // W.I.P
            }
            // Make sure 'logs' folder exists
            if (!Directory.Exists("./logs"))
            {
                _logger.LogInformation("'logs' folder not found...creating a new one.");

                Directory.CreateDirectory("./logs");
            }
            _logger.LogInformation("Done.");

            // Start the bot
            new Client().RunAsync().GetAwaiter().GetResult();
        }
Example #2
0
        public Task InitializeAsync()
        {
            // Binding 'Log' events for logging
            _discordClient.Log  += LogAsync;
            _commandService.Log += LogAsync;

            // Log service initialization completion
            _logger.LogInformation("Initialization complete.");

            // Once all tasks have been completed, return 'Task.CompletedTask'
            return(Task.CompletedTask);
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddTransient <FizzBuzzModel>();

            CustomLogger.LogInformation("Added FizzBuzzModel to services");
        }
Example #4
0
 public static void IntegrationTest()
 {
     CustomLogger.LogInformation("Testing: Beggining integration test");
     TestFromOne();
     TestFromNegative();
     TestFromOver();
     TestAsync();
     CustomLogger.LogInformation("Testing: Integration test finished, see log for results");
 }
Example #5
0
        public async Task InitializeAsync()
        {
            // Register modules that are public and inherit ModuleBase<T>.
            await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);

            // Add additional initialization code here...

            // Log service initialization completion
            _logger.LogInformation("Initialization complete.");
        }
        public string[] Get(int start)
        {
            CustomLogger.LogInformation("Get FizzBuzz list: " + start);

            string[] list;

            try {
                list = fbm.getList(start);
            } catch (CustomException e) {
                CustomLogger.LogError(e.Message);
                list = new string[] { "error, see log for details: " + CustomLogger.GetLogPath() };
            }

            return(list);
        }
Example #7
0
    public void writeListToFile(string[] list)
    {
        CustomLogger.LogInformation("fizzbuzzmodel: writing list to file (async)");

        lock (lk) {
            using (StreamWriter sw = File.AppendText(path)) {
                sw.WriteLineAsync(DateTime.Now.ToString());
                foreach (string s in list)
                {
                    sw.WriteLineAsync(s);
                }
                sw.Close();
            }
        }

        CustomLogger.LogInformation("fizzbuzzmodel: finished writing list to file");
    }
Example #8
0
    public string[] getList(int start)
    {
        CustomLogger.LogInformation("fizzbuzzmodel: retrieving list from " + start);

        if (start > max)
        {
            throw new CustomException("fizzbuzzmodel: start index cannot be bigger than max value");
        }
        else if (start < 0)
        {
            throw new CustomException("fizzbuzzmodel: start index must be positive");
        }

        string[] list = new string[max - start + 1];
        Array.Copy(fizzBuzzList, start, list, 0, max - start + 1);
        Task.Run(() => writeListToFile(list));

        CustomLogger.LogInformation("fizzbuzzmodel: retrieved list");

        return(list);
    }
Example #9
0
    private void createList()
    {
        CustomLogger.LogInformation("fizzbuzzmodel: generating list, max: " + max);

        if (max <= 0)
        {
            CustomLogger.LogWarning("fizzbuzzmodel: max value must be strictly positive, changing value to 20");
            max = 20;
        }

        string[] list = new string[max + 1];

        for (int i = 1; i <= max; i++)
        {
            if (i % 3 == 0 && i % 5 == 0)
            {
                list[i] = "fizzbuzz";
            }
            else if (i % 3 == 0)
            {
                list[i] = "fizz";
            }
            else if (i % 5 == 0)
            {
                list[i] = "buzz";
            }
            else
            {
                list[i] = i.ToString();
            }
        }

        fizzBuzzList = list;

        CustomLogger.LogInformation("fizzbuzzmodel: list generated");
    }