Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PostRunOmrTaskRequest"/> class.
 /// </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;, &#39;GenerateTemplate&#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>
 public PostRunOmrTaskRequest(string name, string actionName, OmrFunctionParam param, string storage = null, string folder = null)
 {
     this.name       = name;
     this.actionName = actionName;
     this.param      = param;
     this.storage    = storage;
     this.folder     = folder;
 }
Exemplo n.º 2
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
            PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(imageFileName, "RecognizeImage", callParams);

            return(this.OmrApi.PostRunOmrTask(request));
        }
Exemplo n.º 3
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
            PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(templateFileName, "FinalizeTemplate", callParams);

            return(this.OmrApi.PostRunOmrTask(request));
        }
Exemplo n.º 4
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
            PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(imageFileName, "CorrectTemplate", callParams);

            return(this.OmrApi.PostRunOmrTask(request));
        }
Exemplo n.º 5
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);

            PostRunOmrTaskRequest request = new PostRunOmrTaskRequest(fileName, "GenerateTemplate", callParams);

            return(this.OmrApi.PostRunOmrTask(request));
        }
Exemplo n.º 6
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);

            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);
        }