Example #1
0
        private void UploadFiles()
        {
            var parameters = new FileUploadPageParameters
            {
                ResourceInfo = Directory.PathStack.Count > 0
                    ? Directory.PathStack[Directory.PathStack.Count - 1].ResourceInfo
                    : new ResourceInfo()
            };

            _navigationService.Navigate(PageToken.FileUpload.ToString(), parameters.Serialize());
        }
Example #2
0
        private void UploadPhotos()
        {
            var parameters = new FileUploadPageParameters
            {
                ResourceInfo = Directory.PathStack.Count > 0
                    ? Directory.PathStack[Directory.PathStack.Count - 1].ResourceInfo
                    : new ResourceInfo(),
                PickerLocationId = PickerLocationId.PicturesLibrary
            };

            _navigationService.Navigate(PageToken.FileUpload.ToString(), parameters.Serialize());
        }
        private void StartUpload()
        {
            var parameters = new FileUploadPageParameters
            {
                ActivationKind = ActivationKind,
                ResourceInfo   = Directory.PathStack.Count > 0
                    ? Directory.PathStack[Directory.PathStack.Count - 1].ResourceInfo
                    : new ResourceInfo(),
                FileTokens = FileTokens
            };

            _navigationService.Navigate(PageToken.FileUpload.ToString(), parameters.Serialize());
        }
Example #4
0
        public override async void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState)
        {
            base.OnNavigatedTo(e, viewModelState);

            var client = ClientService.GetClient();

            if (client == null)
            {
                return;
            }

            _cts = new CancellationTokenSource();
            var parameters   = FileUploadPageParameters.Deserialize(e.Parameter);
            var resourceInfo = parameters?.ResourceInfo;

            if (resourceInfo == null)
            {
                return;
            }
            ResourceInfo              = resourceInfo;
            SuggestedStartLocation    = parameters.PickerLocationId;
            UploadingFilesTitle       = null;
            UploadingFileProgressText = null;
            var i = 0;

            var openPicker = new FileOpenPicker
            {
                SuggestedStartLocation = SuggestedStartLocation
            };

            openPicker.FileTypeFilter.Add("*");
            var storageFiles = await openPicker.PickMultipleFilesAsync();

            foreach (var localFile in storageFiles)
            {
                _currentFile = localFile;

                // Prevent updates to the remote version of the file until
                // we finish making changes and call CompleteUpdatesAsync.
                CachedFileManager.DeferUpdates(localFile);

                if (storageFiles.Count > 1)
                {
                    UploadingFilesTitle = string.Format(_resourceLoader.GetString("UploadingFiles"), ++i, storageFiles.Count);
                }

                try
                {
                    var properties = await localFile.GetBasicPropertiesAsync();

                    BytesTotal = (long)properties.Size;

                    var stream = await localFile.OpenAsync(FileAccessMode.ReadWrite);

                    IProgress <HttpProgress> progress = new Progress <HttpProgress>(ProgressHandler);
                    await client.Upload(ResourceInfo.Path + localFile.Name, stream, localFile.ContentType, _cts, progress);
                }
                catch (ResponseError e2)
                {
                    ResponseErrorHandlerService.HandleException(e2);
                }

                // Let Windows know that we're finished changing the file so
                // the other app can update the remote version of the file.
                // Completing updates may require Windows to ask for user input.
                await CachedFileManager.CompleteUpdatesAsync(localFile);

                UploadingFileProgressText = null;
            }
            _navigationService.GoBack();
        }