Exemplo n.º 1
0
        public async Task AnonymiseAddressData()
        {
            var addresses = await GetAllAddresses();

            var collectionUri = _documentDbHelper.CreateDestinationAddressDocumentCollectionUri();
            var client        = _databaseClient.CreateDestinationDocumentClient();

            var databaseName       = "addresses";
            var databaseCollection = "addresses-anonymised";

            client.CreateDocumentCollectionIfNotExistsAsync(
                UriFactory.CreateDatabaseUri(databaseName),
                new DocumentCollection {
                Id = databaseCollection
            }).
            GetAwaiter()
            .GetResult();

            foreach (var addr in addresses)
            {
                if (addr.Address1 != null)
                {
                    addr.Address1 = addr.Address1.Replace(" ", _utils.RandomString()) + _utils.RandomString();
                }
                if (addr.Address2 != null)
                {
                    addr.Address2 = addr.Address2.Replace(" ", _utils.RandomString()) + _utils.RandomString();
                }
                if (addr.Address3 != null)
                {
                    addr.Address3 = addr.Address3.Replace(" ", _utils.RandomString()) + _utils.RandomString();
                }
                if (addr.Address4 != null)
                {
                    addr.Address4 = addr.Address4.Replace(" ", _utils.RandomString()) + _utils.RandomString();
                }
                if (addr.Address5 != null)
                {
                    addr.Address5 = addr.Address5.Replace(" ", _utils.RandomString()) + _utils.RandomString();
                }
                if (addr.PostCode != null)
                {
                    addr.PostCode = _utils.GenPostCode();
                }

                var response = await client.CreateDocumentAsync(collectionUri, addr);
            }
        }