Esempio n. 1
0
        public async Task <ActionResult <Track> > Post([FromBody] Track track)
        {
            track.Id = await _repo.GetNextId();

            track.AirDistance = _geoService.AirDistance((double)track.StartLat, (double)track.StartLng, (double)track.EndLat, (double)track.EndLng);
            await _repo.Create(track);

            return(new OkObjectResult(track));
        }
Esempio n. 2
0
        public async Task Upload(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            byte[] buffer;
            var    file = TagLib.File.Create(path);

            using (var fileStream = file.FileAbstraction.ReadStream)
                using (var stream = new MemoryStream())
                {
                    await fileStream.CopyToAsync(stream);

                    buffer = stream.ToArray();
                }

            var track = new Track
            {
                Artist = file.Tag.FirstPerformer,
                Title  = file.Tag.Title,
                Data   = buffer
            };
            await trackRepository.Create(track);
        }
Esempio n. 3
0
        public async Task <ActionResult> CreateAnalyticsResult([FromBody] SiddhiOutputModel siddhiOutput)
        {
            var analyticsResult = siddhiOutput.Event;

            analyticsResult.Id = await _repo.GetNextAnalyticsResultId();

            await _repo.Create(analyticsResult);

            Console.WriteLine(analyticsResult.Id + "  " + analyticsResult.RecordId + " " + analyticsResult.Status + "\n");

            Command command = null;

            if (analyticsResult.Status == "Danger")
            {
                command = new Command(1);
            }
            else
            {
                command = new Command(0);
            }

            command.DateTime = DateTime.Now;
            command.RecordId = analyticsResult.RecordId;
            command.Status   = analyticsResult.Status;

            //_ = _hub.Clients.Group("CommandRoom").SendAsync("commands", command);

            _analyticCommandSender.Send(command);

            return(Ok("Analytics result successfully saved to database"));
        }
Esempio n. 4
0
        public async Task <IActionResult> Post([FromBody] TrackCreateDTO trackCreateDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var id = await repository.Create(trackCreateDTO);

            return(CreatedAtAction(nameof(Get), new { id }, null));
        }
Esempio n. 5
0
        public TrackDto Create(TrackDto entity)
        {
            using (_trackRepository)
            {
                var entityToCreate = entity.ConvertToTrackDbModel();

                _trackRepository.Create(entityToCreate);
                _trackRepository.SaveChanges();

                return(entityToCreate.ConvertToTrackDto());
            }
        }
Esempio n. 6
0
        public async Task UndefinedLanguageSlugTest()
        {
            await _repository.Create(new Track
            {
                ID         = 5,
                TrackIndex = 0,
                Type       = StreamType.Video,
                Language   = null,
                EpisodeID  = TestSample.Get <Episode>().ID
            });

            Track track = await _repository.Get(5);

            Assert.Equal("anohana-s1e1.und.video", track.Slug);
        }
Esempio n. 7
0
        public string UploadTrack(UploadTrackDto trackDto)
        {
            var uploader = _userRepository.GetByName(trackDto.UploaderUserName);
            var track    = _trackFactory.Produce(trackDto);

            track.Uploader = uploader;

            var existingUrlIds = _trackRepository.GetTrackTitles(uploader.Id);

            track.UrlId = UrlIdGenerator.Generate(track.Title, existingUrlIds);

            _trackRepository.Create(track);

            return(track.UrlId);
        }
Esempio n. 8
0
        /// <summary>
        /// Set track's index and ensure that every tracks is well-formed.
        /// </summary>
        /// <param name="resource">The resource to fix.</param>
        /// <returns>The <paramref name="resource"/> parameter is returned.</returns>
        private async Task <Episode> _ValidateTracks(Episode resource)
        {
            if (resource.Tracks == null)
            {
                return(resource);
            }

            resource.Tracks = await resource.Tracks.SelectAsync(x =>
            {
                x.Episode = resource;
                return(_tracks.Create(x));
            }).ToListAsync();

            _database.Tracks.AttachRange(resource.Tracks);
            return(resource);
        }
Esempio n. 9
0
        public async Task <bool> Seed()
        {
            var rng          = new Random();
            var listaGeneros = new List <string> ()
            {
                "pop", "mpb", "classical", "rock"
            };

            _ = await _trackRepository.DeleteAll();

            foreach (var genero in listaGeneros)
            {
                var recommendations = GetRecommendations(null, new List <string> ()
                {
                    genero
                }, null, null, null, null, 50, string.Empty);
                foreach (var item in recommendations.Tracks)
                {
                    var name       = item.Name;
                    var artistName = item.Artists.First().Name;
                    var genre      = await _genreRepository.GetByNameAsync(genero);

                    var oTrack = new Track()
                    {
                        Name         = item.Name,
                        NameOfArtist = item.Artists.First().Name,
                        IdGenre      = genre.Id,
                        Price        = rng.Next(1, 60)
                    };

                    try {
                        _ = _trackRepository.Create(oTrack);
                    } catch (System.Exception) {
                        continue;
                    }
                }
            }

            return(true);
        }
Esempio n. 10
0
 public int Create(Track track)
 {
     return(_trackRepository.Create(track));
 }