예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 public Task <FreezeFile> removeAsync(FreezeFile file)
 {
     return(deleteAsync(file));
 }
예제 #4
0
 /* 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);
 }
예제 #5
0
        public Task <FreezeFile> deleteAsync(FreezeFile file)
        {
            var res = Task.Run(() => { File.Delete(file.fileID); return(file); });

            return(res);
        }
예제 #6
0
 public void delete(FreezeFile file)
 {
     var res = deleteAsync(file).Result;
 }
예제 #7
0
 public FreezeFile uploadFile(object threadData, Container container, FreezeFile file, Stream contents, string enchash)
 {
     return(uploadFileAsync(threadData, container, file, contents, enchash).Result);
 }
예제 #8
0
        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));
        }
예제 #9
0
 public Stream downloadFile(object data, FreezeFile file)
 {
     return(downloadFileAsync(data, file).Result);
 }