protected ResourceInfo GetResourceInfo(WebDavTicket ticket) { FileStorageAbsolutePath absPath = ticket.AbsolutePath as FileStorageAbsolutePath; if (absPath == null) { throw new ArgumentException("ticket.AbsolutePath is null."); } ResourceInfo result = new ResourceInfo(); Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo = null; //Получаем оригинальный файл using (IDataReader reader = Mediachase.IBN.Database.ControlSystem.DBFile.GetById(Security.CurrentUser.TimeZoneId, absPath.UniqueId)) { if (reader.Read()) { fileInfo = new Mediachase.IBN.Business.ControlSystem.FileInfo(reader); } } if (fileInfo == null) { throw new HttpException(404, "Not found"); } FileHistoryInfo historyInfo = null; //Поддержка версий if (absPath.IsHistory) { foreach (FileHistoryInfo history in fileInfo.GetHistory()) { if (history.Id == absPath.HistoryId) { historyInfo = history; break; } } } DummyFileInfoWrapper dummyInfo = new DummyFileInfoWrapper(fileInfo, historyInfo); result.AbsolutePath = ticket.ToString(); result.Tag = dummyInfo; result.Name = dummyInfo.Name; result.ContentType = dummyInfo.ContentType; result.ContentLength = dummyInfo.Length; result.ParentName = "root"; result.Modified = dummyInfo.Modified; result.Created = dummyInfo.Created; return(result); }
public DummyFileInfoWrapper(Mediachase.IBN.Business.ControlSystem.FileInfo fileInfo, FileHistoryInfo historyInfo) { _contentType = fileInfo.FileBinaryContentType; _name = fileInfo.Name; _fileBinaryId = fileInfo.FileBinaryId; _legth = fileInfo.Length; _created = fileInfo.Created; _modified = fileInfo.Modified; _containerKey = fileInfo.ContainerKey; _parentDirectoryId = fileInfo.ParentDirectoryId; if (historyInfo != null) { _contentType = historyInfo.FileBinaryContentType; _name = historyInfo.Name; _fileBinaryId = historyInfo.FileBinaryId; _legth = historyInfo.Length; _modified = historyInfo.Modified; } }
protected void Page_Load(object sender, System.EventArgs e) { Response.ContentType = "application/octet-stream"; int FileId = int.Parse(Request.QueryString["Id"]); if (Request.QueryString["CName"] != null && Request.QueryString["CKey"] != null) { string ContainerName = Request.QueryString["CName"]; string ContainerKey = Request.QueryString["CKey"]; BaseIbnContainer bic = BaseIbnContainer.Create(ContainerName, ContainerKey); Mediachase.IBN.Business.ControlSystem.FileStorage fs = (Mediachase.IBN.Business.ControlSystem.FileStorage)bic.LoadControl("FileStorage"); Mediachase.IBN.Business.ControlSystem.FileInfo fi = fs.GetFile(FileId); if (fi == null) { throw new NotExistingIdException(); } FileHistoryInfo fhiLoad = null; if (Request["VId"] != null) { FileHistoryInfo[] _fhi = fi.GetHistory(); foreach (FileHistoryInfo fhi in _fhi) { if (fhi.Id == int.Parse(Request["VId"])) { fhiLoad = fhi; break; } } } if (fhiLoad == null) { Response.ContentType = fi.FileBinaryContentType; if (fi.FileBinaryContentType.ToLower().IndexOf("url") >= 0) { MemoryStream memStream = new MemoryStream(); fs.LoadFile(FileId, memStream); memStream.Position = 0; StreamReader reader = new StreamReader(memStream, Encoding.Unicode); string data = reader.ReadLine(); string sLink = ""; while (data != null) { if (data.IndexOf("URL=") >= 0) { sLink = data.Substring(data.IndexOf("URL=") + 4); break; } data = reader.ReadLine(); } if (sLink != "") { if (!sLink.StartsWith("http://")) { sLink = "http://" + sLink; } Response.Redirect(sLink); return; } } if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType)) { Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } else { Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } fs.LoadFile(FileId, Response.OutputStream); } else { Response.ContentType = fhiLoad.FileBinaryContentType; if (Mediachase.IBN.Business.Common.OpenInNewWindow(fhiLoad.FileBinaryContentType)) { Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name))); } else { Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name))); } fs.LoadFile(fhiLoad, Response.OutputStream); } } else { Mediachase.IBN.Business.ControlSystem.FileInfo fi = Mediachase.IBN.Business.ControlSystem.FileStorage.GetFile(Mediachase.IBN.Business.Security.CurrentUser.UserID, "Read", FileId); if (fi == null) { throw new NotExistingIdException(); } Response.ContentType = fi.FileBinaryContentType; if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType)) { Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } else { Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } Mediachase.IBN.Business.ControlSystem.FileStorage.LightLoadFile(fi, Response.OutputStream); } Response.End(); }
protected void Page_Load(object sender, System.EventArgs e) { // Check Security if (Security.CurrentUser == null) { int iObjectTypeId = -1; int iObjectId = -1; using (IDataReader reader = Mediachase.IBN.Business.User.GetGateByGuid(ExternalID)) { if (reader.Read()) { iObjectTypeId = (int)reader["ObjectTypeId"]; iObjectId = (int)reader["ObjectId"]; } } if (iObjectTypeId != (int)ObjectTypes.Issue) { throw new AccessDeniedException(); } } // Download Response.ContentType = "application/octet-stream"; int FileId = int.Parse(Request.QueryString["Id"]); string ContainerName = Request.QueryString["CName"]; string ContainerKey = Request.QueryString["CKey"]; if (!String.IsNullOrEmpty(ContainerName) && !String.IsNullOrEmpty(ContainerKey)) { BaseIbnContainer bic = BaseIbnContainer.Create(ContainerName, ContainerKey); Mediachase.IBN.Business.ControlSystem.FileStorage fs = (Mediachase.IBN.Business.ControlSystem.FileStorage)bic.LoadControl("FileStorage"); FileInfo fi = fs.GetFile(FileId); if (fi == null) { throw new NotExistingIdException(); } FileHistoryInfo fhiLoad = null; if (Request["VId"] != null) { FileHistoryInfo[] _fhi = fi.GetHistory(); foreach (FileHistoryInfo fhi in _fhi) { if (fhi.Id == int.Parse(Request["VId"])) { fhiLoad = fhi; break; } } } if (fhiLoad == null) { Response.ContentType = fi.FileBinaryContentType; if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType)) { Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } else { Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } fs.LoadFile(FileId, Response.OutputStream); } else { Response.ContentType = fhiLoad.FileBinaryContentType; if (Mediachase.IBN.Business.Common.OpenInNewWindow(fhiLoad.FileBinaryContentType)) { Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name))); } else { Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fhiLoad.Name))); } fs.LoadFile(fhiLoad, Response.OutputStream); } } else { Mediachase.IBN.Business.ControlSystem.FileInfo fi = Mediachase.IBN.Business.ControlSystem.FileStorage.GetFile(Mediachase.IBN.Business.Security.CurrentUser.UserID, "Read", FileId); if (fi == null) { throw new NotExistingIdException(); } Response.ContentType = fi.FileBinaryContentType; if (Mediachase.IBN.Business.Common.OpenInNewWindow(fi.FileBinaryContentType)) { Response.AddHeader("content-disposition", String.Format("inline; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } else { Response.AddHeader("content-disposition", String.Format("attachment; filename=\"{0}\"", GetNameForCurrentBrowser(fi.Name))); } Mediachase.IBN.Business.ControlSystem.FileStorage.LightLoadFile(fi, Response.OutputStream); } Response.End(); }