コード例 #1
0
        private async void SetMyPickListAsync(string message)
        {
            // Show progress indicator 
            base.SetListUnableAndShowMessage(uiMyPicktList, uiMyPickMessage, message);
            base.SetProgressIndicator(true);

            // Create or Open local folder
            StorageFolder folder = await ApplicationData.Current.LocalFolder
                .CreateFolderAsync(SpotObject.PREVIEW_FILE_LOCATION, CreationCollisionOption.OpenIfExists);
            if (folder != null)
            {
                // Get files from local folder.
                // If file is on, set items.
                // Otherwise, show error message.
                this.LocalFileList = await folder.GetFilesAsync();
                if (this.LocalFileList.Count > 0)
                {
                    base.Dispatcher.BeginInvoke(() =>
                    {
                        foreach (StorageFile storageFile in this.LocalFileList)
                        {
                            this.MyPickFileObjectViewModel.IsDataLoaded = true;
                            uiMyPicktList.Visibility = Visibility.Visible;
                            uiMyPickMessage.Visibility = Visibility.Collapsed;

                            FileObjectViewItem fileObjectViewItem = new FileObjectViewItem();
                            fileObjectViewItem.Name = storageFile.Name;
                            fileObjectViewItem.ThumnailType = storageFile.Name.Split('.').Last();
                            fileObjectViewItem.SelectFileImage = FileObjectViewModel.TRANSPARENT_IMAGE_URI;
                            this.MyPickFileObjectViewModel.Items.Add(fileObjectViewItem);
                        }
                    });
                }
                else
                {
                    base.SetListUnableAndShowMessage(uiMyPicktList, uiMyPickMessage, AppResources.NoFileInFolderMessage);
                }
            }

            // Hide progress indicator
            base.SetProgressIndicator(false);
        }
コード例 #2
0
        public async void SetPinInfoListAsync(FileObjectViewItem folder, string message, IStorageManager iStorageManager, int currentPlatformIndex)
        {
            // Set Mutex true and Show Process Indicator
            this.FileObjectViewModel.IsDataLoaded = true;
            this.FileObjectViewModel.IsDataLoading = true;
            this.SetListUnableAndShowMessage(uiPinInfoList, message, uiPinInfoMessage);
            this.SetProgressIndicator(true);

            // Wait tasks
            await App.TaskManager.WaitSignInTask(currentPlatformIndex);
            await App.TaskManager.WaitSignOutTask(currentPlatformIndex);


            // If it haven't signed out before working below code, do it.
            if (iStorageManager.GetAccount() != null)
            {
                // Delete selected file and If folder null, set root.
                this.SelectedFile.Clear();
                if (folder == null)
                {
                    this.Dispatcher.BeginInvoke(() =>
                    {
                        uiPinInfoCurrentPath.Text = "";
                    });

                    this.FolderRootTree.Clear();
                    this.FoldersTree.Clear();

                    FileObject rootFolder = await iStorageManager.GetRootFolderAsync();
                    folder = new FileObjectViewItem();
                    folder.Id = rootFolder.Id;
                }

                // Get files and push to stack tree.
                List<FileObject> files = await iStorageManager.GetFilesFromFolderAsync(folder.Id);
                if (!message.Equals(AppResources.Refreshing))
                {
                    this.FolderRootTree.Push(folder);
                    this.FoldersTree.Push(files);
                }

                // Set file list visible and current path.
                base.Dispatcher.BeginInvoke(() =>
                {
                    // Set file tree to list.
                    uiPinInfoList.Visibility = Visibility.Visible;
                    uiPinInfoCurrentPath.Text = this.GetCurrentPath();
                    this.FileObjectViewModel.SetItems(files, true);
                });

                // If there exists file, show it.
                // Otherwise, show no file message.
                if (files.Count > 0)
                {
                    base.Dispatcher.BeginInvoke(() =>
                    {
                        uiPinInfoMessage.Visibility = Visibility.Collapsed;
                    });
                }
                else
                {
                    base.Dispatcher.BeginInvoke(() =>
                    {
                        uiPinInfoMessage.Text = AppResources.NoFileInFolderMessage;
                    });
                }
            }
            else
            {
                this.Dispatcher.BeginInvoke(() =>
                {
                    uiPinInfoListGrid.Visibility = Visibility.Collapsed;
                    uiPinInfoSignInGrid.Visibility = Visibility.Visible;
                });
            }


            // Set Mutex false and Hide Process Indicator
            this.SetProgressIndicator(false);
            this.FileObjectViewModel.IsDataLoading = false;
        }
コード例 #3
0
ファイル: PinPage.cs プロジェクト: pinthecloud/pin_the_cloud
        protected async void SetPinInfoListAsync(IStorageManager iStorageManager, LongListSelector list, TextBlock messageTextBlock, string message,
            TextBlock pathTextBlock, Grid listGrid, StackPanel signInPanel, ApplicationBarIconButton pinInfoAppBarButton,
            FileObjectViewModel viewModel, List<FileObjectViewItem> selectedFile, FileObjectViewItem folder, bool load)
        {
            // Set Mutex true and Show Process Indicator
            viewModel.IsDataLoaded = true;
            base.SetListUnableAndShowMessage(list, messageTextBlock, message);
            base.SetProgressIndicator(true);

            // Clear selected file and set pin button false.
            selectedFile.Clear();
            base.Dispatcher.BeginInvoke(() =>
            {
                pinInfoAppBarButton.IsEnabled = false;
            });

            // Wait task
            await TaskHelper.WaitSignInTask(iStorageManager.GetStorageName());
            await TaskHelper.WaitSignOutTask(iStorageManager.GetStorageName());

            // If it wasn't signed out, set list.
            // Othersie, show sign in grid.
            if (iStorageManager.GetStorageAccount() != null)  // Wasn't signed out.
            {
                // If it has to load, load new files.
                // Otherwise, set existing files to list.
                List<FileObject> fileObjects = new List<FileObject>();
                if (load)  // Load from server
                {
                    // If folder null, set root.
                    if (folder == null)
                    {
                        iStorageManager.GetFolderRootTree().Clear();
                        iStorageManager.GetFoldersTree().Clear();

                        FileObject rootFolder = await iStorageManager.GetRootFolderAsync();
                        folder = new FileObjectViewItem();
                        folder.Id = rootFolder.Id;
                    }

                    // Get files and push to stack tree.
                    fileObjects = await iStorageManager.GetFilesFromFolderAsync(folder.Id);
                    if (!message.Equals(AppResources.Refreshing))
                    {
                        iStorageManager.GetFoldersTree().Push(fileObjects);
                        if (!iStorageManager.GetFolderRootTree().Contains(folder))
                            iStorageManager.GetFolderRootTree().Push(folder);
                    }
                }
                else  // Set existed file to list
                {
                    fileObjects = iStorageManager.GetFoldersTree().First();
                }


                // If didn't change cloud mode while loading, set it to list.
                if (iStorageManager.GetStorageName().Equals(iStorageManager.GetStorageName()))
                {
                    // Set file list visible and current path.
                    base.Dispatcher.BeginInvoke(() =>
                    {
                        list.Visibility = Visibility.Visible;
                        this.SetCurrentPath(iStorageManager, pathTextBlock);
                        viewModel.SetItems(fileObjects, true);
                    });

                    // If there exists file, show it.
                    // Otherwise, show no file message.
                    if (fileObjects.Count > 0)
                    {
                        base.Dispatcher.BeginInvoke(() =>
                        {
                            messageTextBlock.Visibility = Visibility.Collapsed;
                        });
                    }
                    else
                    {
                        base.Dispatcher.BeginInvoke(() =>
                        {
                            messageTextBlock.Text = AppResources.NoFileInFolderMessage;
                        });
                    }
                }
            }
            else  // Was signed out.
            {
                base.Dispatcher.BeginInvoke(() =>
                {
                    listGrid.Visibility = Visibility.Collapsed;
                    signInPanel.Visibility = Visibility.Visible;
                });
            }

            // Set Mutex false and Hide Process Indicator
            base.SetProgressIndicator(false);
        }
コード例 #4
0
        public void SetItems(List<FileObject> fileObjectList, bool select)
        {
            // If items have something, clear.
            this.Items.Clear();

            // Sorting items
            fileObjectList.Sort((f1, f2) =>
            {
                return f1.Name.CompareTo(f2.Name);
            });
            fileObjectList.Sort((f1, f2) =>
            {
                return f1.Type.CompareTo(f2.Type);
            });

            // Convert jarray spaces to space view items and set to view model
            foreach (FileObject fileObject in fileObjectList)
            {
                // Set new file view item
                FileObjectViewItem fileObjectViewItem = new FileObjectViewItem();
                fileObjectViewItem.Id = fileObject.Id;
                fileObjectViewItem.Name = fileObject.Name;
                fileObjectViewItem.DownloadUrl = fileObject.DownloadUrl;

                // If type is folder, set it.
                // Otherwise, set size also.
                if (fileObject.Type == FileObject.FileObjectType.FOLDER)
                {
                    fileObjectViewItem.ThumnailType = FOLDER;
                }
                else
                {
                    fileObjectViewItem.ThumnailType = fileObject.Extension;

                    // Set Size and Size Unit
                    double size = fileObject.Size;
                    double kbUnit = 1024.0;
                    double mbUnit = Math.Pow(kbUnit, 2);
                    double gbUnit = Math.Pow(kbUnit, 3);
                    if ((size / gbUnit) >= 1)  // GB
                    {
                        fileObjectViewItem.Size = (Math.Round((size / gbUnit) * 10.0) / 10.0).ToString().Replace(',', '.');
                        fileObjectViewItem.SizeUnit = AppResources.GB;
                    }
                    else if ((size / mbUnit) >= 1)  // MB
                    {
                        fileObjectViewItem.Size = (Math.Round((size / mbUnit) * 10.0) / 10.0).ToString().Replace(',', '.');
                        fileObjectViewItem.SizeUnit = AppResources.MB;
                    }
                    else if ((size / kbUnit) >= 1)  // KB
                    {
                        fileObjectViewItem.Size = (Math.Round(size / kbUnit)).ToString().Replace(',', '.');
                        fileObjectViewItem.SizeUnit = AppResources.KB;
                    }
                    else if ((size / kbUnit) < 1)  // Bytes
                    {
                        fileObjectViewItem.Size = size.ToString().Replace(',', '.');
                        fileObjectViewItem.SizeUnit = AppResources.Bytes;
                    }
                    else if (fileObject.Type == FileObject.FileObjectType.GOOGLE_DOC) // Google Doc
                    {
                        fileObjectViewItem.Size = String.Empty;
                        fileObjectViewItem.SizeUnit = AppResources.GoogleDoc;
                    }
                }

                // If select is on, set check image.
                // Otherwise, set transparent image.
                if (select)
                {
                    if (fileObject.Type == FileObject.FileObjectType.FOLDER)
                        fileObjectViewItem.SelectFileImage = TRANSPARENT_IMAGE_URI;
                    else
                        fileObjectViewItem.SelectFileImage = CHECK_NOT_IMAGE_URI;
                    fileObjectViewItem.SelectFileImagePress = false;
                }
                else
                {
                    fileObjectViewItem.SelectFileImage = DOWNLOAD_IMAGE_URI;
                    fileObjectViewItem.SelectFileImagePress = true;
                }

                this.Items.Add(fileObjectViewItem);
            }
        }
コード例 #5
0
        private async void DeleteFileAsync(FileObjectViewItem fileObjectViewItem)
        {
            // Show Deleting message
            base.SetProgressIndicator(true);
            base.Dispatcher.BeginInvoke(() =>
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.ING_IMAGE_URI;
            });


            // Delete
            try
            {
                await App.BlobStorageManager.DeleteFileAsync(fileObjectViewItem.Id);
                base.Dispatcher.BeginInvoke(() =>
                {
                    this.PickFileObjectViewModel.Items.Remove(fileObjectViewItem);
                    if (this.PickFileObjectViewModel.Items.Count < 1)
                    {
                        uiPickFileListEditViewImageButton.Visibility = Visibility.Collapsed;
                        base.SetListUnableAndShowMessage(uiPickFileList, uiPickFileListMessage, AppResources.NoFileInSpotMessage);
                    }
                });
            }
            catch
            {
                base.Dispatcher.BeginInvoke(() =>
                {
                    fileObjectViewItem.SelectFileImage = FileObjectViewModel.FAIL_IMAGE_URI;
                });
            }

            // Hide Progress Indicator
            base.SetProgressIndicator(false);
        }
コード例 #6
0
        private async void PickFileAsync(IStorageManager storageManager, FileObjectViewItem fileObjectViewItem)
        {
            // Show Downloading message
            base.SetProgressIndicator(true);
            base.Dispatcher.BeginInvoke(() =>
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.ING_IMAGE_URI;
                fileObjectViewItem.SelectFileImagePress = false;
            });

            try
            {
                // Download
                await TaskHelper.WaitSignInTask(storageManager.GetStorageName());
                await this.CurrentSpot.DownloadFileObjectAsync(storageManager, this.CurrentSpot.GetFileObject(fileObjectViewItem.Id));
                base.Dispatcher.BeginInvoke(() =>
                {
                    this.PinFileObjectViewModel.IsDataLoaded = false;
                    string currentEditViewMode = uiPickFileListEditViewImageButton.ImageSource;
                    if (currentEditViewMode.Equals(EDIT_IMAGE_URI))  // View Mode
                    {
                        fileObjectViewItem.SelectFileImage = FileObjectViewModel.DOWNLOAD_IMAGE_URI;
                        fileObjectViewItem.SelectFileImagePress = true;
                    }
                    else if (currentEditViewMode.Equals(VIEW_IMAGE_URI))  // Edit Mode
                    {
                        fileObjectViewItem.SelectFileImage = FileObjectViewModel.CHECK_NOT_IMAGE_URI;                        
                    }
                });
            }
            catch
            {
                base.Dispatcher.BeginInvoke(() =>
                {
                    fileObjectViewItem.SelectFileImage = FileObjectViewModel.FAIL_IMAGE_URI;
                });
            }

            // Hide Progress Indicator
            base.SetProgressIndicator(false); 
        }
コード例 #7
0
        private async void LaunchFileAsync(FileObjectViewItem fileObjectViewItem)
        {
            // Show Downloading message
            base.SetProgressIndicator(true);
            base.Dispatcher.BeginInvoke(() =>
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.ING_IMAGE_URI;
                fileObjectViewItem.SelectFileImagePress = false;
            });

            try
            {
                // Download file and Launch files to other reader app.
                await this.CurrentSpot.PreviewFileObjectAsync(this.CurrentSpot.GetFileObject(fileObjectViewItem.Id));
                base.Dispatcher.BeginInvoke(() =>
                {
                    fileObjectViewItem.SelectFileImage = FileObjectViewModel.DOWNLOAD_IMAGE_URI;
                    fileObjectViewItem.SelectFileImagePress = true;
                });
            }
            catch
            {
                base.Dispatcher.BeginInvoke(() =>
                {
                    fileObjectViewItem.SelectFileImage = FileObjectViewModel.FAIL_IMAGE_URI;
                });
            }

            // Hide Progress Indicator
            base.SetProgressIndicator(false);
        }
コード例 #8
0
        private async void PinFileAsync(FileObjectViewItem fileObjectViewItem)
        {
            // Show Uploading message and file for good UX
            base.SetProgressIndicator(true);
            base.Dispatcher.BeginInvoke(() =>
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.ING_IMAGE_URI;
            });

            try
            {
                string blobId = await this.CurrentSpot.AddFileObjectAsync(this.GetCloudStorageFileObjectById(fileObjectViewItem.Id));
                base.Dispatcher.BeginInvoke(() =>
                {
                    this.PickFileObjectViewModel.IsDataLoaded = false;
                    fileObjectViewItem.SelectFileImage = FileObjectViewModel.CHECK_NOT_IMAGE_URI;
                });
            }
            catch
            {
                base.Dispatcher.BeginInvoke(() =>
                {
                    fileObjectViewItem.SelectFileImage = FileObjectViewModel.FAIL_IMAGE_URI;
                });
            }

            // Hide progress message
            base.SetProgressIndicator(false);
        }
コード例 #9
0
        private async void SetPinFileListAsync(IStorageManager iStorageManager, string message, FileObjectViewItem folder)
        {
            // Set Mutex true and Show Process Indicator
            // Clear selected file and set pin button false.
            base.SetListUnableAndShowMessage(uiPinFileList, uiPinFileMessage, message);
            base.SetProgressIndicator(true);
            this.PinSelectedFileList.Clear();
            base.Dispatcher.BeginInvoke(() =>
            {
                this.PinFileAppBarButton.IsEnabled = false;
            });


            try
            {
                // Wait Signin and Sync task
                await TaskHelper.WaitSignInTask(iStorageManager.GetStorageName());
                await TaskHelper.WaitTask(TaskHelper.STORAGE_EXPLORER_SYNC + Switcher.GetCurrentStorage().GetStorageName());

                // Get files from current folder in the cloud.
                // If it is not null, set items.
                // Otherwise, show message
                if (folder == null)
                    this.CurrentFileObjectList = StorageExplorer.GetFilesFromRootFolder();
                else
                    this.CurrentFileObjectList = StorageExplorer.GetTreeForFolder(this.GetCloudStorageFileObjectById(folder.Id));
                if (this.CurrentFileObjectList != null)
                {
                    // If didn't change cloud mode while loading, set it to list.
                    // Set file list visible and current path.
                    base.Dispatcher.BeginInvoke(() =>
                    {
                        this.PinFileObjectViewModel.IsDataLoaded = true;
                        uiPinFileList.Visibility = Visibility.Visible;
                        uiPinFileCurrentPath.Text = StorageExplorer.GetCurrentPath();
                        this.PinFileObjectViewModel.SetItems(this.CurrentFileObjectList, true);
                    });


                    // If there exists file, show it.
                    // Otherwise, show no file message.
                    if (this.CurrentFileObjectList.Count > 0)
                    {
                        base.Dispatcher.BeginInvoke(() =>
                        {
                            uiPinFileMessage.Visibility = Visibility.Collapsed;
                        });
                    }
                    else
                    {
                        base.Dispatcher.BeginInvoke(() =>
                        {
                            uiPinFileMessage.Text = AppResources.NoFileInFolderMessage;
                        });
                    }
                }
                else
                {
                    base.SetListUnableAndShowMessage(uiPinFileList, uiPinFileMessage, AppResources.BadLoadingFileMessage);
                }
            }
            catch
            {
                base.SetListUnableAndShowMessage(uiPinFileList, uiPinFileMessage, AppResources.BadLoadingFileMessage);
            }
            base.SetProgressIndicator(false);
        }