Beispiel #1
0
        public string GenCSharpMds(Mds.Shared.Mds mds)
        {
            var years = new StringBuilder(" new List<Year>{");

            foreach (var item in mds.Years)
            {
                years.AppendLine(GenCSharpYear(item) + ",");
            }
            years.AppendLine("}");

            var authors = new StringBuilder(" new List<Author>{");

            foreach (var item in mds.Authors)
            {
                authors.AppendLine(GenCSharpAuthor(item) + ",");
            }
            authors.AppendLine("}");

            var podcasts = new StringBuilder(" new List<Podcast>{");

            foreach (var item in mds.Podcasts)
            {
                podcasts.AppendLine(GenCSharpPodcast(item) + ",");
            }
            podcasts.AppendLine("}");


            return(@$ "new Mds.Shared.Mds {{
                Authors = {authors},
Beispiel #2
0
        static void OldToNew()
        {
            var path       = @"E:\private\mds.json";
            var resultPath = @"E:\private";
            var json       = File.ReadAllText(path);
            var mds        = JsonConvert.DeserializeObject <Mds.Shared.Old.Mds>(json);

            var xmds = new Mds.Shared.Mds
            {
                Podcasts = mds.Podcasts.Select(x => new Podcast
                {
                    Duration = x.Duration,
                    FileSize = x.FileSize,
                    GoogleId = x.GoogleId,
                    Id       = x.Id,
                    Title    = x.Title,
                }).ToArray(),
                Authors = mds.Authors.Select(x => new Author {
                    Id   = x.Id,
                    Name = x.Name
                }).ToArray(),
                Years = mds.Years.Select(x => new Year {
                    Value = x.Value
                }).ToArray()
            };

            for (int i = 0; i < mds.Years.Count; i++)
            {
                xmds.Years[i].PodcastsCount = mds.Years[i].PodcastIds.Count;
            }
            for (int i = 0; i < mds.Authors.Count; i++)
            {
                xmds.Authors[i].PodcastsCount = mds.Authors[i].PodcastIds.Count;
            }

            for (int i = 0; i < mds.Podcasts.Count; i++)
            {
                xmds.Podcasts[i].AuthorId = mds.Podcasts[i].Author.Id;
                xmds.Podcasts[i].Year     = mds.Podcasts[i].Year;
            }
            File.WriteAllText(Path.Combine(resultPath, "authors.json"), JsonConvert.SerializeObject(xmds.Authors, Formatting.None));
            File.WriteAllText(Path.Combine(resultPath, "years.json"), JsonConvert.SerializeObject(xmds.Years, Formatting.None));
            File.WriteAllText(Path.Combine(resultPath, "podcasts.json"), JsonConvert.SerializeObject(xmds.Podcasts, Formatting.None));
        }