public AsposeCADCloudApiService(IConfiguration config)
        {
            string ClientId     = config["AsposeCADUserData:ClientId"];
            string ClientSecret = config["AsposeCADUserData:ClientSecret"];

            CadCloudApi = new CadApi(appKey: ClientSecret, appSid: ClientId);
        }
示例#2
0
        public void GetImagePropertiesTest(string formatExtension)
        {
            string name    = null;
            string folder  = CloudTestFolder;
            string storage = DefaultStorage;

            foreach (var inputFile in InputTestFiles)
            {
                if (inputFile.Name.EndsWith(formatExtension))
                {
                    name = inputFile.Name;
                }
                else
                {
                    continue;
                }

                this.TestRequestWithTypedResponse(
                    $"input drawing: {name};",
                    name,
                    delegate()
                {
                    var request    = new GetDrawingPropertiesRequest(name, folder, storage);
                    var properties = CadApi.GetDrawingProperties(request);
                    return(properties);
                },
                    (response, result, refInfo) =>
                {
                    Assert.Greater(response.Height, 0);
                    Assert.Greater(response.Width, 0);
                },
                    folder,
                    storage);
            }
        }
示例#3
0
        private void uploadFileToCloudStorage(String fileName)
        {
            var cadApi = new CadApi(AppKey, AppSid);

            string dataFilePath = Path.Combine(pathToDataDir(), fileName);

            var putCreateRequest = new UploadFileRequest(fileName, File.OpenRead(dataFilePath), null);

            cadApi.UploadFile(putCreateRequest);
        }
        public void GetImageRotateFlipTest(
            string formatExtension,
            bool saveResultToStorage,
            params string[] additionalExportFormats)
        {
            string name        = null;
            string cloudFolder = CloudTestFolder;
            string storage     = DefaultStorage;
            string outName     = null;

            List <string> formatsToExport = new List <string>(this.BasicExportFormats);

            foreach (string additionalExportFormat in additionalExportFormats)
            {
                if (!formatsToExport.Contains(additionalExportFormat))
                {
                    formatsToExport.Add(additionalExportFormat);
                }
            }

            foreach (var inputFile in InputTestFiles)
            {
                if (inputFile.Name.EndsWith(formatExtension))
                {
                    name = inputFile.Name;
                }
                else
                {
                    continue;
                }

                foreach (string format in formatsToExport)
                {
                    foreach (var method in _rotateFlipMethods)
                    {
                        outName = $"{name}_{method}.{format}";

                        this.TestRawGetRequest(
                            $"input drawing: {name}; Output format: {format}; Method: {method}",
                            name,
                            outName,
                            saveResultToStorage,
                            delegate(string outPath)
                        {
                            var request = new GetDrawingRotateFlipRequest(name, format, method, cloudFolder, outPath, storage);
                            return(CadApi.GetDrawingRotateFlip(request));
                        },
                            cloudFolder,
                            storage);
                    }

                    break;
                }
            }
        }
示例#5
0
        // Get properties of an image
        private void GetImageProperties()
        {
            var    cadApi   = new CadApi(AppKey, AppSid);
            string fileName = "910609.dxf";

            // Upload document to Cloud Storage
            uploadFileToCloudStorage(fileName);

            var request    = new GetDrawingPropertiesRequest(fileName, null, null);
            var properties = cadApi.GetDrawingProperties(request);
        }
        public void GetDrawingResizeTest(string formatExtension, bool saveResultToStorage, params string[] additionalExportFormats)
        {
            string name        = null;
            int?   newWidth    = 100;
            int?   newHeight   = 150;
            string cloudFolder = CloudTestFolder;
            string storage     = DefaultStorage;
            string outName     = null;

            List <string> formatsToExport = new List <string>(this.BasicExportFormats);

            foreach (string additionalExportFormat in additionalExportFormats)
            {
                if (!formatsToExport.Contains(additionalExportFormat))
                {
                    formatsToExport.Add(additionalExportFormat);
                }
            }

            foreach (var inputFile in InputTestFiles)
            {
                if (inputFile.Name.EndsWith(formatExtension))
                {
                    name = inputFile.Name;
                }
                else
                {
                    continue;
                }

                foreach (string format in formatsToExport)
                {
                    outName = $"{name}_resize.{format}";

                    this.TestRawGetRequest(
                        $"input drawing: {name}; Output format: {format}; New width: {newWidth}; New height: {newHeight}",
                        name,
                        outName,
                        saveResultToStorage,
                        delegate(string outPath)
                    {
                        var request = new GetDrawingResizeRequest(name, format, newWidth, newHeight, cloudFolder, outPath, storage);

                        var stream = CadApi.GetDrawingResize(request);
                        return(stream);
                    },
                        cloudFolder,
                        storage);

                    break;
                }
            }
        }
示例#7
0
        public void PostDrawingSaveAsTest(string formatExtension, bool saveResultToStorage, params string[] additionalExportFormats)
        {
            string name    = null;
            string folder  = CloudTestFolder;
            string storage = DefaultStorage;
            string outName = null;

            List <string> formatsToExport = new List <string>()
            {
                OutputFormatExtension
            };

            foreach (var inputFile in InputTestFiles)
            {
                if (inputFile.Name.EndsWith(formatExtension))
                {
                    name = inputFile.Name;
                }
                else
                {
                    continue;
                }

                var exportOptions = new BmpOptionsDTO()
                {
                    VectorRasterizationOptions = new CadRasterizationOptionsDTO()
                    {
                        PageHeight = 200,
                        PageWidth  = 300
                    }
                };

                foreach (string format in formatsToExport)
                {
                    outName = $"{name}_opts.{format}";

                    this.TestPostWithOptionsRequest(
                        $"Input drawing: {name}; Output format: {format}",
                        name,
                        outName,
                        saveResultToStorage,
                        exportOptions,
                        delegate(BmpOptionsDTO options, string outPath)
                    {
                        var request = new PostDrawingBmpRequest(name, options, folder, outPath, storage);
                        return(CadApi.PostDrawingBmp(request));
                    },
                        folder,
                        storage);
                }
            }
        }
示例#8
0
        // Export existing image to another format. Image is passed as request body
        private void PostImageSaveAs()
        {
            var    cadApi   = new CadApi(AppKey, AppSid);
            string fileName = "01.026.385.01.0.I SOPORTE ENFRIADOR.dwg";
            // Possible values are jpg, bmp, psd, tiff, gif, png, j2k, wmf and pdf
            string formatToExport = "pdf";
            string dataFilePath   = Path.Combine(pathToDataDir(), fileName);
            string destFileName   = "01.026.385.01.0.I SOPORTE ENFRIADOR.pdf";

            var request        = new PostDrawingSaveAsRequest(File.OpenRead(dataFilePath), formatToExport, null, null);
            var responseStream = cadApi.PostDrawingSaveAs(request);

            // Save the output file to disk
            saveFileToDisk(responseStream, destFileName);
        }
        public void PostDrawingSaveAsTest(string formatExtension, bool saveResultToStorage, params string[] additionalExportFormats)
        {
            string name    = null;
            string folder  = CloudTestFolder;
            string storage = DefaultStorage;
            string outName = null;

            List <string> formatsToExport = new List <string>(this.BasicExportFormats);

            foreach (string additionalExportFormat in additionalExportFormats)
            {
                if (!formatsToExport.Contains(additionalExportFormat))
                {
                    formatsToExport.Add(additionalExportFormat);
                }
            }

            foreach (var inputFile in InputTestFiles)
            {
                if (inputFile.Name.EndsWith(formatExtension))
                {
                    name = inputFile.Name;
                }
                else
                {
                    continue;
                }

                foreach (string format in formatsToExport)
                {
                    outName = $"{name}.{format}";

                    this.TestRawPostRequest(
                        $"input drawing: {name}; Output format: {format}",
                        name,
                        outName,
                        saveResultToStorage,
                        delegate(Stream inputStream, string outPath)
                    {
                        var request = new PostDrawingSaveAsRequest(inputStream, format, outPath, storage);
                        return(CadApi.PostDrawingSaveAs(request));
                    },
                        folder,
                        storage);
                }
            }
        }
示例#10
0
        // Change scale of an image from body
        private void PostImageResize()
        {
            var    cadApi   = new CadApi(AppKey, AppSid);
            string fileName = "910609.dxf";
            // Possible values are jpg, bmp, psd, tiff, gif, png, j2k, wmf and pdf
            string formatToExport = "pdf";
            int?   newWidth       = 100;
            int?   newHeight      = 150;
            string dataFilePath   = Path.Combine(pathToDataDir(), fileName);
            string destFileName   = "910609.pdf";

            var request        = new PostDrawingResizeRequest(File.OpenRead(dataFilePath), formatToExport, newWidth, newHeight, null, null);
            var responseStream = cadApi.PostDrawingResize(request);

            // Save the output file to disk
            saveFileToDisk(responseStream, destFileName);
        }
示例#11
0
        // Export existing drawing to another format
        private void GetImageSaveAs()
        {
            var    cadApi   = new CadApi(AppKey, AppSid);
            string fileName = "01.026.385.01.0.I SOPORTE ENFRIADOR.dwg";
            // Possible values are jpg, bmp, psd, tiff, gif, png, j2k, wmf and pdf
            string formatToExport = "pdf";
            string destFileName   = "01.026.385.01.0.I SOPORTE ENFRIADOR.pdf";

            // Upload document to Cloud Storage
            uploadFileToCloudStorage(fileName);

            var request        = new GetDrawingSaveAsRequest(fileName, formatToExport, null, null, null);
            var responseStream = cadApi.GetDrawingSaveAs(request);

            // Save the output file to disk
            saveFileToDisk(responseStream, destFileName);
        }
示例#12
0
        // Rotate and flip existing image and get it from response
        private void PostImageRotateFlip()
        {
            var    cadApi   = new CadApi(AppKey, AppSid);
            string fileName = "01.026.385.01.0.I SOPORTE ENFRIADOR.dwg";
            // Possible values are jpg, bmp, psd, tiff, gif, png, j2k, wmf and pdf
            string formatToExport = "pdf";
            // Possible values are Rotate180FlipNone, Rotate180FlipX, Rotate180FlipXY, Rotate180FlipY, Rotate270FlipNone,
            // Rotate270FlipX, Rotate270FlipXY, Rotate270FlipY, Rotate90FlipNone, Rotate90FlipX, Rotate90FlipXY,
            // Rotate90FlipY, RotateNoneFlipNone, RotateNoneFlipX, RotateNoneFlipXY and RotateNoneFlipY
            var    method       = "Rotate180FlipNone";
            string destFileName = "01.026.385.01.0.I SOPORTE ENFRIADOR.pdf";
            string dataFilePath = Path.Combine(pathToDataDir(), fileName);

            var request        = new PostDrawingRotateFlipRequest(File.OpenRead(dataFilePath), formatToExport, method, null);
            var responseStream = cadApi.PostDrawingRotateFlip(request);

            // Save the output file to disk
            saveFileToDisk(responseStream, destFileName);
        }
示例#13
0
        // Change Scale of an existing image
        private void GetImageResize()
        {
            var cadApi = new CadApi(AppKey, AppSid);

            string fileName = "910609.dxf";
            // Possible values are jpg, bmp, psd, tiff, gif, png, j2k, wmf and pdf
            string formatToExport = "pdf";
            int?   newWidth       = 100;
            int?   newHeight      = 150;
            string destFileName   = "910609.pdf";

            // Upload document to Cloud Storage
            uploadFileToCloudStorage(fileName);

            var request        = new GetDrawingResizeRequest(fileName, formatToExport, newWidth, newHeight, null, null, null);
            var responseStream = cadApi.GetDrawingResize(request);

            // Save the output file to disk
            saveFileToDisk(responseStream, destFileName);
        }
        /// <summary>
        /// Creates the API instances using given access parameters.
        /// </summary>
        /// <param name="appKey">The application key.</param>
        /// <param name="appSid">The application sid.</param>
        /// <param name="baseUrl">The base URL.</param>
        /// <param name="apiVersion">The API version.</param>
        /// <param name="onPremise">on-premise setup.</param>
        /// <param name="debug">if set to <c>true</c> [debug].</param>
        /// <exception cref="System.ArgumentException">Please, specify valid access data (AppKey, AppSid, Base URL)</exception>
        protected void CreateApiInstances(
            string appKey = AppKey, string appSid = AppSid, string baseUrl = BaseUrl,
            AvailableApiVersions apiVersion = AvailableApiVersions.V3,
            bool onPremise = false, bool debug = true)
        {
            if (appKey == AppKey || appSid == AppSid || string.IsNullOrEmpty(baseUrl))
            {
                string serverAccessPath = Path.Combine(LocalTestFolderFullPath, ServerAccessFile);

                FileInfo serverFileInfo = new FileInfo(serverAccessPath);
                if (serverFileInfo.Exists && serverFileInfo.Length > 0)
                {
                    var accessData = JsonConvert.DeserializeObject <ServerAccessData>(File.ReadAllText(serverAccessPath));
                    appKey  = accessData.AppKey;
                    appSid  = accessData.AppSid;
                    baseUrl = accessData.BaseURL;
                }
                else
                {
                    throw new ArgumentException("Please, specify valid access data (AppKey, AppSid, Base URL)");
                }
            }

            CadApi = new CadApi(
                appKey,
                appSid,
#if LOCAL
                "https://localhost:44350",
#else
                baseUrl,
#endif


                apiVersion,
                debug
                );

            UploadInputTestFiles(true);

            InputTestFiles = FetchInputTestFilesInfo().ToList();
        }
示例#15
0
        // Rotate and flip existing image
        private void GetImageRotateFlip()
        {
            var    cadApi   = new CadApi(AppKey, AppSid);
            string fileName = "910609.dxf";
            // Possible values are jpg, bmp, psd, tiff, gif, png, j2k, wmf and pdf
            string formatToExport = "pdf";
            // Possible values are Rotate180FlipNone, Rotate180FlipX, Rotate180FlipXY, Rotate180FlipY, Rotate270FlipNone,
            // Rotate270FlipX, Rotate270FlipXY, Rotate270FlipY, Rotate90FlipNone, Rotate90FlipX, Rotate90FlipXY,
            // Rotate90FlipY, RotateNoneFlipNone, RotateNoneFlipX, RotateNoneFlipXY and RotateNoneFlipY
            var    method       = "Rotate180FlipNone";
            string destFileName = "910609.pdf";

            // Upload document to Cloud Storage
            uploadFileToCloudStorage(fileName);

            var request        = new GetDrawingRotateFlipRequest(fileName, formatToExport, method, null, null, null);
            var responseStream = cadApi.GetDrawingRotateFlip(request);

            // Save the output file to disk
            saveFileToDisk(responseStream, destFileName);
        }