/// <summary> /// Put files to the cloud and call OMR task /// </summary> /// <param name="actionName">The action name string</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(string actionName, 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); } StorageApi storageApi = new StorageApi(AppKey, AppSid, Basepath); storageApi.PutCreate(fileName, "", "", fileData); } OmrApi omrApi = new OmrApi(AppKey, AppSid, Basepath); OMRFunctionParam param = new OMRFunctionParam(); param.FunctionParam = functionParam; param.AdditionalParam = additionalParam; BusyIndicatorManager.UpdateText("Processing task..."); OMRResponse response = omrApi.PostRunOmrTask(fileName, actionName, param, null, null); CheckForError(response); return(response); }
private static Com.Aspose.OMR.Model.OMRResponse RunOmrTask(string actionName, string inputFileName, string functionParam) { // Instantiate Aspose Storage Cloud API SDK OmrApi target = new OmrApi(APIKEY, APPSID, BASEPATH); // Instantiate Aspose OMR Cloud API SDK StorageApi storageApi = new StorageApi(APIKEY, APPSID, BASEPATH); // Init function parameters OMRFunctionParam param = new OMRFunctionParam(); param.FunctionParam = functionParam; // Set 3rd party cloud storage server (if any) string storage = null; string folder = null; // Upload source file to aspose cloud storage storageApi.PutCreate(inputFileName, "", "", System.IO.File.ReadAllBytes(path + inputFileName)); // Invoke Aspose.OMR Cloud SDK API Com.Aspose.OMR.Model.OMRResponse response = target.PostRunOmrTask(inputFileName, actionName, param, storage, folder); return(response); }
/// <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, Basepath); 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); OMRResponse response = omrApi.PostRunOmrTask(fileName, action.ToString(), param, null, null); CheckForError(response); return(response); }