/// <summary>
        /// Returns all documents from DynamoDB table
        /// </summary>
        /// <typeparam name="T">object</typeparam>
        /// <returns></returns>
        public virtual async Task <ICollection <T> > GetAllAsync <T>()
        {
            Logger.Log($"Scanning DynamoDB {_tableName} for all TimeSeries");

            ICollection <T> results = new List <T>();

            try
            {
                var docs = await _dynamoDbClient.ScanAsync(new ScanRequest(_tableName));

                Logger.Log($"Found items: {docs.Items.Count}");

                foreach (var t in docs.Items)
                {
                    // Convert DynamoDB document to C# object
                    var doc = Document.FromAttributeMap(t);
                    var obj = _dynamoDbContext.FromDocument <T>(doc);

                    results.Add(obj);
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.Message);
            }

            return(results);
        }
Ejemplo n.º 2
0
        public void object_mapping_works_for_individual_artist()
        {
            // Arrange
            var expectedUrls = new[]
            {
                "http://www.rickastley.co.uk/",
                "http://en.wikipedia.org/wiki/Rick_Astley",
                "https://www.facebook.com/RickAstley",
                "https://twitter.com/rickastley",
                "https://myspace.com/rickastley",
                "https://www.instagram.com/officialrickastley/",
                "https://www.youtube.com/channel/UCuAXFkgsw1L7xaCfnd5JJOw",
                "https://www.bookogs.com/credit/559827-rick-astley"
            };
            var expectedNameVariations = new[]
            {
                "Astley R.",
                "R Astley",
                "R. Asley",
                "R. Astley",
                "R.Astley",
                "Richard Astley",
                "Rick Ashley",
                "Rick Asley",
                "Rick Astle",
                "Rick Astly"
            };
            var expectedAliases = new []
            {
                new ArtistAlias {
                    Id = "1141583", Name = "Dick Spatsley"
                }
            };
            var expectedGroups = new[]
            {
                new ArtistGroup {
                    Id = "146979", Name = "Band Aid II", IsActive = true
                },
                new ArtistGroup {
                    Id = "420265", Name = "Ferry Aid", IsActive = true
                }
            };
            var regionEndpoint = RegionEndpoint.GetBySystemName("us-west-1");
            var context        = new DynamoDBContext(regionEndpoint);
            var json           = File.ReadAllText("RickAstley.json");
            var doc            = Document.FromJson(json);

            // Act
            var artist = context.FromDocument <Artist>(doc);

            // Assert
            Assert.Equal("72872", artist.Id);
            Assert.Equal("Rick Astley", artist.Name);
            Assert.Equal("Richard Paul Astley", artist.RealName);
            Assert.Equal(expectedNameVariations, artist.NameVariations);
            Assert.Equal(expectedAliases, artist.Aliases, new AliasEqualityComparer());
            Assert.Equal(expectedGroups, artist.Groups, new GroupEqualityComparer());
            Assert.Equal(expectedUrls, artist.Urls);
        }
Ejemplo n.º 3
0
        public static T ToObject <T>(this Dictionary <string, AttributeValue> dictionary)
        {
            var client  = new AmazonDynamoDBClient(RegionEndpoint.SAEast1);
            var context = new DynamoDBContext(client);

            var doc = Document.FromAttributeMap(dictionary);

            return(context.FromDocument <T>(doc));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Click do botão Login
        /// </summary>
        private async Task ObterRelacaoServicosAsync()
        {
            try
            {
                // Mostra a tela de aguarde
                MessagingCenterHelper.TelaAguardeMostrar(this);

                // Verifica se o token do usuário logado ainda é válido
                await LoginService.VerifyIdToken();

                // Obtém dados do DynamoDB
                AmazonDynamoDBClient client  = AwsHelper.AmazonDynamoDBClient;
                DynamoDBContext      context = AwsHelper.DynamoDBContext;

                QueryRequest request = new QueryRequest
                {
                    TableName = Servico.TabelaNome,
                    KeyConditionExpression    = "(PK = :v_PK) AND begins_with(SK, :v_SK)",
                    ExpressionAttributeValues = new Dictionary <string, AttributeValue>
                    {
                        { ":v_PK", new AttributeValue {
                              S = Servico.PkChave
                          } },
                        { ":v_SK", new AttributeValue {
                              S = Servico.SkChave
                          } }
                    }
                };

                // Retorno
                QueryResponse response = await client.QueryAsync(request);

                // Converte o retorno para lista de objetos
                List <Servico> listaRetorno = new List <Servico>();
                foreach (Dictionary <string, AttributeValue> item in response.Items)
                {
                    listaRetorno.Add(context.FromDocument <Servico>(Document.FromAttributeMap(item)));
                }

                // Atualiza a lista
                this.ListaServicos.AddRange(listaRetorno.OrderBy(x => x.Descricao));
            }
            catch (MobileErrorException e)
            {
                MessagingCenterHelper.ExibirMensagem(MobileErrorException.GetMessageFull(e), MessageBox.TipoMensagem.Atencao);
            }
            catch (Exception e)
            {
                MobileErrorException.EnviarErroAppCenter(e);
                MessagingCenterHelper.ExibirMensagem(MobileErrorException.GetMessageFull(e, true), MessageBox.TipoMensagem.Erro);
            }
            finally
            {
                MessagingCenterHelper.TelaAguardeFechar(this);
            }
        }
        public bool IsScriptApplied(string scriptName)
        {
            var schemaVersionTable = Table.LoadTable(_client, SchemaVersionTableName);

            Document itemGet = schemaVersionTable.GetItem(scriptName);

            var script = _dbContext.FromDocument <SchemaVersionDataModel>(itemGet);

            return(script != null);
        }
Ejemplo n.º 6
0
        public void object_mapping_works_for_group_artist()
        {
            // Arrange
            var expectedUrls = new[]
            {
                "http://en.wikipedia.org/wiki/Ferry_Aid"
            };
            var expectedMembers = new[]
            {
                new ArtistMember {
                    Id = "5647", Name = "Nik Kershaw", IsActive = true
                },
                new ArtistMember {
                    Id = "6707", Name = "Mandy Smith", IsActive = true
                },
                new ArtistMember {
                    Id = "7247", Name = "Samantha Fox", IsActive = true
                },
                new ArtistMember {
                    Id = "7705", Name = "Juliet Roberts", IsActive = true
                },
                new ArtistMember {
                    Id = "35301", Name = "Paul McCartney", IsActive = true
                },
                new ArtistMember {
                    Id = "40576", Name = "Andy Bell", IsActive = true
                },
                new ArtistMember {
                    Id = "71081", Name = "Kim Wilde", IsActive = true
                },
                new ArtistMember {
                    Id = "72872", Name = "Rick Astley", IsActive = true
                }
            };
            var regionEndpoint = RegionEndpoint.GetBySystemName("us-west-1");
            var context        = new DynamoDBContext(regionEndpoint);
            var json           = File.ReadAllText("FerryAid.json");
            var doc            = Document.FromJson(json);

            // Act
            var artist = context.FromDocument <Artist>(doc);

            // Assert
            Assert.Equal("420265", artist.Id);
            Assert.Equal("Ferry Aid", artist.Name);
            Assert.Equal(expectedMembers, artist.Members, new MemberEqualityComparer());
            Assert.Equal(expectedUrls, artist.Urls);
        }
Ejemplo n.º 7
0
        public async Task <List <T> > GetAll <T>(string tableName)
        {
            Table  table    = Table.LoadTable(_Client, tableName);
            Search response = table.Scan(new ScanFilter());

            var dbResponse = await response.GetRemainingAsync();

            List <T> data = new List <T>();

            foreach (var item in dbResponse)
            {
                data.Add(_Context.FromDocument <T>(item));
            }

            return(data);
        }
Ejemplo n.º 8
0
        internal static List <T> ConvertAttributesToType <T>(List <Dictionary <string, AttributeValue> > items, DynamoDBContext context)
        {
            if (items is null)
            {
                return(null);
            }

            var result = new List <T>();

            items.ForEach(item =>
            {
                var doc = Document.FromAttributeMap(item);
                result.Add(context.FromDocument <T>(doc));
            });

            return(result);
        }
Ejemplo n.º 9
0
        public void object_mapping_works()
        {
            // Arrange
            var expectedContactInfo = "RCA Records, 1540 Broadway, New York, NY 10036";
            var expectedUrls        = new[]
            {
                "http://www.rcarecords.com/",
                "http://historysdumpster.blogspot.co.uk/2012/08/rca-colour-record-labels-of-70s.html",
                "https://www.bookogs.com/credit/535946-rca"
            };
            var regionEndpoint = RegionEndpoint.GetBySystemName("us-west-1");
            var context        = new DynamoDBContext(regionEndpoint);
            var json           = File.ReadAllText("RCA.json");
            var doc            = Document.FromJson(json);

            // Act
            var label = context.FromDocument <Label>(doc);

            // Assert
            Assert.Equal("895", label.Id);
            Assert.Equal("RCA", label.Name);
            Assert.Equal(expectedUrls, label.Urls);
            Assert.Equal(expectedContactInfo, label.contact_info);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Deserializes a document to an instance of type T.
 /// </summary>
 /// <param name="document">The document defentition for the table type.</param>
 /// <returns>The table specifiec type.</returns>
 public T FromDocument(Document document)
 {
     return(_context.FromDocument <T>(document));
 }
Ejemplo n.º 11
0
 public T FromDocument <T>(Document document)
 {
     return(context.FromDocument <T>(document, operationConfig));
 }
Ejemplo n.º 12
0
        public void object_mapping_works()
        {
            // Arrange
            var expectedStyles = new[]
            {
                "Euro-Disco"
            };
            var expectedGenres = new[]
            {
                "Electronic",
                "Pop"
            };
            var expectedArtists = new[]
            {
                new MasterArtist {
                    Id = "72872", Name = "Rick Astley"
                }
            };
            var expectedTracks = new[]
            {
                new Track {
                    Position = "A", Duration = "3:32", Title = "Never Gonna Give You Up", Type = "track"
                },
                new Track {
                    Position = "B", Duration = "3:30", Title = "Never Gonna Give You Up (Instrumental)", Type = "track"
                }
            };
            var expectedVideos = new[]
            {
                new Video
                {
                    Title       = "Rick Astley - Never Gonna Give You Up (Video)",
                    Duration    = 213,
                    Description = "Rick Astley - Never Gonna Give You Up (Video)",
                    Uri         = "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
                    Embed       = true
                },
                new Video
                {
                    Title       = "Never Gonna Give You Up (Cake Mix)    Rick Astley 1987",
                    Duration    = 346,
                    Description = "Never Gonna Give You Up (Cake Mix)    Rick Astley 1987",
                    Uri         = "https://www.youtube.com/watch?v=1lN2bSlL5SE",
                    Embed       = true
                },
                new Video
                {
                    Title       = "Rick Astley - Never Gonna Give You Up (Stephen Gilham - PHD Extended Mix)",
                    Duration    = 436,
                    Description = "Rick Astley - Never Gonna Give You Up (Stephen Gilham - PHD Extended Mix)",
                    Uri         = "https://www.youtube.com/watch?v=afKTEsELh_s",
                    Embed       = true
                },
                new Video
                {
                    Title       = "Never Gonna Give You Up (Escape to NY Mix)",
                    Duration    = 422,
                    Description = "Never Gonna Give You Up (Escape to NY Mix)",
                    Uri         = "https://www.youtube.com/watch?v=xoPIl7xvK5Q",
                    Embed       = true
                },
            };
            var regionEndpoint = RegionEndpoint.GetBySystemName("us-west-1");
            var context        = new DynamoDBContext(regionEndpoint);
            var json           = File.ReadAllText("NeverGonnaGiveYouUpMaster.json");
            var doc            = Document.FromJson(json);

            // Act
            var master = context.FromDocument <Master>(doc);

            // Assert
            Assert.Equal("96559", master.Id);
            Assert.Equal("Never Gonna Give You Up", master.Title);
            Assert.Equal(1987, master.Year);
            Assert.Equal("249504", master.MainReleaseId);
            Assert.Equal("1612378", master.MostRecentReleaseId);
            Assert.Equal(expectedStyles, master.Styles);
            Assert.Equal(expectedGenres, master.Genres);
            Assert.Equal(expectedArtists, master.Artists, new ArtistCompactEqualityComparer());
            Assert.Equal(expectedTracks, master.Tracks, new TrackEqualityComparer());
            Assert.Equal(expectedVideos, master.Videos, new VideoEqualityComparer());
        }
Ejemplo n.º 13
0
        public void object_mapping_works()
        {
            // Arrange
            var expectedNotes  = "UK Release has a black label with the text \"Manufactured In England\" printed on it.\n\nSleeve:\n\u2117 1987 \u2022 BMG Records (UK) Ltd. \u00a9 1987 \u2022 BMG Records (UK) Ltd.\nDistributed in the UK by BMG Records \u2022  Distribu\u00e9 en Europe par BMG/Ariola \u2022 Vertrieb en Europa d\u00fcrch BMG/Ariola.\n\nCenter labels:\n\u2117 1987 Pete Waterman Ltd.\nOriginal Sound Recording made by PWL.\nBMG Records (UK) Ltd. are the exclusive licensees for the world.\n\nDurations do not appear on the release.";
            var expectedStyles = new[]
            {
                "Euro-Disco"
            };
            var expectedGenres = new[]
            {
                "Electronic",
                "Pop"
            };
            var expectedArtists = new[]
            {
                new ReleaseArtist {
                    Id = "72872", Name = "Rick Astley"
                }
            };
            var expectedFormats = new[]
            {
                new ReleaseFormat {
                    Name = "Vinyl", Descriptions = new List <string> {
                        "7\"", "45 RPM", "Single"
                    }
                }
            };
            var expectedVideos = new[]
            {
                new Video
                {
                    Title       = "Rick Astley - Never Gonna Give You Up (Video)",
                    Duration    = 213,
                    Description = "Rick Astley - Never Gonna Give You Up (Video)",
                    Uri         = "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
                    Embed       = true
                },
                new Video
                {
                    Title       = "Never Gonna Give You Up (Cake Mix)    Rick Astley 1987",
                    Duration    = 346,
                    Description = "Never Gonna Give You Up (Cake Mix)    Rick Astley 1987",
                    Uri         = "https://www.youtube.com/watch?v=1lN2bSlL5SE",
                    Embed       = true
                },
                new Video
                {
                    Title       = "Rick Astley - Never Gonna Give You Up (Stephen Gilham - PHD Extended Mix)",
                    Duration    = 436,
                    Description = "Rick Astley - Never Gonna Give You Up (Stephen Gilham - PHD Extended Mix)",
                    Uri         = "https://www.youtube.com/watch?v=afKTEsELh_s",
                    Embed       = true
                },
                new Video
                {
                    Title       = "Never Gonna Give You Up (Escape to NY Mix)",
                    Duration    = 422,
                    Description = "Never Gonna Give You Up (Escape to NY Mix)",
                    Uri         = "https://www.youtube.com/watch?v=xoPIl7xvK5Q",
                    Embed       = true
                },
            };
            var expectedLabels = new[] { new ReleaseLabel {
                                             Id = "895", Name = "RCA", EntityType = "Label"
                                         } };
            var expectedTracks = new[]
            {
                new Track {
                    Position = "A", Duration = "3:32", Title = "Never Gonna Give You Up", Type = "track"
                },
                new Track {
                    Position = "B", Duration = "3:30", Title = "Never Gonna Give You Up (Instrumental)", Type = "track"
                }
            };
            var regionEndpoint = RegionEndpoint.GetBySystemName("us-west-1");
            var context        = new DynamoDBContext(regionEndpoint);
            var json           = File.ReadAllText("NeverGonnaGiveYouUpRelease.json");
            var doc            = Document.FromJson(json);

            // Act
            var release = context.FromDocument <Release>(doc);

            // Assert
            Assert.Equal("249504", release.Id);
            Assert.Equal("Never Gonna Give You Up", release.Title);
            Assert.Equal(1987, release.Year);
            Assert.Equal("96559", release.Master);
            Assert.Equal("UK", release.Country);
            Assert.Equal(expectedNotes, release.Notes);
            Assert.Equal(expectedStyles, release.Styles);
            Assert.Equal(expectedGenres, release.Genres);
            Assert.Equal(expectedArtists, release.Artists, new ArtistCompactEqualityComparer());
            Assert.Equal(expectedTracks, release.Tracks, new TrackEqualityComparer());
            Assert.Equal(expectedVideos, release.Videos, new VideoEqualityComparer());
            Assert.Equal(expectedLabels, release.Labels, new LabelEqualityComparer());
            Assert.Equal(expectedFormats, release.Formats, new FormatEqualityComparer());
        }