public void Run()
        {
            var name  = "testpage3_embcss.html";
            var xPath = "//ol/li";
            // Upload source file to cloud storage (default is AmazonS3)
            var srcPath = Path.Combine(CommonSettings.DataFolder, name);

            if (File.Exists(srcPath))
            {
                SdkBaseRunner.uploadToStorage(name, CommonSettings.DataFolder);
            }
            else
            {
                throw new Exception(string.Format("Error: file {0} not found.", srcPath));
            }

            IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            // call the SDK method that returns a query result in the response stream.
            Stream stream = docApi.GetDocumentFragmentByXPath(name, xPath, "json", null, null);

            if (stream != null && typeof(FileStream) == stream.GetType())
            {
                string outFile = $"{Path.GetFileNameWithoutExtension(name)}_fragments.json";
                string outPath = Path.Combine(CommonSettings.OutDirectory, outFile);
                using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                {
                    stream.Position = 0;
                    stream.CopyTo(fstr);
                    fstr.Flush();
                    Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                }
            }
        }
Example #2
0
        public void TemplateInput()
        {
            PostSlidesPipelineRequest request = new PostSlidesPipelineRequest
            {
                Pipeline = new Pipeline
                {
                    Files = new FileInfo[]
                    {
                        TestUtils.GetLocalFile("TemplatingCVDataWithBase64.xml", "text/xml"),
                        TestUtils.GetLocalFile("TemplateCV.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation")
                    },
                    Input = new Input
                    {
                        TemplateData = new RequestInputFile {
                            Type = InputFileType.Request, Index = 0
                        },
                        Template = new RequestInputFile {
                            Type = InputFileType.Request, Index = 1
                        }
                    },
                    Tasks = new System.Collections.Generic.List <Task>
                    {
                        new Save {
                            Format = ExportFormat.Pptx, Output = new ResponseOutputFile {
                                Type = OutputFileType.Response
                            }
                        }
                    }
                }
            };
            DocumentApi api      = new DocumentApi(TestUtils.Configuration);
            Stream      response = api.PostSlidesPipeline(request);

            Assert.IsNotNull(response);
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new DocumentApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath = "WordProcessing/four-pages.docx"
                };

                var options = new PreviewOptions()
                {
                    FileInfo   = fileInfo,
                    OutputPath = "Output/preview-page",
                    Pages      = new List <int?> {
                        1, 3
                    },
                    Format = PreviewOptions.FormatEnum.Png
                };

                var request  = new PreviewRequest(options);
                var response = apiInstance.Preview(request);

                foreach (var document in response.Documents)
                {
                    Console.WriteLine("Output file path: " + document.Path);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling api: " + e.Message);
            }
        }
Example #4
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new DocumentApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath = "WordProcessing/sample-10-pages.docx"
                };

                var options = new SplitOptions
                {
                    FileInfo   = fileInfo,
                    OutputPath = "Output/split-to-multipage-document",
                    Pages      = new List <int?> {
                        3, 6, 8
                    },
                    Mode = SplitOptions.ModeEnum.Intervals
                };

                var request  = new SplitRequest(options);
                var response = apiInstance.Split(request);

                foreach (var document in response.Documents)
                {
                    Console.WriteLine("Output file path: " + document.Path);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling api: " + e.Message);
            }
        }
        public void Run()
        {
            string name = "testpage5.html.zip";   // storage file name
            string folder = "HtmlTemp"; // storage folder name

            string filePath = Path.Combine(CommonSettings.DataFolder, name);
            if (File.Exists(filePath))
            {
                SdkBaseRunner.uploadToStorage(name, CommonSettings.DataFolder);
            }
            else
                throw new Exception(string.Format("Error: file {0} not found.", filePath));

            IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            // call SDK method that gets a zip archive with all HTML document images
            Stream stream = docApi.GetDocumentImages(name, null, folder);
            if (stream != null && typeof(FileStream) == stream.GetType())
            {
                string outFile = $"{Path.GetFileNameWithoutExtension(name)}_images.zip";
                string outPath = Path.Combine(CommonSettings.OutDirectory, outFile);
                using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                {
                    stream.Position = 0;
                    stream.CopyTo(fstr);
                    fstr.Flush();
                    Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                }
            }

        }
Example #6
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new DocumentApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath = "WordProcessing/sample-10-pages.docx"
                };

                var options = new SplitOptions
                {
                    FileInfo        = fileInfo,
                    OutputPath      = "Output/split-by-start-end-numbers",
                    StartPageNumber = 3,
                    EndPageNumber   = 7,
                    Mode            = SplitOptions.ModeEnum.Pages
                };

                var request  = new SplitRequest(options);
                var response = apiInstance.Split(request);

                foreach (var document in response.Documents)
                {
                    Console.WriteLine("Output file path: " + document.Path);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling api: " + e.Message);
            }
        }
        public void GetSlidesDocumentRequest()
        {
            DocumentResponse response = null;

            try {
                DocumentApi api = new DocumentApi(AppSID, SecretKey);
                GetSlidesDocumentRequest request = createGetSlidesDocumentRequest();
                response = api.GetSlidesDocument(request);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Example #8
0
        public void Run()
        {
            var    name    = "zero.txt";
            string folder  = null;
            string storage = null;

            DocumentApi api    = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            var         result = api.GetDocument(name, storage, folder);

            if (result != null && typeof(FileStream) == result.GetType())
            {
            }
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new DocumentApi(configuration);

            try
            {
                var item1 = new JoinItem
                {
                    FileInfo = new FileInfo
                    {
                        FilePath = "WordProcessing/sample-10-pages.docx"
                    },
                    Pages = new List <int?> {
                        3, 6, 8
                    }
                };

                var item2 = new JoinItem
                {
                    FileInfo = new FileInfo
                    {
                        FilePath = "WordProcessing/four-pages.docx"
                    },
                    StartPageNumber = 1,
                    EndPageNumber   = 4,
                    RangeMode       = JoinItem.RangeModeEnum.OddPages
                };

                var options = new JoinOptions
                {
                    JoinItems = new List <JoinItem> {
                        item1, item2
                    },
                    OutputPath = "Output/joined-pages.docx"
                };

                var request  = new JoinRequest(options);
                var response = apiInstance.Join(request);

                Console.WriteLine("Output file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling api: " + e.Message);
            }
        }
Example #10
0
        public void Test_GetDocumentImages()
        {
            string name        = "testpage5.html.zip";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";

            string srcPath = Path.Combine(dataFolder, name);

            StorageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(srcPath));
            FileExistResponse resp = StorageApi.GetIsExist(storagePath, null, null);

            Assert.IsTrue(resp.FileExist.IsExist);

            Stream stream = DocumentApi.GetDocumentImages(name, null, folder);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new DocumentApi(configuration);

            try
            {
                var item1 = new JoinItem
                {
                    FileInfo = new FileInfo
                    {
                        FilePath = "WordProcessing/four-pages.docx"
                    }
                };

                var item2 = new JoinItem
                {
                    FileInfo = new FileInfo
                    {
                        FilePath = "WordProcessing/one-page.docx"
                    }
                };

                var options = new JoinOptions
                {
                    JoinItems = new List <JoinItem> {
                        item1, item2
                    },
                    OutputPath = "Output/joined.docx"
                };

                var request  = new JoinRequest(options);
                var response = apiInstance.Join(request);

                Console.WriteLine("Output file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling api: " + e.Message);
            }
        }
        public void Test_GetDocumentImages()
        {
            string name        = "testpage5.html.zip";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";

            string srcPath = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                PutCreateRequest reqCr = new PutCreateRequest(storagePath, fstr);
                this.StorageApi.PutCreate(reqCr);
                GetIsExistRequest reqExist = new GetIsExistRequest(storagePath);
                FileExistResponse resp     = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value);
            }

            Stream stream = DocumentApi.GetDocumentImages(name, null, folder);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
        public void Run()
        {
            string name   = "testpage5.html.zip"; // storage file name
            string folder = "HtmlTemp";           // storage folder name

            string     filePath    = Path.Combine(CommonSettings.DataFolder, name);
            StorageApi storageApi  = new StorageApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            string     storagePath = string.IsNullOrEmpty(folder) ? name : string.Format("{0}/{1}", folder, name);

            if (File.Exists(filePath))
            {
                // upload source file to the cloud storage (default is AmazonS3)
                //filePath = string.Format("file:///{0}", filePath.Replace('\\', '/'));
                storageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(filePath));
            }
            else
            {
                throw new Exception(string.Format("Error: file {0} not found.", filePath));
            }

            IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath);
            // call SDK method that gets a zip archive with all HTML document images
            Stream stream = docApi.GetDocumentImages(name, null, folder);

            if (stream != null && typeof(FileStream) == stream.GetType())
            {
                string outFile = $"{Path.GetFileNameWithoutExtension(name)}_images.zip";
                string outPath = Path.Combine(CommonSettings.OutDirectory, outFile);
                using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write))
                {
                    stream.Position = 0;
                    stream.CopyTo(fstr);
                    fstr.Flush();
                    Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath));
                }
            }
        }
        public void Test_GetDocumentFragmentByXPath_2()
        {
            string name        = "testpage1.html";
            string xpath       = ".//ol/li";
            string folder      = "HtmlTestDoc";
            string storagePath = $"{folder}/{name}";

            string srcPath = Path.Combine(dataFolder, name);

            using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read))
            {
                var reqCr     = new PutCreateRequest(storagePath, fstr);
                var respCr    = this.StorageApi.PutCreate(reqCr);
                var reqExist  = new GetIsExistRequest(storagePath);
                var respExist = this.StorageApi.GetIsExist(reqExist);
                Assert.IsTrue(respExist.FileExist.IsExist.HasValue && respExist.FileExist.IsExist.Value);
            }

            Stream stream = DocumentApi.GetDocumentFragmentByXPath(name, xpath, "json", null, folder);

            Assert.IsNotNull(stream);
            Assert.IsTrue(stream.GetType() == typeof(FileStream));
            Assert.IsTrue(File.Exists(((FileStream)stream).Name));
        }
 public JobTest() : base(UserRole.Admin)
 {
     jobApi      = new JobApi(Configuration);
     documentApi = new DocumentApi(Configuration);
 }
Example #16
0
 public void Init()
 {
     instance = new DocumentApi();
 }
Example #17
0
        public ShareLinkItem createBookmarkAsDocument(Uri link, String title, String description, List <String> spaceKeys, Bitmap icon)
        {
            try {
                DocumentApi documentApi = new DocumentApi(session.GetApiClient());

                LinkV2Record linkRecord = new LinkV2Record();
                linkRecord.Link  = link.ToString();
                linkRecord.Title = title;
                linkRecord.Text  = description;
                linkRecord.Type  = "link";

                CreateDocumentInput  createDocumentInput  = new CreateDocumentInput(linkRecord);
                CreateDocumentResult createDocumentResult = documentApi.CreateDocument(createDocumentInput);
                if (createDocumentResult.Hdr.Rc == 0)
                {
                    DocumentV2Record createdDocument = createDocumentResult.Document;
                    LinkV2Record     createdLink     = null;

                    if (spaceKeys != null)
                    {
                        SpaceApi          spaceApi    = new SpaceApi(session.GetApiClient());
                        ShareObjectInput  shareInput  = new ShareObjectInput(null, spaceKeys, null);
                        ShareObjectResult shareResult = spaceApi.ShareObject(createdDocument.Key, shareInput);
                        if (shareResult.Hdr.Rc == 0)
                        {
                            LinkApi       linkApi       = new LinkApi(session.GetApiClient());
                            GetLinkResult getLinkResult = linkApi.GetLink(createdDocument.Key);
                            if (getLinkResult.Hdr.Rc == 0)
                            {
                                createdLink = getLinkResult.Link;
                            }
                            else
                            {
                                throw new Exception("Vmoso error getting created link. Rc=" + getLinkResult.Hdr.Rc);
                            }
                        }
                        else
                        {
                            throw new Exception("Vmoso error sharing link. Rc=" + shareResult.Hdr.Rc);
                        }
                    }

                    ShareLinkItem item = new ShareLinkItem(createdLink.Title, createdLink.Text);
                    item.Key    = createdLink.Key;
                    item.Link   = new Uri(createdLink.Link);
                    item.Record = createdLink;
                    item.SetIcon(icon);

                    List <ShareSpace> itemSpaces = new List <ShareSpace>();
                    foreach (DisplayRecord spaceDisplayRecord in createdLink.Destinations)
                    {
                        ShareSpace space = new ShareSpace(spaceDisplayRecord.Key, spaceDisplayRecord.DisplayName, null);
                        itemSpaces.Add(space);
                    }

                    item.Spaces = itemSpaces;
                    return(item);
                }
                else
                {
                    throw new Exception("Vmoso error creating link. Rc=" + createDocumentResult.Hdr.Rc);
                }
            } catch (Exception ex)
            {
                throw new Exception("Vmoso error creating link", ex);
            }
        }
Example #18
0
        public ShareLinkItem updateBookmark(String key, Uri link, String title, String description, List <String> spaceKeys, Bitmap icon)
        {
            try
            {
                LinkApi     linkApi     = new LinkApi(session.GetApiClient());
                DocumentApi documentApi = new DocumentApi(session.GetApiClient());

                GetLinkResult getLinkResult = linkApi.GetLink(key);
                if (getLinkResult.Hdr.Rc == 0)
                {
                    LinkV2Record existingLink = getLinkResult.Link;
                    existingLink.Link  = link.ToString();
                    existingLink.Title = title;
                    existingLink.Text  = description;
                    existingLink.Type  = "link";

                    //UpdateLinkInput updateLinkInput = new UpdateLinkInput(existingLink);
                    //UpdateLinkResult updateLinkResult = linkApi.UpdateLink(key, updateLinkInput);

                    UpdateDocumentInput  updateDocumentInput  = new UpdateDocumentInput(existingLink);
                    UpdateDocumentResult updateDocumentResult = documentApi.UpdateDocument(key, updateDocumentInput);

                    if (updateDocumentResult.Hdr.Rc == 0)
                    {
                        DocumentV2Record updatedDocument = updateDocumentResult.Document;

                        SpaceApi spaceApi = new SpaceApi(session.GetApiClient());

                        // Remove spaces
                        foreach (DisplayRecord destination in updatedDocument.Destinations)
                        {
                            if (!spaceKeys.Contains(destination.Key))
                            {
                                List <String> itemKeysToRemove = new List <String>()
                                {
                                    updatedDocument.Key
                                };
                                RemoveObjectsInput  removeObjectsInput  = new RemoveObjectsInput(destination.Key, itemKeysToRemove);
                                RemoveObjectsResult removeObjectsResult = spaceApi.RemoveObjects(destination.Key, removeObjectsInput);
                                if (removeObjectsResult.Hdr.Rc != 0)
                                {
                                    throw new Exception("Vmoso error removing bookmark from space. Rc=" + removeObjectsResult.Hdr.Rc);
                                }
                            }
                            else
                            {
                                spaceKeys.Remove(destination.Key);
                            }
                        }

                        if (spaceKeys.Count > 0)
                        {
                            ShareObjectInput  shareInput  = new ShareObjectInput(null, spaceKeys, null);
                            ShareObjectResult shareResult = spaceApi.ShareObject(updatedDocument.Key, shareInput);
                            if (shareResult.Hdr.Rc != 0)
                            {
                                throw new Exception("Vmoso error sharing bookmark. Rc=" + shareResult.Hdr.Rc);
                            }
                        }

                        getLinkResult = linkApi.GetLink(updatedDocument.Key);
                        if (getLinkResult.Hdr.Rc == 0)
                        {
                            LinkV2Record  updatedLink = getLinkResult.Link;
                            ShareLinkItem item        = new ShareLinkItem(updatedLink.Title, updatedLink.Text);
                            item.Key    = updatedLink.Key;
                            item.Link   = new Uri(updatedLink.Link);
                            item.Record = updatedLink;
                            item.SetIcon(icon);

                            List <ShareSpace> itemSpaces = new List <ShareSpace>();
                            foreach (DisplayRecord spaceDisplayRecord in updatedLink.Destinations)
                            {
                                ShareSpace space = new ShareSpace(spaceDisplayRecord.Key, spaceDisplayRecord.DisplayName, null);
                                itemSpaces.Add(space);
                            }

                            item.Spaces = itemSpaces;
                            return(item);
                        }
                        else
                        {
                            throw new Exception("Vmoso error getting updated link. Rc=" + getLinkResult.Hdr.Rc);
                        }
                    }
                    else
                    {
                        throw new Exception("Vmoso error updating link. Rc=" + updateDocumentResult.Hdr.Rc);
                    }
                }
                else
                {
                    throw new Exception("Vmoso error getting link to update. Rc=" + getLinkResult.Hdr.Rc);
                }
            } catch (Exception ex)
            {
                throw new Exception("Vmoso error getting link to update", ex);
            }
        }
 public DocumentAPIExamples()
 {
     api = new DocumentApi(AppSID, SecretKey);
 }