Пример #1
0
 public void TestFilesRead()
 {
     using (IFilesUnitOfWork unitOfWork = new FilesUnitOfWork(new FileDbContext()))
     {
         unitOfWork.Files.GetAll().ToList().ForEach(file => Console.WriteLine(file.Name));
     }
 }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            int fileId;
            if (int.TryParse(context.Request.QueryString["id"], out fileId))
            {
                fileId = Convert.ToInt32(context.Request.QueryString["id"]);
                string filePath = null;

                using (IFilesUnitOfWork unitOfWork = new FilesUnitOfWork(new FileDbContext()))
                {
                    StoredFile firstOrDefault = unitOfWork.Files.GetById(fileId);
                    if (firstOrDefault != null)
                    {
                        filePath = firstOrDefault.PathOnServer;
                    }
                }
                context.Response.AddHeader(
                    "content-disposition", "attachment;filename=" + "\"" + Path.GetFileName(filePath) + "\"");

                using (FileStream stream = File.OpenRead(filePath))
                {
                    stream.CopyTo(context.Response.OutputStream);
                    context.Response.OutputStream.Flush();
                }
            }
        }
Пример #3
0
 public void TestAddFile()
 {
     using (IFilesUnitOfWork unitOfWork = new FilesUnitOfWork(new FileDbContext()))
     {
         unitOfWork.AttributeTypes.InsertOrUpdate(new AttributeType {Name = "test-test", Type = "Video"});
         unitOfWork.Commit();
     }
 }
Пример #4
0
        public void ProcessRequest(HttpContext context)
        {
            int imageId = int.Parse(context.Request.QueryString["id"]);
            byte[] imageBytes = null;
            using (IFilesUnitOfWork unitOfWork = new FilesUnitOfWork(new FileDbContext()))
            {
                FileImage firstOrDefault = unitOfWork.FileImages.GetById(imageId);
                if (firstOrDefault != null)
                {
                    imageBytes = firstOrDefault.ImageBytes;
                }
                if (imageBytes == null)
                {
                    imageBytes =
                        File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Samples/img/file.png");
                }
            }

            context.Response.AddHeader("content-type", "image/jpeg");
            context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length);
            context.Response.OutputStream.Flush();
        }