public void GenerateDocumentFromFileAndObjectTest()
        {
            var fileName = Path.GetTempFileName();

            try
            {
                var file = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

                var templateBody = Properties.Resources.MeetingNotesTemplate;
                file.Write(templateBody, 0, templateBody.Length);
                file.Close();

                var subject      = "Sample subject";
                var meetingNotes = new MeetingNotes {
                    Subject = subject
                };

                var generator = new WordFormReportGenerator();

                var documentStream = generator.GenerateDocument(fileName, meetingNotes);
                CheckGenerationResult(documentStream, subject);
            }
            finally
            {
                File.Delete(fileName);
            }
        }
Пример #2
0
        public void GenerateForTemplate1()
        {
            var generator = new WordFormReportGenerator();

            var meetingNotes = new MeetingNotes
            {
                Subject      = "Meeting Subject",
                Date         = DateTime.Now,
                Secretary    = "Ivan Markov",
                Participants = new List <Participant>
                {
                    new Participant {
                        Name = "Henry Loyd"
                    }
                },
                Decisions = new List <Decision>
                {
                    new Decision
                    {
                        Solution    = "Make it",
                        ControlDate = DateTime.Now.AddDays(5),
                        Problem     = "Big problem",
                        Responsible = "Mary Stomler"
                    }
                }
            };

            var reportStream  = generator.GenerateDocument("Template1", meetingNotes);
            var outFileStream = new FileStream("report.docx", FileMode.Create);

            reportStream.CopyTo(outFileStream);
            outFileStream.Close();
        }
        public async Task Generate()
        {
            if (meetingNotes == null)
            {
                return;
            }

            var fileDialog = new SaveFileDialog();
            var filename   = await fileDialog.ShowAsync(mainWindow);

            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            var generator = new WordFormReportGenerator();
            var stream    = generator.GenerateDocument("Template1", meetingNotes);

            var fileStream = new FileStream(filename, FileMode.Create);

            stream.CopyTo(fileStream);
            fileStream.Close();

            new Process
            {
                StartInfo = new ProcessStartInfo(filename)
                {
                    UseShellExecute = true
                }
            }.Start();
        }
Пример #4
0
        public JsonResult GenerateReport(MeetingNotes meetingNotes)
        {
            GenerationResult result = new GenerationResult();

            if (ModelState.IsValid)
            {
                try
                {
                    var generator = new WordFormReportGenerator();
                    var template  = new MemoryStream(Properties.Resources.Template1);

                    var document = generator.GenerateDocument(template, meetingNotes) as MemoryStream;

                    var id = Guid.NewGuid();
                    Session[id.ToString()] = document.ToArray();
                    result.DocumentId      = id;
                }
                catch (DocumentGenerationException ex)
                {
                    result.Error = string.Join("", ex.Message);
                }
            }
            else
            {
                result.Error = string.Join("", ModelState.Values.SelectMany(v => v.Errors.Select(err => err.ErrorMessage)));
            }

            return(new JsonResult()
            {
                Data = result
            });
        }
Пример #5
0
        private async Task Generate()
        {
            var main     = Electron.WindowManager.BrowserWindows.First();
            var filename = await Electron.Dialog.ShowSaveDialogAsync(
                main, new SaveDialogOptions { Title = "Save ..." });

            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            var generator = new WordFormReportGenerator();
            var stream    = generator.GenerateDocument("Template1", meetingNotesStorage.MeetingNotes);

            var fileStream = new FileStream(filename, FileMode.Create);

            stream.CopyTo(fileStream);
            fileStream.Close();

            new Process
            {
                StartInfo = new ProcessStartInfo(filename)
                {
                    UseShellExecute = true
                }
            }.Start();
        }
        protected void Generate(object sender, EventArgs e)
        {
            if (meetingNotes == null)
                return;

            var saveFileDialog = new SaveFileDialog();

            if (saveFileDialog.ShowDialog(this) == DialogResult.Cancel)
                return;

            var filename = saveFileDialog.FileName;

            var generator = new WordFormReportGenerator();
            var stream = generator.GenerateDocument("Template1", meetingNotes);

            var fileStream = new FileStream(filename, FileMode.Create);
            stream.CopyTo(fileStream);
            fileStream.Close();

            new Process
            {
                StartInfo = new ProcessStartInfo(filename)
                {
                    UseShellExecute = true
                }
            }.Start();
        }
        public void GenerateDocumentFromStreamAndObjectTest()
        {
            var subject      = "Sample subject";
            var meetingNotes = new MeetingNotes {
                Subject = subject
            };

            var generator      = new WordFormReportGenerator();
            var documentStream = generator.GenerateDocument(new MemoryStream(Properties.Resources.MeetingNotesTemplate), meetingNotes);

            CheckGenerationResult(documentStream, subject);
        }
        public void GenerateDocumentFromTemplateStreamAndSerializedDataTest()
        {
            var generator      = new WordFormReportGenerator();
            var template       = new MemoryStream(Properties.Resources.MeetingNotesTemplate, false);
            var serializedData = Properties.Resources.CorrectMeetingNotesData2;

            var documentStream = generator.GenerateDocument(template, serializedData);

            var document = WordprocessingDocument.Open(documentStream, false);
            var xmlPart  = document.MainDocumentPart.CustomXmlParts.First();

            Assert.AreEqual(serializedData.Length, xmlPart.GetStream().Length);
        }
        public static void GenerateAndOpen(string filename, MeetingNotes meetingNotes)
        {
            var generator = new WordFormReportGenerator();
            var stream    = generator.GenerateDocument("Template1", meetingNotes);

            var fileStream = new FileStream(filename, FileMode.Create);

            stream.CopyTo(fileStream);
            fileStream.Close();

            new Process
            {
                StartInfo = new ProcessStartInfo(filename)
                {
                    UseShellExecute = true
                }
            }.Start();
        }