예제 #1
0
파일: Program.cs 프로젝트: egonl/SharpDocx
        private static void Main()
        {
#if DEBUG
            var viewPath     = $"{BasePath}/Views/Model.cs.docx";
            var documentPath = $"{BasePath}/Documents/Model.docx";
            var model        = CreateViewModel();

            string documentViewer = null; // NET35 and NET45 will automatically search for a Docx viewer.
            //var documentViewer = @"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"; // NETCOREAPP3_1 and NET6_0 won't.

            Ide.Start(viewPath, documentPath, model, null, null, documentViewer);
#else
            var startTime     = DateTime.Now;
            var documentCount = 100;

            // Single threaded performance test.
            for (int i = 0; i < documentCount; ++i)
            {
                GenerateDocument(i);
            }

            // Multi threaded performance test.
            //Parallel.For(0, documentCount, GenerateDocument);

            var totalSeconds = (DateTime.Now - startTime).TotalSeconds;
            Console.WriteLine($"Generated {documentCount} documents in {totalSeconds:N2}s ({documentCount / totalSeconds:N2} documents/s).");
            Console.ReadKey();
#endif
        }
예제 #2
0
        private static void Main()
        {
            var viewPath     = $"{BasePath}/Views/Inheritance.cs.docx";
            var documentPath = $"{BasePath}/Documents/Inheritance.docx";

#if DEBUG
            Ide.Start(viewPath, documentPath, null, typeof(MyDocument), f => ((MyDocument)f).MyProperty = "The code");
#else
            var myDocument = DocumentFactory.Create <MyDocument>(viewPath);
            myDocument.MyProperty = "The Code";

            // It's possible to generate a file or a stream.

            // 1. Generate a file
            // myDocument.Generate(documentPath);

            //2. Generate an output stream.
            using (var outputStream = myDocument.Generate())
            {
                using (var outputFile = File.Open(documentPath, FileMode.Create))
                {
                    outputFile.Write(outputStream.GetBuffer(), 0, (int)outputStream.Length);
                }
            }
#endif
        }
예제 #3
0
        private static void Main()
        {
            var viewPath     = $"{BasePath}/Views/Inheritance.cs.docx";
            var documentPath = $"{BasePath}/Documents/Inheritance.docx";

#if DEBUG
            string documentViewer = null; // NET35 and NET45 will automatically search for a Docx viewer.
            //var documentViewer = @"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"; // NETCOREAPP3_1 and NET6_0 won't.

            Ide.Start(viewPath, documentPath, null, typeof(MyDocument), f => ((MyDocument)f).MyProperty = "The code", documentViewer);
#else
            var myDocument = DocumentFactory.Create <MyDocument>(viewPath);
            myDocument.MyProperty = "The Code";

            // It's possible to generate a file or a stream.

            // 1. Generate a file
            // myDocument.Generate(documentPath);

            //2. Generate an output stream.
            using (var outputStream = myDocument.Generate())
            {
                using (var outputFile = File.Open(documentPath, FileMode.Create))
                {
                    outputFile.Write(outputStream.GetBuffer(), 0, (int)outputStream.Length);
                }
            }
#endif
        }
예제 #4
0
        private static void ExecuteTemplates(out WeakReference loadContextRef)
        {
            var loadCtx = new TestAssemblyLoadContext(Path.GetDirectoryName(typeof(Program).Assembly.Location));

            DocumentFactory.LoadContext = loadCtx;

            var viewPath       = $"{BasePath}/Views/Tutorial.cs.docx";
            var documentPath   = $"{BasePath}/Documents/Tutorial.docx";
            var imageDirectory = $"{BasePath}/Images";

#if DEBUG
            Ide.Start(viewPath, documentPath, null, null, f => f.ImageDirectory = imageDirectory);
#else
            DocumentBase document = DocumentFactory.Create(viewPath);
            document.ImageDirectory = imageDirectory;
            document.Generate(documentPath);
#endif
            loadContextRef = new WeakReference(loadCtx);

            Console.WriteLine("---------------------Assemblies Loaded In the Default Context-------------------------------");
            var assemblyNames = AssemblyLoadContext.Default.Assemblies.Select(s => s.FullName).ToArray();
            Console.WriteLine(string.Join(Environment.NewLine, assemblyNames));

            Console.WriteLine("---------------------Assemblies Loaded In Context-------------------------------");
            assemblyNames = loadCtx.Assemblies.Select(s => s.FullName).ToArray();
            Console.WriteLine(string.Join(Environment.NewLine, assemblyNames));

            loadCtx.Unload();
            DocumentFactory.LoadContext = null;
        }
예제 #5
0
        private static void Main()
        {
#if DEBUG
            var viewPath     = $"{BasePath}\\Views\\Model.cs.docx";
            var documentPath = $"{BasePath}\\Documents\\Model.docx";
            var model        = CreateViewModel();

            Ide.Start(viewPath, documentPath, model);
#else
            var startTime     = DateTime.Now;
            var documentCount = 100;

            // Single threaded performance test.
            for (int i = 0; i < documentCount; ++i)
            {
                GenerateDocument(i);
            }

            // Multi threaded performance test.
            //Parallel.For(0, documentCount, GenerateDocument);

            var totalSeconds = (DateTime.Now - startTime).TotalSeconds;
            Console.WriteLine($"Generated {documentCount} documents in {totalSeconds:N2}s ({documentCount / totalSeconds:N2} documents/s).");
            Console.ReadKey();
#endif
        }
예제 #6
0
        private static void Main()
        {
            var viewPath     = $"{BasePath}/Views/Inheritance.cs.docx";
            var documentPath = $"{BasePath}/Documents/Inheritance.docx";

#if DEBUG
            Ide.Start(viewPath, documentPath, null, typeof(MyDocument), f => ((MyDocument)f).MyProperty = "The code");
#else
            var myDocument = DocumentFactory.Create <MyDocument>(viewPath);
            myDocument.MyProperty = "The Code";
            myDocument.Generate(documentPath);
#endif
        }
예제 #7
0
        private static void Main()
        {
            var viewPath       = $"{BasePath}/Views/Tutorial.cs.docx";
            var documentPath   = $"{BasePath}/Documents/Tutorial.docx";
            var imageDirectory = $"{BasePath}/Images";

#if DEBUG
            Ide.Start(viewPath, documentPath, null, null, f => f.ImageDirectory = imageDirectory);
#else
            DocumentBase document = DocumentFactory.Create(viewPath);
            document.ImageDirectory = imageDirectory;
            document.Generate(documentPath);
#endif
        }
예제 #8
0
파일: Program.cs 프로젝트: egonl/SharpDocx
        private static void Main()
        {
            var viewPath       = $"{BasePath}/Views/Tutorial.cs.docx";
            var documentPath   = $"{BasePath}/Documents/Tutorial.docx";
            var imageDirectory = $"{BasePath}/Images";

#if DEBUG
            string documentViewer = null; // NET35 and NET45 will automatically search for a Docx viewer.
            //var documentViewer = @"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"; // NETCOREAPP3_1 and NET6_0 won't.

            Ide.Start(viewPath, documentPath, null, null, f => f.ImageDirectory = imageDirectory, documentViewer);
#else
            DocumentBase document = DocumentFactory.Create(viewPath);
            document.ImageDirectory = imageDirectory;
            document.Generate(documentPath);
#endif
        }