Пример #1
0
 public static string MediaUrl(this UrlHelper url, Content item)
 {
     return item.HasMediaFullVersion ?
         String.Format("{0}{1}",
         !item.IsMediaOnRemoteServer ? url.SiteRoot() : "",
         item.ContentMedia.FullVersion().MediaUrl()
         )
         : "";
 }
Пример #2
0
        // **************************************
        // AppendToTitleData
        // **************************************
        public static string AppendToTitleData(this User user, Content content)
        {
            string append = null;

            if (user != null){
                if (user.HasAccessToContentWithRole(content, Roles.Plugger)) {
                    append = user.AppendSignatureToTitle ? user.Signature : null;
                } else if (user.ParentUser != null && user.ParentUser.AppendSignatureToTitle) {
                    append = user.ParentSignature();
                }
            }

            return append;
        }
Пример #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Contents EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToContents(Content content)
 {
     base.AddObject("Contents", content);
 }
Пример #4
0
 /// <summary>
 /// Create a new Content object.
 /// </summary>
 /// <param name="contentId">Initial value of the ContentId property.</param>
 /// <param name="catalogId">Initial value of the CatalogId property.</param>
 /// <param name="createdByUserId">Initial value of the CreatedByUserId property.</param>
 /// <param name="createdOn">Initial value of the CreatedOn property.</param>
 /// <param name="lastUpdatedByUserId">Initial value of the LastUpdatedByUserId property.</param>
 /// <param name="lastUpdatedOn">Initial value of the LastUpdatedOn property.</param>
 /// <param name="isControlledAllIn">Initial value of the IsControlledAllIn property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="artist">Initial value of the Artist property.</param>
 public static Content CreateContent(global::System.Int32 contentId, global::System.Int32 catalogId, global::System.Int32 createdByUserId, global::System.DateTime createdOn, global::System.Int32 lastUpdatedByUserId, global::System.DateTime lastUpdatedOn, global::System.Boolean isControlledAllIn, global::System.String title, global::System.String artist)
 {
     Content content = new Content();
     content.ContentId = contentId;
     content.CatalogId = catalogId;
     content.CreatedByUserId = createdByUserId;
     content.CreatedOn = createdOn;
     content.LastUpdatedByUserId = lastUpdatedByUserId;
     content.LastUpdatedOn = lastUpdatedOn;
     content.IsControlledAllIn = isControlledAllIn;
     content.Title = title;
     content.Artist = artist;
     return content;
 }
Пример #5
0
 private static void UpdateContentId3Tag(Content content, FileInfo file)
 {
     ID3Writer.NormalizeTag(file.FullName, content);
 }
Пример #6
0
        // **************************************
        // RepushMedia
        // **************************************
        private static void RepushMedia(Content content, ContentMedia media, string filePath, FileInfo file)
        {
            AmazonCloudService.GetContentMedia(filePath, media);
            var tempFile = new FileInfo(filePath);

            Log.Debug(String.Format("Remote file for {0} downloaded", content.ContentId));

            UpdateContentId3Tag(content, tempFile);
            UpdateMediaId3info(media, tempFile);

            AmazonCloudService.PutContentMedia(tempFile.FullName, media);

            Log.Debug(String.Format("Re-uploaded remote file  {0}", file.FullName));

            //File.Delete(tempFile.FullName);
        }
Пример #7
0
        //: BaseService, IContentAdminService {
        // **************************************
        //  Update
        // **************************************
        public static void Update(Content contentModel, 
			IList<int> tagsModel,
			IDictionary<TagType, string> newTagsModel,
			IList<ContentRepresentationUpdateModel> representationModel)
        {
            using (var ctx = new SongSearchContext()) {
                    //UpdateModelWith Content
                    var content = ctx.Contents
                            .Include("Tags")
                            .Include("Catalog")
                            .Include("ContentRepresentations")
                            .Include("ContentRepresentations.Territories")
                        .Where(c => c.ContentId == contentModel.ContentId).SingleOrDefault();// && user.UserCatalogRoles.Any(x => x.CatalogId == c.CatalogId)).SingleOrDefault();

                    if (content == null) {
                        throw new ArgumentOutOfRangeException("Content does not exist");
                    }

                    content.UpdateModelWith(contentModel);

                    //UpdateModelWith Tags
                    tagsModel = tagsModel.Where(t => t > 0).ToList();
                    // create new tags
                    var newTags = ctx.CreateTags(newTagsModel);
                    tagsModel = tagsModel.Union(newTags).ToList();

                    // add to tagsModel
                    content = ctx.UpdateTags(content, tagsModel);

                    //UpdateModelWith Representation
                    content = ctx.UpdateRepresentation(content, representationModel);

                    content.LastUpdatedByUserId = Account.User().UserId;
                    content.LastUpdatedOn = DateTime.Now;

                    ctx.SaveChanges();

                    CacheService.InitializeApp(true);
                    //CacheService.CacheUpdate(CacheService.CacheKeys.Content);
                    //CacheService.CacheUpdate(CacheService.CacheKeys.Rights);
                    //CacheService.CacheUpdate(CacheService.CacheKeys.TopTags);
                    //CacheService.CacheUpdate(CacheService.CacheKeys.Tags);
                    //CacheService.CacheUpdate(CacheService.CacheKeys.Territories);
                }
        }
Пример #8
0
        // **************************************
        // UpdateTags
        // **************************************
        private static Content UpdateTags(this SongSearchContext ctx, Content content, IList<int> tagsModel)
        {
            if (tagsModel == null) { return content; }

            var contentTags = content.Tags.ToList();

            var contentTagsToRemove = contentTags.Where(t => !tagsModel.Contains(t.TagId));
            contentTagsToRemove.ForEach(x => content.Tags.Remove(x));

            var contentTagsToAdd = tagsModel.Except(contentTags.Select(t => t.TagId).Intersect(tagsModel));

            foreach (var contentTag in contentTagsToAdd) {
                var tag = ctx.Tags.SingleOrDefault(t => t.TagId == contentTag);
                if (tag != null) {
                    content.Tags.Add(tag);
                }
            }

            return content;
        }
Пример #9
0
        public static byte[] WriteMediaSignature(byte[] mediaFile, Content content, User user)
        {
            var tempPath = String.Concat(SystemConfig.ZipPath, "\\", Guid.NewGuid(), ".mp3");

                File.WriteAllBytes(tempPath, mediaFile);
                // id3

                ID3Writer.UpdateUserTag(tempPath, content, user);

                var assetFile = new FileInfo(tempPath);

                if (assetFile.Exists) {
                    var assetBytes = File.ReadAllBytes(tempPath);
                    File.Delete(tempPath);
                    return assetBytes;
                } else {
                    var ex = new ArgumentOutOfRangeException("Content media file is missing");
                    Log.Error(ex);
                    throw ex;
                }
        }
Пример #10
0
        public virtual ActionResult Save(Content content, 
			IList<int> tags,
			IDictionary<TagType, string> newTags,
			IList<ContentRepresentationUpdateModel> representation,
			bool returnData = true)
        {
            try {
                //if (ModelState.IsValid) {
                    //do some saving
                if (Account.User().HasAccessToContentWithRole(content, Roles.Admin)) {
                    ContentAdminService.Update(content, tags, newTags, representation);
                    UserEventLogService.LogContentEvent(ContentActions.UpdateContent, content.ContentId);

                }
                //}
                if (returnData) {
                    var vm = GetEditModel(content.ContentId);

                    //if (Request.IsAjaxRequest()) {
                        vm.ViewMode = ViewModes.Embedded;
                        vm.EditMode = EditModes.Saving;
                        return View("ctrlContentDetail", vm);

                    //} else {
                    //    vm.ViewMode = ViewModes.Normal;
                    //    vm.EditMode = EditModes.Viewing;
                    //    return View("Detail", vm);
                    //}
                } else {
                    return Content(content.ContentId.ToString());
                }
            }
            catch (Exception ex) {
                Log.Error(ex);
                this.FeedbackError(ex.Message);
                return RedirectToAction(MVC.Error.Problem());
            }
        }
Пример #11
0
 // **************************************
 // UpdateModel:
 //    Content
 // **************************************
 public static void UpdateModelWith(this Content currentContent, Content content)
 {
     //Monkey code
     currentContent.IsControlledAllIn = content.IsControlledAllIn;
     currentContent.HasMediaPreviewVersion = content.HasMediaPreviewVersion;
     currentContent.HasMediaFullVersion = content.HasMediaFullVersion;
     currentContent.Title = (content.Title ?? currentContent.Title);//.ToUpper();
     currentContent.Artist = (content.Artist ?? currentContent.Artist);//.ToUpper();
     currentContent.Writers = content.Writers;
     currentContent.Pop = content.Pop;
     currentContent.Country = content.Country;
     currentContent.ReleaseYear = content.ReleaseYear;
     currentContent.RecordLabel = content.RecordLabel;
     currentContent.Lyrics = content.Lyrics;
     currentContent.LyricsIndex = content.Lyrics.MakeIndexValue();
     currentContent.Notes = content.Notes;
     currentContent.Keywords = content.Keywords;
     currentContent.SimilarSongs = content.SimilarSongs;
     currentContent.LicensingNotes = content.LicensingNotes;
     currentContent.SoundsLike = content.SoundsLike;
     currentContent.Instruments = content.Instruments;
 }
Пример #12
0
 // **************************************
 // FileSignature
 // **************************************
 public static string FileSignature(this User user, Content content)
 {
     return user != null ? (
         user.HasAccessToContentWithRole(content, Roles.Plugger) ?
             user.Signature
             : user.ParentSignature())
         : "";
 }
Пример #13
0
 public static bool HasAccessToContentWithRole(this User user, Content content, Roles role)
 {
     if (user.IsSuperAdmin()) {
         return true;
     } else {
         return user.UserCatalogRoles.Any(c => c.CatalogId == content.CatalogId && c.RoleId <= (int)role);
     }
 }
Пример #14
0
 public static bool HasAccessToContent(this User user, Content content)
 {
     if (user.IsSuperAdmin()) {
         return true;
     } else {
         return user.UserCatalogRoles.Any(c => c.CatalogId == content.CatalogId);
     }
 }
Пример #15
0
        // **************************************
        // AddSongPreviews
        // **************************************
        private CatalogUploadState AddSongPreviews(CatalogUploadState state)
        {
            if (state.TempFiles != null && state.TempFiles.Count() > 0) {

                var uploadFiles = MoveToMediaVersionFolder(state.TempFiles.Distinct().ToList(), state.MediaVersion);

                //Attach previews
                uploadFiles = state.UploadFiles != null ?
                    (uploadFiles != null ?
                        uploadFiles.Union(state.UploadFiles).ToList()
                        : state.UploadFiles)
                    : uploadFiles;

                state.UploadFiles = uploadFiles.Distinct().ToList();
            }

            IList<Content> contentList = new List<Content>();
            IDictionary<UploadFile, ID3Data> taggedContent = new Dictionary<UploadFile, ID3Data>();

            //var contentFiles = state.UploadFiles.Select(f => f.FileName).Distinct().ToList();

            foreach (var file in state.UploadFiles) {

                taggedContent.Add(file, ID3Reader.GetID3Metadata(file.FilePath));
            }

            // try filename
            // try title + artist
            var taggedFullSongs = taggedContent.Where(c => c.Key.FileMediaVersion == MediaVersion.Full);
            var taggedPreviews = taggedContent.Where(c => c.Key.FileMediaVersion == MediaVersion.Preview);
            foreach (var itm in taggedFullSongs) {

                var preview = new KeyValuePair<UploadFile, ID3Data>();

                if (itm.Value.Title != null && itm.Value.Artist != null) {
                    //Get a matching preview file based on ID3 data or filename
                    preview = taggedPreviews.Where(c => c.Value.Title != null && c.Value.Artist != null)
                                        .FirstOrDefault(c =>
                                        c.Value.Title.Equals(itm.Value.Title, StringComparison.InvariantCultureIgnoreCase) &&
                                        c.Value.Artist.Equals(itm.Value.Artist, StringComparison.InvariantCultureIgnoreCase)
                                        );
                }
                if (preview.Key == null && itm.Key.FileName != null) {
                    preview = taggedPreviews.Where(c => c.Key.FileName != null)
                            .FirstOrDefault(c =>
                            c.Key.FileName.Equals(itm.Key.FileName, StringComparison.InvariantCultureIgnoreCase)
                            );
                }

                var id3 = itm.Value;
                //var file = new FileInfo(itm.Key.FilePath);
                var fileNameData = Path.GetFileNameWithoutExtension(itm.Key.FileName).Split('-');

                var title = id3.Title.AsNullIfWhiteSpace() ?? fileNameData.First();
                var artist = id3.Artist.AsNullIfWhiteSpace() ?? (fileNameData.Length > 1 ? fileNameData[1] : "");
                var album = id3.Album.AsNullIfWhiteSpace() ?? "";
                string year = id3.Year.AsNullIfWhiteSpace() ?? (fileNameData.Length > 2 ? fileNameData[2] : "");
                int releaseYear;
                int.TryParse(year, out releaseYear);

                //var kb = (int)(file.Length * 8 / 1024);
                //var secs = (id3.LengthMilliseconds / 1000);

                var content = new Content() {
                    Title = title,
                    Artist = artist,
                    ReleaseYear = releaseYear.AsNullIfZero(),
                    Notes = !String.IsNullOrWhiteSpace(album) ? String.Concat("Album: ", album) : null,
                    HasMediaFullVersion = true,
                    HasMediaPreviewVersion = preview.Key != null,
                    //FileType = "mp3",
                    //FileSize = (int)file.Length,
                    //BitRate = secs > 0 ? (kb / secs) : 0,
                    UploadFiles = new List<UploadFile>()
                };

                content.UploadFiles.Add(itm.Key);
                if (preview.Key != null) { content.UploadFiles.Add(preview.Key); }

                contentList.Add(content);
            }

            state.Content = contentList;

            return state;
        }
Пример #16
0
        // **************************************
        // UpdateRepresentation:
        // **************************************
        private static Content UpdateRepresentation(this SongSearchContext ctx, Content content, IList<ContentRepresentationUpdateModel> representationModel)
        {
            if (representationModel == null) { return content; }

            var territories = ctx.Territories.ToList();

            // get rid of empty items or items to delete
            representationModel = representationModel.Where(r => r.ModelAction != ModelAction.Delete
                //&& r.RightsHolderName != null
                && r.RepresentationShare != null
                ).ToList();

            var contentRepresentations = content.ContentRepresentations.ToList();

            var removeReps = contentRepresentations.Where(x => !representationModel
                .Select(r => r.ContentRepresentationId)
                .Contains(x.ContentRepresentationId)
                )
                .ToList();

            foreach (var rep in removeReps) {

                var repTerritories = rep.Territories.ToList();
                repTerritories.ForEach(x => rep.Territories.Remove(x));
                content.ContentRepresentations.Remove(rep);

                ctx.ContentRepresentations.DeleteObject(rep);
            }

            foreach (var rm in representationModel) {

                ContentRepresentation contentRepresentation = contentRepresentations.SingleOrDefault(x => x.ContentRepresentationId == rm.ContentRepresentationId) ??
                    new ContentRepresentation() {
                        CreatedByUserId = Account.User().UserId,
                        CreatedOn = DateTime.Now };

                // RightsHolderName
                //contentRight.RightsHolderName = rm.RightsHolderName.AsEmptyIfNull().ToUpper();

                // RightsTypeId
                contentRepresentation.RightsTypeId = (int)rm.RightsTypeId;

                // Share %
                var share = rm.RepresentationShare.Replace("%", "").Trim();
                decimal shareWhole;

                if (decimal.TryParse(share, out shareWhole)) {
                    contentRepresentation.RepresentationShare = decimal.Divide(Math.Abs(shareWhole), 100);
                }

                // Territories
                var territoryModel = rm.Territories.Where(x => x > 0).ToList();

                var repTerritories = contentRepresentation.Territories.ToList();
                var removeTerritories = repTerritories.Where(x => !territoryModel.Contains(x.TerritoryId));
                removeTerritories.ForEach(x => contentRepresentation.Territories.Remove(x));
                var addTerritories = territoryModel.Except(repTerritories.Select(x => x.TerritoryId).Intersect(territoryModel));

                foreach (var tm in addTerritories) {
                    var ter = territories.Single(t => t.TerritoryId == tm);
                    contentRepresentation.Territories.Add(ter);
                }

                // Add to collection if a new contentRight
                if (contentRepresentation.ContentRepresentationId == 0 && contentRepresentation.RepresentationShare >= 0) {
                    content.ContentRepresentations.Add(contentRepresentation);
                }
            }

            return content;
        }
 // **************************************
 // CreateContent
 // **************************************
 public static int CreateContent(Content item)
 {
     throw new NotImplementedException();
 }