示例#1
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);
                }
            }
        }