Esempio n. 1
0
        public bool Delete(TempUploadedFile file)
        {
            dbContext.TempUploadedFiles.Remove(file);
            int result = dbContext.SaveChanges();

            return(result > 0);
        }
Esempio n. 2
0
        public ActionResult Create3(List <VMFileCreate> files)
        {
            string log = "Create3 ";

            log += files != null ? "fileCount = " + files.Count : String.Empty;
            this.serviceLog.LogMessage("FileController", log);

            if (files == null)
            {
                return(this.RedirectToErrorPage("Il faudrait peut etre ajouter de fichiers!"));
            }


            foreach (var file in files)
            {//TODO : Automapper
                TempUploadedFile modelFile = new TempUploadedFile()
                {
                    Description = file.File.Description,
                    Tags        = file.File.Tags,
                    Name        = file.File.DisplayName,
                    Id          = file.File.Id,
                    ProjectId   = file.File.ProjectId,
                    Status      = Domain.Models.ProcessStatus.ProcessingNotStarted
                };
                modelFile = this.serviceTempFile.Update(modelFile);

                this.serviceFile.Create(modelFile, CurrentUser);
            }

            return(RedirectToAction("Files", "Project", new { id = files[0].Project.Id }));
        }
Esempio n. 3
0
        public bool Create(TempUploadedFile file)
        {
            dbContext.TempUploadedFiles.Add(file);
            int result = dbContext.SaveChanges();

            return(result > 0);
        }
Esempio n. 4
0
        public bool Process(TempUploadedFile file)
        {
            Thumbnail thumb = null;

            // Generate thumbnail

            thumb = ProcessThumbnail(file);


            try
            {
                ProjectFile projectFile = ProcessProjectFile(file, thumb);
            }
            catch (Exception exc)
            {
                this.serviceLog.LogError("TempFileService::Process-projectFile", exc);
            }



            // delete temp
            this.DeleteById(file.Id);

            return(true);
        }
Esempio n. 5
0
        private string GenerateProjectFileInternalName(TempUploadedFile file)
        {
            string filenameWithoutExtension = file.Name;// System.IO.Path.GetFileNameWithoutExtension(file.Path);
            string extension       = System.IO.Path.GetExtension(file.Path);
            string encodedFilename = new HtmlString(filenameWithoutExtension).ToString();

            return(string.Format("{0}_{1}{2}", encodedFilename, DateTime.Now.Ticks, extension));
        }
Esempio n. 6
0
        public TempUploadedFile Update(TempUploadedFile modelFile)
        {
            TempUploadedFile data = GetById(modelFile.Id);

            if (data != null)
            {
                data.Description = modelFile.Description;
                data.Name        = modelFile.Name;
                data.Tags        = modelFile.Tags;
                data.Status      = modelFile.Status;
                this.fileRepo.SaveChanges(data);
            }
            return(data);
        }
Esempio n. 7
0
        public int Create(TempUploadedFile modelFile, UserProfileInfo CurrentUser)
        {
            ProjectFile f = new ProjectFile();

            f.AuthCredentialId = modelFile.AuthCredentialId;
            f.Description      = modelFile.Description;
            f.DisplayName      = modelFile.Name;
            f.InternalName     = modelFile.Name;
            f.ProjectId        = modelFile.ProjectId;
            f.Tags             = modelFile.Tags;
            f.ThumbnailId      = null;
            f.TempFileId       = modelFile.Id;
            f.PublicUrl        = "~/Content/Data/tempfile_sound.mp3";
            return(Create(f, CurrentUser));
        }
Esempio n. 8
0
        public void TempFileService_ProcessTest()
        {
            TempUploadedFile file = new TempUploadedFile();

            file.Description       = "description";
            file.Name              = "Test file Name";
            file.Path              = "Data/mabenz.mp3";
            file.ProjectId         = 1;
            file.Tags              = "tag1,tag2";
            file.AuthCredentialId  = 1;
            file.Creator           = serviceUser.GetCurrentUser();
            file.StorageCredential = repoAuthCredential.GetById(1);

            var result = serviceTempFile.Process(file);

            Assert.IsTrue(result);
        }
Esempio n. 9
0
        private Thumbnail ProcessThumbnail(TempUploadedFile file)
        {
            Thumbnail thumb = null;

            try
            {
                Stream ms = new MemoryStream();

                string thumbPublicUrl = string.Empty;
                if (this.serviceLocalStorage.DownloadFile(ref ms, file.Path, _container))
                {
                    var    picture            = serviceWaveform.GetWaveform(file.Path, ms);
                    byte[] pictureasByteArray = BitmapHelper.ImageToByte2(picture);

                    thumbPublicUrl = this.serviceLocalStorage.UploadFile(pictureasByteArray, file.Path, "projects");
                }

                ms.Close();

                string internalName = GenerateThumbnailName(file);
                string path         = GenerateThumbnailPath(file);


                thumb = new Thumbnail()
                {
                    AuthCredentialId = file.AuthCredentialId,
                    DisplayName      = file.Name,
                    InternalName     = internalName,
                    Path             = path,
                    PublicUrl        = thumbPublicUrl//dropboxsavedFile.PublicUrl
                };
            }
            catch (Exception exc)
            {
                this.serviceLog.LogError("TempFileService::Process-Thumbnail", exc);
                thumb = new Thumbnail()
                {
                    PublicUrl = "/content/images/thumbnail_error.png"
                };
            }

            this.repositoryThumbnail.Create(thumb);

            return(thumb);
        }
Esempio n. 10
0
        public JsonResult Upload(IEnumerable <HttpPostedFileBase> files, int id, int cloudStorage)
        {
            string log = "Upload file to " + id + " into " + cloudStorage;

            log += files != null ? "count = " + files.Count() : string.Empty;
            this.serviceLog.LogMessage("FileController", log);

            VMFileUpload result = new VMFileUpload();

            result.files = new List <UploadedFile>();
            foreach (var baseFile in files)
            {
                TempUploadedFile tmpFile = new TempUploadedFile();

                using (var binaryReader = new BinaryReader(baseFile.InputStream))
                {
                    tmpFile.Data = binaryReader.ReadBytes(baseFile.ContentLength);
                }
                tmpFile.Name             = baseFile.FileName;
                tmpFile.ProjectId        = id;
                tmpFile.Size             = tmpFile.Data.Length;
                tmpFile.AuthCredentialId = cloudStorage;

                tmpFile.Id = this.serviceTempFile.Create(tmpFile, CurrentUser);
                UploadedFile f = new UploadedFile()
                {
                    name = tmpFile.Name,
                    size = tmpFile.Size,
                    //url = Url.Action("GetTempFile", new { id = tmpFile.Id }),
                    //thumbnailUrl = "http//:www.google.com/picture1.jpg",
                    deleteUrl  = Url.Action("DeleteTempFile", new { id = tmpFile.Id }),
                    deleteType = "POST"
                };
                result.files.Add(f);
            }



            return(new JsonResult()
            {
                Data = result
            });
        }
    protected void uxUploadButton_Click(object sender, EventArgs e)
    {
        if (uxUploadRQFile.HasFile)
        {
            if (uxUploadRQFile.PostedFile.ContentLength
                > DataAccessContext.Configurations.GetIntValue("UploadSize") * SystemConst.UploadSizeConfigFactor)
            {
                uxMessageDiv.Visible   = true;
                uxUploadRQMessage.Text = "Upload size is exceeded.";
                return;
            }

            TempUploadedFile = new TempUploadedFile(
                new FileManager(),
                SystemConst.OptionFileTempPath,
                SystemConst.OptionFileUpload,
                uxUploadRQFile.FileName);

            uxUploadRQFile.PostedFile.SaveAs(TempUploadedFile.GetTempFileLocalPath());
            UploadedFile            = uxUploadRQFile.FileName;
            uxMessageDiv.Visible    = false;
            uxUploadedFilename.Text = " - " + UploadedFile;
        }

        Control parent  = this.Parent;
        Control control = null;

        while (parent.GetType() != typeof(Page))
        {
            control = parent.FindControl("uxAddItemButtonModalPopup");
            if (control != null)
            {
                break;
            }
            parent = parent.Parent;
        }
        if (control != null)
        {
            ModalPopupExtender popup = (ModalPopupExtender)control;
            popup.Show();
        }
    }
Esempio n. 12
0
 /// <summary>
 /// store the byte[] locally and create a record in the tempfile table
 /// </summary>
 /// <param name="file"></param>
 /// <param name="userProfile"></param>
 /// <returns></returns>
 public int Create(TempUploadedFile file, UserProfileInfo userProfile)
 {
     file.Creator     = userProfile;
     file.Status      = Models.ProcessStatus.UploadInProgress;
     file.FailedCount = 0;
     try
     {
         file.Path = Guid.NewGuid().ToString() + file.Name;
         this.serviceLocalStorage.UploadFile(file.Data, file.Path, _container);
     }
     catch (Exception exc)
     {
         this.serviceLog.LogError("TempFileService::Create", exc);
         return(-1);
     }
     if (this.fileRepo.Create(file))
     {
         return(file.Id);
     }
     return(-1);
 }
Esempio n. 13
0
 protected void uxUploadButton_Click(object sender, EventArgs e)
 {
     if (uxUploadFile.HasFile)
     {
         if (uxUploadFile.PostedFile.ContentLength
             > DataAccessContext.Configurations.GetIntValue("UploadSize") * SystemConst.UploadSizeConfigFactor)
         {
             uxMessageDiv.Visible = true;
             uxUploadMessage.Text = " " + GetLanguageText("OptionUploadMaxLimit");
             return;
         }
         TempUploadedFile = new TempUploadedFile(
             new FileManager(),
             SystemConst.OptionFileTempPath,
             SystemConst.OptionFileUpload,
             uxUploadFile.FileName);
         uxUploadFile.PostedFile.SaveAs(TempUploadedFile.GetTempFileLocalPath());
         UploadedFile            = uxUploadFile.FileName;
         uxMessageDiv.Visible    = false;
         uxUploadedFilename.Text = " - " + UploadedFile;
     }
 }
Esempio n. 14
0
 public void MoveToErrorQueue(TempUploadedFile nextFile)
 {
     nextFile.Status = Models.ProcessStatus.Failed;
     nextFile.FailedCount++;
     this.fileRepo.SaveChanges(nextFile);
 }
Esempio n. 15
0
 private string GenerateProjectFilePath(TempUploadedFile file)
 {
     return(String.Format("/Projects/{0}/Files/", file.ProjectId));
 }
Esempio n. 16
0
 private string GenerateThumbnailPath(TempUploadedFile file)
 {
     // return String.Format("/Projects/{0}/Thumbnails/", file.ProjectId);
     return(String.Format("{0}/Files/", file.ProjectId));
 }
Esempio n. 17
0
        private string GenerateThumbnailName(TempUploadedFile file)
        {
            string encodedFilename = new HtmlString(file.Name).ToString();

            return(string.Format("{0}_{1}.png", encodedFilename, DateTime.Now.Ticks));
        }
Esempio n. 18
0
        private ProjectFile ProcessProjectFile(TempUploadedFile file, Thumbnail thumb)
        {
            if (file == null)
            {
                this.serviceLog.LogError("TempFileService::ProcessProjectFile", "WTF : file is null!", null);
                return(null);
            }
            Stream   ms       = new MemoryStream();
            Metadata metadata = null;

            if (this.serviceLocalStorage.DownloadFile(ref ms, file.Path, _container))
            {
                metadata = serviceWaveform.GetMetadata(file.Path, ms);
            }
            string  internalName = this.GenerateProjectFileInternalName(file);
            string  path         = this.GenerateProjectFilePath(file);
            MogFile uploadedFile = null;

            if (file.StorageCredential == null)
            {
                this.serviceLog.LogError("TempFileService::ProcessProjectFile", "WTF : StorageCredential is null!", null);
                return(null);
            }
            switch (file.StorageCredential.CloudService)
            {
            case CloudStorageServices.Dropbox:
                uploadedFile = this.serviceDropbox.UploadFile((MemoryStream)ms, internalName, file.StorageCredential, path);
                if (uploadedFile == null)
                {
                    this.serviceLog.LogError("TempFileService::ProcessProjectFile", "WTF : dropbox uploadedFile is null!", null);
                    return(null);
                }
                uploadedFile.PublicUrl = this.serviceDropbox.GetMedialUrl(uploadedFile.Path, file.StorageCredential);
                break;

            case CloudStorageServices.Skydrive:
                uploadedFile = this.serviceSkydrive.UploadFile((MemoryStream)ms, internalName, file.StorageCredential, path);
                if (uploadedFile == null)
                {
                    this.serviceLog.LogError("TempFileService::ProcessProjectFile", "WTF : Skydrive uploadedFile is null!", null);
                    return(null);
                }
                uploadedFile.PublicUrl = this.serviceSkydrive.GetMedialUrl(uploadedFile.Path, file.StorageCredential);
                break;
            }


            ProjectFile projectFile = this.serviceMogFile.GetByTempFileId(file.Id);

            if (projectFile == null)
            {
                this.serviceLog.LogError("TempFileService::ProcessProjectFile", "WTF : projectFile is null!", null);
                return(null);
            }

            if (thumb != null)
            {
                projectFile.ThumbnailId = thumb.Id;
            }

            projectFile.Path       = uploadedFile.Path;
            projectFile.PublicUrl  = uploadedFile.PublicUrl;
            projectFile.TempFileId = null;

            projectFile.SetMetadata(metadata);
            this.serviceMogFile.SaveChanges(projectFile);



            return(projectFile);
        }
Esempio n. 19
0
 public int SaveChanges(TempUploadedFile data)
 {
     dbContext.Entry(data).State = System.Data.Entity.EntityState.Modified;
     return(dbContext.SaveChanges());
 }