Esempio n. 1
0
 public static void RunTests()
 {
     ZipOps.Test();
     Validator.Test();
     PdfOps.Test();
     MergeOps.Test();
 }
 /// <summary>
 /// Creates a response containing a comma-separated values (CSV) file created from the top level of a row tree. There will be one column for each merge
 /// field specified in the list of field names.
 /// </summary>
 public static EwfResponse CreateMergedCsvResponse(Func <string> extensionlessFileNameCreator, MergeRowTree rowTree, IEnumerable <string> fieldNames)
 {
     return(Create(
                ContentTypes.Csv,
                new EwfResponseBodyCreator(writer => MergeOps.CreateTabularTextFile(rowTree, fieldNames, writer)),
                fileNameCreator: () => extensionlessFileNameCreator() + FileExtensions.Csv));
 }
 /// <summary>
 /// Creates a response containing a tab-separated values file created from the top level of a row tree. There will be one column for each merge field
 /// specified in the list of field names.
 /// </summary>
 public static EwfResponse CreateMergedTabSeparatedValuesResponse(
     Func <string> extensionlessFileNameCreator, MergeRowTree rowTree, IEnumerable <string> fieldNames, bool omitHeaderRow = false)
 {
     return(Create(
                ContentTypes.TabSeparatedValues,
                new EwfResponseBodyCreator(writer => MergeOps.CreateTabularTextFile(rowTree, fieldNames, writer, useTabAsSeparator: true, omitHeaderRow: omitHeaderRow)),
                fileNameCreator: () => extensionlessFileNameCreator() + FileExtensions.Txt));
 }
 /// <summary>
 /// Creates a response by merging a row tree with a Microsoft Word document. If you would like each row to be on a separate page, set the first paragraph in
 /// the input file to have a page break before it.
 /// </summary>
 public static EwfResponse CreateMergedMsWordDocResponse(
     Func <string> extensionlessFileNameCreator, MergeRowTree rowTree, bool ensureAllFieldsHaveValues, Action <Action <Stream> > inputStreamProvider)
 {
     return(Create(
                ContentTypes.WordDoc,
                new EwfResponseBodyCreator(
                    destinationStream => inputStreamProvider(inputStream => MergeOps.CreateMsWordDoc(rowTree, ensureAllFieldsHaveValues, inputStream, destinationStream))),
                fileNameCreator: () => extensionlessFileNameCreator() + FileExtensions.WordDoc));
 }
Esempio n. 5
0
        // merge two sets of columns, matching on equality
        // note that this may include columns with the same name and different types, so create heading will fail
        public static DataColumn[] Merge(MergeOps op, IEnumerable <DataColumn> leftcols, IEnumerable <DataColumn> rightcols)
        {
            switch (op)
            {
            case MergeOps.UseAllLeft:
                return(leftcols.ToArray());

            case MergeOps.UseAllRight:
                return(rightcols.ToArray());

            default:
                var cols1 = leftcols.Where(c => rightcols.Contains(c) ? TestOp(op, MergeOps.Match) : TestOp(op, MergeOps.Left));
                var cols2 = rightcols.Where(c => leftcols.Contains(c) ? false : TestOp(op, MergeOps.Right));
                return(cols1.Concat(cols2).ToArray());
            }
        }
        public void PracticesMerge()
        {
            var practiceData = new PracticeMockData(
                "Entymology Associates of Rock Chester",
                new[] { "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" }.Select(s => new PracticeManagerMockData(s)),
                new[]
            {
                new PhysicianMockData("*****@*****.**", "Joan", "Ann"), new PhysicianMockData("*****@*****.**", "Johnny", "Ann"),
                new PhysicianMockData("*****@*****.**", "Billy", "Pullman"), new PhysicianMockData("*****@*****.**", "William", "Smithers")
            });

            var practiceFields = new List <MergeField <PracticeMockData> >(MergeFieldOps.CreateBasicField(new PracticeName()).ToCollection());
            var managerFields  =
                new List <MergeField <PracticeManagerMockData> >(MergeFieldOps.CreateBasicField(new MergeFields.PracticeManagerMergeFields.Email()).ToCollection());
            var physicianFields =
                new List <MergeField <PhysicianMockData> >(
                    new[]
            {
                MergeFieldOps.CreateBasicField(new MergeFields.PhysicianMergeFields.Email()), MergeFieldOps.CreateBasicField(new FirstName()),
                MergeFieldOps.CreateBasicField(new LastName())
            });

            var managersChild = new MergeDataTreeChild <PracticeMockData, PracticeManagerMockData>(
                "PracticeManagers",
                managerFields.AsReadOnly(),
                data => data.Managers);
            var physiciansChild = new MergeDataTreeChild <PracticeMockData, PhysicianMockData>("Physicians", physicianFields.AsReadOnly(), data => data.Physicians);
            var mergeTree       = MergeDataTreeOps.CreateRowTree(
                practiceFields.AsReadOnly(),
                practiceData.ToCollection(),
                new List <MergeDataTreeChild <PracticeMockData> > {
                managersChild, physiciansChild
            }.AsReadOnly());

            using (var templateStream = File.OpenRead(testingPracticesWordTemplatePath)) {
                using (var destinationStream = File.Create(getFilePath("practices_merge_test"))) {
                    MergeOps.CreateMsWordDoc(mergeTree, true, templateStream, destinationStream);
                    doneCreating = DateTime.Now;
                }
            }
        }
 /// <summary>
 /// Creates a response containing a single-sheet Excel workbook created from the top level of a row tree. There will be one column for each merge field
 /// specified in the list of field names. Each column head will be named by calling ToEnglishFromCamel on the merge field's name or using the Microsoft Word
 /// name without modification, the latter if useMsWordFieldNames is true.
 /// </summary>
 public static EwfResponse CreateMergedExcelWorkbookResponse(
     Func <string> extensionlessFileNameCreator, MergeRowTree rowTree, IEnumerable <string> fieldNames, bool useMsWordFieldNames = false)
 {
     return(CreateExcelWorkbookResponse(extensionlessFileNameCreator, () => MergeOps.CreateExcelFileWriter(rowTree, fieldNames, useMsWordFieldNames)));
 }
        public void PersonMerge()
        {
            var singlePersonMergeData = new MergeTestData
            {
                FullName = "Johnny Rockets, King of the Dinosaurs",
                Things   =
                    new List <MergeTestData.Thing>(
                        new[]
                {
                    new MergeTestData.Thing {
                        TheValue = "Something"
                    }, new MergeTestData.Thing {
                        TheValue = "Another thing"
                    },
                    new MergeTestData.Thing {
                        TheValue = "One more thing"
                    }, new MergeTestData.Thing {
                        TheValue = "Last thing"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Okay THIS is the last thing"
                    }, new MergeTestData.Thing {
                        TheValue = "Something again"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Another thing again"
                    }, new MergeTestData.Thing {
                        TheValue = "One more thing again"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Last thing again"
                    }, new MergeTestData.Thing {
                        TheValue = "Okay THIS is the last thing again"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Something one more time"
                    }, new MergeTestData.Thing {
                        TheValue = "Another thing one more time"
                    },
                    new MergeTestData.Thing {
                        TheValue = "One more thing one more time"
                    }, new MergeTestData.Thing {
                        TheValue = "Last thing one more time"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Okay THIS is the last thing one more time"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Something that is getting old"
                    }, new MergeTestData.Thing {
                        TheValue = "Another thing that is getting old"
                    },
                    new MergeTestData.Thing {
                        TheValue = "One more thing that is getting old"
                    }, new MergeTestData.Thing {
                        TheValue = "Last thing that is getting old"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Okay THIS is the last thing that is getting old"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Something about the end of all things"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Another thing about the end of all things"
                    },
                    new MergeTestData.Thing {
                        TheValue = "One more thing about the end of all things"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Last thing about the end of all things"
                    },
                    new MergeTestData.Thing {
                        TheValue = "Okay THIS is the last thing about the end of all things"
                    },
                })
            };

            var mergingInfoFields       = new List <MergeField <MergeTestData> >(new[] { MergeFieldOps.CreateBasicField(new FullName()) });
            var internalTableDataFields = new List <MergeField <MergeTestData.Thing> >(new[] { MergeFieldOps.CreateBasicField(new TheValue()) });

            var mergeTree = MergeDataTreeOps.CreateRowTree(
                mergingInfoFields.AsReadOnly(),
                singlePersonMergeData.ToSingleElementArray(),
                new List <MergeDataTreeChild <MergeTestData> >
            {
                new MergeDataTreeChild <MergeTestData, MergeTestData.Thing>("Things", internalTableDataFields.AsReadOnly(), info => info.Things)
            }.AsReadOnly());

            using (var templateStream = File.OpenRead(testingWordTemplatePath)) {
                using (var destinationStream = File.Create(getFilePath("basic_merge_test"))) {
                    MergeOps.CreateMsWordDoc(mergeTree, true, templateStream, destinationStream);
                    doneCreating = DateTime.Now;
                }
            }
        }
Esempio n. 9
0
 // Merge two tuple headings
 public static DataHeading Merge(MergeOps op, DataHeading left, DataHeading right)
 {
     return(Create(DataColumn.Merge(op, left.Columns, right.Columns)));
 }
Esempio n. 10
0
 /// <summary>
 /// Creates a response containing a single-sheet Excel workbook created from the top level of a row tree. There will be one column for each merge field
 /// specified in the list of field names. Each column head will be named by calling ToEnglishFromCamel on the merge field's name or using the Microsoft Word
 /// name without modification, the latter if useMsWordFieldNames is true.
 /// </summary>
 public EwfResponse(Func <string> extensionlessFileNameCreator, MergeRowTree rowTree, IEnumerable <string> fieldNames, bool useMsWordFieldNames = false)
     : this(extensionlessFileNameCreator, () => MergeOps.CreateExcelFileWriter(rowTree, fieldNames, useMsWordFieldNames))
 {
 }
Esempio n. 11
0
        private static void testMailMerging()
        {
            const string outputFolderName = "MergeOps";
            var          outputFolder     = EwlStatics.CombinePaths(TestStatics.OutputFolderPath, outputFolderName);

            IoMethods.DeleteFolder(outputFolder);
            Directory.CreateDirectory(outputFolder);

            var inputTestFiles = EwlStatics.CombinePaths(TestStatics.InputTestFilesFolderPath, outputFolderName);
            var wordDocx       = EwlStatics.CombinePaths(inputTestFiles, "word.docx");
            var pdf            = EwlStatics.CombinePaths(inputTestFiles, "pdf.pdf");

            var singleTestRow      = new PseudoTableRow(1).ToCollection();
            var testRows           = new[] { new PseudoTableRow(1), new PseudoTableRow(2), new PseudoTableRow(3) };
            var singleRowTree      = MergeStatics.CreatePseudoTableRowTree(singleTestRow);
            var pseudoTableRowTree = MergeStatics.CreatePseudoTableRowTree(testRows);

            var explanations = new List <Tuple <String, String> >();

            // Single row to merge against

            // Word files

            const string singleRowWordDoc = "SingleRowMsWordDoc" + FileExtensions.WordDocx;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, singleRowWordDoc))) {
                using (var word = File.OpenRead(wordDocx))
                    MergeOps.CreateMsWordDoc(singleRowTree, false, word, outputFile);
                explanations.Add(Tuple.Create(singleRowWordDoc, "Should be {0} with only one page, and FullName merged in the upper left.".FormatWith(wordDocx)));
            }

            const string singleRowWordDocAsPdf = "SingleRowMsWordDoc" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, singleRowWordDocAsPdf)))
                MergeOps.CreatePdfFromMsWordDoc(singleRowTree, false, wordDocx, outputFile);
            explanations.Add(
                Tuple.Create(singleRowWordDocAsPdf, "Should be {0} with only one page, FullName merged in the upper left, saved as a PDF.".FormatWith(wordDocx)));

            //Excel
            const string singleRowExcel = "SingleRowExcel" + FileExtensions.ExcelXlsx;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, singleRowExcel)))
                MergeOps.CreateExcelWorkbook(singleRowTree, MergeOps.GetExcelSupportedMergeFields(singleRowTree), outputFile);
            explanations.Add(
                Tuple.Create(
                    singleRowExcel,
                    "An Excel file with the first row frozen and bold with the merge field names. Note that only supported field types may be dispalyed. One more row with data should be present."));

            // Pdf
            const string singleRowPdf = "SingleRowPdf" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, singleRowPdf)))
                MergeOps.CreatePdf(singleRowTree, false, pdf, outputFile);
            explanations.Add(Tuple.Create(singleRowPdf, "Should be {0} with only one page, FullName filled in and 'Test' displayed.".FormatWith(pdf)));

            // Multiple rows to merge against

            // Word files
            const string multipleRowsWordDoc = "MultipleRowMsWordDoc" + FileExtensions.WordDocx;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, multipleRowsWordDoc))) {
                using (var word = File.OpenRead(wordDocx))
                    MergeOps.CreateMsWordDoc(pseudoTableRowTree, false, word, outputFile);
                explanations.Add(
                    Tuple.Create(multipleRowsWordDoc, "Should be {0} with three pages, and FullName merged in the upper left.".FormatWith(wordDocx)));
            }

            const string multipleRowsWordDocAsPdf = "MultipleRowMsWordDoc" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, multipleRowsWordDocAsPdf)))
                MergeOps.CreatePdfFromMsWordDoc(pseudoTableRowTree, false, wordDocx, outputFile);
            explanations.Add(
                Tuple.Create(multipleRowsWordDocAsPdf, "Should be {0} with three pages, FullName merged in the upper left, saved as a PDF.".FormatWith(wordDocx)));

            // Excel
            const string multipleRowExcel = "MultipleRowExcel" + FileExtensions.ExcelXlsx;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, multipleRowExcel)))
                MergeOps.CreateExcelWorkbook(pseudoTableRowTree, MergeOps.GetExcelSupportedMergeFields(pseudoTableRowTree), outputFile);
            explanations.Add(
                Tuple.Create(
                    multipleRowExcel,
                    "An Excel file with the first row frozen and bold with the merge field names. Note that only supported field types may be dispalyed. Three more row with data should be present."));

            // Pdf
            const string multipleRowPdf = "MultipleRowPdf" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(EwlStatics.CombinePaths(outputFolder, multipleRowPdf)))
                MergeOps.CreatePdf(pseudoTableRowTree, false, pdf, outputFile);
            explanations.Add(Tuple.Create(multipleRowPdf, "Should be {0} with three pages, FullName filled in and 'Test' displayed.".FormatWith(pdf)));

            TestStatics.OutputReadme(outputFolder, explanations);
        }
Esempio n. 12
0
        // --- static

        static bool TestOp(MergeOps a, MergeOps b)
        {
            return((a & b) != 0);
        }