Example #1
0
        public async Task <IList <Root> > GetScheduleOnNextWeekAsync()
        {
            var scheduleResponse = await client.GetAsync(Links.BaseLink + Links.ScheduleLink);

            if (scheduleResponse.IsSuccessStatusCode)
            {
                var content = await scheduleResponse.Content.ReadAsStringAsync();

                var doc     = parser.ParseDocument(content);
                var element = doc.QuerySelector("script[type='text/javascript']");
                var id      = TextWorker.GetUserId(element.TextContent);

                var weekNumber  = (int)DateTime.Now.DayOfWeek;
                var dataRequest = DateTime.Now;
                if (weekNumber != 0)
                {
                    var weekStart = weekNumber - 1;
                    dataRequest = dataRequest.AddDays(-weekStart);
                }
                else
                {
                    dataRequest = dataRequest.AddDays(-6);
                }
                var jsonShedule = await GetJsonSchedule(id, dataRequest.AddDays(7));

                var schedule = JsonConvert.DeserializeObject <IList <Root> >(jsonShedule);
                return(schedule);
            }
            return(new List <Root>());
        }
Example #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var     requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic sportMessage = JsonConvert.DeserializeObject <CoachTextDto>(requestBody);


            try
            {
                var                 accountSid         = System.Environment.GetEnvironmentVariable("AccountSid");
                var                 authToken          = System.Environment.GetEnvironmentVariable("AuthToken");
                var                 fromPhone          = System.Environment.GetEnvironmentVariable("FromPhone");
                ISmsRepository      smsRepository      = new SmsRepository(accountSid, authToken, fromPhone);
                var                 connectionString   = System.Environment.GetEnvironmentVariable("SQLAZURECONNSTR_TrainingModel");
                var                 options            = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString ?? throw new InvalidOperationException()).Options;
                var                 context            = new PwsodbContext(options);
                ITrainingRepository trainingRepository = new TrainingRepository(context);
                var                 worker             = new TextWorker(trainingRepository, smsRepository);
                var                 numOfSms           = await worker.SendSmsForSport(sportMessage);

                return((ActionResult) new OkObjectResult(numOfSms));
            }
            catch (Exception ex)
            {
                return((ActionResult) new BadRequestObjectResult(ex));
            }
        }
Example #3
0
        public void SendEmailsForSport_WithoutMock(int sportId, int?locationId, int?categoryId, int?teamId, bool?selected, bool?volunteerOnly, int expected)

        {
            IConfiguration config           = new ConfigurationBuilder().AddJsonFile("appsettings.test.json").Build();
            var            connectionString = config["TrainingDatabase"];
            var            options          = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString).Options;

            PwsodbContext context = new PwsodbContext(options);

            const string plainTextContent = "testing PWSO sending text messages";
            CoachTextDto message          = new CoachTextDto
            {
                SportId     = sportId,
                Message     = plainTextContent,
                IsVolunteer = volunteerOnly,
                Selected    = selected,
                ProgramId   = locationId,
                SportTypeId = categoryId,
                TeamId      = teamId
            };
            ITrainingRepository trainingRepository = new TrainingRepository(context);
            var            accountSid      = config["AccountSid"];
            var            authToken       = config["AuthToken"];
            var            fromPhone       = config["FromPhone"];
            ISmsRepository emailRepository = new SmsRepository(accountSid, authToken, fromPhone);
            TextWorker     worker          = new TextWorker(trainingRepository, emailRepository);


            //var actual = worker.SendSmsForSport(message);
            //Assert.Equal(expected, actual.Result);
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic teams       = JsonConvert.DeserializeObject <TournamentDto>(requestBody);


            try
            {
                var apiKey = System.Environment.GetEnvironmentVariable("ApiKey");
                IEmailRepository emailRepository         = new EmailRepository(apiKey);
                var                  connectionString    = System.Environment.GetEnvironmentVariable("SQLAZURECONNSTR_TrainingModel");
                var                  options             = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString).Options;
                PwsodbContext        context             = new PwsodbContext(options);
                ITrainingRepository  trainingRepository  = new TrainingRepository(context);
                IReferenceRepository referenceRepository = new ReferenceRepository(context);
                ReferenceWorker      refWorker           = new ReferenceWorker(referenceRepository);
                EmailWorker          emailWorker         = new EmailWorker(trainingRepository, emailRepository);
                var                  accountSid          = System.Environment.GetEnvironmentVariable("AccountSid");
                var                  authToken           = System.Environment.GetEnvironmentVariable("AuthToken");
                var                  fromPhone           = System.Environment.GetEnvironmentVariable("FromPhone");
                ISmsRepository       smsRepository       = new SmsRepository(accountSid, authToken, fromPhone);
                var                  textWorker          = new TextWorker(trainingRepository, smsRepository);

                foreach (var team in teams.Teams)
                {
                    var emailMessage = refWorker.ChampionshipEmailPreparation(team);
                    var textMessage  = refWorker.ChampionshipTextPreparation(team);
                    var numOfEmails  = await emailWorker.SendEmailsForSport(emailMessage);

                    var numOfSms = await textWorker.SendSmsForSport(textMessage);
                }

                return((ActionResult) new OkObjectResult(1));
            }
            catch (Exception ex)
            {
                return((ActionResult) new BadRequestObjectResult(ex));
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            List <Symbol> symbols = new List <Symbol>();

            Console.WriteLine("Введите текст, который нужно зашифровать");
            string Text = Console.ReadLine();//"Это текст который я придумал для себя лично";

            // Обработка исключения связанного с неккоректным вводом
            if (Text.Length < 2)
            {
                Console.WriteLine("Вы ввели слишком короткий текст");
                Console.WriteLine("Вместо него будет введено слово 'Тортик'\nПотому что тортик это клево :)");
                Text = "Тортик";
            }
            // Кодируем текст методом Шеннона Фано (код подключен из проекта прошлой лабораторной)
            symbols = TextWorker.Fragmentation(Text);
            Sort.SortListDesc(symbols);
            MethodShenonnaFano.Algoritm(symbols);
            OutputRezultInConsole.OutputRezult(symbols);

            // Кодируем исходный текст и фасуем его по сообщениям определенной длины
            List <string> messages = new List <string>();

            messages = CodingHemming.PreparingMessage(symbols, Text);

            Console.WriteLine("Нажмите клавишу для продолжения");
            Console.ReadKey(true);
            Console.Clear();

            //Эмуляция отправки сообщения с одной ошибкой
            CodingHemming.SendingMessageEmulation(messages);

            // Повторный расчет контрольных бит
            CodingHemming.CalculationControlBits(messages);
            // Превращаем полученное сообщение обратно в текст
            string Message = CodingHemming.DeleteControlBits(messages);

            Decoder.DecoderMethShenonnaFano(symbols, Message);

            Console.ReadKey(true);
        }
Example #6
0
 public TextWorkerTest()
 {
     _mockTrainingRepository = new Mock <ITrainingRepository>();
     _mockSmsRepository      = new Mock <ISmsRepository>();
     _worker = new TextWorker(_mockTrainingRepository.Object, _mockSmsRepository.Object);
 }