Ejemplo n.º 1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // The base page has already created the module, we only have to cast it here to the right type.
            this._downloadsModule = base.Module as DownloadsModule;

            this._fileId = Int32.Parse(Request.QueryString["FileId"]);
            if (this._fileId > 0)
            {
                this._file = this._downloadsModule.GetFileById(this._fileId);
                if (! this.IsPostBack)
                {
                    BindFile();
                }
                this.btnDelete.Visible = true;
                this.btnDelete.Attributes.Add("onclick", "return confirm('Are you sure?');");
            }
            else
            {
                // It is possible that a new file is already uploaded and in the database. The
                // tempFileId parameter in the viewstate should indicate this.
                if (ViewState["tempFileId"] != null)
                {
                    int tempFileId = (int)ViewState["tempFileId"];
                    this._file = this._downloadsModule.GetFileById(tempFileId);
                }
                else
                {
                    // New file.
                    this._file = new File();
                    // Copy roles that have view rights from parent section.
                    foreach (Permission permission in this._downloadsModule.Section.SectionPermissions)
                    {
                        this._file.AllowedRoles.Add(permission.Role);
                    }
                    this.calDatePublished.SelectedDate = DateTime.Now;
                }
                this.btnDelete.Visible = false;
            }
            if (! this.IsPostBack)
            {
                BindRoles();
            }
        }
Ejemplo n.º 2
0
 public virtual void SaveFileInfo(File file)
 {
     // Obtain current NHibernate session.
     ISession session = this._sessionManager.OpenSession();
     // Save meta-information
     session.SaveOrUpdate(file);
 }
Ejemplo n.º 3
0
 public virtual void SaveFile(File file, System.IO.Stream fileContents)
 {
     // Save physical file.
     string physicalFilePath = System.IO.Path.Combine(this.FileDir, file.FilePath);
     this._fileService.WriteFile(physicalFilePath, fileContents);
     // Save meta-information.
     SaveFileInfo(file);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Increase the number of downloads for the given file.
 /// </summary>
 /// <param name="file"></param>
 public virtual void IncreaseNrOfDownloads(File file)
 {
     ISession session = this._sessionManager.OpenSession();
     // First refresh the file to prevent stale updates because downloads can take a little while.
     session.Refresh(file);
     file.NrOfDownloads++;
     SaveFileInfo(file);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Get the a file as stream.
 /// </summary>
 /// <returns></returns>
 public System.IO.Stream GetFileAsStream(File file)
 {
     if (file.IsDownloadAllowed(HttpContext.Current.User.Identity))
     {
         string physicalFilePath = System.IO.Path.Combine(this.FileDir, file.FilePath);
         if (System.IO.File.Exists(physicalFilePath))
         {
             return this._fileService.ReadFile(physicalFilePath);
         }
         else
         {
             throw new System.IO.FileNotFoundException("File not found", physicalFilePath);
         }
     }
     else
     {
         throw new AccessForbiddenException("The current user has no permission to download the file.");
     }
 }
Ejemplo n.º 6
0
 public virtual void DeleteFile(File file)
 {
     // Delete physical file.
     string physicalFilePath = System.IO.Path.Combine(this.FileDir, file.FilePath);
     this._fileService.DeleteFile(physicalFilePath);
     // Delete meta information.
     ISession session = this._sessionManager.OpenSession();
     session.Delete(file);
 }