public GetScheduleWeekResponse GetScheduleWeek(GetScheduleWeekRequest request) { OutputWeek week = new OutputWeek() { Name = nameComposer.GetWeekName(request.TypiconId, request.Date) }; GetScheduleDayRequest dayRequest = new GetScheduleDayRequest() { Date = request.Date, TypiconId = request.TypiconId, Handler = request.Handler, Language = request.Language, ThrowExceptionIfInvalid = request.ThrowExceptionIfInvalid, ApplyParameters = request.ApplyParameters, CheckParameters = request.CheckParameters }; int i = 0; while (i < 7) { GetScheduleDayResponse dayResponse = GetScheduleDay(dayRequest); week.Days.Add(dayResponse.Day); dayRequest.Date = dayRequest.Date.AddDays(1); i++; } return(new GetScheduleWeekResponse() { Week = week }); }
public GetScheduleWeekResponse GetScheduleWeek(GetScheduleWeekRequest request) { ScheduleWeek week = new ScheduleWeek() { Name = ruleSerializer.BookStorage.Oktoikh.GetWeekName(request.Date, false) }; GetScheduleDayRequest dayRequest = new GetScheduleDayRequest() { Date = request.Date, Typicon = request.Typicon, Handler = request.Handler, Language = request.Language, ThrowExceptionIfInvalid = request.ThrowExceptionIfInvalid, ApplyParameters = request.ApplyParameters, CheckParameters = request.CheckParameters }; int i = 0; while (i < 7) { GetScheduleDayResponse dayResponse = GetScheduleDay(dayRequest); week.Days.Add(dayResponse.Day); dayRequest.Date = dayRequest.Date.AddDays(1); i++; } return(new GetScheduleWeekResponse() { Week = week }); }
public void BerlukiRu_ComparingRequests() { EFUnitOfWork _unitOfWork = new EFUnitOfWork(); //BookStorage.Instance = BookStorageFactory.Create(); TypiconEntity typiconEntity = _unitOfWork.Repository <TypiconEntity>().Get(c => c.Name == "Типикон"); DateTime date = new DateTime(2017, 9, 24); //сначала как в запросе в контроллере BerlukiRuController GetScheduleDayRequest dayRequest1 = new GetScheduleDayRequest() { Date = date, Handler = new ScheduleHandler(), Typicon = typiconEntity, CheckParameters = new CustomParamsCollection <IRuleCheckParameter>().SetModeParam(HandlingMode.AstronomicDay) }; ScheduleService scheduleService = ScheduleServiceFactory.Create(); GetScheduleDayResponse dayResponse1 = scheduleService.GetScheduleDay(dayRequest1); //теперь как TypiconController GetScheduleDayRequest dayRequest2 = new GetScheduleDayRequest() { Date = date, Typicon = typiconEntity, Handler = new ScheduleHandler(), CheckParameters = new CustomParamsCollection <IRuleCheckParameter>().SetModeParam(HandlingMode.AstronomicDay) }; GetScheduleDayResponse dayResponse2 = scheduleService.GetScheduleDay(dayRequest2); GetScheduleWeekRequest weekRequest = new GetScheduleWeekRequest() { Date = date, Typicon = typiconEntity, Handler = new ScheduleHandler(), CheckParameters = new CustomParamsCollection <IRuleCheckParameter>().SetModeParam(HandlingMode.AstronomicDay) }; GetScheduleWeekResponse weekResponse = scheduleService.GetScheduleWeek(weekRequest); Assert.AreEqual(dayResponse1.Day.Name, dayResponse2.Day.Name); Assert.AreEqual(dayResponse1.Day.Name, weekResponse.Week.Days.Last().Name); }
public GetScheduleWeekResponse GetScheduleWeek(GetScheduleWeekRequest request) { string key = KEY_DAY + request.Date; var value = cacheStorage.Retrieve <ScheduleWeek>(key); if (value == null) { var response = service.GetScheduleWeek(request); value = response.Week; Store(key, value); return(response); } return(new GetScheduleWeekResponse() { Week = value }); }
public void BerlukiRu_Test() { EFUnitOfWork _unitOfWork = new EFUnitOfWork(); //BookStorage.Instance = BookStorageFactory.Create(); TypiconEntity typiconEntity = _unitOfWork.Repository <TypiconEntity>().Get(c => c.Name == "Типикон"); DateTime date = new DateTime(2017, 09, 03);//DateTime.Now; if ((date.DayOfWeek == DayOfWeek.Sunday) && (date.Hour > 17)) { date = date.AddDays(1); } GetScheduleWeekRequest weekRequest = new GetScheduleWeekRequest() { Date = date, Typicon = typiconEntity, Handler = new ScheduleHandler(), CheckParameters = new CustomParamsCollection <IRuleCheckParameter>().SetModeParam(HandlingMode.AstronomicDay) }; ScheduleService scheduleService = ScheduleServiceFactory.Create(); GetScheduleWeekResponse weekResponse = scheduleService.GetScheduleWeek(weekRequest); HtmlScheduleWeekViewer htmlViewer = new HtmlScheduleWeekViewer(); htmlViewer.Execute(weekResponse.Week); string resultString = htmlViewer.ResultString; weekRequest.Date = date.AddDays(7); weekResponse = scheduleService.GetScheduleWeek(weekRequest); htmlViewer.Execute(weekResponse.Week); resultString += htmlViewer.ResultString; Assert.Pass(resultString); }
private string GetHtmlString(DateTime date) { var response = _typiconEntityService.GetTypiconEntity(1); if ((date.DayOfWeek == DayOfWeek.Sunday) && (date.Hour > 17)) { date = date.AddDays(1); } var weekRequest = new GetScheduleWeekRequest() { Date = date, Typicon = response.TypiconEntity, Handler = new ScheduleHandler(), CheckParameters = new CustomParamsCollection <IRuleCheckParameter>().SetModeParam(HandlingMode.AstronomicDay) }; var weekResponse = _scheduleService.GetScheduleWeek(weekRequest); var htmlViewer = new HtmlScheduleWeekViewer(); htmlViewer.Execute(weekResponse.Week); string resultString = htmlViewer.ResultString; weekRequest.Date = date.AddDays(7); weekResponse = _scheduleService.GetScheduleWeek(weekRequest); htmlViewer.Execute(weekResponse.Week); resultString += htmlViewer.ResultString; _typiconEntityService.UpdateTypiconEntity(new UpdateTypiconEntityRequest() { TypiconEntity = response.TypiconEntity }); return(resultString); }
private void Execute() { if (textBoxFilePath.Text == "") { MessageBox.Show("Задайте путь к папке для сохранения файлов.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //try //{ GetScheduleWeekRequest weekRequest = new GetScheduleWeekRequest() { Date = SelectedDate, Typicon = _typiconEntity, Handler = new ScheduleHandler(), Language = "cs-ru", ThrowExceptionIfInvalid = checkBoxException.Checked, ApplyParameters = CustomParameters, CheckParameters = new CustomParamsCollection <IRuleCheckParameter>().SetModeParam(HandlingMode.AstronomicDay) }; GetScheduleWeekResponse weekResponse = _scheduleService.GetScheduleWeek(weekRequest); _unitOfWork.SaveChanges(); //string messageString = ""; if (checkBoxDocx.Checked) { HandleTemplateRequest request = new HandleTemplateRequest() { FileTemplateName = Properties.Settings.Default.TemplateFilePath, OutputFolderPath = Properties.Settings.Default.OutputDirectoryPath, ScheduleFileStart = Properties.Settings.Default.ScheduleFileStart, ScheduleWeek = weekResponse.Week, OpenFileAfterHandling = checkBoxIsDocxOpen.Checked, }; var response = _docxTemplateService.Operate(request); if (response.Exception != null) { MessageBox.Show(response.Exception.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //if (textBoxTemplatePath.Text == "") //{ // MessageBox.Show("Определите файл docx шаблона.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} //string fileTemplateName = textBoxTemplatePath.Text; //string fileOutputName = GetFileName(_selectedDate) + ".docx"; //if (File.Exists(fileOutputName)) // File.Delete(fileOutputName); //string dirPath = Path.GetDirectoryName(fileOutputName); //if (!Directory.Exists(dirPath)) // Directory.CreateDirectory(dirPath); //File.Copy(fileTemplateName, fileOutputName); //DocxScheduleWeekViewer docxViewer = new DocxScheduleWeekViewer(fileOutputName); //docxViewer.Execute(weekResponse.Week); //messageString += "\nПечатная версия была успешно сохранена. "; FillDateCaptions(); //if (checkBoxIsDocxOpen.Checked) //{ // System.Diagnostics.Process proc = new System.Diagnostics.Process(); // proc.StartInfo.FileName = fileOutputName; // proc.StartInfo.UseShellExecute = true; // proc.Start(); //} } if (checkBoxBigDocx.Checked) { HandleTemplateRequest request = new HandleTemplateRequest() { FileTemplateName = Properties.Settings.Default.BigTemplateFilePath, OutputFolderPath = Properties.Settings.Default.OutputDirectoryPath, ScheduleFileStart = Properties.Settings.Default.BigScheduleFileStart, DaysPerTable = 4, ScheduleWeek = weekResponse.Week, OpenFileAfterHandling = checkBoxIsBigDocxOpen.Checked, }; var response = _docxTemplateService.Operate(request); if (response.Exception != null) { MessageBox.Show(response.Exception.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //if (textBoxTemplatePath.Text == "") //{ // MessageBox.Show("Определите файл docx шаблона.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} //string fileTemplateName = textBoxTemplatePath.Text; //string fileOutputName = GetFileName(_selectedDate) + ".docx"; //if (File.Exists(fileOutputName)) // File.Delete(fileOutputName); //string dirPath = Path.GetDirectoryName(fileOutputName); //if (!Directory.Exists(dirPath)) // Directory.CreateDirectory(dirPath); //File.Copy(fileTemplateName, fileOutputName); //DocxScheduleWeekViewer docxViewer = new DocxScheduleWeekViewer(fileOutputName); //docxViewer.Execute(weekResponse.Week); //messageString += "\nПечатная версия была успешно сохранена. "; FillDateCaptions(); //if (checkBoxIsDocxOpen.Checked) //{ // System.Diagnostics.Process proc = new System.Diagnostics.Process(); // proc.StartInfo.FileName = fileOutputName; // proc.StartInfo.UseShellExecute = true; // proc.Start(); //} } if (checkBoxTxt.Checked) { HtmlScheduleWeekViewer htmlViewer = new HtmlScheduleWeekViewer(); htmlViewer.Execute(weekResponse.Week); //textBoxResult.Clear(); //textBoxResult.AppendText(htmlViewer.ResultString); if (checkBoxWordpress.Checked) { using (FormPassword testDialog = new FormPassword()) { // Show testDialog as a modal dialog and determine if DialogResult = OK. if (testDialog.ShowDialog(this) == DialogResult.OK) { if (testDialog.textBoxPassword.Text == Properties.Settings.Default.PasswordToPostWordpress) { DateTime datePub = _selectedDate.AddDays(-8).AddHours(17).AddMinutes(30); PostToWordPress(weekResponse.Week.Name, htmlViewer.ResultString, datePub); MessageBox.Show($"Запись размещена на сайте. Дата публикации - {datePub.ToString("hh:mm dd MMMM yyyy года.")}", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { // Read the contents of testDialog's TextBox. MessageBox.Show("Неверный пароль. Расписание не было опубликовано на сайте.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } } //MessageBox.Show(messageString, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); #region to TextBox textBoxResult.Clear(); textBoxResult.AppendText(weekResponse.Week.Name + Environment.NewLine); foreach (ScheduleDay day in weekResponse.Week.Days) { textBoxResult.AppendText("--------------------------" + Environment.NewLine); textBoxResult.AppendText(day.Date.ToShortDateString() + Environment.NewLine); textBoxResult.AppendText(day.Name + Environment.NewLine); textBoxResult.AppendText("Знак службы: " + day.SignName + Environment.NewLine); foreach (WorshipRuleViewModel el in day.Schedule) { string str = !string.IsNullOrEmpty(el.Time) ? $"{el.Time} " : ""; str += $"{el.Name} {el.AdditionalName + Environment.NewLine}"; textBoxResult.AppendText(str); } } #endregion //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); //} }