示例#1
0
        public void GetCanonical_DoesNotError()
        {
            // arrange
            string canonJson = File.ReadAllText(".\\TestData\\canon.json");

            RdostrId[]       rdostrId         = JsonConvert.DeserializeObject <RdostrId[]>(canonJson);
            string           radiohead        = "Radiohead";
            string           jackieWilson     = "Jackie Wilson";
            CanonicalService canonicalService = new CanonicalService();

            // act
            try
            {
                RdostrId artistRdostrId0 = canonicalService.GetArtistId(radiohead);
                RdostrId artistRdostrId1 = canonicalService.GetArtistId(jackieWilson);

                // assert
                Assert.AreEqual(rdostrId[0].Urn, artistRdostrId0.Urn);
                Assert.AreEqual(rdostrId[0].UrnId, artistRdostrId0.UrnId);
                Assert.AreEqual(rdostrId[1].Urn, artistRdostrId1.Urn);
                Assert.AreEqual(rdostrId[1].UrnId, artistRdostrId1.UrnId);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
示例#2
0
        public async Task <List <EntityRelationship> > PushRelatedArtist(string artistId, List <Artist> relatedArtists)
        {
            Artist baseArtist = await GetArtist(artistId);

            CanonicalService          canonicalService       = new CanonicalService();
            List <EntityRelationship> entityRelationshipList = new List <EntityRelationship>();

            try
            {
                RdostrId baseArtistRdo   = canonicalService.GetArtistId(baseArtist.name);
                string   baseArtistId    = $"{baseArtist.name}:{baseArtistRdo.Id}";
                JObject  baseArtistProps = JObject.FromObject(new {
                    Properties = new
                    {
                        type       = "artist",
                        spotifyid  = baseArtist.spotify.id,
                        spotifyuri = baseArtist.spotify.uri,
                        images     = baseArtist.images[0]
                    }
                });
                Entity baseArtistEntity = new Entity(baseArtistId, baseArtist.name, baseArtistProps);
                foreach (Artist relatedArtist in relatedArtists)
                {
                    RdostrId relatedArtistRdo   = canonicalService.GetArtistId(relatedArtist.name);
                    string   relatedArtistId    = $"{relatedArtist.name}:{relatedArtistRdo.Id}";
                    JObject  relatedArtistProps = JObject.FromObject(new
                    {
                        Properties = new
                        {
                            type       = "artist",
                            spotifyid  = relatedArtist.spotify.id,
                            spotifyuri = relatedArtist.spotify.uri,
                            images     = relatedArtist.images[0]
                        }
                    });
                    Entity             relatedEntity      = new Entity(relatedArtistId, relatedArtist.name, relatedArtistProps);
                    EntityRelationship entityRelationship = new EntityRelationship
                    {
                        FromVertex       = baseArtistEntity,
                        Relationship     = "related",
                        RelationshipDate = DateTime.UtcNow,
                        ToVertex         = relatedEntity
                    };
                    entityRelationshipList.Add(entityRelationship);
                }
            }
            catch
            {
            }

            return(entityRelationshipList);
        }
示例#3
0
        public RdostrId GetArtistId(string input)
        {
            string token = input.Trim().ToLower();
            string urn   = $"urn:rdostr:v1:artist/{token}";

            var md5 = MD5.Create();

            byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(urn));
            string checksum  = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();

            Console.WriteLine(checksum);

            RdostrId rdostrId = new RdostrId()
            {
                Version = "1",
                Urn     = urn,
                Id      = checksum,
                UrnId   = $"urn:rdostr:v1:{checksum}"
            };

            return(rdostrId);
        }