Пример #1
0
        public void MogFile_Metadata()
        {
            Mp3Metadata data = new Mp3Metadata();
            data.Duration = "4:07";

            ProjectFile file = new ProjectFile();
            file.SetMetadata(data);

            var retrievedMetadata  = file.GetMetadata() as Mp3Metadata;

            Assert.IsNotNull(retrievedMetadata);
            Assert.IsFalse(String.IsNullOrEmpty(retrievedMetadata.Duration));
        }
Пример #2
0
        private VMFile getViewModel(ProjectFile file)
        {
            VMFile model = new VMFile();
            //TODO automapper
            model.CreatedOn = file.CreatedOn;
            model.Creator = file.Creator;
            model.Deleted = file.Deleted;
            model.DeletedBy = file.DeletedBy;
            model.DeletedById = file.DeletedById;
            model.DeletedOn = file.DeletedOn;
            model.Description = file.Description;
            model.DisplayName = file.DisplayName;
            model.DownloadCount = file.DownloadCount;
            model.FileStatus = file.FileStatus;
            model.Id = file.Id;
            model.InternalName = file.InternalName;
            model.Likes = file.Likes;
            model.ModifiedOn = file.ModifiedOn;
            model.PlayCount = file.PlayCount;
            model.Project = file.Project;
            model.ProjectId = file.ProjectId;
            model.Tags = file.Tags;
            model.Metadata = file.Metadata;
            model.MetadataType = file.MetadataType;
            model.Permissions.Add(SecureActivity.TrackEdit, serviceSecurity.HasRight(SecureActivity.TrackEdit, CurrentUser, file));
            model.Permissions.Add(SecureActivity.ProjectEdit, serviceSecurity.HasRight(SecureActivity.ProjectEdit, CurrentUser, file.Project));
            model.Permissions.Add(SecureActivity.TrackDelete, serviceSecurity.HasRight(SecureActivity.TrackDelete, CurrentUser, file));
            if (file.ThumbnailId != null)
            {
                model.ThumbnailUrl = file.Thumbnail.PublicUrl;//this.serviceDropBox.GetMedialUrl(file.Thumbnail.Path, file.StorageCredential);

            }
            else
            {
                model.ThumbnailUrl = "~/Content/Images/thumbnail_temp.png";
            }

            model.PublicUrl = file.PublicUrl;// this.serviceDropBox.GetMedialUrl(file.Path, file.StorageCredential);

            model.isPendingProcessing = file.TempFileId != null;
            return model;
        }
Пример #3
0
        public void FileService_Create()
        {
            var project = serviceProject.GetNew(1,10,false,false).ToList();
            var storageCredential = this.repoCredential.GetById(1);
            var user = serviceUser.GetAll().FirstOrDefault();
            ProjectFile f = new ProjectFile();
            f.Description = "Test + " + DateTime.Now.ToString();
            f.Tags = FileType.Drums.ToString();
            f.Likes = 42;
            f.DisplayName = "TEST FILE " + DateTime.Now.Ticks;
            f.InternalName = "TEST FILE INTERNAL " + DateTime.Now.Ticks;
            f.ProjectId = project[0].Id;
            f.AuthCredentialId = storageCredential.Id;

            int i = this.serviceFile.Create(f, user);
            var activities = this.serviceProject.GetProjectActivity(f.ProjectId);
            var fileActivities = activities.Where(a => (a.Type & ActivityType.File) == ActivityType.File).ToList();

            Assert.IsTrue(i > 0);
            Assert.IsTrue(f.Id > 0);
            Assert.IsTrue(fileActivities.Count > 0);
        }
Пример #4
0
        private void notifyFileCreation(ProjectFile file)
        {
            List<Notification> notifications = new List<Notification>();
            string message = String.Format("a new file was uploaded by {0} in {1} ",
                file.Creator.DisplayName
                , file.Project.Name);

            // get all the followers of the uploader
            var followers = serviceFollow.GetFollowerUsers(file.Creator.Id);

            foreach (var follower in followers)
            {
                //TODO : message translation + Url management
                Notification n = new Notification()
                {
                    Message = message,
                    UserId = follower.Id,
                    PictureUrl = file.Creator.PictureUrl,
                    Url = "/File/Display/" + file.Id
                };
                notifications.Add(n);
            }

            //get all the followers of the project
            var interrestedPeoples = serviceFollow.GetFollowsByProject(file.ProjectId);
            foreach (var follower in interrestedPeoples)
            {
                // do not add the notification if it was already added
                if (notifications.Where(n => n.UserId == follower.FollowerId).FirstOrDefault() == null)
                {
                    //TODO : message translation + Url management
                    Notification n = new Notification()
                    {
                        Message = message,
                        UserId = follower.Id,
                        PictureUrl = file.Creator.PictureUrl,
                        Url = "/File/Display/" + file.Id
                    };
                    notifications.Add(n);
                }
            }

            //Notify the project owner
            if (notifications.Where(n => n.UserId == file.Project.Creator.Id).FirstOrDefault() != null)
            {
                //TODO : message translation + Url management
                Notification n = new Notification()
                {
                    Message = message,
                    UserId = file.Project.Creator.Id,
                    PictureUrl = file.Creator.PictureUrl,
                    Url = "/File/Display/" + file.Id
                };
            }

            repoNotification.Create(notifications);
        }
Пример #5
0
        public void LogFileCreation(ProjectFile file)
        {
            Activity act = new Activity();
            act.FileId = file.Id;
            act.ProjectId = file.ProjectId;
            act.Who = file.Creator;
            act.When = DateTime.Now;
            act.Type = ActivityType.Create | ActivityType.File;
            repoActivity.Create(act);

            notifyFileCreation(file);
        }
Пример #6
0
 public bool Create(ProjectFile file)
 {
     dbContext.Files.Add(file);
     int result = dbContext.SaveChanges();
     return (result > 0);
 }
Пример #7
0
        public int Save(ProjectFile file)
        {
            if (file.Id >0)
            {//todo : check if file is attached to dbContext
                return dbContext.SaveChanges();

            }
            else
            {
                throw new Exception("use Create() instead!");
            }
        }
Пример #8
0
 public String RefreshFile(ProjectFile file)
 {
     if (file == null)
     {
         return null;
     }
     string refreshedUrl = GetMedialUrl(file.Path, file.StorageCredential);
     return refreshedUrl;
 }
Пример #9
0
        private ProjectFile RefreshIfNeeded(ProjectFile file)
        {
            if (file.StorageCredential != null)
            {
                string refreshedUrl = String.Empty;
                if (!this.CheckIfFileExists(file.PublicUrl))
                {
                    try
                    {
                        switch (file.StorageCredential.CloudService)
                        {
                            case CloudStorageServices.Dropbox:

                                refreshedUrl = serviceDropBox.RefreshFile(file);

                                //todo : check later...
                                break;
                            case CloudStorageServices.GoogleDrive:
                                //todo : check later...
                                break;
                            case CloudStorageServices.Skydrive:
                                //file maybe deleted, or public link has expired
                                file.PublicUrl = serviceSkydrive.RefreshFile(file);
                                //TODO : save the file.

                                break;

                        }
                        if (!String.IsNullOrEmpty(refreshedUrl))
                        {// we need to update the record in the DB
                            file.PublicUrl = refreshedUrl;
                            this.repoFile.Save(file);
                        }
                    }
                    catch (Exception exc)
                    {//toDO : file does not exists anymore
                        // mark it for deletion

                    }

                }

            }
            return file;
        }
Пример #10
0
        public MogFile UploadFile(byte[] data, string filename, AuthCredential credential, string remotePath = null)
        {
            MetaData meta = this.Upload(data, filename, credential, remotePath);
            if (!String.IsNullOrEmpty(meta.Name))
            {//ok upload went fine

                ProjectFile file = new ProjectFile();
                file.InternalName = meta.Name;
                file.DisplayName = meta.Name;
                file.CreatedOn = DateTime.Now;
                file.Path = meta.Path;

                return file;
            }
            return null;
        }
Пример #11
0
 private bool incrementPlayCount(ProjectFile file)
 {
     file.PlayCount++;
     this.repoFile.Save(file);
     return true;
 }
Пример #12
0
 public int SaveChanges(ProjectFile file)
 {
     return this.repoFile.Save(file);
 }
Пример #13
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);
 }
Пример #14
0
        public int Create(ProjectFile file, UserProfileInfo userProfile)
        {
            file.CreatedOn = DateTime.Now;
            file.ModifiedOn = DateTime.Now;
            file.Creator = userProfile;
            file.Likes = 0;

            file.DownloadCount = 0;
            file.FileStatus = FileStatus.Draft;
            //file.FileType = FileType.Unknown;

            if (this.repoFile.Create(file))
            {
                file = this.repoFile.GetById(file.Id);
                serviceActivity.LogFileCreation(file);

                return file.Id;
            }
            return -1;
        }
Пример #15
0
 public String RefreshFile(ProjectFile file)
 {
     return file.PublicUrl;
 }