public void SetFileds(FileMetadata_Info info)
        {
            id           = info.id;
            name         = info.name;
            itemtype     = (info.kind == "FOLDER") ? RemoteItemType.Folder : RemoteItemType.File;
            size         = info.contentProperties?.size;
            modifiedDate = info.modifiedDate;
            createdDate  = info.createdDate;
            if (info.clientProperties != null)
            {
                modifiedDate = info.clientProperties.dateUpdated;
                createdDate  = info.clientProperties.dateCreated;
            }
            hash = info.contentProperties?.md5;
            if (hash != null)
            {
                hash = "MD5:" + hash;
            }
            parentIDs = info.parents;

            isRoot = info.isRoot ?? isRoot;
            if (isRoot)
            {
                SetParent(this);
            }

            Age = DateTime.Now;
        }
Example #2
0
 public GoogleDriveSystemItem(IRemoteServer server, FileMetadata_Info info, params IRemoteItem[] parent) : base(server, parent)
 {
     SetFileds(info);
     if (parent?.Length > 0)
     {
         isRoot = false;
     }
 }
Example #3
0
        public async Task <FileMetadata_Info> FilesUpdate(string fileId, FileMetadata_Info newinfo, CancellationToken ct = default(CancellationToken))
        {
            var fields = "mimeType,name,trashed";

            Log("FilesUpdate");
            await EnsureToken(ct).ConfigureAwait(false);

            try
            {
                using (var handler = new HttpClientHandler())
                {
                    handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                    using (var client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Auth.access_token);
                        return(await DoWithRetry(async() =>
                        {
                            var req = new HttpRequestMessage(new HttpMethod("PATCH"),
                                                             ConfigAPI.drive_uri + "/files/" + fileId + "?fields=" + fields);

                            DataContractJsonSerializer jsonSer = new DataContractJsonSerializer(typeof(FileMetadata_Info));

                            MemoryStream ms = new MemoryStream();
                            jsonSer.WriteObject(ms, newinfo);
                            ms.Position = 0;

                            StreamReader sr = new StreamReader(ms);
                            var content = new StringContent(sr.ReadToEnd(), System.Text.Encoding.UTF8, "application/json");

                            req.Content = content;
                            var response = await client.SendAsync(req, ct).ConfigureAwait(false);

                            if (!response.IsSuccessStatusCode)
                            {
                                Log("FilesUpdate(error)", await response.Content.ReadAsStringAsync().ConfigureAwait(false));
                            }
                            response.EnsureSuccessStatusCode();
                            string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                            var data = ParseResponse <FileMetadata_Info>(responseBody);
                            return await FilesGet(fileId, ct).ConfigureAwait(false);
                        }, ct, "FilesUpdate").ConfigureAwait(false));
                    }
                }
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception)
            {
                return(null);
            }
        }
    public AmazonDriveBaseStream(AmazonDrive Drive, FileMetadata_Info downitem, bool autodecrypt = true, JobControler.Job parentJob = null) : base()
    {
        this.Drive       = Drive;
        targetItem       = downitem;
        FileSize         = targetItem.OrignalLength ?? 0;
        this.autodecrypt = autodecrypt;
        if (parentJob == null)
        {
            downloadJob = JobControler.CreateNewJob(
                type: JobControler.JobClass.Download,
                info: new JobControler.Job.SubInfo
                {
                    type = JobControler.Job.SubInfo.SubType.DownloadFile,
                    size = downitem.contentProperties?.size ?? 0,
                });
            downloadJob.DisplayName = downitem.name;
            downloadJob.ProgressStr = "wait for download";
            downloadJob.Progress    = -1;
            ct = downloadJob.ct;
        }
        else
        {
            ct = parentJob.ct;
        }

        if (FileSize < 0)
        {
            return;
        }

        if (downitem.contentProperties?.size > ConfigAPI.FilenameChangeTrickSize && !Regex.IsMatch(downitem.name, "^[\x20-\x7e]*$"))
        {
            Interlocked.Increment(ref Config.AmazonDriveTempCount);
            OrgFilename = targetItem.name;
            Config.Log.LogOut("AmazonDriveBaseStream : <BIG FILE> temporary filename change");
            Config.Log.LogOut("AmazonDriveBaseStream : orgnal name : " + OrgFilename);
            Drive.renameItem(targetItem.id, ConfigAPI.temporaryFilename + targetItem.id).Wait();
        }

        InitStream();
        if (parentJob == null)
        {
            JobControler.Run(downloadJob, (j) =>
                {
                    downloadJob.ProgressStr = "download...";
                    downloadJob.Wait(ct: ct);
                    downloadJob.Progress    = 1;
                    downloadJob.ProgressStr = "done.";
                });
        }
    }
Example #5
0
        public void SetFileds(FileMetadata_Info info)
        {
            id           = info.id;
            name         = info.name;
            itemtype     = (info.IsFolder) ? RemoteItemType.Folder : RemoteItemType.File;
            size         = info.size;
            modifiedDate = info.ModifiedDate;
            createdDate  = info.CreatedDate;
            accessDate   = info.AccessDate;
            hash         = info.md5Checksum;
            if (hash != null)
            {
                hash = "MD5:" + hash;
            }
            parentIDs = info.parents;

            isRoot = (parentIDs == null || parentIDs.Length == 0);
            if (isRoot)
            {
                SetParent(this);
            }

            Age = DateTime.Now;
        }
 public AmazonDriveSystemItem(IRemoteServer server, FileMetadata_Info info, params IRemoteItem[] parent) : base(server, parent)
 {
     SetFileds(info);
 }