Exemplo n.º 1
0
        public string ToYAMLInsert()
        {
            var convertedAlbumType = string.IsNullOrEmpty(AlbumType) ? string.Empty : AlbumType.ToRailsSym();
            var allowedAlbumTypes  = new List <string> {
                ":album", ":demo", ":mini_album", ":live"
            };

            if (!allowedAlbumTypes.Contains(convertedAlbumType))
            {
                Logging.Logging.Instance.LogError(string.Format("'{0}' is not recognized as a valid album type for album {1}-{2}. value is fallbacked to ':album'", AlbumType, Id, Title), ErrorLevel.Warning);
                convertedAlbumType = ":album";
            }

            var sb = new StringBuilder();

            sb.AppendFormat("id: {0}", Id);
            sb.AppendLine();
            sb.AppendLine("model: album");
            sb.AppendFormat("title: '{0}'", Title.GetSafeRails());
            sb.AppendLine();
            sb.AppendFormat("music_label_id: {0}", LabelVendor.Id);
            sb.AppendLine();
            sb.AppendFormat("artist_ids: [{0}]", Artist.Id);
            sb.AppendLine();
            sb.AppendFormat("cover: '{0}'", CoversRootUri + CoverName);
            sb.AppendLine();
            sb.AppendFormat("album_type: {0}", convertedAlbumType);
            sb.AppendLine();
            sb.AppendFormat("music_genre: \"{0}\"", RawAlbumMusicGenre);
            sb.AppendLine();
            if (ProcessedAlbumMusicGenre != null)
            {
                sb.AppendFormat("music_genre_music_types: [{0}]",
                                (ProcessedAlbumMusicGenre.MusicTypes.Count() == 0)? ""
                                    : ProcessedAlbumMusicGenre.MusicTypes.Select(val => string.Format("\"{0}\"", val)).
                                Aggregate((acc, next) => acc + ", " + next));
                sb.AppendLine();
                sb.AppendFormat("music_genre_main_styles: [{0}]",
                                (ProcessedAlbumMusicGenre.MainStyles.Count() == 0)? ""
                                    : ProcessedAlbumMusicGenre.MainStyles.Select(val => string.Format("\"{0}\"", val)).
                                Aggregate((acc, next) => acc + ", " + next));
                sb.AppendLine();
                sb.AppendFormat("music_genre_style_alterations: [{0}]",
                                (ProcessedAlbumMusicGenre.StyleAlterations.Count() == 0)? ""
                                    : ProcessedAlbumMusicGenre.StyleAlterations.Select(val => string.Format("\"{0}\"", val)).
                                Aggregate((acc, next) => acc + ", " + next));
                sb.AppendLine();
            }
            sb.AppendFormat("release_date: {0}", ReleaseDate);
            sb.AppendLine();
            sb.AppendFormat("created_at: {0}", CreationDate);
            sb.AppendLine();
            sb.AppendFormat("updated_at: {0}", CreationDate);
            sb.AppendLine();
            sb.AppendFormat("created_by: {0}", Reviewer.Id);
            sb.AppendLine();
            return(sb.ToString());
        }
Exemplo n.º 2
0
        public string ToRailsInsert()
        {
            var sb = new StringBuilder();

            sb.AppendFormat("{0} = {1}.new", RailsModelName, RailsModelName.ToCamelCase());
            sb.AppendLine();
            var convertedAlbumType = string.IsNullOrEmpty(AlbumType) ? string.Empty : AlbumType.ToRailsSym();
            var allowedAlbumTypes  = new List <string> {
                ":album", ":demo", ":mini_album", ":live"
            };

            if (!allowedAlbumTypes.Contains(convertedAlbumType))
            {
                Logging.Logging.Instance.LogError(string.Format("'{0}' is not recognized as a valid album type for album {1}-{2}. value is fallbacked to ':album'", AlbumType, Id, Title), ErrorLevel.Warning);
                convertedAlbumType = ":album";
            }
            sb.AppendFormat("{0}.assign_attributes({{ id: {1}, title: '{2}', release_date: DateTime.parse('{3}'), kind_cd: {4}.kinds({5}), music_label_id: {6}, created_at: DateTime.parse('{7}'), updated_at: DateTime.parse('{7}'), artist_ids: [{8}], creator_id: {9}, updater_id: {9}, published: true, remote_cover_url: \"{10}\" }}, :without_protection => true)",
                            RailsModelName, Id, Title.GetSafeRails(), ReleaseDate, RailsModelName.ToCamelCase(), convertedAlbumType, LabelVendor.Id, CreationDate, Artist.Id, Reviewer.Id, CoversRootUri + CoverName);
            sb.AppendLine();
            sb.AppendFormat("{0}s << {0}", RailsModelName);
            sb.AppendLine();
            sb.AppendLine();
            return(sb.ToString());
        }