Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            //}
        }