Пример #1
0
        /// <summary>
        /// A list of all directories on the drive
        /// </summary>
        public DirectoryStructureViewModel()
        {
            var children = DirectoryStructure.GetDrives();

            this.Items = new ObservableCollection <DirectoryItemViewModel>(
                children.Select(drive => new DirectoryItemViewModel(null, drive.Name, drive.Id, DirectoryItemType.Drive)));
            ActionType = new ObservableCollection <DirectoryItemActionType>();
            ActionType.Add(DirectoryItemActionType.None);
        }
        /// <summary>
        /// Expands the item and collects all children
        /// </summary>
        private void Expand()
        {
            if (this.Type == DirectoryItemType.File)
            {
                return;
            }

            var children = DirectoryStructure.GetDirectoryContents(this.Id);

            this.Children = new ObservableCollection <DirectoryItemViewModel>(
                children.Select(content => new DirectoryItemViewModel(this, content.Name, content.Id, content.Type)));
        }
Пример #3
0
        /// <summary>
        /// Uploads a new file to the drive
        /// </summary>
        public static void UploadFile(string filePath, string parentId)
        {
            var fileMetadata = new Google.Apis.Drive.v3.Data.File()
            {
                Name = DirectoryStructure.GetFileFolderName(filePath)
            };

            fileMetadata.Parents = new List <string>();
            fileMetadata.Parents.Add(parentId);

            FilesResource.CreateMediaUpload request;
            using (var stream = new FileStream(filePath, FileMode.Open))
            {
                request        = service.Files.Create(fileMetadata, stream, null);
                request.Fields = "id, parents";
                request.Upload();
            }
        }