Exemplo n.º 1
0
        public SubmissionModule() : base("api/submission")
        {
            this.Post["/", true] = (_, cancel) =>
            {
                return(Task.Run <dynamic>(() =>
                {
                    var file = this.Request.Files.FirstOrDefault();
                    string filename = file.Name;
                    string title = this.Request.Query.Title ?? filename;
                    var cloudService = new SoundCloudService();
                    cloudService.Upload(new UploadTrack()
                    {
                        Title = title,
                        Filename = filename,
                        Data = file.Value
                    });
                    return HttpStatusCode.OK;
                }));
            };

            this.Get["/", true] = (_, cancel) =>
            {
                return(Task.Run <dynamic>(() =>
                {
                    var cloudService = new SoundCloudService();
                    var token = cloudService.GetAccessToken();
                    var tracks = cloudService.GetTracksAsync(token);
                    tracks.Wait();
                    return Response.AsJson(tracks.Result.ToList(), HttpStatusCode.OK);
                }));
            };
        }
Exemplo n.º 2
0
        public SubmissionModule() : base("api/submissions")
        {
            this.Post["/", true] = (_, cancel) =>
            {
                return(Task.Run <dynamic>(() =>
                {
                    var file = this.Request.Files.FirstOrDefault();
                    string filename = file.Name;
                    string title = this.Request.Query.Title ?? filename;
                    var cloudService = new SoundCloudService();
                    cloudService.Upload(new UploadTrack()
                    {
                        Title = title,
                        Filename = filename,
                        Data = file.Value
                    });
                    return HttpStatusCode.OK;
                }));
            };

            this.Get["/", true] = (_, cancel) =>
            {
                return(Task.Run <dynamic>(() =>
                {
                    var cloudService = new SoundCloudService();
                    var token = cloudService.GetAccessToken();
                    var tracks = cloudService.GetTracksAsync(token);
                    tracks.Wait();

                    // Convert SoundCloud Track into DTO object with relevant info
                    Mapper.CreateMap <Track, TrackDto>()
                    .ForMember(dest => dest.SoundCloudMeta, opt => opt.ResolveUsing <SoundCloudMetaResolver>());
                    var trackList = tracks.Result.ToList();
                    List <TrackDto> dtoList = new List <TrackDto>();
                    for (int i = 0; i < trackList.Count; i++)
                    {
                        dtoList.Add(Mapper.Map <TrackDto>(trackList[i]));
                    }

                    return Response.AsJson(dtoList, HttpStatusCode.OK);
                }));
            };
        }
Exemplo n.º 3
0
        public SubmissionModule() : base("api/submissions")
        {
            this.Post["/", true] = (_, cancel) =>
            {
                return(Task.Run <dynamic>(() =>
                {
                    var file = this.Request.Files.FirstOrDefault();
                    string filename = file.Name;
                    string title = this.Request.Form.Title;
                    string username = this.Context.CurrentUser.UserName;
                    if (file == null || string.IsNullOrEmpty(filename) || string.IsNullOrEmpty(username))
                    {
                        return HttpStatusCode.BadRequest;
                    }
                    if (title == null)
                    {
                        title = filename;
                    }
                    var cloudService = new SoundCloudService();
                    var response = cloudService.Upload(new UploadTrack()
                    {
                        Title = title,
                        Filename = filename,
                        Data = file.Value,
                    });
                    db.Set(new AuthEvent()
                    {
                        At = DateTime.UtcNow, Username = username
                    });

                    // Get the track id of the uploaded track
                    int trackId = response.id;

                    // Store custom meta information to database.
                    if (trackId > 0)
                    {
                        CustomTrackMetaDto dto = new CustomTrackMetaDto();
                        dto.TrackId = trackId;
                        dto.Username = username;
                        // Add the meta information
                        dto.SongTitle = this.Request.Form.SongTitle;
                        dto.StageName = this.Request.Form.StageName;
                        dto.Musicians = this.Request.Form.Musicians;
                        dto.Composers = this.Request.Form.Composers;

                        db.Set <CustomTrackMetaDto>(dto);
                    }

                    return HttpStatusCode.OK;
                }));
            };

            this.Get["/", true] = (_, cancel) =>
            {
                return(Task.Run <dynamic>(() =>
                {
                    var cloudService = new SoundCloudService();
                    var token = cloudService.GetAccessToken();
                    var tracks = cloudService.GetTracks(token);

                    // Convert SoundCloud Track into DTO object with relevant info
                    Mapper.CreateMap <Track, TrackDto>()
                    .ForMember(dest => dest.SoundCloudMeta, opt => opt.ResolveUsing <SoundCloudMetaResolver>());
                    var trackList = tracks.ToList();
                    List <TrackDto> dtoList = new List <TrackDto>();
                    for (int i = 0; i < trackList.Count; i++)
                    {
                        dtoList.Add(Mapper.Map <TrackDto>(trackList[i]));
                    }

                    // Get other track information stored in CouchDB
                    var db = new CouchDBService();
                    for (int i = 0; i < dtoList.Count; i++)
                    {
                        TrackDto dto = dtoList[i];

                        // Add custom meta information
                        CustomTrackMetaDto meta = null;
                        CustomTrackMetaDto[] metaObjects = db.FindByTrackId <CustomTrackMetaDto>(dto.Id).ToArray();
                        if (metaObjects.Length > 0)
                        {
                            meta = metaObjects[0];
                        }
                        dto.CustomTrackMeta = meta;
                    }

                    return Response.AsJson(dtoList, HttpStatusCode.OK);
                }));
            };

            this.Get["/list", true] = (_, cancel) =>
            {
                return(Task.Run <dynamic>(() =>
                {
                    var cloudService = new SoundCloudService();
                    var token = cloudService.GetAccessToken();
                    var tracks = cloudService.GetTracks(token);

                    // Convert SoundCloud Track into DTO object with relevant info
                    Mapper.CreateMap <Track, TrackDto>()
                    .ForMember(dest => dest.SoundCloudMeta, opt => opt.ResolveUsing <SoundCloudMetaResolver>());
                    var trackList = tracks.ToList();
                    List <TrackDto> dtoList = new List <TrackDto>();
                    foreach (var track in trackList)
                    {
                        var tra = Mapper.Map <TrackDto>(track);
                        tra.Embed = Embedd(track.id, track.secret_token);
                        dtoList.Add(tra);
                    }

                    // Get other track information stored in CouchDB
                    var db = new CouchDBService();
                    for (int i = 0; i < dtoList.Count; i++)
                    {
                        TrackDto dto = dtoList[i];

                        // Add custom meta information
                        CustomTrackMetaDto meta = null;
                        CustomTrackMetaDto[] metaObjects = db.FindByTrackId <CustomTrackMetaDto>(dto.Id).ToArray();
                        if (metaObjects.Length > 0)
                        {
                            meta = metaObjects[0];
                        }
                        dto.CustomTrackMeta = meta;
                    }

                    return Response.AsJson(dtoList, HttpStatusCode.OK);
                }));
            };
        }