Ejemplo n.º 1
0
        //get all files from Google Drive.
        public static List <CloudStorageFile> GetDriveFiles()
        {
            DriveService service = GetService();

            // define parameters of request.
            FilesResource.ListRequest FileListRequest = service.Files.List();

            //listRequest.PageSize = 10;
            //listRequest.PageToken = 10;
            FileListRequest.Fields = "nextPageToken, files(id, name, size, version, createdTime)";

            //get file list.
            IList <Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;
            List <CloudStorageFile> FileList             = new List <CloudStorageFile>();

            if (files != null && files.Count > 0)
            {
                foreach (var file in files)
                {
                    CloudStorageFile File = new CloudStorageFile
                    {
                        Id          = file.Id,
                        Name        = file.Name,
                        Size        = file.Size,
                        Version     = file.Version,
                        CreatedTime = file.CreatedTime
                    };
                    FileList.Add(File);
                }
            }
            return(FileList);
        }
Ejemplo n.º 2
0
        //Delete file from the Google drive
        public static void DeleteFile(CloudStorageFile files)
        {
            DriveService service = GetService();

            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }

                if (files == null)
                {
                    throw new ArgumentNullException(files.Id);
                }

                // Make the request.
                service.Files.Delete(files.Id).Execute();
            }
            catch (Exception ex)
            {
                throw new Exception("Request Files.Delete failed.", ex);
            }
        }
        public static List <CloudStorageFile> GetFtpServerFiles()
        {
            // Get FtpClient
            FtpClient client = GetFtpClient();

            // Ftp server File list
            List <CloudStorageFile> fileList = new List <CloudStorageFile>();

            try
            {
                // Connect to Ftp Server
                client.Connect();

                // Check if the folder has been exsiting
                bool isFolderExists = client.DirectoryExists("/" + Globals.CLOUD_EVATEL_FOLDER + "/");


                // When folder is existing
                if (isFolderExists)
                {
                    //var result = client.GetListing(Globals.CLOUD_EVATEL_FOLDER);
                    // Set working directory
                    client.SetWorkingDirectory("/" + Globals.CLOUD_EVATEL_FOLDER + "/");
                    var result = client.GetListing();

                    //Console.WriteLine("");
                    foreach (var file in result)
                    {
                        CloudStorageFile cloudFile = new CloudStorageFile
                        {
                            //Id = file.Id,
                            Name = file.Name,
                            Size = file.Size,
                            //Version = file.Version,
                            CreatedTime = file.Modified
                                          //Link = file.
                        };
                        fileList.Add(cloudFile);
                    }
                }
            }
            catch (Exception ex)
            {
                // ERROR HANDLE WILL BE DONE
                //ViewBag.ErrorMessage = Globals.FTP_CONNECTION_ERROR + "\n" + ex.Message;
                //return View("FtpServerForm");
            }

            // Sort by file created time
            return(fileList.OrderByDescending(f => f.CreatedTime).ToList());
        }
Ejemplo n.º 4
0
        // Get google drive files from folder
        public static List <CloudStorageFile> GetDriveFilesFromFolder()
        {
            DriveService service = GetService();

            // Get Folder ID for Evatel sound records
            string folderId = GetGoogleDriveFolderId(Globals.CLOUD_EVATEL_FOLDER, service);
            List <CloudStorageFile> fileList = new List <CloudStorageFile>();
            string pageToken = null;

            do
            {
                var request = service.Files.List();
                request.Q         = "'" + folderId + "' in parents";
                request.Spaces    = "drive";
                request.Fields    = "nextPageToken, files(id, name, size, version, createdTime, webContentLink)";
                request.PageToken = pageToken;
                var result = request.Execute();
                foreach (var file in result.Files)
                {
                    CloudStorageFile googleFile = new CloudStorageFile
                    {
                        Id          = file.Id,
                        Name        = file.Name,
                        Size        = file.Size,
                        Version     = file.Version,
                        CreatedTime = file.CreatedTime,
                        Link        = file.WebContentLink
                    };
                    fileList.Add(googleFile);
                }

                pageToken = result.NextPageToken;
            } while (pageToken != null);

            return(fileList);
        }