Esempio n. 1
0
        //[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());
            }
        }
Esempio n. 2
0
        public async void TestDropBox()
        {
            InitDropbox();
            var imgRepo = new ImagesRepository(conn);
            var url     = dbBase.GeneratedAuthenticationURL();
            var token   = dbBase.GenerateAccessToken();
            var image   = await dbBase.Upload("/Dropbox/DotNetApi/products", "туфли.png",
                                              @"D:\Projects\prom\SmartRetail.Mvc\SmartRetail.App.Web\pic\туфли.jpg");

            var img = new Image
            {
                prod_id  = 1,
                img_name = "shoes",
                img_type = "jpg",
                img_url  = image
            };

            Thread.Sleep(500);
            imgRepo.Add(img);
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        // GET: /<controller>/
        public void GetFile(ExportFile file)
        {
            if (file.ClassName.Contains("Proprietar", StringComparison.InvariantCultureIgnoreCase))
            {
                var    wbk          = Excel.Exporter.CycleProprietari(context, excelConfiguration.Get(1, "Proprietar"), "NoContext,InSet,Context");
                byte[] fileContents = null;
                using (var stream = new MemoryStream())
                {
                    wbk.Write(stream);
                    fileContents = stream.ToArray();

                    //return File(fileContents, System.Net.Mime.MediaTypeNames.Application.Octet, "ProprietariValidati.xls");
                }
            }

            if (file.ClassName.Contains("ActProprietate", StringComparison.InvariantCultureIgnoreCase))
            {
                var    wbk          = Excel.Exporter.CycleActeProprietate(context, excelConfiguration.Get(1, "ActProprietate"), "NoContext,InSet,Context");
                byte[] fileContents = null;
                using (var stream = new MemoryStream())
                {
                    wbk.Write(stream);
                    fileContents = stream.ToArray();
                    //return File(fileContents, System.Net.Mime.MediaTypeNames.Application.Octet, "ActeProprietateValidate.xls");
                }
            }

            if (file.ClassName.Contains("Parcel", StringComparison.InvariantCultureIgnoreCase))
            {
                var    wbk          = Excel.Exporter.CycleParcele(context, excelConfiguration.Get(1, "Parcela"), "NoContext,InSet,Context");
                byte[] fileContents = null;
                using (var stream = new MemoryStream())
                {
                    wbk.Write(stream);
                    fileContents = stream.ToArray();
                    //return File(fileContents, System.Net.Mime.MediaTypeNames.Application.Octet, "ParceleValidate.xls");
                }
            }

            if (file.ClassName.Contains("Inscrie", StringComparison.InvariantCultureIgnoreCase))
            {
                var    wbk          = Excel.Exporter.CycleInscrieri(context, excelConfiguration.Get(1, "Inscriere"), "NoContext,InSet,Context");
                byte[] fileContents = null;
                using (var propStream = new MemoryStream())
                {
                    wbk.Write(propStream);
                    fileContents = propStream.ToArray();
                    //return File(fileContents, System.Net.Mime.MediaTypeNames.Application.Octet, "CentralizatorValidat.xls");
                }
            }

            if (file.ClassName.Contains("dxf", StringComparison.InvariantCultureIgnoreCase))
            {
                var dxfFullPath = dXFRepo.GetFullPath(file.Display);

                var stream = DXF.Exporter.Get(dxfFullPath, cadGenExporter, (x) => hubContext.Clients.All.SendAsync("receivemessage", x));
                stream.Seek(0, SeekOrigin.Begin);
                var success = dropBoxBase.Upload(@"/CadGen/DXFResults", file.Display, stream);
            }
            //return new NotFoundResult();
        }