/// <summary> /// Initializes a new instance of the <see cref="UploadViewModel" /> class. /// </summary> /// <param name="navigationFacade">The navigation facade.</param> /// <param name="photoService">The photo service.</param> /// <param name="authEnforcementHandler">Authentication enforcement handler.</param> /// <param name="uploadFinishedHandler">The handler that is called when the upload finished.</param> /// <param name="dialogService">The dialog service.</param> public UploadViewModel(INavigationFacade navigationFacade, IPhotoService photoService, IAuthEnforcementHandler authEnforcementHandler, IUploadFinishedHandler uploadFinishedHandler, IDialogService dialogService) { _navigationFacade = navigationFacade; _photoService = photoService; _authEnforcementHandler = authEnforcementHandler; _uploadFinishedHandler = uploadFinishedHandler; _dialogService = dialogService; // Initialize commands UploadCommand = new RelayCommand(OnUpload, () => !IsBusy); ChooseCategoryCommand = new RelayCommand(OnChooseCategory, () => !IsBusy); }
/// <summary> /// Invoked when the application is activated through sharing association. /// </summary> /// <param name="args">Event data for the event.</param> protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args) { IAppEnvironment mainAppEnvironment = null; IUploadFinishedHandler mainUploadFinishedHandler = null; if (UnityBootstrapper.Container != null) { // We need to save the app environment from the current app. mainAppEnvironment = ServiceLocator.Current.GetInstance <IAppEnvironment>(); mainUploadFinishedHandler = ServiceLocator.Current.GetInstance <IUploadFinishedHandler>(); } else { // We only configure unity if the main app is not already launched. UnityBootstrapper.Init(); UnityBootstrapper.ConfigureRegistries(); } // Overwrite existing app environment instance. UnityBootstrapper.Container.RegisterInstance(typeof(IAppEnvironment), new AppEnvironment()); // Do initializations, trying restoring current user into the // provided app environment. await AppInitialization.DoInitializations(); // Overwrite existing upload finished handler to make sure, the app // does not navigate to the categories page after successful upload, // but closes the share target window instead. var uploadFinishedHandler = new ShareTargetUploadFinishedHandler(() => { // Restore original app environment. if (mainAppEnvironment != null) { UnityBootstrapper.Container.RegisterInstance(typeof(IAppEnvironment), mainAppEnvironment); } // Restore original upload finished handler. if (mainUploadFinishedHandler != null) { var uploadFinishedHandlerType = mainUploadFinishedHandler.GetType(); UnityBootstrapper.Container.RegisterType(typeof(IUploadFinishedHandler), uploadFinishedHandlerType); } args.ShareOperation.ReportCompleted(); }); UnityBootstrapper.Container.RegisterInstance(typeof(IUploadFinishedHandler), uploadFinishedHandler); // Access data that has been shared. var data = args.ShareOperation.Data; if (data.Contains(StandardDataFormats.StorageItems)) { try { var items = await data.GetStorageItemsAsync(); // We expect the shared data to be a StorageFile. var file = items.FirstOrDefault() as StorageFile; if (file != null) { GetOrCreateRootFrame(); var navigationFacade = ServiceLocator.Current.GetInstance <INavigationFacade>(); navigationFacade.NavigateToCropView(file); Window.Current.Activate(); } } catch (Exception) { args.ShareOperation.ReportCompleted(); } } }