Exemplo n.º 1
0
        public async Task AddOverwrite(FSItem item)
        {
            try
            {
                Directory.CreateDirectory(cachePath);

                // To copy a source file to file in cache folder
                var sourceFile = Path.Combine(cachePath, item.Id);
                var sourceFileInfoPath = sourceFile + ".info";
                var tempFile = sourceFile + ".temp";
                File.Copy(sourceFile, tempFile, true);
                BoschHelper.Encrypt(sourceFile, tempFile);
                var tempFileInfo = new FileInfo(tempFile);

                File.Delete(sourceFileInfoPath);
                var info = new UploadInfo(item)
                {
                    Length = tempFileInfo.Length,
                    Path = tempFile,
                    SourcePath = tempFile,
                    Overwrite = true
                };

                await WriteInfo(sourceFileInfoPath, info);
                leftUploads.Add(info);
                allUploads.TryAdd(info.Id, info);
                OnUploadAdded?.Invoke(info);
            }
            catch(Exception ex)
            {

            }
        }
Exemplo n.º 2
0
        public async Task AddUpload(FSItem parent, string file)
        {
            Directory.CreateDirectory(cachePath);
            var fileinfo = new FileInfo(file);
            var infoId = Guid.NewGuid().ToString();

            // To copy a source file to file in cache folder
            var tempFile = Path.Combine(cachePath, infoId) + ".temp";
            var tempFileInfo = new FileInfo(tempFile);
            File.Copy(file, tempFile, true);
            BoschHelper.Encrypt(file, tempFile);

            var info = new UploadInfo
            {
                Id = infoId,
                Length = tempFileInfo.Length,
                Path = Path.Combine(parent.Path, Path.GetFileName(file)),
                ParentId = parent.Id,
                SourcePath = tempFile
            };

            var path = Path.Combine(cachePath, info.Id);
            await WriteInfo(path + ".info", info);
            leftUploads.Add(info);
            allUploads.TryAdd(info.Id, info);
            OnUploadAdded?.Invoke(info);
        }