/// <summary>
        /// Uploads selected images on cloud storage
        /// </summary>
        private async void OnUploadImages()
        {
            try
            {
                BusyIndicatorManager.Enable();
                ControlHelper.HideAllChildViews();

                Dictionary <string, byte[]> imagesData = new Dictionary <string, byte[]>();
                string folderPath = string.IsNullOrEmpty(this.ExtraStoragePath) ? string.Empty : this.ExtraStoragePath + @"\";

                foreach (FileToUpload item in this.ImagesToUpload)
                {
                    imagesData.Add(string.Concat(folderPath, item.Name), File.ReadAllBytes(item.FullPath));
                }

                await Task.Run(() => CoreApi.StorageUploadImages(imagesData));

                if (this.ViewClosed != null)
                {
                    this.ViewClosed(this.ExtraStoragePath);
                }

                this.view.Close();
            }
            catch (Exception e)
            {
                DialogManager.ShowErrorDialog(e.Message);
            }
            finally
            {
                BusyIndicatorManager.Disable();
                ControlHelper.RestoreHidderChildViews();
            }
        }
Пример #2
0
        /// <summary>
        /// Calls template generation
        /// </summary>
        private async Task GenerateTemplate()
        {
            this.view.Hide();
            BusyIndicatorManager.Enable();

            string expectedFileNameExtension = ".txt";

            byte[] templateDescriptionBytes = Encoding.UTF8.GetBytes(this.TemplateDescription);

            if (!Path.HasExtension(this.TemplateName) ||
                (Path.HasExtension(this.TemplateName) && Path.GetExtension(this.TemplateName) != expectedFileNameExtension))
            {
                this.TemplateName += expectedFileNameExtension;
            }

            try
            {
                this.GenerationContent = await Task.Run(() => CoreApi.GenerateTemplate(
                                                            this.TemplateName,
                                                            templateDescriptionBytes,
                                                            this.ExtraStoragePath,
                                                            string.Empty));

                this.GenerationContent.Name = this.TemplateName;
            }
            catch (Exception e)
            {
                DialogManager.ShowErrorDialog(e.Message);
            }
            finally
            {
                BusyIndicatorManager.Disable();
            }
        }
        /// <summary>
        /// Runs template finalization
        /// </summary>
        private void OnFinilizeTemplate()
        {
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (sender, args) =>
            {
                string templateData   = TemplateSerializer.TemplateToJson(this, false);
                string additionalPars = string.Empty;

                try
                {
                    string           templateName       = Path.GetFileNameWithoutExtension(this.TemplateImageName) + "_template.omr";
                    FinalizationData finalizationResult = CoreApi.FinalizeTemplate(templateName, Encoding.UTF8.GetBytes(templateData), this.TemplateId, additionalPars);

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.ProcessFinalizationResponse(finalizationResult);
                    });
                }
                catch (Exception e)
                {
                    DialogManager.ShowErrorDialog(e.Message);
                }
            };

            worker.RunWorkerCompleted += (sender, args) =>
            {
                BusyIndicatorManager.Disable();
            };

            BusyIndicatorManager.Enable();

            worker.RunWorkerAsync();
        }
Пример #4
0
 public MainWindow()
 {
     InitializeComponent();
     PagesManager.Init(MainContainer);
     BusyIndicatorManager.Init(AppWideBusyIndicator);
     PagesManager.SwitchPage(PagesManager.Page.SelectFilePage, null);
 }
Пример #5
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);
        }
        /// <summary>
        /// Runs template correction
        /// </summary>
        private void OnCorrectTemplate()
        {
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (sender, args) =>
            {
                string templateData = TemplateSerializer.TemplateToJson(this, false);

                byte[] imageData = TemplateSerializer.CompressImage(this.TemplateImage, this.ImageSizeInBytes);

                //string imageData = TemplateConverter.CheckAndCompressImage(this.TemplateImage, this.ImageFileFormat, this.ImageSizeInBytes);

                string additionalPars = string.Empty;

                try
                {
                    TemplateViewModel correctedTemplate = CoreApi.CorrectTemplate(this.TemplateImageName,
                                                                                  imageData,
                                                                                  templateData,
                                                                                  this.WasUploaded,
                                                                                  additionalPars);

                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.ClearSelection();
                        this.PageQuestions.Clear();

                        this.AddQuestions(correctedTemplate.PageQuestions);
                        this.TemplateId = correctedTemplate.TemplateId;

                        this.FinalizationComplete = false;

                        double koeff     = this.TemplateImage.PixelWidth / correctedTemplate.PageWidth;
                        ZoomKoefficient *= koeff;
                        this.OnPropertyChanged(nameof(this.PageScale));

                        this.PageWidth   = correctedTemplate.PageWidth;
                        this.PageHeight  = correctedTemplate.PageHeight;
                        this.WasUploaded = true;

                        this.Warnings.Add("Template correction complete!");
                    });
                }
                catch (Exception e)
                {
                    DialogManager.ShowErrorDialog(e.Message);
                }
            };

            worker.RunWorkerCompleted += (sender, args) =>
            {
                BusyIndicatorManager.Disable();
            };

            BusyIndicatorManager.Enable();

            worker.RunWorkerAsync();
        }
Пример #7
0
        /// <summary>
        /// Remove files from cloud storage
        /// </summary>
        /// <param name="files">List of file names to remove</param>
        public static void StorageCleanUp(List <string> files)
        {
            StorageApi storageApi = new StorageApi(AppKey, AppSid, Basepath);

            foreach (string file in files)
            {
                BusyIndicatorManager.UpdateText("Storage clean up...\n Deleting file: " + file);

                FileExistResponse existsResponse = storageApi.GetIsExist(file, "", "");
                if (existsResponse.FileExist.IsExist)
                {
                    RemoveFileResponse deleteResponse = storageApi.DeleteFile(file, "", "");
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Remove files from cloud storage
        /// </summary>
        /// <param name="files">List of file names to remove</param>
        public static void StorageCleanUp(List <string> files)
        {
            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);

            foreach (string file in files)
            {
                BusyIndicatorManager.UpdateText("Storage clean up...\n Deleting file: " + file);

                FileExistResponse existsResponse = storageApi.GetIsExist(new GetIsExistRequest(file));
                if (existsResponse.FileExist.IsExist == true)
                {
                    RemoveFileResponse deleteResponse = storageApi.DeleteFile(new DeleteFileRequest(file));
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Upload provided images on cloud storage
        /// </summary>
        /// <param name="imagesToUpload">Dictionary with images in (name, data) pairs</param>
        public static void StorageUploadImages(Dictionary <string, byte[]> imagesToUpload)
        {
            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.");
            }

            try
            {
                foreach (KeyValuePair <string, byte[]> item in imagesToUpload)
                {
                    BusyIndicatorManager.UpdateText("Uploading image " + item.Key + "...");

                    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(item.Value))
                    {
                        storageApi.PutCreate(new PutCreateRequest(item.Key, 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;
            }
        }
        private void SelectFileClicked(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog
            {
                FileName   = "Document",
                DefaultExt = ".txt",
                Filter     = "Text documents (.txt)|*.txt"
            };

            if (dlg.ShowDialog() == true)
            {
                var logic = new Logic(dlg.FileName);
                BusyIndicatorManager.ShowDuringAction(() =>
                {
                    logic.DoWork();
                    Application.Current.Dispatcher.Invoke((Action)(() =>
                    {
                        var vasyaVm = new VasyaVM(logic);
                        PagesManager.SwitchPage(PagesManager.Page.WorkAreaPage, vasyaVm);
                    }));
                }, "Reading file and creating image representation");
            }
        }
Пример #11
0
        private void RegisterServices()
        {
            _phoneContainer.RegisterInstance(typeof(IAnalytics), null, _analytics);

            _phoneContainer.RegisterHandler(typeof(ILocalizationManager), null, c => Application.Current.Resources["Localization"]);
            _phoneContainer.RegisterHandler(typeof(IBusyIndicatorManager), null, c => BusyIndicatorManager.Create((PhoneApplicationPage)RootFrame.Content));
            _phoneContainer.Singleton <SettingsController>();
            _phoneContainer.PerRequest <INotificationsService, NotificationsService>();
            _phoneContainer.PerRequest <IErrorHandler, ErrorHandler>();

            _phoneContainer.PerRequest <ITileManager, TileManager>();
            _phoneContainer.PerRequest <IBookRepository, BookRepository>();
            _phoneContainer.PerRequest <ICatalogRepository, CatalogRepository>();
            _phoneContainer.PerRequest <IWebDataGateway, WebDataGateway>();
            _phoneContainer.PerRequest <IWebClient, WebClient.WebClient>();
            _phoneContainer.PerRequest <ICatalogReaderFactory, CatalogReaderFactory>();
            _phoneContainer.PerRequest <ICatalogAuthorizationFactory, CatalogAuthorizationFactory>();
            _phoneContainer.PerRequest <IAcquisitionServiceFactory, AcquisitionServiceFactory>();

            _phoneContainer.Singleton <BookmarksController>();
            _phoneContainer.PerRequest <IBookmarkRepository, BookmarkRepository>();

            _phoneContainer.Singleton <SearchInBookController>();

            _phoneContainer.PerRequest <BookSearch>();

            _phoneContainer.Singleton <ISdCardStorage, SdCardStorage>();
            _phoneContainer.PerRequest <DataBaseInitializer>();

            _phoneContainer.PerRequest <IStorageStateSaver, StorageStateSaver>();

            _phoneContainer.PerRequest <ILiveLogin, LiveLogin>();
            _phoneContainer.PerRequest <ISkyDriveService, SkyDriveService>();

            _phoneContainer.Handler <AppSettings>(container => AppSettings.Default);

            _phoneContainer.PerRequest <SharingDataModel>();

            _phoneContainer.PerRequest <IBusyOverlayManager, BusyOverlayManager>();

            _phoneContainer.PerRequest <BookTool>();

            _phoneContainer.Singleton <CatalogController>();

            _phoneContainer.PerRequest <IFileLoadingFactory, FileLoadingFactory>();
            _phoneContainer.Singleton <DownloadController>();
            _phoneContainer.Singleton <IBookDownloader, BookDownloader>();
            _phoneContainer.Singleton <IDownloadsContainer, DownloadsContainer>();
            _phoneContainer.PerRequest <IBookDownloadsRepository, BookDownloadsRepository>();
        }
Пример #12
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);
        }