public DocumentCollection GetDocs()
        {
            var datLines = new List <string>(new string[] {
                "þDOCIDþþBEGATTþþVOLUMEþþDOCTYPEþþNATIVEþ",
                "þDOC000001þþDOC000001þþVOL001þþEMAILþþX:\\VOL001\\NATIVE\\0001\\DOC000001.XLSXþ",
                "þDOC000002þþDOC000001þþVOL001þþPDFþþþ",
                null, null
            });

            var optLines = new List <string[]> {
                new string[] { "DOC000001", "VOL001", "X:\\VOL001\\IMAGES\\0001\\DOC000001.jpg", "Y", "", "", "1" },
                new string[] { "DOC000002", "VOL001", "X:\\VOL001\\IMAGES\\0001\\DOC000002.tif", "Y", "", "", "2" },
                new string[] { "DOC000003", "VOL001", "X:\\VOL001\\IMAGES\\0001\\DOC000003.tif", "", "", "", "" }
            };

            var mockReader = new Mock <TextReader>();
            int calls      = 0;

            mockReader
            .Setup(r => r.ReadLine())
            .Returns(() => datLines[calls])
            .Callback(() => calls++);
            FileInfo infile        = new FileInfo(@"X:\VOL001\infile.dat");
            bool     hasHeader     = true;
            string   keyColName    = "DOCID";
            string   parentColName = "BEGATT";
            string   childColName  = String.Empty;
            string   childColDelim = ";";
            RepresentativeBuilder        repSetting = new RepresentativeBuilder("NATIVE", Representative.FileType.Native);
            List <RepresentativeBuilder> reps       = new List <RepresentativeBuilder>();

            reps.Add(repSetting);
            var             builder = new DatBuilder();
            IParser         parser  = new DatParser(Delimiters.CONCORDANCE);
            List <string[]> records = parser.Parse(mockReader.Object);

            builder.HasHeader              = hasHeader;
            builder.KeyColumnName          = keyColName;
            builder.ParentColumnName       = parentColName;
            builder.ChildColumnName        = childColName;
            builder.ChildSeparator         = childColDelim;
            builder.RepresentativeBuilders = reps;
            builder.ParentColumnName       = infile.Directory.FullName;
            List <Document> documents  = builder.Build(records);
            var             docs       = new DocumentCollection(documents);
            var             optBuilder = new OptBuilder();

            optBuilder.PathPrefix  = String.Empty;
            optBuilder.TextBuilder = null;
            List <Document> optDocs = optBuilder.Build(optLines);

            docs.AddRange(optDocs);
            docs[1].SetParent(docs[0]);
            return(docs);
        }
示例#2
0
        /// <summary>
        /// Executes the imports, edits, and exports in the job.
        /// </summary>
        public virtual DocumentCollection Execute()
        {
            DocumentCollection     docs            = new DocumentCollection();
            Transformer            transformer     = new Transformer();
            IList <Transformation> transformations = GetTransformations();

            foreach (Import import in Imports)
            {
                IImporter          importer     = import.BuildImporter();
                DocumentCollection importedDocs = importer.Import(import.File, import.Encoding);
                docs.AddRange(importedDocs);

                if (import.GetType().Equals(typeof(DatImport)))
                {
                    DatImport datImport = (DatImport)import;

                    if (datImport.FolderPrependFields != null)
                    {
                        foreach (string field in datImport.FolderPrependFields)
                        {
                            MetaDataTransformation edit = MetaDataTransformation.Builder
                                                          .Start(field, null, String.Empty)
                                                          .SetPrependDir(import.File.Directory)
                                                          .Build();
                            transformations.Add(edit);
                        }
                    }

                    if (datImport.FolderPrependLinks != null)
                    {
                        Regex  find    = new Regex(@"\\?(.+)");
                        string replace = Path.Combine(import.File.Directory.FullName, "$1");

                        foreach (var type in datImport.FolderPrependLinks)
                        {
                            RepresentativeTransformation edit = RepresentativeTransformation.Builder
                                                                .Start(type, find, replace)
                                                                .Build();
                            transformations.Add(edit);
                        }
                    }
                }
            }

            transformer.Transform(docs, transformations);

            foreach (Export export in Exports)
            {
                export.BuildExporter().Export(docs);
            }

            return(docs);
        }