コード例 #1
0
        /// <summary>
        /// Process the import request
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                base.ProcessRecord();

                string accessKey = null;
                string blobUri = null;

                switch (this.ParameterSetName)
                {
                    case ByContainerNameParameterSet:
                        accessKey =
                            System.Convert.ToBase64String(
                                this.StorageContext.StorageAccount.Credentials.ExportKey());

                        blobUri =
                            this.StorageContext.BlobEndPoint +
                            this.StorageContainerName + "/" +
                            this.BlobName;
                        break;

                    case ByContainerObjectParameterSet:
                        accessKey =
                            System.Convert.ToBase64String(
                                this.StorageContainer.CloudBlobContainer.ServiceClient.Credentials.ExportKey());

                        blobUri =
                            this.StorageContainer.Context.BlobEndPoint +
                            this.StorageContainer.Name + "/" +
                            this.BlobName;
                        break;
                }

                string fullyQualifiedServerName =
                    this.SqlConnectionContext.ServerName + DataServiceConstants.AzureSqlDatabaseDnsSuffix;

                // Create Web Request Inputs - Blob Storage Credentials and Server Connection Info
                ImportInput importInput = new ImportInput
                {
                    BlobCredentials = new BlobStorageAccessKeyCredentials
                    {
                        StorageAccessKey = accessKey,
                        Uri = blobUri
                    },
                    ConnectionInfo = new ConnectionInfo
                    {
                        ServerName = fullyQualifiedServerName,
                        DatabaseName = this.DatabaseName,
                        UserName = this.SqlConnectionContext.SqlCredentials.UserName,
                        Password = this.SqlConnectionContext.SqlCredentials.Password
                    }
                };

                if (this.MyInvocation.BoundParameters.ContainsKey("Edition"))
                {
                    importInput.AzureEdition = this.Edition.ToString();
                }

                if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseMaxSize"))
                {
                    importInput.DatabaseSizeInGB = this.DatabaseMaxSize;
                }

                ImportExportRequest request =
                    this.ImportSqlAzureDatabaseProcess(this.SqlConnectionContext.ServerName, importInput);

                if (request != null)
                {
                    request.SqlCredentials = this.SqlConnectionContext.SqlCredentials;
                    request.ServerName = this.SqlConnectionContext.ServerName;
                    this.WriteObject(request);
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.SqlConnectionContext.ClientRequestId,
                    ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Performs the call to import database using the server data service context channel.
        /// </summary>
        /// <param name="serverName">The name of the server to connect to.</param>
        /// <param name="input">The <see cref="ImportInput"/> object that contains 
        /// all the connection information</param>
        /// <returns>The result of the import request.  Upon success the <see cref="ImportExportRequest"/>
        /// for the request</returns>
        internal ImportExportRequest ImportSqlAzureDatabaseProcess(string serverName, ImportInput input)
        {
            ImportExportRequest result = null;

            try
            {
                XmlElement requestId = RetryCall(subscription =>
                    this.Channel.ImportDatabase(subscription, serverName, input));
                Microsoft.WindowsAzure.ServiceManagement.Operation operation = WaitForSqlDatabaseOperation();

                if (requestId != null)
                {
                    result = new ImportExportRequest();
                    result.RequestGuid = requestId.InnerText;
                }
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.SqlConnectionContext.ClientRequestId,
                    ex);
            }

            return result;
        }
コード例 #3
0
 /// <summary>
 /// Imports a database from blob storage
 /// </summary>
 /// <param name="proxy">Channel used for communication with Azure's service management APIs</param>
 /// <param name="subscriptionId">The subscription ID in which the server resides</param>
 /// <param name="serverName">The name of the server to put the database in</param>
 /// <param name="input">The input data for the import operation</param>
 /// <returns>An <see cref="XmlElement"/> containing the request ID (GUID).</returns>
 public static XmlElement ImportDatabase(
     this ISqlDatabaseManagement proxy,
     string subscriptionId,
     string serverName,
     ImportInput input)
 {
     return proxy.EndImportDatabase(proxy.BeginImportDatabase(
         subscriptionId,
         serverName,
         input,
         null,
         null));
 }
コード例 #4
0
 /// <summary>
 /// A mock call to BeginImportDatabase
 /// </summary>
 /// <param name="subscriptionId">The subscription Id to pass through</param>
 /// <param name="serverName">The server name to pass through</param>
 /// <param name="input">The input object to pass through</param>
 /// <param name="callback">The callback object to pass through</param>
 /// <param name="state">The state object to pass through</param>
 /// <returns>An <see cref="IAsyncResult"/> of the mock request</returns>
 public IAsyncResult BeginImportDatabase(
     string subscriptionId,
     string serverName,
     ImportInput input,
     AsyncCallback callback,
     object state)
 {
     SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult();
     result.Values["subscriptionId"] = subscriptionId;
     result.Values["serverName"] = serverName;
     result.Values["input"] = input;
     result.Values["callback"] = callback;
     result.Values["state"] = state;
     return result;
 }
コード例 #5
0
        public void ImportAzureSqlDatabaseProcessTest()
        {
            string serverName = "TestServer";
            ImportInput input = new ImportInput()
            {
                AzureEdition = "Web",
                DatabaseSizeInGB = 1,
                BlobCredentials = new BlobStorageAccessKeyCredentials()
                {
                    Uri = "blobUri",
                    StorageAccessKey = "storage access key"
                },
                ConnectionInfo = new ConnectionInfo()
                {
                    DatabaseName = "databaseName",
                    Password = "******",
                    ServerName = "serverName",
                    UserName = "******"
                }
            };

            Guid testGuid = Guid.NewGuid();

            MockCommandRuntime commandRuntime = new MockCommandRuntime();
            SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement();
            channel.ImportDatabaseThunk = ar =>
            {
                Assert.AreEqual(serverName, (string)ar.Values["serverName"]);
                Assert.AreEqual(
                    input.AzureEdition,
                    ((ImportInput)ar.Values["input"]).AzureEdition);
                Assert.AreEqual(
                    input.DatabaseSizeInGB,
                    ((ImportInput)ar.Values["input"]).DatabaseSizeInGB);
                Assert.AreEqual(
                    input.BlobCredentials.Uri,
                    ((ImportInput)ar.Values["input"]).BlobCredentials.Uri);
                Assert.AreEqual(
                    input.ConnectionInfo.DatabaseName,
                    ((ImportInput)ar.Values["input"]).ConnectionInfo.DatabaseName);
                Assert.AreEqual(
                    input.ConnectionInfo.Password,
                    ((ImportInput)ar.Values["input"]).ConnectionInfo.Password);
                Assert.AreEqual(
                    input.ConnectionInfo.ServerName,
                    ((ImportInput)ar.Values["input"]).ConnectionInfo.ServerName);
                Assert.AreEqual(
                    input.ConnectionInfo.UserName,
                    ((ImportInput)ar.Values["input"]).ConnectionInfo.UserName);

                XmlElement operationResult =
                    new XmlDocument().CreateElement(
                        "guid",
                        "http://schemas.microsoft.com/2003/10/Serialization/");

                operationResult.InnerText = testGuid.ToString();
                return operationResult;
            };

            StartAzureSqlDatabaseImport importAzureSqlDatabase =
                new StartAzureSqlDatabaseImport(channel) { ShareChannel = true };
            importAzureSqlDatabase.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription();
            importAzureSqlDatabase.CommandRuntime = commandRuntime;
            var result = importAzureSqlDatabase.ImportSqlAzureDatabaseProcess(serverName, input);
            Assert.AreEqual(testGuid.ToString(), result.RequestGuid);

            Assert.AreEqual(0, commandRuntime.ErrorStream.Count);
        }