public ActionResult Sample38() { // 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 email = Request.Form["email"]; String firstName = Request.Form["firstName"]; String lastName = Request.Form["lastName"]; String basePath = Request.Form["basePath"]; String fileId = Request.Form["fileId"]; String url = Request.Form["url"]; var file = Request.Files["file"]; String fileGuId = ""; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("email", email); result.Add("firstName", firstName); result.Add("lastName", lastName); String message = null; // Check is all needed fields are entered if (clientId == null || privateKey == null || email == null || firstName == null || lastName == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample38", null, result); } else { // Create string array with emails String[] collaborators = new String[1]; collaborators[0] = email; //Set base path for API if it's not entered by user if (basePath == "") { basePath = "https://api.groupdocs.com/v2.0"; } // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Check is chosen local file if (!file.ContentLength.Equals(0)) { // Upload file with empty description. Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream); // Check is upload successful if (upload.Guid != null) { // Put uploaded file GuId to the result's list fileGuId = upload.Guid; } // If upload was failed return error else { message = "UploadFile returns error"; result.Add("error", message); return View("Sample38", null, result); } } //Check is url entered if (!url.Equals("")) { //Make request to upload file from entered Url String guid = service.UploadUrl(url); if (guid != null) { //Get all files from GroupDocs account Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true); if (storageInfo.Files.Length > 0) { // Get file id by uploaded file GuId for (int i = 0; i < storageInfo.Files.Length; i++) { if (storageInfo.Files[i].Guid == guid) { fileGuId = storageInfo.Files[i].Guid; } } } else { message = "Get files list is failed"; result.Add("error", message); return View("Sample38", null, result); } } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample38", null, result); } } //Check is file guid entered if (!fileId.Equals("")) { fileGuId = fileId; } result.Add("fileId", fileGuId); // Generate Embed Annotation url with file GUID string iframe = null; if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-annotation2/embed/" + fileGuId; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps.groupdocs.com/document-annotation2/embed/" + fileGuId; } string userGuid = null; //Get all users from GroupDocs account Groupdocs.Api.Contract.GetAccountUsersResult allUsers = service.GetAccountUsers(); if (allUsers != null) { //Check is user allready exist in GroupDocs Account for (int i = 0; i < allUsers.Users.Length; i++) { if (email.Equals(allUsers.Users[i].PrimaryEmail)) { //If user exist take his GUID userGuid = allUsers.Users[i].Guid; break; } } //If user not exist create him if (userGuid == null) { //Create User info object Groupdocs.Api.Contract.UserInfo user = new Groupdocs.Api.Contract.UserInfo(); //Create Role info object Groupdocs.Api.Contract.RoleInfo roleInfo = new Groupdocs.Api.Contract.RoleInfo(); //Create array of roles. Groupdocs.Api.Contract.RoleInfo[] roleList = new Groupdocs.Api.Contract.RoleInfo[1]; //Set user role Id. Can be: 1 - SysAdmin, 2 - Admin, 3 - User, 4 - Guest roleInfo.Id = 3; //Set user role name. Can be: SysAdmin, Admin, User, Guest roleInfo.Name = "User"; roleList[0] = roleInfo; //Set nick name as entered first name user.NickName = firstName; //Set first name as entered first name user.FirstName = firstName; //Set last name as entered last name user.LastName = lastName; user.Roles = roleList; //Set email as entered email user.PrimaryEmail = email; //Creating of new User user - object with new user info Groupdocs.Api.Contract.UserIdentity newUser = service.UpdateAccountUser(user); // If request return's null return error to the template if (newUser.Guid != null) { //Get GUID of new user userGuid = newUser.Guid; } else { message = "Failed to create new user"; result.Add("error", message); return View("Sample38", null, result); } } //Get all collaborators for document Groupdocs.Api.Contract.Annotation.GetCollaboratorsResult getCollaborators = service.GetAnnotationCollaborators(fileGuId); if (getCollaborators != null) { //Check is user allready in collaborators for (int n = 0; n < getCollaborators.Collaborators.Length; n++) { //If user allready in collaborators sign iframe URL with his Client ID if (getCollaborators.Collaborators[n].FirstName.Equals(firstName)) { iframe = iframe + "?uid=" + userGuid; iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); break; } } //If user is not in collaborators add him as collaborator if (iframe.Contains("?uid=")) { result.Add("iframe", iframe); return View("Sample38", null, result); } else { // Make request to set annotation collaborators Groupdocs.Api.Contract.Annotation.SetCollaboratorsResult collaborate = service.SetAnnotationCollaborators(fileGuId, collaborators); // Check is request return data if (collaborate != null) { //Sign iframe URL iframe = iframe + "?uid=" + userGuid; iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); // Return primary email to the template result.Add("collaborator", collaborate.Collaborators[0].PrimaryEmail); //Return iframe URl to the template result.Add("iframe", iframe); return View("Sample38", null, result); } // If request return's null return error to the template else { message = "Failed to add new collaborator"; result.Add("error", message); return View("Sample38", null, result); } } } else { message = "Faild to get all collaborators for document"; result.Add("error", message); return View("Sample38", null, result); } } else { message = "Faild to get all users from account"; result.Add("error", message); return View("Sample38", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample38"); } }
public ActionResult Sample41() { // 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[] emailsArray = Request.Form["email[]"].Split(','); String[] emails = new String[emailsArray.Length - 1]; String basePath = Request.Form["basePath"]; String fileId = Request.Form["fileId"]; String url = Request.Form["url"]; var file = Request.Files["file"]; String callback = Request.Form["callbackUrl"]; String fileGuId = ""; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); String message = null; // Check is all needed fields are entered if (clientId == null || privateKey == null || emails == null) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample41", null, result); } else { //Add all emails to array if (emailsArray[emailsArray.Length - 1].Equals("")) { for (int n = 0; n < emailsArray.Length - 1; n++) { emails[n] = emailsArray[n]; } } else { emails = new String[emailsArray.Length]; for (int n = 0; n < emailsArray.Length; n++) { emails[n] = emailsArray[n]; } } //path to settings file - temporary save clientId and apiKey like to property file create_info_file(clientId, privateKey, ""); //remove temporary file with callback info String callbackInfo = AppDomain.CurrentDomain.BaseDirectory + "callback_info.txt"; if (System.IO.File.Exists(callbackInfo)) { System.IO.File.Delete(callbackInfo); } //Set base path for API if it's not entered by user if (basePath == "") { basePath = "https://api.groupdocs.com/v2.0"; } // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //Check is chosen local file if (!file.ContentLength.Equals(0)) { // Upload file with empty description. Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream); // Check is upload successful if (upload.Guid != null) { // Put uploaded file GuId to the result's list fileGuId = upload.Guid; } // If upload was failed return error else { message = "UploadFile returns error"; result.Add("error", message); return View("Sample41", null, result); } } //Check is url entered if (!url.Equals("")) { //Make request to upload file from entered Url String guid = service.UploadUrl(url); if (guid != null) { //Get all files from GroupDocs account Groupdocs.Api.Contract.ListEntitiesResult storageInfo = service.GetFileSystemEntities("My Web Documents", 0, -1, null, false, null, null, true); if (storageInfo.Files.Length > 0) { // Get file id by uploaded file GuId for (int i = 0; i < storageInfo.Files.Length; i++) { if (storageInfo.Files[i].Guid == guid) { fileGuId = storageInfo.Files[i].Guid; } } } else { message = "Get files list is failed"; result.Add("error", message); return View("Sample41", null, result); } } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample41", null, result); } } //Check is file guid entered if (!fileId.Equals("")) { fileGuId = fileId; } result.Add("fileId", fileGuId); // Generate Embed Annotation url with file GUID string iframe = null; if (callback == null) { callback = ""; } result.Add("callbackUrl", callback); //Set file sesion callback - will be trigered when user add, remove or edit commit for annotation Groupdocs.Api.Contract.Annotation.SetSessionCallbackUrlResult setCallback = service.SetSessionCallbackUrl(fileGuId, callback); //Generate iframe URL for iframe if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com/document-annotation2/embed/" + fileGuId; } if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId; } if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-apps-groupdocs.dynabic.com/document-annotation2/embed/" + fileGuId; } if (basePath.Equals("https://realtime-api.groupdocs.com/v2.0")) { iframe = "https://realtime-apps.groupdocs.com/document-annotation2/embed/" + fileGuId; } //Prepare variables string userGuid = null; String email = String.Empty; String[] Email = new String[emails.Length]; int counter = 0; //Get all users from account Groupdocs.Api.Contract.GetAccountUsersResult allUsers = service.GetAccountUsers(); if (allUsers != null) { //Loop for all users foreach (var item in emails) { //Get current user email email = item; //Add all entered by user emails to emails array to collaborators for (int m = 0; m < emails.Length; m++) { Email[m] = emails[m]; } //Loop to get user GUID if user with same email already exist for (int i = 0; i < allUsers.Users.Length; i++) { userGuid = string.Empty; if (email.Equals(allUsers.Users[i].PrimaryEmail)) { userGuid = allUsers.Users[i].Guid; break; } } //If user not exist create it if (userGuid == null || userGuid == string.Empty) { //Create new user Groupdocs.Api.Contract.UserInfo user = new Groupdocs.Api.Contract.UserInfo(); Groupdocs.Api.Contract.RoleInfo roleInfo = new Groupdocs.Api.Contract.RoleInfo(); Groupdocs.Api.Contract.RoleInfo[] roleList = new Groupdocs.Api.Contract.RoleInfo[1]; roleInfo.Id = 3; roleInfo.Name = "User"; roleList[0] = roleInfo; user.FirstName = email; user.LastName = email; user.Roles = roleList; user.PrimaryEmail = email; //Add new user to account Groupdocs.Api.Contract.UserIdentity newUser = service.UpdateAccountUser(user); if (newUser.Guid != null) { userGuid = newUser.Guid; } else { message = "Update account user is failed"; result.Add("error", message); return View("Sample41", null, result); } } System.Threading.Thread.Sleep(2000); //Get all collaborators for selected document Groupdocs.Api.Contract.Annotation.GetCollaboratorsResult getCollaborators = service.GetAnnotationCollaborators(fileGuId); if (getCollaborators != null) { //Check if user already collaborator of the document String urlParameter = null; for (int n = 0; n < getCollaborators.Collaborators.Length; n++) { //If user is collaborator add his GUID to the URl if (getCollaborators.Collaborators[n].PrimaryEmail.Equals(email)) { iframe = iframe + "?uid=" + userGuid; urlParameter = userGuid; iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); break; } } //If this parameters is null that means that user not a collaborator if (iframe.Contains("?uid=") && urlParameter != null) { if (counter == 0) { counter = 1; result.Add("iframe", iframe); } } else { if (counter == 0) { //Add user to collaborators of the document Groupdocs.Api.Contract.Annotation.SetCollaboratorsResult collaborate = service.SetAnnotationCollaborators(fileGuId, Email); if (collaborate != null) { counter = 1; iframe = iframe + "?uid=" + userGuid; iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); result.Add("iframe", iframe); } else { result.Add("error", "Set annotation colaborator is failed"); return View("Sample41", null, result); } } } } else { result.Add("error", "Get annotation colaborators is failed"); return View("Sample41", null, result); } } return View("Sample41", null, result); } else { result.Add("error", "Faild to get all users from account"); return View("Sample41", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample41"); } }
public ActionResult Sample22() { // 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 email = Request.Form["email"]; String firstName = Request.Form["firstName"]; String lastName = Request.Form["lastName"]; String fileId = Request.Form["fileId"]; String url = Request.Form["url"]; var file = Request.Files["file"]; String guid = ""; String basePath = Request.Form["basePath"]; // Set entered data to the results list result.Add("clientId", clientId); result.Add("privateKey", privateKey); result.Add("email", email); result.Add("firstName", firstName); result.Add("lastName", lastName); String message = null; // Check is all needed fields are entered if (String.IsNullOrEmpty(clientId) || String.IsNullOrEmpty(privateKey) || String.IsNullOrEmpty(email) || String.IsNullOrEmpty(lastName) || String.IsNullOrEmpty(firstName)) { // If not all fields entered send error message message = "Please enter all parameters"; result.Add("error", message); return View("Sample22", null, result); } else { if (basePath.Equals("")) { basePath = "https://api.groupdocs.com/v2.0"; } result.Add("basePath", basePath); // Create service for Groupdocs account GroupdocsService service = new GroupdocsService(basePath, clientId, privateKey); //if URL to web file was provided - upload the file from Web and get it's GUID if (!url.Equals("")) { //Make request to upload file from entered Url String uploadWeb = service.UploadUrl(url); if (uploadWeb != null) { //If file uploaded return his GuId guid = uploadWeb; } //If file wasn't uploaded return error else { result.Add("error", "Something wrong with entered data"); return View("Sample22", null, result); } } //if file was uploaded locally - upload the file and get it's GUID if (!file.FileName.Equals("")) { //Upload local file Groupdocs.Api.Contract.UploadRequestResult upload = service.UploadFile(file.FileName, String.Empty, file.InputStream); if (upload.Guid != null) { //If file uploaded return his guid guid = upload.Guid; } else { //If file wasn't uploaded return error result.Add("error", "Something wrong with entered data"); return View("Sample22", null, result); } } if (!fileId.Equals("")) { guid = fileId; } result.Add("fileId", guid); //Create User info object Groupdocs.Api.Contract.UserInfo user = new Groupdocs.Api.Contract.UserInfo(); //Create Role info object Groupdocs.Api.Contract.RoleInfo roleInfo = new Groupdocs.Api.Contract.RoleInfo(); //Create array of roles. Groupdocs.Api.Contract.RoleInfo[] roleList = new Groupdocs.Api.Contract.RoleInfo[1]; //Set user role Id. Can be: 1 - SysAdmin, 2 - Admin, 3 - User, 4 - Guest roleInfo.Id = 3; //Set user role name. Can be: SysAdmin, Admin, User, Guest roleInfo.Name = "User"; roleList[0] = roleInfo; //Set nick name as entered first name user.NickName = firstName; //Set first name as entered first name user.FirstName = firstName; //Set last name as entered last name user.LastName = lastName; user.Roles = roleList; //Set email as entered email user.PrimaryEmail = email; //Creating of new User user - object with new user info Groupdocs.Api.Contract.UserIdentity newUser = service.UpdateAccountUser(user); // If request return's null return error to the template if (newUser.Guid != null) { //Create array with entered email for SetAnnotationCollaborators method String[] emails = new String[1]; emails[0] = email; //Make request to Ant api for set new user as annotation collaborator Groupdocs.Api.Contract.Annotation.SetCollaboratorsResult addCollaborator = service.SetAnnotationCollaborators(guid, emails, "2.0"); if (addCollaborator.Collaborators != null) { //Set reviewers rights for new user. Groupdocs.Api.Contract.Annotation.SetReviewerRightsResult setReviewer = service.SetReviewerRights(guid, addCollaborator.Collaborators); String iframe = ""; if (basePath.Equals("https://api.groupdocs.com/v2.0")) { iframe = "https://apps.groupdocs.com//document-annotation2/embed/" + guid + "?&uid=" + newUser.Guid + "&download=true"; } else if (basePath.Equals("https://dev-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://dev-apps-groupdocs.dynabic.com//document-annotation2/embed/" + guid + "?&uid=" + newUser.Guid + "&download=true"; } else if (basePath.Equals("https://stage-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://stage-api-groupdocs.dynabic.com//document-annotation2/embed/" + guid + "?&uid=" + newUser.Guid + "&download=true"; } else if (basePath.Equals("https://realtime-api-groupdocs.dynabic.com/v2.0")) { iframe = "https://realtime-apps-groupdocs.dynabic.com//document-annotation2/embed/" + guid + "?&uid=" + newUser.Guid + "&download=true"; } //Sign iframe URL with private key iframe = Groupdocs.Security.UrlSignature.Sign(iframe, privateKey); //Return GuId of new User to the template result.Add("url", iframe); return View("Sample22", null, result); } //If Collaborators is empty return error else { result.Add("error", "Collaborators is empty"); return View("Sample22", null, result); } } //If upload file returns faile, return error to the template else { result.Add("error", "Upload is failed"); return View("Sample22", null, result); } } } // If data not posted return to template for filling of necessary fields else { return View("Sample22"); } }