/// <summary> /// Run specific OMR task /// </summary> /// <param name="request">Request. <see cref="PostRunOmrTaskRequest" /></param> /// <returns><see cref="OmrResponse"/></returns> public OmrResponse PostRunOmrTask(PostRunOmrTaskRequest request) { // verify the required parameter 'name' is set if (request.name == null) { throw new ApiException(400, "Missing required parameter 'name' when calling PostRunOmrTask"); } // verify the required parameter 'actionName' is set if (request.actionName == null) { throw new ApiException(400, "Missing required parameter 'actionName' when calling PostRunOmrTask"); } // verify the required parameter 'param' is set if (request.param == null) { throw new ApiException(400, "Missing required parameter 'param' when calling PostRunOmrTask"); } // create path and map variables var resourcePath = this.configuration.GetApiRootUrl() + "/omr/{name}/runOmrTask"; resourcePath = Regex .Replace(resourcePath, "\\*", string.Empty) .Replace("&", "&") .Replace("/?", "?"); resourcePath = UrlHelper.AddPathParameter(resourcePath, "name", request.name); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "actionName", request.actionName); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "storage", request.storage); resourcePath = UrlHelper.AddQueryParameterToUrl(resourcePath, "folder", request.folder); var postBody = SerializationHelper.Serialize(request.param); // http body (model) parameter try { var response = this.apiInvoker.InvokeApi( resourcePath, "POST", postBody, null, null); if (response != null) { return((OmrResponse)SerializationHelper.Deserialize(response, typeof(OmrResponse))); } return(null); } catch (ApiException ex) { if (ex.ErrorCode == 404) { return(null); } throw; } }
/// <summary> /// Runs mark recognition on image /// </summary> /// <param name="templateId">Template ID</param> /// <param name="imagePath">Path to the image</param> /// <returns>Recognition response</returns> protected OmrResponse RecognizeImage(string templateId, string imagePath) { // upload image on cloud string imageFileName = Path.GetFileName(imagePath); this.UploadFile(imagePath, imageFileName); // provide template id as function parameter OmrFunctionParam callParams = new OmrFunctionParam(); callParams.FunctionParam = templateId; // call image recognition PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(imageFileName, "RecognizeImage", callParams); return(this.OmrApi.PostRunOmrTask(request)); }
/// <summary> /// Run template finalization /// </summary> /// <param name="templateId">Template id recieved after template correction</param> /// <param name="correctedTemplatePath">Path to corrected template (.omrcr)</param> /// <returns>Finalization response</returns> protected OmrResponse FinalizeTemplate(string templateId, string correctedTemplatePath) { // upload corrected template data on cloud string templateFileName = Path.GetFileName(correctedTemplatePath); this.UploadFile(correctedTemplatePath, templateFileName); // provide template id as function parameter OmrFunctionParam callParams = new OmrFunctionParam(); callParams.FunctionParam = templateId; // call template finalization PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(templateFileName, "FinalizeTemplate", callParams); return(this.OmrApi.PostRunOmrTask(request)); }
/// <summary> /// Run template correction /// </summary> /// <param name="templateImagePath">Path to template image</param> /// <param name="templateDataDir">Path to template data file (.omr)</param> /// <returns>Correction response</returns> protected OmrResponse CorrectTemplate(string templateImagePath, string templateDataDir) { // upload template image string imageFileName = Path.GetFileName(templateImagePath); this.UploadFile(templateImagePath, imageFileName); // locate generated template file (.omr) and provide it's data as function parameter string templateDataPath = Path.Combine(templateDataDir, Path.GetFileNameWithoutExtension(imageFileName) + ".omr"); OmrFunctionParam callParams = new OmrFunctionParam(); callParams.FunctionParam = Utility.SerializeFiles(new string[] { templateDataPath }); // call template correction PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(imageFileName, "CorrectTemplate", callParams); return(this.OmrApi.PostRunOmrTask(request)); }
/// <summary> /// Generate new template based on provided text description /// </summary> /// <param name="templateFilePath">Path to template text description</param> /// <param name="logosFolder">Name of the cloud folder with logo images</param> /// <returns>Generation response</returns> protected OmrResponse GenerateTemplate(string templateFilePath, string logosFolder) { // upload template text description string fileName = Path.GetFileName(templateFilePath); this.UploadFile(templateFilePath, fileName); // provide function parameters OmrFunctionParam callParams = new OmrFunctionParam(); callParams.FunctionParam = JsonConvert.SerializeObject(new Dictionary <string, string> { { "ExtraStoragePath", logosFolder } }, Formatting.Indented); PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(fileName, "GenerateTemplate", callParams); return(this.OmrApi.PostRunOmrTask(request)); }
/// <summary> /// Put files to the cloud and call OMR task /// </summary> /// <param name="action">The executed OMR function</param> /// <param name="fileName">The file name</param> /// <param name="fileData">The file data</param> /// <param name="functionParam">The function parameters</param> /// <param name="wasUploaded">Indicates if image was already uploaded on cloud</param> /// <param name="trackFile">Track file so that it can be deleted from cloud</param> /// <param name="additionalParam">The additional (debug) parameters</param> /// <returns>Task response</returns> public static OmrResponse RunOmrTask(OmrFunctions action, string fileName, byte[] fileData, string functionParam, bool wasUploaded, bool trackFile, string additionalParam) { if (string.IsNullOrEmpty(AppKey) || string.IsNullOrEmpty(AppSid)) { throw new Exception("Please specify App Key and App SID in Settings->Credentials in order to use OMR functions."); } if (!wasUploaded) { BusyIndicatorManager.UpdateText("Uploading files..."); if (trackFile) { CloudStorageManager.TrackFileUpload(fileName); } try { string baseHost = new Uri(Basepath).GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped).ToString(); Configuration storageConfiguration = new Configuration(); storageConfiguration.AppKey = AppKey; storageConfiguration.AppSid = AppSid; storageConfiguration.ApiBaseUrl = baseHost; StorageApi storageApi = new StorageApi(storageConfiguration); using (Stream stream = new MemoryStream(fileData)) { storageApi.PutCreate(new PutCreateRequest(fileName, stream)); } } catch (ApiException e) { if (e.ErrorCode == 401) { // handle authentification exception throw new Exception("Aspose Cloud Authentification Failed! Please check App Key and App SID in Settings->Credentials."); } throw; } } OmrApi omrApi = new OmrApi(AppKey, AppSid); OmrFunctionParam param = new OmrFunctionParam(); param.FunctionParam = functionParam; param.AdditionalParam = additionalParam; string busyMessage = ""; switch (action) { case OmrFunctions.CorrectTemplate: busyMessage = "Performing Template Correction..."; break; case OmrFunctions.FinalizeTemplate: busyMessage = "Performing Template Finalization..."; break; case OmrFunctions.RecognizeImage: busyMessage = "Performing Recognition..."; break; case OmrFunctions.GenerateTemplate: busyMessage = "Generating Template..."; break; } BusyIndicatorManager.UpdateText(busyMessage); var request = new PostRunOmrTaskRequest(fileName, action.ToString(), param); OmrResponse response = omrApi.PostRunOmrTask(request); CheckForError(response); return(response); }