public static PSDataShareSourceDataSet ToPsObject(this ConsumerSourceDataSet sourceDataSet)
 {
     return(new PSDataShareSourceDataSet
     {
         Name = sourceDataSet.Name,
         Id = sourceDataSet.Id,
         DataSetId = sourceDataSet.DataSetId,
         DataSetName = sourceDataSet.DataSetName,
         DataSetType = sourceDataSet.DataSetType,
         Type = sourceDataSet.Type
     });
 }
Exemple #2
0
        public static async Task Main(string[] args)
        {
            Console.WriteLine("\r\n\r\nReading the configurations...");
            IConfigurationRoot configurationRoot = new ConfigurationBuilder()
                                                   .SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("AppSettings.json").Build();
            var configuration = configurationRoot.GetSection("configs").Get <Configuration>();

            Console.WriteLine("\r\n\r\nIdempotent creates for provider resources...");
            var            providerContext       = new UserContext(configuration.Provider);
            IResourceGroup providerResourceGroup = providerContext.IdempotentCreateResourceGroup();
            Account        providerAccount       = providerContext.IdempotentCreateAccount();
            Share          share = providerContext.IdempotentCreateShare();

            Console.WriteLine($"\r\n\r\nAssign MSI of {providerAccount.Id} as the Blob Reader on the Provider Storage...");
            await providerContext.AssignRoleTaskAsync(
                configuration.Provider,
                providerAccount.Identity.PrincipalId,
                "2a2b9908-6ea1-4ae2-8e65-a410df84e7d1");

            Console.WriteLine("\r\n\r\nCreate data set and send invitation");
            DataSet dataSet = providerContext.CreateIfNotExistDataSet(configuration.Provider);

            Invitation invitation = providerContext.CreateIfNotExistInvitation(configuration.Consumer);

            Console.WriteLine("\r\n\r\nIdempotent creates for consumer");
            var            consumerContext       = new UserContext(configuration.Consumer);
            IResourceGroup consumerResourceGroup = consumerContext.IdempotentCreateResourceGroup();
            Account        consumerAccount       = consumerContext.IdempotentCreateAccount();

            Console.WriteLine("\r\n\r\nTo accept the invitation create a share subscription/received share...");
            ShareSubscription shareSubscription = consumerContext.CreateIfNotExistShareSubscription(invitation);

            Console.WriteLine($"\r\n\r\nAssign MSI of {consumerAccount.Id} as the Blob Contributor on the consumer Storage...");
            await consumerContext.AssignRoleTaskAsync(
                configuration.Consumer,
                consumerAccount.Identity.PrincipalId,
                "ba92f5b4-2d11-453d-a403-e96b0029c9fe");

            Console.WriteLine("\r\n\r\nCreate data set mapping to setup storage for the consumer");
            ConsumerSourceDataSet consumerSourceDataSet = consumerContext.GetConsumerSourceDataSet();
            DataSetMapping        dataSetMapping        = consumerContext.CreateDataSetMapping(
                configuration.Consumer,
                consumerSourceDataSet);

            Console.WriteLine("\r\n\r\nInitiate a snapshot copy (duration depends on how large the data is)...");
            ShareSubscriptionSynchronization response = consumerContext.Synchronize();

            Console.WriteLine(
                $"Synchronization Status: {response.Status}. Check resource {consumerAccount.Id} on https://portal.azure.com for further details. \r\n\r\n Hit Enter to continue...");

            Console.ReadLine();
        }
Exemple #3
0
        public DataSetMapping CreateDataSetMapping(Principal principal, ConsumerSourceDataSet consumerSourceDataSet)
        {
            DataSetMapping dataSetMapping;

            try
            {
                dataSetMapping = this.DataShareClient.DataSetMappings.Get(
                    this.Principal.DataShareResourceGroup,
                    this.Principal.DataShareAccountName,
                    this.Principal.DataShareShareSubscriptionName,
                    this.Principal.DataShareDataSetMappingName);

                Console.WriteLine("\r\n\r\nFound existing data set mapping.");

                return(dataSetMapping);
            }
            catch (DataShareErrorException exception)
            {
                if (exception.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    Console.WriteLine("\r\n\r\nData set mapping does not exist. Creating a new one...");

                    var dataSetMappingPayload = new BlobContainerDataSetMapping
                    {
                        DataSetId          = consumerSourceDataSet.DataSetId,
                        StorageAccountName = principal.StorageAccountName,
                        ContainerName      = principal.StorageContainerName,
                        SubscriptionId     = principal.SubscriptionId,
                        ResourceGroup      = principal.StorageResourceGroup
                    };

                    dataSetMapping = this.DataShareClient.DataSetMappings.Create(
                        this.Principal.DataShareResourceGroup,
                        this.Principal.DataShareAccountName,
                        this.Principal.DataShareShareSubscriptionName,
                        this.Principal.DataShareDataSetMappingName,
                        dataSetMappingPayload);

                    Console.WriteLine($"\r\n\r\nCreated data set mapping {dataSetMapping.Id}...");

                    return(dataSetMapping);
                }

                throw;
            }
        }