Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run specific OMR task
        /// </summary>
        /// <param name="name">Name of the file to recognize.</param>
        /// <param name="actionName">Action name [&#39;CorrectTemplate&#39;, &#39;FinalizeTemplate&#39;, &#39;RecognizeImage&#39;]</param>
        /// <param name="param">Function params, specific for each actionName</param>
        /// <param name="storage">Image&#39;s storage.</param>
        /// <param name="folder">Image&#39;s folder.</param>
        /// <returns>OMRResponse</returns>
        public OMRResponse PostRunOmrTask(string name, string actionName, OMRFunctionParam param, string storage, string folder)
        {
            // verify the required parameter 'name' is set
            if (name == null)
            {
                throw new ApiException(400, "Missing required parameter 'name' when calling PostRunOmrTask");
            }

            // verify the required parameter 'actionName' is set
            if (actionName == null)
            {
                throw new ApiException(400, "Missing required parameter 'actionName' when calling PostRunOmrTask");
            }


            var _apiPath = "/omr/{name}/runOmrTask";

            _apiPath = _apiPath.Replace("{format}", "json");
            _apiPath = _apiPath.Replace("{" + "name" + "}", ApiClient.ParameterToString(name));

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            if (actionName != null)
            {
                queryParams.Add("actionName", ApiClient.ParameterToString(actionName));                      // query parameter
            }
            if (storage != null)
            {
                queryParams.Add("storage", ApiClient.ParameterToString(storage));       // query parameter
            }
            if (folder != null)
            {
                queryParams.Add("folder", ApiClient.ParameterToString(folder)); // query parameter
            }
            postBody = ApiClient.Serialize(param);                              // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            RestResponse response = (RestResponse)ApiClient.CallApi(_apiPath, "POST", queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling PostRunOmrTask: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling PostRunOmrTask: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((OMRResponse)ApiClient.Deserialize(response, typeof(OMRResponse), response.Headers));
        }
Exemplo n.º 3
0
        /// <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
            return(this.OmrApi.PostRunOmrTask(imageFileName, "RecognizeImage", callParams, null, null));
        }
Exemplo n.º 4
0
        /// <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
            return(this.OmrApi.PostRunOmrTask(templateFileName, "FinalizeTemplate", callParams, null, null));
        }
Exemplo n.º 5
0
        /// <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
            return(this.OmrApi.PostRunOmrTask(imageFileName, "CorrectTemplate", callParams, null, null));
        }
Exemplo n.º 6
0
        /// <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);

            return(this.OmrApi.PostRunOmrTask(fileName, "GenerateTemplate", callParams, null, null));
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// PostRunOmrTask
        /// </summary>
        /// <param name="name"></param>
        /// <param name="actionName"></param>
        /// <param name="functionParams"></param>
        /// <param name="additionalParams"></param>
        /// <param name="storage"></param>
        /// <param name="folder"></param>
        /// <returns></returns>
        public OMRResponse PostRunOmrTask(string name, string actionName, OMRFunctionParam functionParam,
                                          string storage, string folder)
        {
            // create path and map variables
            string ResourcePath =
                "/omr/{name}/runOmrTask/?appSid={appSid}&amp;actionName={actionName}&amp;storage={storage}&amp;folder={folder}"
                .Replace("{format}", "json");

            ResourcePath = Regex.Replace(ResourcePath, "\\*", "")
                           .Replace("&amp;", "&")
                           .Replace("/?", "?")
                           .Replace("toFormat={toFormat}", "format={format}");

            // query params
            Dictionary <string, string> queryParams  = new Dictionary <String, String>();
            Dictionary <string, string> headerParams = new Dictionary <String, String>();
            Dictionary <string, object> formParams   = new Dictionary <String, object>();

            // verify required params are set
            if (name == null)
            {
                throw new ApiException(400, "missing required params");
            }
            if (name == null)
            {
                ResourcePath = Regex.Replace(ResourcePath, @"([&?])name=", "");
            }
            else
            {
                ResourcePath = ResourcePath.Replace("{" + "name" + "}", apiInvoker.ToPathValue(name));
            }
            if (actionName == null)
            {
                ResourcePath = Regex.Replace(ResourcePath, @"([&?])actionName=", "");
            }
            else
            {
                ResourcePath = ResourcePath.Replace("{" + "actionName" + "}", apiInvoker.ToPathValue(actionName));
            }
            if (storage == null)
            {
                ResourcePath = Regex.Replace(ResourcePath, @"([&?])storage=", "");
            }
            else
            {
                ResourcePath = ResourcePath.Replace("{" + "storage" + "}", apiInvoker.ToPathValue(storage));
            }
            if (folder == null)
            {
                ResourcePath = Regex.Replace(ResourcePath, @"([&?])folder=", "");
            }
            else
            {
                ResourcePath = ResourcePath.Replace("{" + "folder" + "}", apiInvoker.ToPathValue(folder));
            }
            try
            {
                if (typeof(OMRResponse) == typeof(ResponseMessage))
                {
                    byte[] response = apiInvoker.invokeBinaryAPI(basePath, ResourcePath, "POST", queryParams,
                                                                 functionParam, headerParams, formParams);
                    return((OMRResponse)ApiInvoker.deserialize(response, typeof(OMRResponse)));
                }
                else
                {
                    string response = apiInvoker.invokeAPI(basePath, ResourcePath, "POST", queryParams, functionParam,
                                                           headerParams, formParams);
                    if (response != null)
                    {
                        return((OMRResponse)ApiInvoker.deserialize(response, typeof(OMRResponse)));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode == 404)
                {
                    return(null);
                }
                else
                {
                    throw ex;
                }
            }
        }