//[TestMethod()]
        public async Task InitTestDirectory()
        {
            try
            {
                DropBoxBase dropboxBase = new DropBoxBase();

                await dropboxBase.CreateFolder("dir1");

                await dropboxBase.CreateFolder("dir2");

                var mathImgPath    = "F:/Imagens/math.jpg";
                var bugDeadImgPath = "F:/Imagens/testcase.png";
                var especPdfPath   = "C:/Users/Usuário/Downloads/Enunciado.pdf";

                await dropboxBase.Upload("dir1/math.jpg", mathImgPath);

                await dropboxBase.Upload("dir2/trab_teste_sw.pdf", especPdfPath);

                await dropboxBase.Upload(Path.GetFileName(bugDeadImgPath), bugDeadImgPath);

                dropboxBase.Close();
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }
        }
Exemple #2
0
        private void InitDropbox()
        {
            dbBase = new DropBoxBase("o9340xsv2mzn7ws", "xzky2fzfnmssik1");
            var url   = dbBase.GeneratedAuthenticationURL();
            var token = dbBase.GenerateAccessToken();

            imgRepo = new ImagesRepository(conn);
        }
 public ProcessController(DropBoxBase _dropBox, CadSysContext _context, IRepo _repo, IExcelConfigurationRepo _excelConfiguration, ServiceBuilder serviceBuilder)
 {
     dropBox            = _dropBox;
     context            = _context;
     repo               = _repo;
     excelConfiguration = _excelConfiguration;
     dxfRepo            = (IFileRepo)serviceBuilder.GetService("DXFRepo");
     excelRepo          = (IFileRepo)serviceBuilder.GetService("ExcelRepo");
 }
Exemple #4
0
 public ExportController(CadSysContext _context, IExcelConfigurationRepo _excelConfiguration, ServiceBuilder _serviceBuilder, IExporter _cadGenExporter, IHubContext <MessagesHub> _hubContext, DropBoxBase _dropBoxBase)
 {
     context            = _context;
     excelConfiguration = _excelConfiguration;
     dXFRepo            = (IFileRepo)_serviceBuilder.GetService("DXFRepo");
     cadGenExporter     = _cadGenExporter;
     hubContext         = _hubContext;
     dropBoxBase        = _dropBoxBase;
 }
        //[TestMethod()]
        public async Task GetSharedLinkNotExistTest()
        {
            try
            {
                dropboxBase = new DropBoxBase();
                var url = await dropboxBase.GetSharedLink("dir2/trab_teste_sw.pdf");

                Assert.AreEqual(null, url);
                dropboxBase.Close();
            }
            catch (Exception e)
            {
                dropboxBase.Close();
                Console.Write(e.ToString());
                throw e;
            }
        }
Exemple #6
0
    void Start()
    {
        if (loaded)
        {
            return;
        }

        try
        {
            dropBoxBase = new DropBoxBase();

            loaded = true;
        }
        catch (Exception)
        {
            loaded = false;
        }
    }
        public async Task GetSharedLinkExistTest()
        {
            try
            {
                var urlExpected = "https://www.dropbox.com/s/j02x06nvxvlec33/math.jpg?dl=0";
                dropboxBase = new DropBoxBase();
                var url = await dropboxBase.GetSharedLink("dir1/math.jpg");

                dropboxBase.Close();

                Assert.AreEqual(urlExpected, url);
            }
            catch (Exception e)
            {
                dropboxBase.Close();
                Console.Write(e.ToString());
                throw e;
            }
        }
        //[TestMethod()]
        public async Task CreateSharedLinkTest()
        {
            try
            {
                dropboxBase = new DropBoxBase();
                var url = await dropboxBase.CreateSharedLink("dir1/math.jpg");

                dropboxBase.Close();

                Assert.AreNotEqual(null, url);
                Console.Write("url = {0}", url);
            }
            catch (Exception e)
            {
                dropboxBase.Close();
                Console.Write(e.ToString());
                throw e;
            }
        }
Exemple #9
0
        public static void Export(CadSysContext context, DropBoxBase dropBoxClient, string ai, string ap, string f, string o)
        {
            dropBoxClient.Delete(o);
            dropBoxClient.CreateFolder(o);
            CreateOutputDir();

            var fise = dropBoxClient.ListFolder(f, false, true, ".pdf");

            //Parallel.ForEach(fise, new ParallelOptions { MaxDegreeOfParallelism = 4 }, x =>
            fise.ToList().ForEach(x =>
            {
                Pizdificator pizd;
                pizd = GatherFromContext(context, Path.GetFileNameWithoutExtension(x));

                var files = GatherFromFiles(pizd, dropBoxClient, ai, ap, f);

                AggregateAndExport(dropBoxClient, $"{outputLocalDir}/{Path.GetFileName(x)}", o, files);
            });
        }
Exemple #10
0
        public static string[] GatherFromFiles(Pizdificator pizdificator, DropBoxBase dropBoxClient, string ai, string ap, string f)
        {
            var result = new List <string>();

            result.Add($"{f}/{pizdificator.NrCadGeneral}.pdf");



            pizdificator.IndecsiProprietari?.ForEach(x =>
            {
                if (dropBoxClient.FolderExists($"{ai}/{x}"))
                {
                    var files = dropBoxClient.ListFolder($"{ai}/{x}/", false, true).OrderBy(y => y);

                    files.ToList().ForEach(y => result.Add($"{ai}/{x}/{y}"));
                }
            });


            pizdificator.IndecsiActe?.ForEach(x =>
            {
                if (dropBoxClient.FolderExists($"{ap}/{x}"))
                {
                    var files = dropBoxClient.ListFolder($"{ap}/{x}/", false, true).OrderBy(y => y);

                    files.ToList().ForEach(y => result.Add($"{ap}/{x}/{y}"));
                }

                if (dropBoxClient.FileExists($"{ap}/{x}.pdf"))
                {
                    result.Add($"{ap}/{x}.pdf");
                }
            });

            return(result.ToArray());
        }
Exemple #11
0
        public static void AggregateAndExport(DropBoxBase dropBoxClient, string outputLocalFile, string dropBoxOutputFolder, params string[] inputFilePaths)
        {
            Document document = new Document();
            //var stream = new FileStream(outputLocalFile, FileMode.Create);
            var writer = PdfWriter.GetInstance(document, new FileStream(outputLocalFile, FileMode.Create));

            var nrCadGeneral = "";// Path.GetFileNameWithoutExtension(outputLocalFile);

            //PdfCopy pdfCopy = new PdfCopy(document, new FileStream(outputLocalFile, FileMode.Create));
            document.Open();
            PdfContentByte pcb = writer.DirectContentUnder;

            for (var i = 0; i < inputFilePaths.Count(); i++)
            {
                CreateSourceDir(nrCadGeneral);

                var copied = dropBoxClient.Download(inputFilePaths[i], $"{sourceLocalDir}{nrCadGeneral}");

                if (!copied)
                {
                    continue;
                }

                var sourceFile = $"{sourceLocalDir}{nrCadGeneral}/{Path.GetFileName(inputFilePaths[i])}";

                var ext = Path.GetExtension(inputFilePaths[i]);

                switch (ext.ToLower())
                {
                case ".jpg":
                case ".jpeg":


                    var image = Image.GetInstance(sourceFile);

                    image.ScaleToFit(PageSize.A4);
                    image.SetAbsolutePosition(0, 0);

                    //pdfCopy.AddPage(PageSize.A4,0);
                    //pdfCopy.AddDirectImageSimple(image);

                    //pdfCopy.DirectContent.AddImage(image);

                    document.SetPageSize(PageSize.A4);
                    document.NewPage();
                    document.Add(image);



                    break;

                case ".pdf":

                    var reader = new PdfReader(sourceFile);
                    for (var p = 1; p <= reader.NumberOfPages; p++)
                    {
                        document.SetPageSize(reader.GetPageSizeWithRotation(p));
                        document.NewPage();
                        PdfImportedPage page = writer.GetImportedPage(reader, p);
                        pcb.AddTemplate(page, 0, 0);
                    }
                    ////pdfCopy.AddDocument(new PdfReader(sourceFile));
                    //reader.Close();

                    break;
                }

                DeleteSourceDir(nrCadGeneral);
            }

            document.Close();
            writer.Close();


            Task.Factory.StartNew(() => dropBoxClient.Upload(dropBoxOutputFolder, Path.GetFileName(inputFilePaths[0]), outputLocalFile));
        }
Exemple #12
0
 public PDFController(CadSysContext _context, DropBoxBase _dropBoxBase)
 {
     dropBoxBase = _dropBoxBase;
     context     = _context;
 }