Exemple #1
0
 /// <summary>
 /// Logs in to the Coyote system
 /// </summary>
 /// <param name="username">Username to log in with</param>
 /// <param name="password">Password to log in with</param>
 public async Task LoginAsync(string username, string password)
 {
     await coyoteHandler.Login(username, password).ConfigureAwait(false);
 }
Exemple #2
0
        private static void Main(string[] args)
        {
            analyzed = new HashSet <int>();

            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
                         .AddEnvironmentVariables("ELEIA_")
                         .AddCommandLine(args)
                         .Build();

            var username = config.GetValue <string>("username");
            var password = config.GetValue <string>("password");

            timeBetweenUpdates = config.GetValue("timeBetweenUpdates", 60);

            nagMessage = config.GetValue("nagMessage", "Hej! Twój post prawdopodobnie zawiera niesformatowany kod. Użyj znaczników ``` aby oznaczyć, co jest kodem, będzie łatwiej czytać. (jestem botem, ta akcja została wykonana automatycznie, prawdopodobieństwo {0})");

            Endpoints.IsDebug = config.GetValue("useDebug4p", true);
            postComments      = config.GetValue("postComments", false);

            var serviceProvider = new ServiceCollection()
                                  .AddLogging(builder => builder
                                              .AddConfiguration(config.GetSection("Logging"))
                                              .AddConsole())
                                  .AddSingleton(config)
                                  .AddTransient <CoyoteHandler>()
                                  .AddTransient <PostAnalyzer>()
                                  .BuildServiceProvider();

            ch = serviceProvider.GetService <CoyoteHandler>();
            pa = serviceProvider.GetService <PostAnalyzer>();

            logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger("Eleia");
            logger.LogInformation("Eleia is running...");

            if (postComments && (username == null || password == null))
            {
                logger.LogError("Username or password is not provided, but posting comments is set. Exiting.");
                Thread.Sleep(100);
                Environment.Exit(1);
            }

            logger.LogDebug("Will use username: {0}, will post comments: {1}, will use real 4programmers.net: {2}", username, postComments, !Endpoints.IsDebug);

            if (postComments)
            {
                ch.Login(username, password).Wait();
            }

            if (timeBetweenUpdates <= 0)
            {
                AnalyzeNewPosts().Wait();
                logger.LogDebug("Single run completed");
            }
            else if (timeBetweenUpdates > 0)
            {
                while (true)
                {
                    AnalyzeNewPosts().Wait();
                    logger.LogDebug("Going to sleep for {0} minutes", timeBetweenUpdates);
                    Thread.Sleep(TimeSpan.FromMinutes(timeBetweenUpdates));
                }
            }
        }