コード例 #1
0
 private void ThrowIfPersonNull(Person person)
 {
     if (person == null)
         throw new ArgumentNullException(nameof(person));
     if (string.IsNullOrEmpty(person.Name))
         throw new ArgumentNullException(nameof(person.Name));
     if (string.IsNullOrEmpty(person.Id))
         throw new ArgumentNullException(nameof(person.Id));
 }
コード例 #2
0
 public async Task AddWithRelationToPerson(Movie movie, Person existingPerson, string relationType)
 {
     await _db.PersonMatch()
         .Where((Person person) => person.Name == existingPerson.Name)
         .CreateUnique(
             $"person-[:{relationType}]->(movie:Movie {{newMovie}})")
         .WithParam("newMovie", movie)
         .ExecuteWithoutResultsAsync();
 }
コード例 #3
0
 public async Task AddPersonAsync(Person person)
 {
     ThrowIfPersonNull(person);
     if ((await GetPersonByNameAsync(person.Name)) != null)
     {
         await UpdatePersonAsync(person);
         return;
     }
     await _personRepo.Add(person);
 }
コード例 #4
0
        public async Task<List<MixedResult>> GetDegreesOfSeparation(Person startingPerson, Person endingPerson)
        {
            if (startingPerson == null)
                throw new ArgumentNullException(nameof(startingPerson));
            if (endingPerson == null)
                throw new ArgumentNullException(nameof(endingPerson));

            var results = await _personRepo.GetPath(startingPerson, endingPerson);
            var r = results;
            return r;
        }
コード例 #5
0
 public async Task AddOrUpdateMovieWithRelationAsync(Movie movie, Person person, string relationType)
 {
     ThrowIfMovieNull(movie);
     ThrowIfPersonNull(person);
     if ((await GetMovieByTitleAndYearAsync(movie.Title, movie.Year)) == null)
     {
         await _movieRepo.AddWithRelationToPerson(movie, person, relationType);
         return;
     }
     //await UpdateMovieAsync(movie);
     await _movieRepo.AddRelationToPerson(movie, person, relationType);
 }
コード例 #6
0
 public async Task Update(Person updatedPerson)
 {
     await _db.PersonMerge()
         .Where((Person person) => person.Id == updatedPerson.Id)
         .OnCreate()
         .Set("person = {_updatedPerson}")
         .WithParams(new
         {
             _updatedPerson = updatedPerson
         })
         .ExecuteWithoutResultsAsync();
 }
コード例 #7
0
        public async Task<IActionResult> AddActor()
        {
            Person p = new Person
            {
                Name = "Aiden Buckles",
                Id = "2345"
            };

            await _personService.AddPersonAsync(p);
            var r = await _personService.GetPersonByNameAsync("Will Czifro");

            return Ok(r);
        }
コード例 #8
0
        public Task<List<MixedResult>> GetPath(Person startingPerson, Person endingPerson)
        {
            var query = _db
                .Match("x=shortestPath((start:Person)" +
                       "-[*]-(end:Person))")
                .Where((Person start) => start.Name == startingPerson.Name)
                .AndWhere((Person end) => end.Name == endingPerson.Name)
                .Return(x => new MixedResult
                {
                    Nodes = Return.As<IEnumerable<Node<MixedData>>>("nodes(x)"),
                    Relationships = Return.As<IEnumerable<RelationshipInstance<object>>>("rels(x)")
                });

            var str = query.Query.QueryText;

            return Task.FromResult(query
                .Results
                .ToList());
        }
        private static void PersonCollector(IPersonService personService, IMovieService movieService,
                                            MyApiFilmsClient client, ConcurrentQueue queue)
        {
            while (queue.IncompleteMoviesWaiting() || queue.IncompletePersonsWaiting())
            {
                if (!queue.IncompletePersonsWaiting())
                {
                    continue;
                }
                // ApiPerson is an alias for FilmIndustryNetwork.MyApiFilms.Entities.Person
                // This is to distinguish between FilmIndustryNetwork.MyApiFilms.Entities.Person
                // and FilmIndustryNetwork.Entities.Person
                ApiPerson apiPerson;
                var       name = queue.PopIncompletePerson();

                if (name == "---")
                {
                    continue;
                }

                try
                {
                    apiPerson =
                        client.GetDataAsObject <PersonResponse>(name, DataSetType.Person)?.Data?.Names?.FirstOrDefault();

                    if (apiPerson == null)
                    {
                        throw new Exception();
                    }
                }
                catch (MyApiFilmsTimeoutException e)
                {
                    // TODO: setup logging
                    FillQueueFromList(null, personService, new [] { name }, queue, 1);
                    continue;
                }
                catch (NoMyApiFilmsResponseException e)
                {
                    // TODO: setup logging
                    continue;
                }
                catch (Exception)
                {
                    // TODO: setup logging
                    FillQueueFromList(null, personService, new[] { name }, queue, 1);
                    continue;
                }

                var person = new Person
                {
                    Bio            = apiPerson.Bio,
                    BirthName      = apiPerson.BirthName,
                    DateOfBirth    = apiPerson.DateOfBirth,
                    Id             = apiPerson.IdIMDB,
                    Name           = apiPerson.Name,
                    NeedsApiLookup = false,
                    PlaceOfBirth   = apiPerson.PlaceOfBirth,
                    UrlPhoto       = apiPerson.UrlPhoto
                };

                FillQueueFromList(movieService, null, apiPerson.Filmographies
                                  .Where(x => x.Section == "Actor" || x.Section == "Director" || x.Section == "Writer")
                                  .SelectMany(f => f.Filmography.Select(m => m.Title)).ToList(), queue, 0);

                AddRelationshipsToQueue(
                    apiPerson.Filmographies
                    .Where(x => x.Section == "Actor")
                    .SelectMany(f => f.Filmography
                                .Where(mm => mm.Remarks != null && !mm.Remarks.Contains("(TV Series)"))
                                .Select(m => m.IMDBId)), new[] { person.Name }, queue,
                    RelationTypes.ActedIn);
                AddRelationshipsToQueue(
                    apiPerson.Filmographies
                    .Where(x => x.Section == "Director")
                    .SelectMany(f => f.Filmography
                                .Where(mm => mm.Remarks != null && !mm.Remarks.Contains("(TV Series)"))
                                .Select(m => m.IMDBId)), new[] { person.Name }, queue,
                    RelationTypes.DirectorFor);
                AddRelationshipsToQueue(
                    apiPerson.Filmographies
                    .Where(x => x.Section == "Writer")
                    .SelectMany(f => f.Filmography
                                .Where(mm => mm.Remarks != null && !mm.Remarks.Contains("(TV Series)"))
                                .Select(m => m.IMDBId)), new[] { person.Name }, queue,
                    RelationTypes.WriterOf);

                if (personService.GetPersonByNameAsync(person.Name).Result != null)
                {
                    continue;
                }

                personService.AddPersonAsync(person).Wait();
            }
        }
コード例 #10
0
        public async Task AddRelationToPerson(Movie existingMovie, Person existingPerson, string relationType)
        {
            var query = _db.Match($"(movie:Movie)",
                $"(person:Person)")
                .Where((Movie movie) => movie.Title == existingMovie.Title)
                .AndWhere((Person person) => person.Name == existingPerson.Name)
                .CreateUnique(
                    $"person-[:{relationType}]->movie");

            var q = query.Query;
            await query.ExecuteWithoutResultsAsync();

        }
コード例 #11
0
 public async Task Add(Person person)
 {
     await _db.PersonCreate()
         .WithParam("newPerson", person)
         .ExecuteWithoutResultsAsync();
 }
コード例 #12
0
 public async Task UpdatePersonAsync(Person person)
 {
     ThrowIfPersonNull(person);
     await _personRepo.Update(person);
 }
        private static void PersonCollector(IPersonService personService, IMovieService movieService, 
            MyApiFilmsClient client, ConcurrentQueue queue)
        {
            while (queue.IncompleteMoviesWaiting() || queue.IncompletePersonsWaiting())
            {
                if (!queue.IncompletePersonsWaiting()) continue;
                // ApiPerson is an alias for FilmIndustryNetwork.MyApiFilms.Entities.Person
                // This is to distinguish between FilmIndustryNetwork.MyApiFilms.Entities.Person
                // and FilmIndustryNetwork.Entities.Person
                ApiPerson apiPerson;
                var name = queue.PopIncompletePerson();

                if (name == "---") continue;

                try
                {
                    apiPerson =
                        client.GetDataAsObject<PersonResponse>(name, DataSetType.Person)?.Data?.Names?.FirstOrDefault();

                    if (apiPerson == null) throw new Exception();
                }
                catch (MyApiFilmsTimeoutException e)
                {
                    // TODO: setup logging
                    FillQueueFromList(null, personService, new [] {name}, queue, 1);
                    continue;
                }
                catch (NoMyApiFilmsResponseException e)
                {
                    // TODO: setup logging
                    continue;
                }
                catch (Exception)
                {
                    // TODO: setup logging
                    FillQueueFromList(null, personService, new[] { name }, queue, 1);
                    continue;
                }

                var person = new Person
                {
                    Bio = apiPerson.Bio,
                    BirthName = apiPerson.BirthName,
                    DateOfBirth = apiPerson.DateOfBirth,
                    Id = apiPerson.IdIMDB,
                    Name = apiPerson.Name,
                    NeedsApiLookup = false,
                    PlaceOfBirth = apiPerson.PlaceOfBirth,
                    UrlPhoto = apiPerson.UrlPhoto
                };

                FillQueueFromList(movieService, null, apiPerson.Filmographies
                    .Where(x => x.Section == "Actor" || x.Section == "Director" || x.Section == "Writer")
                    .SelectMany(f => f.Filmography.Select(m => m.Title)).ToList(), queue, 0);

                AddRelationshipsToQueue(
                    apiPerson.Filmographies
                        .Where(x => x.Section == "Actor")
                        .SelectMany(f => f.Filmography
                                          .Where(mm => mm.Remarks != null && !mm.Remarks.Contains("(TV Series)"))
                                          .Select(m => m.IMDBId)), new[] {person.Name}, queue,
                    RelationTypes.ActedIn);
                AddRelationshipsToQueue(
                    apiPerson.Filmographies
                        .Where(x => x.Section == "Director")
                        .SelectMany(f => f.Filmography
                                          .Where(mm => mm.Remarks != null && !mm.Remarks.Contains("(TV Series)"))
                                          .Select(m => m.IMDBId)), new[] { person.Name }, queue,
                    RelationTypes.DirectorFor);
                AddRelationshipsToQueue(
                    apiPerson.Filmographies
                        .Where(x => x.Section == "Writer")
                        .SelectMany(f => f.Filmography
                                          .Where(mm => mm.Remarks != null && !mm.Remarks.Contains("(TV Series)"))
                                          .Select(m => m.IMDBId)), new[] { person.Name }, queue,
                    RelationTypes.WriterOf);

                if (personService.GetPersonByNameAsync(person.Name).Result != null) continue;

                personService.AddPersonAsync(person).Wait();
            }
        }