Exemple #1
0
        public FileInfo GetFileInfo(int ID)
        {
            var blob = this.Find <Zetbox.App.Base.Blob>(ID);

            string path = Path.Combine(DocumentCache, blob.StoragePath);

            if (path.Length >= 256)
            {
                var dir = Path.GetDirectoryName(path);
                if (dir.Length >= 256 - 41 - 4)
                {
                    throw new PathTooLongException("DocumentCache path is far too long. Should be less then 256 - 41 for guid and 4 for extension. Path includes DocumentStore\\year\\month\\day. FullPath: " + path);
                }
                var name = Path.GetFileNameWithoutExtension(path);
                var ext  = Path.GetExtension(path);
                name = name.Substring(0, 255 - dir.Length - ext.Length);
                path = Path.Combine(dir, name + ext);
            }
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            if (!File.Exists(path))
            {
                using (var stream = proxy.GetBlobStream(ID))
                    using (var file = new FileStream(path, FileMode.Create, FileAccess.Write))
                    {
                        file.SetLength(0);
                        stream.CopyTo(file);
                    }
                File.SetAttributes(path, FileAttributes.ReadOnly);
            }

            return(new FileInfo(path));
        }
Exemple #2
0
 public Stream GetBlobStream(int ID)
 {
     using (Logging.Facade.InfoTraceMethodCallFormat("GetBlobStream", "ID=[{0}]", ID))
     {
         try
         {
             return(_implementor.GetBlobStream(ID));
         }
         catch (Exception ex)
         {
             Logging.Facade.Error("GetBlobStream", ex);
             throw;
         }
     }
 }