private ErrorDetails GetErrorDetails(Exception error) { ErrorDetails errorDetails = new ErrorDetails(); if (error is HttpException && (error as HttpException).GetHttpCode() == 404) { ErrorCode.Text = (error as HttpException).GetHashCode().ToString(); errorDetails.What = "Requested resource could not be found"; errorDetails.Why = "Specified url is incorrect."; errorDetails.Suggestion = "Check the specified url."; } else if (error is SqlException) { ErrorCode.Text = "Database error"; errorDetails.What = "Maybe borke Database"; errorDetails.Why = "Could not established connection with database"; errorDetails.Suggestion = "Report problem to the system administrator"; } else if (error is ApplicationException) { ErrorCode.Text = "Application Broken"; errorDetails.What = "Oupps!.. Somesing wrong happened"; errorDetails.Why = "You broke it all :("; errorDetails.Suggestion = "Please, try again later"; } else { ErrorCode.Text = "Unexpected Error"; errorDetails.What = "Unexpected Error"; errorDetails.Why = "Undefined"; errorDetails.Suggestion = "Resolved programers"; } return errorDetails; }
private ErrorResponse(SerializationInfo info, StreamingContext context) { if (info.MemberCount != 1) throw new ArgumentException(); foreach (SerializationEntry entry in info) { _errorKind = entry.Name; _errorDetails = JsonConvert.DeserializeObject<ErrorDetails>(entry.Value.ToString()); } }
void BeforeNavigate(string url, int flags, string targetFrameName, ref object postData, string headers, ref bool cancel) { _error = null; }
internal ZmqDeviceException(ErrorDetails errorDetails) : base(errorDetails) { }
private void DisplayErrorDetails(ErrorDetails errorDetails) { lblWhat.Text = errorDetails.What; lblWhy.Text = errorDetails.Why; lblSuggestion.Text = errorDetails.Suggestion; }
internal ZmqException(ErrorDetails errorDetails) : this(errorDetails.ErrorCode, errorDetails.Message) { }
/// <summary> /// Manually initiate a failover for the IoT Hub to its secondary region /// </summary> /// <remarks> /// Manually initiate a failover for the IoT Hub to its secondary region. To /// learn more, see https://aka.ms/manualfailover /// </remarks> /// <param name='iotHubName'> /// Name of the IoT hub to failover /// </param> /// <param name='resourceGroupName'> /// Name of the resource group containing the IoT hub resource /// </param> /// <param name='failoverRegion'> /// Region the hub will be failed over to /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="ErrorDetailsException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse> BeginManualFailoverWithHttpMessagesAsync(string iotHubName, string resourceGroupName, string failoverRegion, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (iotHubName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "iotHubName"); } if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } if (failoverRegion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "failoverRegion"); } FailoverInput failoverInput = new FailoverInput(); if (failoverRegion != null) { failoverInput.FailoverRegion = failoverRegion; } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("iotHubName", iotHubName); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("failoverInput", failoverInput); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "BeginManualFailover", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{iotHubName}/failover").ToString(); _url = _url.Replace("{iotHubName}", System.Uri.EscapeDataString(iotHubName)); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (failoverInput != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(failoverInput, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 202) { var ex = new ErrorDetailsException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); ErrorDetails _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <ErrorDetails>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
private async Task <FileManagerResponse> MoveToAsync(string path, string targetPath, string[] names, string[] renamedFiles = null, params FileManagerDirectoryContent[] data) { FileManagerResponse moveResponse = new FileManagerResponse(); try { renamedFiles = renamedFiles ?? new string[0]; foreach (var item in data) { if (item.IsFile) { if (await IsFileExists(targetPath + item.Name)) { int index = -1; if (renamedFiles.Length > 0) { index = Array.FindIndex(renamedFiles, Items => Items.Contains(item.Name)); } if ((path == targetPath) || (index != -1)) { var newName = await FileRename(targetPath, item.Name); await MoveItems(rootPath + item.FilterPath, targetPath, item.Name, newName); copiedFiles.Add(GetFileDetails(targetPath, item)); } else { this.existFiles.Add(item.Name); } } else { await MoveItems(rootPath + item.FilterPath, targetPath, item.Name, null); copiedFiles.Add(GetFileDetails(targetPath, item)); } } else { if (!await IsFolderExists(rootPath + item.FilterPath + item.Name)) { missingFiles.Add(item.Name); } else if (await IsFolderExists(targetPath + item.Name)) { int index = -1; if (renamedFiles.Length > 0) { index = Array.FindIndex(renamedFiles, Items => Items.Contains(item.Name)); } if ((path == targetPath) || (index != -1)) { item.Path = rootPath + item.FilterPath + item.Name; item.Name = await FileRename(targetPath, item.Name); MoveSubFolder(item, targetPath); copiedFiles.Add(GetFileDetails(targetPath, item)); } else { existFiles.Add(item.Name); } } else { item.Path = rootPath + item.FilterPath + item.Name; MoveSubFolder(item, targetPath); copiedFiles.Add(GetFileDetails(targetPath, item)); } } } CloudBlobDirectory directory = (CloudBlobDirectory)item; moveResponse.Files = copiedFiles; CloudBlobDirectory directory1 = container.GetDirectoryReference(targetPath); if (existFiles.Count > 0) { ErrorDetails er = new ErrorDetails(); er.FileExists = existFiles; er.Code = "400"; er.Message = "File Already Exists"; moveResponse.Error = er; } if (missingFiles.Count > 0) { var nameList = missingFiles[0]; for (int k = 1; k < missingFiles.Count; k++) { nameList = nameList + ", " + missingFiles[k]; } throw new FileNotFoundException(nameList + " not found in given location."); } return(moveResponse); } catch (Exception e) { ErrorDetails er = new ErrorDetails(); er.Code = "404"; er.Message = e.Message.ToString(); er.FileExists = moveResponse.Error?.FileExists; moveResponse.Error = er; return(moveResponse); } }
private ErrorRecord NewError(string errorId, string resourceId, object targetObject, params object[] args) { ErrorDetails details = new ErrorDetails(base.GetType().Assembly, "UpdateDataStrings", resourceId, args); return(new ErrorRecord(new InvalidOperationException(details.Message), errorId, ErrorCategory.InvalidOperation, targetObject)); }
private ErrorDetails ProcessApiCallFailedException(ApiCallFailedException apiCallFailedException) { ErrorDetails returnValue = new ErrorDetails(_httpContext.TraceIdentifier, apiCallFailedException.StatusCode, apiCallFailedException.Message); return(returnValue); }
// Renames file(s) or folder(s) public async Task <FileManagerResponse> RenameAsync(string path, string oldName, string newName, params FileManagerDirectoryContent[] selectedItems) { FileManagerResponse renameResponse = new FileManagerResponse(); List <FileManagerDirectoryContent> details = new List <FileManagerDirectoryContent>(); CloudBlobDirectory directory = (CloudBlobDirectory)item; FileManagerDirectoryContent entry = new FileManagerDirectoryContent(); bool isAlreadyAvailable = false; bool isFile = false; foreach (var Fileitem in selectedItems) { FileManagerDirectoryContent s_item = Fileitem; isFile = s_item.IsFile; if (isFile) { isAlreadyAvailable = await IsFileExists(path + newName); } else { isAlreadyAvailable = await IsFolderExists(path + newName); } entry.Name = newName; entry.Type = s_item.Type; entry.IsFile = isFile; entry.Size = s_item.Size; entry.HasChild = s_item.HasChild; entry.FilterPath = path; details.Add(entry); break; } if (!isAlreadyAvailable) { if (isFile) { CloudBlob existBlob = container.GetBlobReference(path + oldName); CloudBlob newBlob = container.GetBlobReference(path + newName); await newBlob.StartCopyAsync(existBlob.Uri); await existBlob.DeleteIfExistsAsync(); } else { CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path + oldName); var items = await AsyncReadCall(path + oldName, "Rename"); foreach (var item in items.Results) { string name = item.Uri.AbsolutePath.Replace(sampleDirectory.Uri.AbsolutePath, "").Replace("%20", " "); CloudBlob newBlob = container.GetBlobReference(path + newName + "/" + name); await newBlob.StartCopyAsync(item.Uri); await container.GetBlobReference(path + oldName + "/" + name).DeleteAsync(); } } renameResponse.Files = (IEnumerable <FileManagerDirectoryContent>)details; } else { ErrorDetails er = new ErrorDetails(); er.FileExists = existFiles; er.Code = "400"; er.Message = "File or Folder Already Already Exists"; renameResponse.Error = er; } return(renameResponse); }
private void UpdatePanel() { base.SuspendLayout(); base.CaptionStrip.SuspendLayout(); try { WorkUnit workUnit = this.WorkUnit; if (workUnit != null) { this.Text = workUnit.Text; base.Icon = workUnit.Icon; if (this.descriptionLabel.Links.Count > 0) { this.descriptionLabel.Links.Clear(); } WorkUnitStatus status = workUnit.Status; this.UpdateProgressBar(status); bool flag = true; bool flag2 = true; TaskState taskState = 0; if (base.Parent is WorkUnitsPanel) { taskState = ((WorkUnitsPanel)base.Parent).TaskState; flag = (taskState != null && status != WorkUnitStatus.NotStarted); flag2 = (taskState == null || (taskState == 1 && status == WorkUnitStatus.InProgress) || (taskState == 1 && status == WorkUnitStatus.NotStarted)); } base.StatusVisible = (status != WorkUnitStatus.InProgress); string status2 = LocalizedDescriptionAttribute.FromEnum(typeof(WorkUnitStatus), status); StringBuilder stringBuilder = new StringBuilder(2048); if (flag2) { if (taskState == 1 && status == WorkUnitStatus.InProgress) { string text = (workUnit.StatusDescription == null) ? null : workUnit.StatusDescription.Trim(); if (!string.IsNullOrEmpty(text)) { stringBuilder.AppendLine(Strings.StatusDescription(text)); } } else { string value = (workUnit.Description == null) ? null : workUnit.Description.Trim(); if (!string.IsNullOrEmpty(value)) { stringBuilder.AppendLine(value); } } } string executedCommandTextForWorkUnit = workUnit.ExecutedCommandTextForWorkUnit; switch (status) { case WorkUnitStatus.NotStarted: base.StatusImage = null; base.Status = ""; if (taskState == 1) { base.Status = Strings.WorkUnitStatusPending; } else if (taskState == 2) { base.Status = Strings.WorkUnitStatusCancelled; base.StatusImage = WorkUnitPanel.warning; if (workUnit.CanShowExecutedCommand && !string.IsNullOrEmpty(executedCommandTextForWorkUnit)) { stringBuilder.AppendLine(Strings.MshCommandExecutedFailed(executedCommandTextForWorkUnit)); } } break; case WorkUnitStatus.InProgress: base.Status = ""; base.StatusImage = null; break; case WorkUnitStatus.Completed: if (!flag2) { base.Status = status2; base.StatusImage = ((workUnit.Warnings.Count == 0) ? WorkUnitPanel.completed : WorkUnitPanel.warning); if (workUnit.Warnings.Count > 0) { stringBuilder.AppendLine(workUnit.WarningsDescription); } if (workUnit.CanShowExecutedCommand && !string.IsNullOrEmpty(executedCommandTextForWorkUnit)) { stringBuilder.AppendLine(Strings.MshCommandExecutedSuccessfully(executedCommandTextForWorkUnit)); } } break; case WorkUnitStatus.Failed: if (!flag2) { base.FastSetIsMinimized(false); base.Status = status2; base.StatusImage = WorkUnitPanel.failed; if (workUnit.Errors.Count > 0) { for (int i = 0; i < workUnit.Errors.Count; i++) { stringBuilder.AppendLine(Strings.WorkUnitError); ErrorRecord errorRecord = workUnit.Errors[i]; ErrorDetails errorDetails = errorRecord.ErrorDetails; string text2 = null; if (errorDetails != null && !string.IsNullOrEmpty(errorDetails.RecommendedAction)) { text2 = errorDetails.RecommendedAction; } else { LocalizedException ex = errorRecord.Exception as LocalizedException; if (ex != null) { Uri uri = null; if (Microsoft.Exchange.CommonHelpProvider.HelpProvider.TryGetErrorAssistanceUrl(ex, out uri)) { text2 = uri.ToString(); } } } if (errorDetails != null) { if (!string.IsNullOrEmpty(errorDetails.Message)) { stringBuilder.AppendLine(errorDetails.Message); } } else { Exception ex2 = errorRecord.Exception; string text3 = ""; while (ex2 != null) { if (ex2.Message != text3) { text3 = ex2.Message; stringBuilder.AppendLine(text3); } ex2 = ex2.InnerException; if (ex2 != null) { stringBuilder.AppendLine(); } } } if (!string.IsNullOrEmpty(text2)) { string value2 = Strings.WorkUnitErrorAssistanceLink; LinkLabel.Link link = new LinkLabel.Link(); link.LinkData = text2; link.Start = new StringInfo(stringBuilder.ToString()).LengthInTextElements; link.Length = new StringInfo(value2).LengthInTextElements; this.descriptionLabel.Links.Add(link); stringBuilder.AppendLine(value2); } if (i < workUnit.Errors.Count - 1) { stringBuilder.AppendLine(); } } } if (workUnit.Warnings.Count > 0) { if (workUnit.Errors.Count > 0) { stringBuilder.AppendLine(); } stringBuilder.AppendLine(workUnit.WarningsDescription); } if (workUnit.CanShowExecutedCommand && !string.IsNullOrEmpty(executedCommandTextForWorkUnit)) { if (workUnit.Warnings.Count > 0 || workUnit.Errors.Count > 0) { stringBuilder.AppendLine(); } stringBuilder.AppendLine(Strings.MshCommandExecutedFailed(executedCommandTextForWorkUnit)); } } break; } if (workUnit.CanShowElapsedTime && flag) { stringBuilder.AppendLine(); stringBuilder.AppendLine(workUnit.ElapsedTimeText); } this.Description = stringBuilder.ToString().Trim(); this.TimerEnabled = (status == WorkUnitStatus.InProgress); } } finally { base.CaptionStrip.ResumeLayout(false); base.CaptionStrip.PerformLayout(); base.ResumeLayout(); } }
internal ErrorResponse(ErrorDetails error) { Error = error; }
/// <summary> /// Get the operation result for a long running operation. /// </summary> /// <param name='locationName'> /// The location of the operation. /// </param> /// <param name='operationResultId'> /// The ID of the operation result to get. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="ErrorDetailsException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <object> > GetWithHttpMessagesAsync(string locationName, string operationResultId, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (locationName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "locationName"); } if (operationResultId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "operationResultId"); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("locationName", locationName); tracingParameters.Add("operationResultId", operationResultId); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/providers/Microsoft.HealthcareApis/locations/{locationName}/operationresults/{operationResultId}").ToString(); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{locationName}", System.Uri.EscapeDataString(locationName)); _url = _url.Replace("{operationResultId}", System.Uri.EscapeDataString(operationResultId)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("GET"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 404) { var ex = new ErrorDetailsException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); ErrorDetails _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <ErrorDetails>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <object>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <OperationResultsDescription>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } // Deserialize Response if ((int)_statusCode == 404) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <ErrorDetails>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
private void BeforeNavigate2(object pDisp, ref object url, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel) { _error = null; }
/// <summary> /// Update the state of the specified private endpoint connection associated /// with the workspace. /// </summary> /// <param name='resourceGroupName'> /// The name of the resource group that contains the service instance. /// </param> /// <param name='workspaceName'> /// The name of workspace resource. /// </param> /// <param name='privateEndpointConnectionName'> /// The name of the private endpoint connection associated with the Azure /// resource /// </param> /// <param name='properties'> /// The private endpoint connection properties. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="ErrorDetailsException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <PrivateEndpointConnectionDescription> > BeginCreateOrUpdateWithHttpMessagesAsync(string resourceGroupName, string workspaceName, string privateEndpointConnectionName, PrivateEndpointConnectionDescription properties, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); } if (resourceGroupName != null) { if (resourceGroupName.Length > 90) { throw new ValidationException(ValidationRules.MaxLength, "resourceGroupName", 90); } if (resourceGroupName.Length < 1) { throw new ValidationException(ValidationRules.MinLength, "resourceGroupName", 1); } if (!System.Text.RegularExpressions.Regex.IsMatch(resourceGroupName, "^[-\\w\\._\\(\\)]+$")) { throw new ValidationException(ValidationRules.Pattern, "resourceGroupName", "^[-\\w\\._\\(\\)]+$"); } } if (workspaceName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "workspaceName"); } if (workspaceName != null) { if (workspaceName.Length > 24) { throw new ValidationException(ValidationRules.MaxLength, "workspaceName", 24); } if (workspaceName.Length < 3) { throw new ValidationException(ValidationRules.MinLength, "workspaceName", 3); } } if (privateEndpointConnectionName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "privateEndpointConnectionName"); } if (properties == null) { throw new ValidationException(ValidationRules.CannotBeNull, "properties"); } if (properties != null) { properties.Validate(); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("workspaceName", workspaceName); tracingParameters.Add("privateEndpointConnectionName", privateEndpointConnectionName); tracingParameters.Add("properties", properties); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "BeginCreateOrUpdate", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HealthcareApis/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName}").ToString(); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{workspaceName}", System.Uri.EscapeDataString(workspaceName)); _url = _url.Replace("{privateEndpointConnectionName}", System.Uri.EscapeDataString(privateEndpointConnectionName)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (properties != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(properties, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new ErrorDetailsException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); ErrorDetails _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <ErrorDetails>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <PrivateEndpointConnectionDescription>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <PrivateEndpointConnectionDescription>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
void NavigateError(object pDisp, ref object url, ref object frame, ref object statusCode, ref bool cancel) { _error = new ErrorDetails((string)url, (int)statusCode); }
/// <summary> /// Initializes a new <see cref="Error" />. /// </summary> /// <param name="error">Inner error details</param> public Error(ErrorDetails details) { Details = details; }
internal ZmqSocketException(ErrorDetails errorDetails) : base(errorDetails) { }
/// <summary> /// The Get Task Status returns the status of the specified task id. /// After calling an asynchronous task, you can call Get Task Status /// to determine whether the task has succeeded, failed, or is still /// in progress. /// </summary> /// <param name='taskId'> /// Required. The task Id for the request you wish to track. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// Info about the async task /// </returns> public async Task <TaskStatusInfo> GetOperationStatusAsync(string taskId, CancellationToken cancellationToken) { // Validate if (taskId == null) { throw new ArgumentNullException("taskId"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("taskId", taskId); TracingAdapter.Enter(invocationId, this, "GetOperationStatusAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/"; if (this.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Credentials.SubscriptionId); } url = url + "/cloudservices/"; url = url + Uri.EscapeDataString(this.CloudServiceName); url = url + "/resources/"; url = url + Uri.EscapeDataString(this.ResourceNamespace); url = url + "/~/"; url = url + "CisVault"; url = url + "/"; url = url + Uri.EscapeDataString(this.ResourceName); url = url + "/api/jobs/"; url = url + Uri.EscapeDataString(taskId); List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2014-01-01.1.0"); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept", "application/xml"); httpRequest.Headers.Add("x-ms-version", "2014-01-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result TaskStatusInfo result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new TaskStatusInfo(); XDocument responseDoc = XDocument.Parse(responseContent); XElement jobStatusInfoElement = responseDoc.Element(XName.Get("JobStatusInfo", "http://windowscloudbackup.com/CiS/V2013_03")); if (jobStatusInfoElement != null) { XElement jobIdElement = jobStatusInfoElement.Element(XName.Get("JobId", "http://windowscloudbackup.com/CiS/V2013_03")); if (jobIdElement != null) { string jobIdInstance = jobIdElement.Value; result.TaskId = jobIdInstance; } XElement statusElement = jobStatusInfoElement.Element(XName.Get("Status", "http://windowscloudbackup.com/CiS/V2013_03")); if (statusElement != null) { AsyncTaskStatus statusInstance = ((AsyncTaskStatus)Enum.Parse(typeof(AsyncTaskStatus), statusElement.Value, true)); result.Status = statusInstance; } XElement resultElement = jobStatusInfoElement.Element(XName.Get("Result", "http://windowscloudbackup.com/CiS/V2013_03")); if (resultElement != null) { AsyncTaskResult resultInstance = ((AsyncTaskResult)Enum.Parse(typeof(AsyncTaskResult), resultElement.Value, true)); result.Result = resultInstance; } XElement errorElement = jobStatusInfoElement.Element(XName.Get("Error", "http://windowscloudbackup.com/CiS/V2013_03")); if (errorElement != null) { ErrorDetails errorInstance = new ErrorDetails(); result.Error = errorInstance; XElement codeElement = errorElement.Element(XName.Get("Code", "http://schemas.microsoft.com/wars")); if (codeElement != null) { string codeInstance = codeElement.Value; errorInstance.Code = codeInstance; } XElement messageElement = errorElement.Element(XName.Get("Message", "http://schemas.microsoft.com/wars")); if (messageElement != null) { string messageInstance = messageElement.Value; errorInstance.Message = messageInstance; } } XElement taskResultElement = jobStatusInfoElement.Element(XName.Get("TaskResult", "http://windowscloudbackup.com/CiS/V2013_03")); if (taskResultElement != null) { AsyncTaskAggregatedResult taskResultInstance = ((AsyncTaskAggregatedResult)Enum.Parse(typeof(AsyncTaskAggregatedResult), taskResultElement.Value, true)); result.AsyncTaskAggregatedResult = taskResultInstance; } XElement jobStepsSequenceElement = jobStatusInfoElement.Element(XName.Get("JobSteps", "http://windowscloudbackup.com/CiS/V2013_03")); if (jobStepsSequenceElement != null) { foreach (XElement jobStepsElement in jobStepsSequenceElement.Elements(XName.Get("JobStep", "http://windowscloudbackup.com/CiS/V2013_03"))) { TaskStep jobStepInstance = new TaskStep(); result.TaskSteps.Add(jobStepInstance); XElement messageElement2 = jobStepsElement.Element(XName.Get("Message", "http://windowscloudbackup.com/CiS/V2013_03")); if (messageElement2 != null) { string messageInstance2 = messageElement2.Value; jobStepInstance.Message = messageInstance2; } XElement statusElement2 = jobStepsElement.Element(XName.Get("Status", "http://windowscloudbackup.com/CiS/V2013_03")); if (statusElement2 != null) { AsyncTaskStatus statusInstance2 = ((AsyncTaskStatus)Enum.Parse(typeof(AsyncTaskStatus), statusElement2.Value, true)); jobStepInstance.Status = statusInstance2; } XElement resultElement2 = jobStepsElement.Element(XName.Get("Result", "http://windowscloudbackup.com/CiS/V2013_03")); if (resultElement2 != null) { AsyncTaskResult resultInstance2 = ((AsyncTaskResult)Enum.Parse(typeof(AsyncTaskResult), resultElement2.Value, true)); jobStepInstance.Result = resultInstance2; } XElement detailElement = jobStepsElement.Element(XName.Get("Detail", "http://windowscloudbackup.com/CiS/V2013_03")); if (detailElement != null) { string detailInstance = detailElement.Value; jobStepInstance.Detail = detailInstance; } XElement errorCodeElement = jobStepsElement.Element(XName.Get("ErrorCode", "http://windowscloudbackup.com/CiS/V2013_03")); if (errorCodeElement != null) { string errorCodeInstance = errorCodeElement.Value; jobStepInstance.ErrorCode = errorCodeInstance; } } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }