/// <summary> /// Get string of the flight plan to export. /// </summary> /// <exception cref="Exception"></exception> public static string GetExportText(ExportInput input) { var route = input.Route; var from = route.FirstWaypoint.ID.Substring(0, 4); var to = route.LastWaypoint.ID.Substring(0, 4); return($"RTE {from}{to}01 " + JarDesignAirbusProvider.GetExportText(input)); }
/// <summary> /// Exports a database into 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 that contains the database</param> /// <param name="input">The input data for the export operation</param> /// <returns>An <see cref="XmlElement"/> containing the request ID (GUID).</returns> public static XmlElement ExportDatabase( this ISqlDatabaseManagement proxy, string subscriptionId, string serverName, ExportInput input) { return(proxy.EndExportDatabase(proxy.BeginExportDatabase( subscriptionId, serverName, input, null, null))); }
/// <summary> /// Starts a mock call to Begin Export Database. /// </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>A <see cref="SimpleServiceManagementAsyncResult"/> object</returns> public IAsyncResult BeginExportDatabase( string subscriptionId, string serverName, ExportInput 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); }
private static ExportInput BuildExportInput(long time, string serverName, string databaseName) { string key, blobUri; PrepareBlob(time, databaseName, out key, out blobUri); var exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = key, Uri = blobUri }, ConnectionInfo = BuildConnectionInfo(serverName, databaseName) }; return(exportInputs); }
public async Task <string> DoExportAsync(string blobUri, IProgress <int> progress) { //Setup Web Request for Export Operation WebRequest webRequest = WebRequest.Create(EndPointUri + @"/Export"); webRequest.Method = WebRequestMethods.Http.Post; webRequest.ContentType = @"application/xml"; //Create Web Request Inputs - Blob Storage Credentials and Server Connection Info var exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = StorageKey, Uri = String.Format(blobUri, DatabaseName, DateTime.UtcNow.Ticks) }, ConnectionInfo = new ConnectionInfo { ServerName = ServerName, DatabaseName = DatabaseName, UserName = UserName, Password = Password } }; //Perform Web Request Stream webRequestStream = await webRequest.GetRequestStreamAsync(); progress.Report(20); var dataContractSerializer = new DataContractSerializer(exportInputs.GetType()); dataContractSerializer.WriteObject(webRequestStream, exportInputs); webRequestStream.Close(); return(await ExportAwaiterAsync(webRequest, progress)); }
public string DoExport(ExportDatabaseEventSource log, string blobUri, bool whatIf) { string requestGuid = null; //Setup Web Request for Export Operation WebRequest webRequest = WebRequest.Create(this.EndPointUri + @"/Export"); webRequest.Method = WebRequestMethods.Http.Post; webRequest.ContentType = @"application/xml"; //Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ExportInput exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = this.StorageKey, Uri = String.Format(blobUri, this.DatabaseName, DateTime.UtcNow.Ticks.ToString()) }, ConnectionInfo = new ConnectionInfo { ServerName = this.ServerName, DatabaseName = this.DatabaseName, UserName = this.UserName, Password = this.Password } }; //Perform Web Request DataContractSerializer dataContractSerializer = new DataContractSerializer(exportInputs.GetType()); log.RequestUri(webRequest.RequestUri.AbsoluteUri); if (whatIf) { using (var strm = new MemoryStream()) { dataContractSerializer.WriteObject(strm, exportInputs); strm.Flush(); strm.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(strm)) { log.WouldHaveSent(reader.ReadToEnd()); } } return null; } else { using (var strm = new MemoryStream()) { dataContractSerializer.WriteObject(strm, exportInputs); strm.Flush(); strm.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(strm)) { log.SendingRequest(reader.ReadToEnd()); } } Stream webRequestStream = webRequest.GetRequestStream(); dataContractSerializer.WriteObject(webRequestStream, exportInputs); webRequestStream.Close(); //Get Response and Extract Request Identifier WebResponse webResponse = null; XmlReader xmlStreamReader = null; try { //Initialize the WebResponse to the response from the WebRequest webResponse = webRequest.GetResponse(); xmlStreamReader = XmlReader.Create(webResponse.GetResponseStream()); xmlStreamReader.ReadToFollowing("guid"); requestGuid = xmlStreamReader.ReadElementContentAsString(); return requestGuid; } catch (WebException responseException) { log.RequestFailed(responseException.Message); if (responseException.Response != null) { log.ErrorStatusCode((int)(((HttpWebResponse)responseException.Response).StatusCode)); log.ErrorStatusDescription(((HttpWebResponse)responseException.Response).StatusDescription); } return null; } } }
public string DoExport(string blobUri, bool whatIf) { _log.Info("Starting SQL DAC Export Operation"); string requestGuid = null; bool exportComplete = false; string exportedBlobPath = null; //Setup Web Request for Export Operation WebRequest webRequest = WebRequest.Create(this.EndPointUri + @"/Export"); webRequest.Method = WebRequestMethods.Http.Post; webRequest.ContentType = @"application/xml"; //Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ExportInput exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = this.StorageKey, Uri = String.Format(blobUri, this.DatabaseName, DateTime.UtcNow.Ticks.ToString()) }, ConnectionInfo = new ConnectionInfo { ServerName = this.ServerName, DatabaseName = this.DatabaseName, UserName = this.UserName, Password = this.Password } }; //Perform Web Request DataContractSerializer dataContractSerializer = new DataContractSerializer(exportInputs.GetType()); _log.Info("http POST {0}", webRequest.RequestUri.AbsoluteUri); if (whatIf) { _log.Trace("Would have sent:"); using (var strm = new MemoryStream()) { dataContractSerializer.WriteObject(strm, exportInputs); strm.Flush(); strm.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(strm)) { _log.Trace(reader.ReadToEnd()); } } return null; } else { _log.Info("Making Web Request For Export Operation..."); Stream webRequestStream = webRequest.GetRequestStream(); dataContractSerializer.WriteObject(webRequestStream, exportInputs); webRequestStream.Close(); //Get Response and Extract Request Identifier WebResponse webResponse = null; XmlReader xmlStreamReader = null; try { //Initialize the WebResponse to the response from the WebRequest webResponse = webRequest.GetResponse(); xmlStreamReader = XmlReader.Create(webResponse.GetResponseStream()); xmlStreamReader.ReadToFollowing("guid"); requestGuid = xmlStreamReader.ReadElementContentAsString(); _log.Info($"Export Request '{requestGuid}' submitted"); //Get Export Operation Status string last = null; while (!exportComplete) { List<StatusInfo> statusInfoList = CheckRequestStatus(requestGuid); var status = statusInfoList.FirstOrDefault().Status; if (!String.Equals(last, status, StringComparison.OrdinalIgnoreCase)) { _log.Info(status); } last = status; if (statusInfoList.FirstOrDefault().Status == "Failed") { _log.Error("Database export failed: {0}", statusInfoList.FirstOrDefault().ErrorMessage); exportComplete = true; } if (statusInfoList.FirstOrDefault().Status == "Completed") { exportedBlobPath = statusInfoList.FirstOrDefault().BlobUri; _log.Info("Export Complete - Database exported to: {0}", exportedBlobPath); exportComplete = true; } Thread.Sleep(5 * 1000); } return exportedBlobPath; } catch (WebException responseException) { _log.Error("Request Falied:{0}", responseException.Message); if (responseException.Response != null) { _log.Error("Status Code: {0}", ((HttpWebResponse)responseException.Response).StatusCode); _log.Error("Status Description: {0}", ((HttpWebResponse)responseException.Response).StatusDescription); } return null; } } }
public string DoExport(string blobUri, bool whatIf) { _log.Info("Starting SQL DAC Export Operation"); string requestGuid = null; bool exportComplete = false; string exportedBlobPath = null; //Setup Web Request for Export Operation WebRequest webRequest = WebRequest.Create(this.EndPointUri + @"/Export"); webRequest.Method = WebRequestMethods.Http.Post; webRequest.ContentType = @"application/xml"; //Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ExportInput exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = this.StorageKey, Uri = String.Format(blobUri, this.DatabaseName, DateTime.UtcNow.Ticks.ToString()) }, ConnectionInfo = new ConnectionInfo { ServerName = this.ServerName, DatabaseName = this.DatabaseName, UserName = this.UserName, Password = this.Password } }; //Perform Web Request DataContractSerializer dataContractSerializer = new DataContractSerializer(exportInputs.GetType()); _log.Info("http POST {0}", webRequest.RequestUri.AbsoluteUri); if (whatIf) { _log.Trace("Would have sent:"); using (var strm = new MemoryStream()) { dataContractSerializer.WriteObject(strm, exportInputs); strm.Flush(); strm.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(strm)) { _log.Trace(reader.ReadToEnd()); } } return(null); } else { _log.Info("Making Web Request For Export Operation..."); Stream webRequestStream = webRequest.GetRequestStream(); dataContractSerializer.WriteObject(webRequestStream, exportInputs); webRequestStream.Close(); //Get Response and Extract Request Identifier WebResponse webResponse = null; XmlReader xmlStreamReader = null; try { //Initialize the WebResponse to the response from the WebRequest webResponse = webRequest.GetResponse(); // See CA3053. Default XmlReaderSettings contains an insecure XmlResolver. Best to specify null. XmlReaderSettings xmlSettings = new XmlReaderSettings(); xmlSettings.XmlResolver = null; xmlStreamReader = XmlReader.Create(webResponse.GetResponseStream(), xmlSettings); xmlStreamReader.ReadToFollowing("guid"); requestGuid = xmlStreamReader.ReadElementContentAsString(); _log.Info($"Export Request '{requestGuid}' submitted"); //Get Export Operation Status string last = null; while (!exportComplete) { List <StatusInfo> statusInfoList = CheckRequestStatus(requestGuid); var status = statusInfoList.FirstOrDefault().Status; if (!String.Equals(last, status, StringComparison.OrdinalIgnoreCase)) { _log.Info(status); } last = status; if (statusInfoList.FirstOrDefault().Status == "Failed") { _log.Error("Database export failed: {0}", statusInfoList.FirstOrDefault().ErrorMessage); exportComplete = true; } if (statusInfoList.FirstOrDefault().Status == "Completed") { exportedBlobPath = statusInfoList.FirstOrDefault().BlobUri; _log.Info("Export Complete - Database exported to: {0}", exportedBlobPath); exportComplete = true; } Thread.Sleep(5 * 1000); } return(exportedBlobPath); } catch (WebException responseException) { _log.Error("Request Failed:{0}", responseException.Message); if (responseException.Response != null) { _log.Error("Status Code: {0}", ((HttpWebResponse)responseException.Response).StatusCode); _log.Error("Status Description: {0}", ((HttpWebResponse)responseException.Response).StatusDescription); } return(null); } } }
public string DoExport(string blobUri) { logger.Info(String.Format("Starting Export Operation - {0}\n\r", DateTime.Now)); string requestGuid = null; bool exportComplete = false; string exportedBlobPath = null; //Setup Web Request for Export Operation WebRequest webRequest = WebRequest.Create(this.EndPointUri + @"/Export"); webRequest.Method = WebRequestMethods.Http.Post; webRequest.ContentType = @"application/xml"; //Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ExportInput exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = this.StorageKey, Uri = String.Format(blobUri, this.DatabaseName, DateTime.UtcNow.Ticks.ToString()) }, ConnectionInfo = new ConnectionInfo { ServerName = this.ServerName, DatabaseName = this.DatabaseName, UserName = this.UserName, Password = this.Password } }; //Perform Web Request logger.Info("Making Web Request For Export Operation..."); Stream webRequestStream = webRequest.GetRequestStream(); DataContractSerializer dataContractSerializer = new DataContractSerializer(exportInputs.GetType()); dataContractSerializer.WriteObject(webRequestStream, exportInputs); webRequestStream.Close(); //Get Response and Extract Request Identifier logger.Info("Reading Response and extracting Export Request Identifier..."); WebResponse webResponse = null; XmlReader xmlStreamReader = null; try { //Initialize the WebResponse to the response from the WebRequest webResponse = webRequest.GetResponse(); xmlStreamReader = XmlReader.Create(webResponse.GetResponseStream()); xmlStreamReader.ReadToFollowing("guid"); requestGuid = xmlStreamReader.ReadElementContentAsString(); logger.Info(String.Format("Your Export Request Guid is: {0}", requestGuid)); //Get Export Operation Status while (!exportComplete) { logger.Info("Checking export status..."); List<StatusInfo> statusInfoList = CheckRequestStatus(requestGuid); StatusInfo statusInfo = statusInfoList.FirstOrDefault(); logger.Info(statusInfo.Status); if (statusInfo.Status == "Failed") { logger.Info(String.Format("Database export failed: {0}", statusInfo.ErrorMessage)); exportComplete = true; } if (statusInfo.Status == "Completed") { exportedBlobPath = statusInfo.BlobUri; logger.Info(String.Format("Export Complete - Database exported to: {0}\n\r", exportedBlobPath)); exportComplete = true; } if (!exportComplete) { Thread.Sleep(3000); } } return exportedBlobPath; } catch (WebException responseException) { logger.ErrorFormat("Request Falied:{0}", responseException,responseException.Message); if (responseException.Response != null) { logger.ErrorFormat("Status Code: {0}", ((HttpWebResponse)responseException.Response).StatusCode); logger.ErrorFormat("Status Description: {0}\n\r", ((HttpWebResponse)responseException.Response).StatusDescription); } return null; } }
public string DoExport(string blobUri) { logger.Info(String.Format("Starting Export Operation - {0}\n\r", DateTime.Now)); string requestGuid = null; bool exportComplete = false; string exportedBlobPath = null; //Setup Web Request for Export Operation WebRequest webRequest = WebRequest.Create(this.EndPointUri + @"/Export"); webRequest.Method = WebRequestMethods.Http.Post; webRequest.ContentType = @"application/xml"; //Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ExportInput exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = this.StorageKey, Uri = String.Format(blobUri, this.DatabaseName, DateTime.UtcNow.Ticks.ToString()) }, ConnectionInfo = new ConnectionInfo { ServerName = this.ServerName, DatabaseName = this.DatabaseName, UserName = this.UserName, Password = this.Password } }; //Perform Web Request logger.Info("Making Web Request For Export Operation..."); Stream webRequestStream = webRequest.GetRequestStream(); DataContractSerializer dataContractSerializer = new DataContractSerializer(exportInputs.GetType()); dataContractSerializer.WriteObject(webRequestStream, exportInputs); webRequestStream.Close(); //Get Response and Extract Request Identifier logger.Info("Reading Response and extracting Export Request Identifier..."); WebResponse webResponse = null; XmlReader xmlStreamReader = null; try { //Initialize the WebResponse to the response from the WebRequest webResponse = webRequest.GetResponse(); xmlStreamReader = XmlReader.Create(webResponse.GetResponseStream()); xmlStreamReader.ReadToFollowing("guid"); requestGuid = xmlStreamReader.ReadElementContentAsString(); logger.Info(String.Format("Your Export Request Guid is: {0}", requestGuid)); //Get Export Operation Status while (!exportComplete) { logger.Info("Checking export status..."); List <StatusInfo> statusInfoList = CheckRequestStatus(requestGuid); StatusInfo statusInfo = statusInfoList.FirstOrDefault(); logger.Info(statusInfo.Status); if (statusInfo.Status == "Failed") { logger.Info(String.Format("Database export failed: {0}", statusInfo.ErrorMessage)); exportComplete = true; } if (statusInfo.Status == "Completed") { exportedBlobPath = statusInfo.BlobUri; logger.Info(String.Format("Export Complete - Database exported to: {0}\n\r", exportedBlobPath)); exportComplete = true; } if (!exportComplete) { Thread.Sleep(3000); } } return(exportedBlobPath); } catch (WebException responseException) { logger.ErrorFormat("Request Falied:{0}", responseException, responseException.Message); if (responseException.Response != null) { logger.ErrorFormat("Status Code: {0}", ((HttpWebResponse)responseException.Response).StatusCode); logger.ErrorFormat("Status Description: {0}\n\r", ((HttpWebResponse)responseException.Response).StatusDescription); } return(null); } }
public string DoExport(ExportDatabaseEventSource log, string blobUri, bool whatIf) { string requestGuid = null; //Setup Web Request for Export Operation WebRequest webRequest = WebRequest.Create(this.EndPointUri + @"/Export"); webRequest.Method = WebRequestMethods.Http.Post; webRequest.ContentType = @"application/xml"; //Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ExportInput exportInputs = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = this.StorageKey, Uri = String.Format(blobUri, this.DatabaseName, DateTime.UtcNow.Ticks.ToString()) }, ConnectionInfo = new ConnectionInfo { ServerName = this.ServerName, DatabaseName = this.DatabaseName, UserName = this.UserName, Password = this.Password } }; //Perform Web Request DataContractSerializer dataContractSerializer = new DataContractSerializer(exportInputs.GetType()); log.RequestUri(webRequest.RequestUri.AbsoluteUri); if (whatIf) { using (var strm = new MemoryStream()) { dataContractSerializer.WriteObject(strm, exportInputs); strm.Flush(); strm.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(strm)) { log.WouldHaveSent(reader.ReadToEnd()); } } return(null); } else { using (var strm = new MemoryStream()) { dataContractSerializer.WriteObject(strm, exportInputs); strm.Flush(); strm.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(strm)) { log.SendingRequest(reader.ReadToEnd()); } } Stream webRequestStream = webRequest.GetRequestStream(); dataContractSerializer.WriteObject(webRequestStream, exportInputs); webRequestStream.Close(); //Get Response and Extract Request Identifier WebResponse webResponse = null; XmlReader xmlStreamReader = null; try { //Initialize the WebResponse to the response from the WebRequest webResponse = webRequest.GetResponse(); xmlStreamReader = XmlReader.Create(webResponse.GetResponseStream()); xmlStreamReader.ReadToFollowing("guid"); requestGuid = xmlStreamReader.ReadElementContentAsString(); return(requestGuid); } catch (WebException responseException) { log.RequestFailed(responseException.Message); if (responseException.Response != null) { log.ErrorStatusCode((int)(((HttpWebResponse)responseException.Response).StatusCode)); log.ErrorStatusDescription(((HttpWebResponse)responseException.Response).StatusDescription); } return(null); } } }
public void ExportAzureSqlDatabaseProcessTest() { string serverName = "TestServer"; ExportInput input = new ExportInput() { BlobCredentials = new BlobStorageAccessKeyCredentials() { Uri = "blobUri", StorageAccessKey = "storage access key" }, ConnectionInfo = new ConnectionInfo() { DatabaseName = "databaseName", Password = "******", ServerName = "serverName", UserName = "******" } }; Guid guid = Guid.NewGuid(); MockCommandRuntime commandRuntime = new MockCommandRuntime(); SimpleSqlDatabaseManagement channel = new SimpleSqlDatabaseManagement(); channel.ExportDatabaseThunk = ar => { Assert.AreEqual(serverName, (string)ar.Values["serverName"]); Assert.AreEqual( input.BlobCredentials.Uri, ((ExportInput)ar.Values["input"]).BlobCredentials.Uri); Assert.AreEqual( input.ConnectionInfo.DatabaseName, ((ExportInput)ar.Values["input"]).ConnectionInfo.DatabaseName); Assert.AreEqual( input.ConnectionInfo.Password, ((ExportInput)ar.Values["input"]).ConnectionInfo.Password); Assert.AreEqual( input.ConnectionInfo.ServerName, ((ExportInput)ar.Values["input"]).ConnectionInfo.ServerName); Assert.AreEqual( input.ConnectionInfo.UserName, ((ExportInput)ar.Values["input"]).ConnectionInfo.UserName); XmlElement operationResult = new XmlDocument().CreateElement( "guid", "http://schemas.microsoft.com/2003/10/Serialization/"); operationResult.InnerText = guid.ToString(); return(operationResult); }; StartAzureSqlDatabaseExport exportAzureSqlDatabase = new StartAzureSqlDatabaseExport(channel) { ShareChannel = true }; exportAzureSqlDatabase.CurrentSubscription = UnitTestHelper.CreateUnitTestSubscription(); exportAzureSqlDatabase.CommandRuntime = commandRuntime; var result = exportAzureSqlDatabase.ExportSqlAzureDatabaseProcess(serverName, input); Assert.AreEqual(guid.ToString(), result.RequestGuid); Assert.AreEqual(0, commandRuntime.ErrorStream.Count); }
/// <summary> /// Process the export request /// </summary> protected override void ProcessRecord() { this.WriteVerbose("Starting to process the record"); 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 ExportInput exportInput = new ExportInput { 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 } }; this.WriteVerbose("AccessKey: " + accessKey); this.WriteVerbose("blobUri: " + blobUri); this.WriteVerbose("ServerName: " + exportInput.ConnectionInfo.ServerName); this.WriteVerbose("DatabaseName: " + exportInput.ConnectionInfo.DatabaseName); this.WriteVerbose("UserName: "******"Password: " + exportInput.ConnectionInfo.Password); ImportExportRequest request = this.ExportSqlAzureDatabaseProcess(this.SqlConnectionContext.ServerName, exportInput); 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); } }
/// <summary> /// Performs the call to export 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="ExportInput"/> object that contains /// all the connection information</param> /// <returns>The result of export request. Upon success the <see cref="ImportExportRequest"/> /// for the request</returns> internal ImportExportRequest ExportSqlAzureDatabaseProcess(string serverName, ExportInput input) { ImportExportRequest result = null; try { XmlElement requestId = RetryCall(subscription => this.Channel.ExportDatabase(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); }
/// <summary> /// Execute the srcDatabase backup /// </summary> /// <param name="database">Name of srcDatabase to backup</param> /// <param name="tables">List of tables for selective backup, null if backup entire srcDatabase</param> /// <param name="filename">Generated filename for blob storage</param> /// <returns></returns> public string Backup(string database, List<string> tables, out string filename) { var time = DateTime.Now; filename = string.Format("{0}-{1}-{2}-{3}-{4}-{5}.bacpac", database, time.Year, time.Month, time.Day, time.Hour, time.Minute); var credentials = new BlobStorageAccessKeyCredentials() { StorageAccessKey = _storageKey, Uri = StorageUrl + filename }; var connectionInfo = new ConnectionInfo { ServerName = _serverName, DatabaseName = database, UserName = _sqlUsername, Password = _sqlPassword }; // create the request var request = WebRequest.Create(string.Format(_serviceUrl, (tables != null ? "SelectiveExport" : "Export"))); request.Method = "POST"; request.ContentType = "application/xml"; using (var stream = request.GetRequestStream()) { DataContractSerializer dcs; if (tables != null) { var selectiveExport = new SelectiveExportInput() { ConnectionInfo = connectionInfo, BlobCredentials = credentials, Tables = tables.Select(a => new TableName() { Name = a }).ToArray() }; dcs = new DataContractSerializer(typeof(SelectiveExportInput)); dcs.WriteObject(stream, selectiveExport); } else { var exportInput = new ExportInput() { ConnectionInfo = connectionInfo, BlobCredentials = credentials }; dcs = new DataContractSerializer(typeof(ExportInput)); dcs.WriteObject(stream, exportInput); } } // make the post using (var response = (HttpWebResponse)request.GetResponse()) { if (response.StatusCode != HttpStatusCode.OK) { throw new HttpException((int)response.StatusCode, response.StatusDescription); } var sr = new System.IO.StreamReader(response.GetResponseStream()); var result = sr.ReadToEnd().Trim(); var xml = XDocument.Parse(result); var node = xml.Descendants().First(); return node.Value; } }