コード例 #1
0
        /// <summary>
        /// Compares properties of expected and response
        /// </summary>
        private static void CompareRecommendedActionProperties(RecommendedAction expected, RecommendedAction response, string expectedState = null)
        {
            Assert.Equal(expected.Properties.RecommendationReason, response.Properties.RecommendationReason);
            Assert.Equal(expected.Properties.ValidSince, response.Properties.ValidSince);
            Assert.Equal(expected.Properties.LastRefresh, response.Properties.LastRefresh);
            Assert.Equal(expected.Properties.State.ActionInitiatedBy, response.Properties.State.ActionInitiatedBy);
            Assert.Equal(expectedState ?? expected.Properties.State.CurrentValue, response.Properties.State.CurrentValue);
            Assert.Equal(expected.Properties.State.LastModified, response.Properties.State.LastModified);

            Assert.Equal(expected.Properties.IsExecutableAction, response.Properties.IsExecutableAction);
            Assert.Equal(expected.Properties.IsRevertableAction, response.Properties.IsRevertableAction);
            Assert.Equal(expected.Properties.IsArchivedAction, response.Properties.IsArchivedAction);

            Assert.Equal(expected.Properties.ExecuteActionStartTime, response.Properties.ExecuteActionStartTime);
            Assert.Equal(expected.Properties.ExecuteActionDuration, response.Properties.ExecuteActionDuration);
            Assert.Equal(expected.Properties.RevertActionStartTime, response.Properties.RevertActionStartTime);
            Assert.Equal(expected.Properties.RevertActionDuration, response.Properties.RevertActionDuration);

            Assert.Equal(expected.Properties.ExecuteActionInitiatedBy, response.Properties.ExecuteActionInitiatedBy);
            Assert.Equal(expected.Properties.ExecuteActionInitiatedTime, response.Properties.ExecuteActionInitiatedTime);
            Assert.Equal(expected.Properties.RevertActionInitiatedBy, response.Properties.RevertActionInitiatedBy);
            Assert.Equal(expected.Properties.RevertActionInitiatedTime, response.Properties.RevertActionInitiatedTime);
            Assert.Equal(expected.Properties.Score, response.Properties.Score);

            CompareRecommendedActionImplementationInfo(expected.Properties.ImplementationDetails, response.Properties.ImplementationDetails);
            CompareRecommendedActionErrorInfo(expected.Properties.ErrorDetails, response.Properties.ErrorDetails);
            CompareRecommendedActionImpactInfo(expected.Properties.EstimatedImpact, response.Properties.EstimatedImpact);
            CompareRecommendedActionImpactInfo(expected.Properties.ObservedImpact, response.Properties.ObservedImpact);
            CompareRecommendedActionMetricInfo(expected.Properties.TimeSeries, response.Properties.TimeSeries);
            CompareRecommendedActionLinkedObjects(expected.Properties.LinkedObjects, response.Properties.LinkedObjects);
            CompareRecommendedActionDetails(expected.Properties.Details, response.Properties.Details);
        }
コード例 #2
0
ファイル: SmartPosterRecord.cs プロジェクト: zerenat/testRepo
        public override void ParseJSON(JSONObject jsonObject)
        {
            base.ParseJSON(jsonObject);

            JSONObject uriRecordJSON;

            if (jsonObject.TryGetObject("uri_record", out uriRecordJSON))
            {
                uriRecord = new UriRecord(uriRecordJSON);
            }

            titleRecords = new List <TextRecord>();
            JSONArray titleRecordsJSON;

            if (jsonObject.TryGetArray("title_records", out titleRecordsJSON))
            {
                int length = titleRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    titleRecords.Add(new TextRecord(titleRecordsJSON[i].Object));
                }
            }

            iconRecords = new List <MimeMediaRecord>();
            JSONArray iconRecordsJSON;

            if (jsonObject.TryGetArray("icon_records", out iconRecordsJSON))
            {
                int length = iconRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    iconRecords.Add(new MimeMediaRecord(iconRecordsJSON[i].Object));
                }
            }

            extraRecords = new List <NDEFRecord>();
            JSONArray extraRecordsJSON;

            if (jsonObject.TryGetArray("extra_records", out extraRecordsJSON))
            {
                int length = extraRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    extraRecords.Add(new MimeMediaRecord(extraRecordsJSON[i].Object));
                }
            }

            int actionValue;

            jsonObject.TryGetInt("action", out actionValue);
            action = (RecommendedAction)actionValue;

            jsonObject.TryGetInt("size", out size);
            jsonObject.TryGetString("mime_type", out mimeType);
        }
コード例 #3
0
        /// <summary>
        /// Validates single recommended action object
        /// </summary>
        private static void ValidateSingleRecommendedAction(RecommendedAction response, string expectedResponseType, string expectedState = null)
        {
            Assert.NotNull(response);

            RecommendedAction expected = CreateRecommendedActionListForValidation().SingleOrDefault(a => a.Name.Equals(response.Name));

            Assert.NotNull(expected);

            Assert.Equal(expectedResponseType, response.Type);
            CompareRecommendedActionProperties(expected, response, expectedState);
        }
コード例 #4
0
ファイル: SmartPosterRecord.cs プロジェクト: zerenat/testRepo
 public SmartPosterRecord(string uri, RecommendedAction action, int size, string mimeType, List <TextRecord> titleRecords, List <MimeMediaRecord> iconRecords, List <NDEFRecord> extraRecords)
 {
     this.type         = NDEFRecordType.SMART_POSTER;
     this.uriRecord    = new UriRecord(uri);
     this.titleRecords = titleRecords;
     this.iconRecords  = iconRecords;
     this.extraRecords = extraRecords;
     this.action       = action;
     this.size         = size;
     this.mimeType     = mimeType;
 }
コード例 #5
0
ファイル: SmartPosterRecord.cs プロジェクト: zerenat/testRepo
 public SmartPosterRecord(string uri, RecommendedAction action = RecommendedAction.UNKNOWN, int size = 0, string mimeType = "")
 {
     this.type         = NDEFRecordType.SMART_POSTER;
     this.uriRecord    = new UriRecord(uri);
     this.action       = action;
     this.size         = size;
     this.mimeType     = mimeType;
     this.titleRecords = new List <TextRecord>();
     this.iconRecords  = new List <MimeMediaRecord>();
     this.extraRecords = new List <NDEFRecord>();
 }
コード例 #6
0
ファイル: WriteErrorActivity.cs プロジェクト: x1m0/PowerShell
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Exception.Expression != null)
            {
                targetCommand.AddParameter("Exception", Exception.Get(context));
            }

            if (Message.Expression != null)
            {
                targetCommand.AddParameter("Message", Message.Get(context));
            }

            if (ErrorRecord.Expression != null)
            {
                targetCommand.AddParameter("ErrorRecord", ErrorRecord.Get(context));
            }

            if (Category.Expression != null)
            {
                targetCommand.AddParameter("Category", Category.Get(context));
            }

            if (ErrorId.Expression != null)
            {
                targetCommand.AddParameter("ErrorId", ErrorId.Get(context));
            }

            if (TargetObject.Expression != null)
            {
                targetCommand.AddParameter("TargetObject", TargetObject.Get(context));
            }

            if (RecommendedAction.Expression != null)
            {
                targetCommand.AddParameter("RecommendedAction", RecommendedAction.Get(context));
            }

            if (CategoryActivity.Expression != null)
            {
                targetCommand.AddParameter("CategoryActivity", CategoryActivity.Get(context));
            }

            if (CategoryReason.Expression != null)
            {
                targetCommand.AddParameter("CategoryReason", CategoryReason.Get(context));
            }

            if (CategoryTargetName.Expression != null)
            {
                targetCommand.AddParameter("CategoryTargetName", CategoryTargetName.Get(context));
            }

            if (CategoryTargetType.Expression != null)
            {
                targetCommand.AddParameter("CategoryTargetType", CategoryTargetType.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
コード例 #7
0
        /// <summary>
        /// Updates a database recommended action.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// The name of the resource group that contains the resource. You can obtain
        /// this value from the Azure Resource Manager API or the portal.
        /// </param>
        /// <param name='serverName'>
        /// The name of the server.
        /// </param>
        /// <param name='databaseName'>
        /// The name of the database.
        /// </param>
        /// <param name='advisorName'>
        /// The name of the Database Advisor.
        /// </param>
        /// <param name='recommendedActionName'>
        /// The name of Database Recommended Action.
        /// </param>
        /// <param name='parameters'>
        /// The requested recommended action resource state.
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="CloudException">
        /// 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 <RecommendedAction> > UpdateWithHttpMessagesAsync(string resourceGroupName, string serverName, string databaseName, string advisorName, string recommendedActionName, RecommendedAction parameters, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (resourceGroupName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "serverName");
            }
            if (databaseName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "databaseName");
            }
            if (advisorName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "advisorName");
            }
            if (recommendedActionName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "recommendedActionName");
            }
            if (parameters == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "parameters");
            }
            if (Client.SubscriptionId == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
            }
            string apiVersion = "2020-11-01-preview";
            // 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("serverName", serverName);
                tracingParameters.Add("databaseName", databaseName);
                tracingParameters.Add("advisorName", advisorName);
                tracingParameters.Add("recommendedActionName", recommendedActionName);
                tracingParameters.Add("parameters", parameters);
                tracingParameters.Add("apiVersion", apiVersion);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "Update", 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.Sql/servers/{serverName}/databases/{databaseName}/advisors/{advisorName}/recommendedActions/{recommendedActionName}").ToString();

            _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName));
            _url = _url.Replace("{serverName}", System.Uri.EscapeDataString(serverName));
            _url = _url.Replace("{databaseName}", System.Uri.EscapeDataString(databaseName));
            _url = _url.Replace("{advisorName}", System.Uri.EscapeDataString(advisorName));
            _url = _url.Replace("{recommendedActionName}", System.Uri.EscapeDataString(recommendedActionName));
            _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId));
            List <string> _queryParameters = new List <string>();

            if (apiVersion != null)
            {
                _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(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("PATCH");
            _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 (parameters != null)
            {
                _requestContent      = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, 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 CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                try
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <CloudError>(_responseContent, Client.DeserializationSettings);
                    if (_errorBody != null)
                    {
                        ex      = new CloudException(_errorBody.Message);
                        ex.Body = _errorBody;
                    }
                }
                catch (JsonException)
                {
                    // Ignore the exception
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_httpResponse.Headers.Contains("x-ms-request-id"))
                {
                    ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                }
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new AzureOperationResponse <RecommendedAction>();

            _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 <RecommendedAction>(_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);
        }
コード例 #8
0
        public override void ParseJSON(JSONObject jsonObject)
        {
            base.ParseJSON(jsonObject);

            JSONObject uriRecordJSON;

            if (jsonObject.TryGetObject("uri_record", out uriRecordJSON))
            {
                uriRecord = new UriRecord(uriRecordJSON);
            }

            titleRecords = new List <TextRecord>();
            JSONArray titleRecordsJSON;

            if (jsonObject.TryGetArray("title_records", out titleRecordsJSON))
            {
                int length = titleRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    titleRecords.Add(new TextRecord(titleRecordsJSON[i].Object));
                }
            }

            iconRecords = new List <MimeMediaRecord>();
            JSONArray iconRecordsJSON;

            if (jsonObject.TryGetArray("icon_records", out iconRecordsJSON))
            {
                int length = iconRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    iconRecords.Add(new MimeMediaRecord(iconRecordsJSON[i].Object));
                }
            }

            extraRecords = new List <NDEFRecord>();
            JSONArray extraRecordsJSON;

            if (jsonObject.TryGetArray("extra_records", out extraRecordsJSON))
            {
                int length = extraRecordsJSON.Length;
                for (int i = 0; i < length; i++)
                {
                    JSONObject     extraRecordJSON = extraRecordsJSON[i].Object;
                    NDEFRecord     record          = null;
                    NDEFRecordType type            = (NDEFRecordType)extraRecordJSON["type"].Integer;
                    switch (type)
                    {
                    case NDEFRecordType.ABSOLUTE_URI: record = new AbsoluteUriRecord(extraRecordJSON); break;

                    case NDEFRecordType.EMPTY: record = new EmptyRecord(extraRecordJSON); break;

                    case NDEFRecordType.EXTERNAL_TYPE: record = new ExternalTypeRecord(extraRecordJSON); break;

                    case NDEFRecordType.MIME_MEDIA: record = new MimeMediaRecord(extraRecordJSON); break;

                    case NDEFRecordType.SMART_POSTER: record = new SmartPosterRecord(extraRecordJSON); break;

                    case NDEFRecordType.TEXT: record = new TextRecord(extraRecordJSON); break;

                    case NDEFRecordType.UNKNOWN: record = new UnknownRecord(extraRecordJSON); break;

                    case NDEFRecordType.URI: record = new UriRecord(extraRecordJSON); break;

                    default: record = new UnknownRecord(extraRecordJSON); break;
                    }

                    extraRecords.Add(record);
                }
            }

            int actionValue;

            jsonObject.TryGetInt("action", out actionValue);
            action = (RecommendedAction)actionValue;

            jsonObject.TryGetInt("size", out size);
            jsonObject.TryGetString("mime_type", out mimeType);
        }
コード例 #9
0
 /// <summary>
 /// Updates a database recommended action.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the resource. You can obtain
 /// this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='serverName'>
 /// The name of the server.
 /// </param>
 /// <param name='databaseName'>
 /// The name of the database.
 /// </param>
 /// <param name='advisorName'>
 /// The name of the Database Advisor.
 /// </param>
 /// <param name='recommendedActionName'>
 /// The name of Database Recommended Action.
 /// </param>
 /// <param name='parameters'>
 /// The requested recommended action resource state.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <RecommendedAction> UpdateAsync(this IDatabaseRecommendedActionsOperations operations, string resourceGroupName, string serverName, string databaseName, string advisorName, string recommendedActionName, RecommendedAction parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serverName, databaseName, advisorName, recommendedActionName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #10
0
 /// <summary>
 /// Updates a database recommended action.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the resource. You can obtain
 /// this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='serverName'>
 /// The name of the server.
 /// </param>
 /// <param name='databaseName'>
 /// The name of the database.
 /// </param>
 /// <param name='advisorName'>
 /// The name of the Database Advisor.
 /// </param>
 /// <param name='recommendedActionName'>
 /// The name of Database Recommended Action.
 /// </param>
 /// <param name='parameters'>
 /// The requested recommended action resource state.
 /// </param>
 public static RecommendedAction Update(this IDatabaseRecommendedActionsOperations operations, string resourceGroupName, string serverName, string databaseName, string advisorName, string recommendedActionName, RecommendedAction parameters)
 {
     return(operations.UpdateAsync(resourceGroupName, serverName, databaseName, advisorName, recommendedActionName, parameters).GetAwaiter().GetResult());
 }