//### callback check for Sample21 public ActionResult signature_callback() { // Get user info String infoFile = AppDomain.CurrentDomain.BaseDirectory + "user_info.txt"; System.IO.StreamReader userInfoFile = new System.IO.StreamReader(infoFile); String clientId = userInfoFile.ReadLine(); String privateKey = userInfoFile.ReadLine(); userInfoFile.Close(); // Check is data posted if (Request.HttpMethod == "POST") { System.IO.StreamReader reader = new System.IO.StreamReader(Request.InputStream); String jsonString = reader.ReadToEnd(); var data = System.Web.Helpers.Json.Decode(jsonString); String jobId = data.SourceId; jobId = jobId.Replace(" ", ""); String fileId = ""; // Create service for Groupdocs account GroupdocsService service = new GroupdocsService("https://api.groupdocs.com/v2.0", clientId, privateKey); //Make request to api for get document info by job id Groupdocs.Api.Contract.GetJobDocumentsResult job = service.GetJobDocuments(jobId); String name = ""; if (job.Inputs[0].Outputs[0].Guid != "") { //Return file guid to the template fileId = job.Inputs[0].Outputs[0].Guid; name = job.Inputs[0].Outputs[0].Name; } // Definition of folder where to download file String downloadFolder = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; if (!Directory.Exists(downloadFolder)) { DirectoryInfo di = Directory.CreateDirectory(downloadFolder); } //### Make a request to Storage Api for dowloading file // Download file bool file = service.DownloadFile(fileId, downloadFolder + name); return View("signature_callback"); } // If data not posted return to template for filling of necessary fields else { String jobId = clientId + ":" + privateKey; return View("signature_callback", null, jobId); } }
public ActionResult Sample04() { // Check is data posted if (Request.HttpMethod == "POST") { //### Set variables and get POST data System.Collections.Hashtable result = new System.Collections.Hashtable(); String clientId = Request.Form["clientId"]; String privateKey = Request.Form["privateKey"]; String fileId = Request.Form["fileId"]; result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("fileId", fileId); String message = null; // Check is all needed fields are entered if (clientId == null || privateKey == null || fileId == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample04", null, result); } else { String basePath = Request.Form["basePath"]; //Check is base path entered if (basePath.Equals("")) { //If base path empty set base path to the dev server basePath = "https://api.groupdocs.com/v2.0"; } result.Add("basePath", basePath); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //### Get all files and folders from account. Groupdocs.Api.Contract.ListEntitiesResult files = service.GetFileSystemEntities("", 0, -1, null, true, null, null); //Create empty variable for file name String name = null; // Check is files is not null if (files.Files != null) { // Obtaining file name for entered file Id for (int i = 0; i < files.Files.Length; i++) { if (files.Files[i].Guid == fileId) { name = files.Files[i].Name; } } } // Definition of folder where to download file String LocalPath = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; //### Make a request to Storage Api for dowloading file // Download file bool file = service.DownloadFile(fileId, LocalPath + name); // If file downloaded successful if (file != false) { // Put file info to the result's list result.Add("path", LocalPath); result.Add("name", name); // Return to the template return View("Sample04", null, result); } // If file download failed else { // Return error to the template message = "DownloadFile returns error"; result.Add("error", message); return View("Sample04", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample04"); } }
public ActionResult Sample42() { // Check is data posted if (Request.HttpMethod == "POST") { //### Set variables and get POST data System.Collections.Hashtable result = new System.Collections.Hashtable(); String clientId = Request.Form["clientId"]; String privateKey = Request.Form["privateKey"]; String fileId = Request.Form["fileId"]; String basePath = Request.Form["basePath"]; String guid = ""; String message = null; String iframe = ""; String name = ""; if (clientId == null || privateKey == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample42", null, result); } else { if (basePath == "") { basePath = "https://api.groupdocs.com/v2.0"; } //Add data to template result.Add("basePath", basePath); result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("fileId", fileId); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Create list with URL's Groupdocs.Api.Contract.Annotation.ListAnnotationsResult allAnnotations = service.ListAnnotations(fileId); if (allAnnotations.Annotations.Length != 0) { Random rand = new Random(); //Create job which will get document with annotations Groupdocs.Api.Contract.CreateJobResult createJob = service.CreateJob(Groupdocs.Common.JobActions.ImportAnnotations, null, false, false, "test" + rand.Next()); if (!createJob.JobGuid.Equals("")) { //Add document with annotations to new job Boolean addJobDocument = service.AddJobDocument(createJob.JobGuid, fileId, "pdf", false); if (addJobDocument.Equals(false)) { message = "Add document to job is failed"; result.Add("error", message); return View("Sample42", null, result); } else { //Run job Boolean schedule = service.ScheduleJob(createJob.JobId); System.Threading.Thread.Sleep(5000); //Get documents from job int counter = 5; for (int i = 0; i < counter; i++) { Groupdocs.Api.Contract.GetJobDocumentsResult getDocument = service.GetJobDocuments(createJob.JobId); if (!getDocument.JobStatus.ToString().Equals("Archived")) { System.Threading.Thread.Sleep(5000); } else { guid = getDocument.Inputs[0].Outputs[0].Guid; name = getDocument.Inputs[0].Outputs[0].Name; break; } } if (String.IsNullOrEmpty(guid)) { message = "Get document from job is failed or job is Draft"; result.Add("error", message); return View("Sample42", null, result); } else { // Generate Embed Annotation url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-annotation/embed/" + guid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-annotation/embed/" + guid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-apps-groupdocs.dynabic.com/document-annotation/embed/" + guid; } if (basePath.Equals("https://realtime-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://realtime-apps-groupdocs.dynabic.com/document-annotation/embed/" + guid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); // Definition of folder where to download file String downloadFolder = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; if (!Directory.Exists(downloadFolder)) { DirectoryInfo di = Directory.CreateDirectory(downloadFolder); } //### Make a request to Storage Api for dowloading file // Download file bool file = service.DownloadFile(guid, downloadFolder + name); message = "File with annotations was downloaded to server's local folder. You can download it from "; result.Add("message", message); result.Add("name", name); return View("Sample42", null, result); } } } else { message = "Create job is failed"; result.Add("error", message); return View("Sample42", null, result); } } else { message = "Get all anotations is failed"; result.Add("error", message); return View("Sample42", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample42"); } }
public ActionResult Sample27() { // Check is data posted if (Request.HttpMethod == "POST") { //### Set variables and get POST data System.Collections.Hashtable result = new System.Collections.Hashtable(); String clientId = Request.Form["clientId"]; String privateKey = Request.Form["privateKey"]; String fileId = Request.Form["fileId"]; String url = Request.Form["url"]; String name = Request.Form["name"]; String sex = Request.Form["sex"]; String age = Request.Form["age"]; String sunrise = Request.Form["sunrise"]; String resultType = Request.Form["type"]; String fileGuId = ""; var file = Request.Files["file"]; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("name", name); result.Add("sex", sex); result.Add("age", age); result.Add("sunrise", sunrise); result.Add("type", resultType); String iframe = ""; String message = null; // Check is all needed fields are entered if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey)) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample27", null, result); } else { String basePath = Request.Form["basePath"]; //Check is base path entered if (basePath.Equals("")) { //If base path empty set base path to the dev server basePath = "https://api.groupdocs.com/v2.0"; } result.Add("basePath", basePath); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Make request to get document pages as images //if URL to web file was provided - upload the file from Web and get it's GUID if (url != "") { //Make request to upload file from entered Url String guid = service.UploadUrl(url); if (guid != null) { //If file uploaded return his GuId fileGuId = guid; } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample27", null, result); } } //if file was uploaded locally - upload the file and get it's GUID if (file.FileName != "") { //Upload local file Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, "uploaded", file.InputStream); if (upload.Guid != null) { //If file uploaded return his guid fileGuId = upload.Guid; } else { //If file wasn't uploaded return error result.Add("error", "Something wrong with entered data"); return View("Sample27", null, result); } } //If user choose file guid if (!fileId.Equals("")) { //Set file guid as entered by user file guid fileGuId = fileId; } System.Collections.Hashtable enteredData = new System.Collections.Hashtable(); enteredData.Add("sex", sex); enteredData.Add("age", age); enteredData.Add("sunrise", sunrise); enteredData.Add("name", name); //Set fileds counter Int32 count = enteredData.Count; //Create Datasource object Groupdocs.Assembly.Data.Datasource dataSource = new Groupdocs.Assembly.Data.Datasource(); //Create array of DatasourceField objects Groupdocs.Assembly.Data.DatasourceField[] fieldArray = new Groupdocs.Assembly.Data.DatasourceField[count]; //Create array od objects with string[] values = new string[1]; //Set DatasourceFiled data Int32 counter = 0; foreach (System.Collections.DictionaryEntry fields in enteredData) { //Set object array content values.SetValue(System.Convert.ToString(fields.Value), 0); Groupdocs.Assembly.Data.DatasourceField field = new Groupdocs.Assembly.Data.DatasourceField(); Groupdocs.Assembly.Data.DatasourceFieldType type = new Groupdocs.Assembly.Data.DatasourceFieldType(); type = 0; field.Name = System.Convert.ToString(fields.Key); field.Type = type; field.Values = values; //Push DatasourceField to array of DatasourceField objects fieldArray.SetValue(field, counter); counter++; } //Set feilds array to the Datasource dataSource.Fields = fieldArray; //Add new Datasource to GroupDocs decimal addDataSource = service.AddDataSource(dataSource); //Check is not empty addDataSource if (!addDataSource.Equals("")) { //If status ok merge Datasource to new pdf file decimal job = service.MergeTemplate(fileGuId, addDataSource, resultType, false); if (!job.Equals("")) { Groupdocs.Api.Contract.GetJobDocumentsResult jobInfo = new Groupdocs.Api.Contract.GetJobDocumentsResult(); //### Check job status for (int n = 0; n <= 5; n++) { //Delay necessary that the inquiry would manage to be processed System.Threading.Thread.Sleep(5000); //Make request to api for get document info by job id jobInfo = service.GetJobDocuments(job); //Check job status, if status is Completed or Archived exit from cycle if (jobInfo.JobStatus.Equals("Completed") || jobInfo.JobStatus.Equals("Archived")) { break; //If job status Postponed throw exception with error } else if (jobInfo.JobStatus.Equals("Postponed")) { result.Add("error", "Job is fail"); return View("Sample27", null, result); } } //Get guid String guid = jobInfo.Inputs[0].Outputs[0].Guid; //Get name String fileName = jobInfo.Inputs[0].Outputs[0].Name; // Definition of folder where to download file String LocalPath = AppDomain.CurrentDomain.BaseDirectory + "downloads/"; if (!Directory.Exists(LocalPath)) { DirectoryInfo di = Directory.CreateDirectory(LocalPath); } //### Make a request to Storage Api for dowloading file // Download file bool download = service.DownloadFile(guid, LocalPath + fileName); // If file downloaded successful if (download != false) { // Generate Embed viewer url with entered file id if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com/document-viewer/embed/" + guid; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps.groupdocs.com/document-viewer/embed/" + guid; } iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); // Put file info to the result's list result.Add("message", "File was converted and downloaded to the " + LocalPath + "/" + fileName); result.Add("fileId", guid); // Return to the template return View("Sample27", null, result); } } else { result.Add("error", "MargeTemplate is fail"); return View("Sample27", null, result); } } else { result.Add("error", "AddDataSource returned empty job id"); return View("Sample27", null, result); } return View("Sample27", null, result); } } // If data not posted return to template for filling of necessary fields else { return View("Sample27"); } }