private FileCache _buildCache() { var uc = FileCache.Load("./foo.cache"); var c = new BUCommon.Container { accountID = 1, id = "blargacct", name = "blarg account", type = "blarg" }; var ff = new FreezeFile { fileID = "blarg" , localHash = new BUCommon.Hash { type = "SHA0", raw = new byte[] { 0, 22, 44, 11 } } , mimeType = "application/byte-stream" , modified = new DateTime(2016, 12, 01) , path = "blarg/blarg1.obj" , storedHash = BUCommon.Hash.Create("SHA0", new byte[] { 22, 44, 0, 89 }) , uploaded = new DateTime(2016, 12, 03) , container = c }; uc.add(c); uc.add(ff); return(uc); }
public async Task <FreezeFile> uploadFileAsync(object threadData, Container container, FreezeFile file, Stream contents, string enchash) { var path = string.Empty; if (string.IsNullOrWhiteSpace(file.fileID)) { var str1 = file.path; if (System.Environment.OSVersion.Platform != System.PlatformID.Unix) { str1 = file.path.Replace('/', '\\'); } path = Path.Combine(container.id, str1); } else { path = file.fileID; } { string fn = Path.GetFileName(path); /* c:\tmp\foo\bar\ baz.jpg (7) 15+7 22 - 7 = 15 */ string pp = path.Substring(0, path.Length - fn.Length); Directory.CreateDirectory(pp); } FileStream strm = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete); int len = await IOUtils.WriteStream(contents, strm); strm.Flush(); strm.Seek(0, SeekOrigin.Begin); var hasha = (System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("SHA256"); var hash = hasha.ComputeHash(strm); strm.Close(); strm.Dispose(); strm = null; var ff = new FreezeFile { fileID = path , container = container , path = file.path , uploaded = DateTime.UtcNow , modified = file.modified }; { var sb = new StringBuilder(); for (int i = 0; i < hash.Length; ++i) { sb.AppendFormat("{0:x2}", hash[i]); } ff.storedHash = Hash.Create("SHA256", sb.ToString()); } return(ff); }
public Task <FreezeFile> removeAsync(FreezeFile file) { return(deleteAsync(file)); }
/* so, this should place it in the recycle bin, but * that's windows only, and i don't know really what * else to do... */ public void remove(FreezeFile file) { delete(file); }
public Task <FreezeFile> deleteAsync(FreezeFile file) { var res = Task.Run(() => { File.Delete(file.fileID); return(file); }); return(res); }
public void delete(FreezeFile file) { var res = deleteAsync(file).Result; }
public FreezeFile uploadFile(object threadData, Container container, FreezeFile file, Stream contents, string enchash) { return(uploadFileAsync(threadData, container, file, contents, enchash).Result); }
public async Task <Stream> downloadFileAsync(object data, FreezeFile file) { var fstrm = new FileStream(file.fileID, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); return(await Task.Run(() => fstrm)); }
public Stream downloadFile(object data, FreezeFile file) { return(downloadFileAsync(data, file).Result); }