コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        private async void LaunchFileAsync(FileObjectViewItem fileObjectViewItem)
        {
            // Show Downloading message
            base.SetProgressRing(uiFileListProgressRing, true);
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.DOWNLOAD_IMAGE_URI;
                fileObjectViewItem.SelectFileImagePress = false;
            });

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

            // Hide Progress Indicator
            base.SetProgressRing(uiFileListProgressRing, false);
        }
コード例 #4
0
        private async void PinFileAsync(FileObjectViewItem fileObjectViewItem)
        {
            // Show Uploading message and file for good UX
            base.SetProgressRing(uiPinPivotProgressRing, true);
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.ING_IMAGE_URI;
            });

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

            // Hide progress message
            base.SetProgressRing(uiPinPivotProgressRing, false);
        }
コード例 #5
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.SetProgressRing(uiPinPivotProgressRing, true);
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                uiPinFileList.Visibility = Visibility.Collapsed;
                uiPinFileMessage.Text = message;
                uiPinFileMessage.Visibility = Visibility.Visible;
            });
            this.PinSelectedFileList.Clear();

            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.
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        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)
                    {
                        await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            uiPinFileMessage.Visibility = Visibility.Collapsed;
                        });
                    }
                    else
                    {
                        await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            uiPinFileMessage.Text = AppResources.NoFileInFolderMessage;
                        });
                    }
                }
                else
                {
                    await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        uiPinFileList.Visibility = Visibility.Collapsed;
                        uiPinFileMessage.Text = AppResources.BadLoadingFileMessage;
                        uiPinFileMessage.Visibility = Visibility.Visible;
                    });
                }
            }
            catch
            {
                uiPinFileList.Visibility = Visibility.Collapsed;
                uiPinFileMessage.Text = AppResources.BadLoadingFileMessage;
                uiPinFileMessage.Visibility = Visibility.Visible;
            }
            base.SetProgressRing(uiPinPivotProgressRing, false);
        }
コード例 #6
0
        private async void DeleteFileAsync(FileObjectViewItem fileObjectViewItem)
        {
            // Show Deleting message
            base.SetProgressRing(uiPickPivotFileListProgressRing, true);
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.ING_IMAGE_URI;
            });


            // Delete
            try
            {
                await App.BlobStorageManager.DeleteFileAsync(fileObjectViewItem.Id);
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    this.PickFileObjectViewModel.Items.Remove(fileObjectViewItem);
                    if (this.PickFileObjectViewModel.Items.Count < 1)
                    {
                        uiPickFileListEditViewButton.Visibility = Visibility.Collapsed;
                        uiPickFileList.Visibility = Visibility.Collapsed;
                        uiPickFileListMessage.Text = AppResources.NoFileInSpotMessage;
                        uiPickFileListMessage.Visibility = Visibility.Visible;
                    }
                });
            }
            catch
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.FAIL_IMAGE_URI;
            }

            // Hide Progress Indicator
            base.SetProgressRing(uiPickPivotFileListProgressRing, false);
        }
コード例 #7
0
        private async void PickFileAsync(IStorageManager storageManager, FileObjectViewItem fileObjectViewItem)
        {
            // Show Downloading message
            base.SetProgressRing(uiPickPivotFileListProgressRing, true);
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                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));
                await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
               { 
                    this.PinFileObjectViewModel.IsDataLoaded = false;

                    BitmapImage currentEditViewModeBitmapImage = (BitmapImage)uiPickFileListEditViewButtonImage.Source;
                    string currentEditViewMode = currentEditViewModeBitmapImage.UriSource.ToString();
                    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
            {
                fileObjectViewItem.SelectFileImage = FileObjectViewModel.FAIL_IMAGE_URI;
            }

            // Hide Progress Indicator
            base.SetProgressRing(uiPickPivotFileListProgressRing, false);
        }