Ejemplo n.º 1
0
 private void GetParameters()
 {
     try
     {
         SubFolder = Request["subfolder"];
         SubFolder = SubFolder.Replace('\\', '\0');
         SubFolder = SubFolder.Replace('/', '\0');
     }
     catch (Exception)
     {
         SubFolder = "";
     }
     try
     {
         OrderBy = Request["orderby"].ToUpper();
         if (OrderBy != "ASC" && OrderBy != "DESC")
         {
             OrderBy = "ASC";
         }
     }
     catch (Exception)
     {
         OrderBy = "ASC";
     }
     try
     {
         color = ColorTranslator.FromHtml(Request["bgcolor"].ToString());
     }
     catch (Exception)
     {
         color = Color.White;
     }
     body.Attributes["bgcolor"] = ColorTranslator.ToHtml(color);
     try
     {
         FileExtension = Request["fileextension"].ToUpper();
         if (FileExtension == "")
         {
             FileExtension = "*";
         }
     }
     catch (Exception)
     {
         FileExtension = "*";
     }
     try
     {
         ShowDownloadCount = (Request["showdownloadcount"].ToUpper() == "TRUE");
         if (ShowDownloadCount)
         {
             dc = new DownloadCount();
             GridView1.Columns[1].Visible = true;
         }
     }
     catch (Exception)
     {
         ShowDownloadCount = false;
     }
 }
Ejemplo n.º 2
0
 private void GetParameters()
 {
     try
     {
         SubFolder = Request["subfolder"];
         SubFolder = SubFolder.Replace('\\', '\0');
         SubFolder = SubFolder.Replace('/', '\0');
     }
     catch (Exception)
     {
         SubFolder = "";
     }
     try
     {
         OrderBy =  Request["orderby"].ToUpper();
         if (OrderBy != "ASC" && OrderBy != "DESC")
         {
             OrderBy = "ASC";
         }
     }
     catch (Exception)
     {
         OrderBy = "ASC";
     }
     try
     {
         color = ColorTranslator.FromHtml(Request["bgcolor"].ToString());
     }
     catch (Exception)
     {
         color = Color.White;
     }
     body.Attributes["bgcolor"] = ColorTranslator.ToHtml(color);
     try
     {
         FileExtension = Request["fileextension"].ToUpper();
         if (FileExtension == "")
         {
             FileExtension = "*";
         }
     }
     catch (Exception)
     {
         FileExtension = "*";
     }
     try
     {
         ShowDownloadCount = (Request["showdownloadcount"].ToUpper() == "TRUE");
         if (ShowDownloadCount)
         {
             dc = new DownloadCount();
             GridView1.Columns[1].Visible = true;
         }
     }
     catch (Exception)
     {
         ShowDownloadCount = false;
     }
 }
Ejemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     dc = new DownloadCount();
     loadGrid();
     lblDownloadsCount.Text = dc.Count().ToString();
 }
Ejemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            DownloadCount dc       = new DownloadCount();
            const long    packSize = 20000;// 65536;
            string        fileName = context.Request.Url.Segments[context.Request.Url.Segments.Length - 1];
            FileStream    file;
            long          offset         = 0;
            long          rangeBegin     = 0;
            long          rangeEnd       = 0;
            long          dataTransfered = 0;
            long          fileSize       = 0;

            if (context.Session != null)
            {
                try
                {
                    context.Session.Add("ID", context.Session.SessionID);
                }
                catch (Exception)
                {
                    context.Session.Add("ID", dc.Count().ToString());
                }
            }

            if (File.Exists(Configuration.FilesPath + fileName))
            {
                context.Response.Clear();

                file = new FileStream(Configuration.FilesPath + fileName, FileMode.Open, FileAccess.Read);

                fileSize   = file.Length;
                rangeBegin = 0;
                rangeEnd   = file.Length;

                CalculateRange(context.Request, file.Length, ref rangeBegin, ref rangeEnd);

                //If isn't range
                if (rangeBegin == 0 && (rangeEnd == file.Length))
                {
                    context.Response.StatusCode = 200;
                }
                else
                {
                    context.Response.AppendHeader("Content-Range", "bytes " + rangeBegin + "-" + rangeEnd + "/" + file.Length.ToString());
                    context.Response.StatusCode = 206;
                }

                context.Response.AppendHeader("Content-Length", file.Length.ToString());
                context.Response.AppendHeader("Last-Modified", File.GetLastAccessTimeUtc(Configuration.FilesPath + fileName).ToString());
                context.Response.AppendHeader("Accept-Ranges", "bytes");
                context.Response.AppendHeader("ETag", "id_test");
                context.Response.ContentType = "application/octet-stream";

                if (!context.Request.HttpMethod.Equals("HEAD"))
                {
                    context.Response.Flush();

                    offset = rangeBegin;
                    int    readCount;
                    byte[] buffer = new Byte[packSize];
                    file.Seek(offset, SeekOrigin.Begin);
                    while (context.Response.IsClientConnected && offset < rangeEnd)
                    {
                        readCount = file.Read(buffer, 0, (int)Math.Min(rangeEnd - rangeBegin, buffer.Length));

                        context.Response.OutputStream.Write(buffer, 0, readCount);
                        context.Response.Flush();

                        offset         += readCount;
                        dataTransfered += readCount;
                    }
                }
                file.Dispose();
                file.Close();
            }
            else
            {
                Error.ErrorLog err = new Error.ErrorLog(new Exception("Filename = " + Configuration.FilesPath + fileName), context.Request);
                context.Response.StatusCode = 404;
            }

            dc.AddDownload(context, fileName, fileSize, dataTransfered, rangeBegin, rangeEnd);
            context.Response.End();
        }
Ejemplo n.º 5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     dc = new DownloadCount();
     loadGrid();
     lblDownloadsCount.Text = dc.Count().ToString();
 }
Ejemplo n.º 6
0
        public void ProcessRequest(HttpContext context)
        {
            DownloadCount dc = new DownloadCount();
            const long packSize = 20000;// 65536;
            string fileName = context.Request.Url.Segments[context.Request.Url.Segments.Length - 1];
            FileStream file;
            long offset = 0;
            long rangeBegin = 0;
            long rangeEnd = 0;
            long dataTransfered = 0;
            long fileSize = 0;

            if (context.Session != null)
            {
                try
                {
                    context.Session.Add("ID", context.Session.SessionID);
                }
                catch (Exception)
                {
                    context.Session.Add("ID", dc.Count().ToString());
                }
            }

            if (File.Exists(Configuration.FilesPath + fileName))
            {
                context.Response.Clear();

                file = new FileStream(Configuration.FilesPath + fileName, FileMode.Open, FileAccess.Read);

                fileSize = file.Length;
                rangeBegin = 0;
                rangeEnd = file.Length;

                CalculateRange(context.Request, file.Length, ref rangeBegin, ref rangeEnd);

                //If isn't range
                if (rangeBegin == 0 && (rangeEnd == file.Length))
                {
                    context.Response.StatusCode = 200;
                }
                else
                {
                    context.Response.AppendHeader("Content-Range", "bytes " + rangeBegin + "-" + rangeEnd + "/" + file.Length.ToString());
                    context.Response.StatusCode = 206;
                }

                context.Response.AppendHeader("Content-Length", file.Length.ToString());
                context.Response.AppendHeader("Last-Modified", File.GetLastAccessTimeUtc(Configuration.FilesPath + fileName).ToString());
                context.Response.AppendHeader("Accept-Ranges", "bytes");
                context.Response.AppendHeader("ETag", "id_test");
                context.Response.ContentType = "application/octet-stream";

                if (!context.Request.HttpMethod.Equals("HEAD"))
                {
                    context.Response.Flush();

                    offset = rangeBegin;
                    int readCount;
                    byte[] buffer = new Byte[packSize];
                    file.Seek(offset, SeekOrigin.Begin);
                    while (context.Response.IsClientConnected && offset < rangeEnd)
                    {
                        readCount = file.Read(buffer, 0, (int)Math.Min(rangeEnd - rangeBegin, buffer.Length));

                        context.Response.OutputStream.Write(buffer, 0, readCount);
                        context.Response.Flush();

                        offset += readCount;
                        dataTransfered += readCount;
                    }
                }
                file.Dispose();
                file.Close();
            }
            else
            {
                Error.ErrorLog err = new Error.ErrorLog(new Exception("Filename = " + Configuration.FilesPath + fileName), context.Request);
                context.Response.StatusCode = 404;
            }

            dc.AddDownload(context, fileName, fileSize, dataTransfered, rangeBegin, rangeEnd);
            context.Response.End();
        }