Ejemplo n.º 1
0
        /// <summary>
        ///   Checks the state of an existing Feature.
        /// </summary>
        /// <param name = "request"><see cref = "CheckFeatureStateRequest" /> instance that defines the criteria by which the Feature will be queried.</param>
        /// <returns>
        ///   <see cref = "CheckFeatureStateResponse" /> containing the results of the request for the state of a Feature.
        /// </returns>
        public CheckFeatureStateResponse CheckFeatureState(CheckFeatureStateRequest request)
        {
            CheckFeatureStateResponse response;

            using (PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.CheckFeatureState))
            {
                Feature feature;

                try
                {
                    feature = m_StorageContainer.Retrieve(request.Key);
                }
                catch (Exception e)
                {
                    CheckFeatureStateException checkFeatureStateException =
                        new CheckFeatureStateException(
                            string.Format(
                                CultureInfo.CurrentUICulture,
                                ExceptionMessageResources.CHECK_FEATURE_STATE_EXCEPTION,
                                request.Key.Id,
                                request.Key.Space),
                            e);
                    m_Logger.Error(checkFeatureStateException);

                    throw checkFeatureStateException;
                }

                response = CheckFeatureStateResponse.Create(request.Header.MessageId, feature);
                LogInteraction(request, response);
            }

            return(response);
        }
        public void PerformanceCounterReporterReportsCountAndElapsedTime()
        {
            using (PerformanceCounterReporterFactory.CreateReporter(
                       PerformanceCounterCategoryTestManager.SampleCounterCategoryName,
                       PerformanceCounterCategoryTestManager.SampleOperationCounterName,
                       PerformanceCounterCategoryTestManager.SampleExecutionTimeCounterName))
            {
                Thread.Sleep(250);
            }

            float operationCount =
                new PerformanceCounter(
                    PerformanceCounterCategoryTestManager.SampleCounterCategoryName,
                    PerformanceCounterCategoryTestManager.SampleOperationCounterName,
                    true).NextValue();

            Assert.AreEqual(1.0, operationCount);

            float executionTime =
                new PerformanceCounter(
                    PerformanceCounterCategoryTestManager.SampleCounterCategoryName,
                    PerformanceCounterCategoryTestManager.SampleExecutionTimeCounterName,
                    true).NextValue();

            Assert.IsTrue(executionTime > 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Stores a feature that can be queried and updated.
        /// </summary>
        /// <param name = "request"><see cref = "CreateFeatureRequest" /> instance that defines the state required to create a new Feature.</param>
        /// <returns>
        ///   <see cref = "CreateFeatureResponse" /> containing the results of the request to create a new Feature.
        /// </returns>
        public CreateFeatureResponse CreateFeature(CreateFeatureRequest request)
        {
            CreateFeatureResponse response;

            using (PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.CreateFeature))
            {
                Feature feature;

                EnsureOwnerId(request.Feature);
                CheckDuplicateKey(request.Feature);

                try
                {
                    feature = m_StorageContainer.Store(request.Feature);
                }
                catch (Exception e)
                {
                    CreateFeatureException createFeatureException =
                        new CreateFeatureException(ExceptionMessageResources.FEATURE_CREATION_EXCEPTION, e);
                    m_Logger.Error(createFeatureException);

                    throw createFeatureException;
                }

                response = CreateFeatureResponse.Create(request.Header.MessageId, feature);
                LogInteraction(request, response);
            }

            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Retrieves the defined features.
        /// </summary>
        /// <param name = "request"><see cref = "RetrieveDefinedFeaturesRequest" /> instance containing the criteria by which the <see
        ///    cref = "Feature" />s are selected.</param>
        /// <returns>
        ///   <see cref = "RetrieveDefinedFeaturesResponse" /> instance containing the results based on the given criteria.
        /// </returns>
        public RetrieveDefinedFeaturesResponse RetrieveDefinedFeatures(RetrieveDefinedFeaturesRequest request)
        {
            RetrieveDefinedFeaturesResponse response;

            using (PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.RetrieveDefinedFeatures))
            {
                IList <Feature> features;
                try
                {
                    features = m_StorageContainer.Retrieve(request.FeatureScope);
                }
                catch (Exception)
                {
                    RetrieveDefinedFeaturesException retrieveDefinedFeaturesException =
                        new RetrieveDefinedFeaturesException(
                            string.Format(
                                CultureInfo.CurrentUICulture,
                                ExceptionMessageResources.RETRIEVE_DEFINED_FEATURES_EXCEPTION,
                                request.FeatureScope.OwnerId,
                                request.FeatureScope.Space));
                    m_Logger.Error(retrieveDefinedFeaturesException);

                    throw retrieveDefinedFeaturesException;
                }

                response = RetrieveDefinedFeaturesResponse.Create(request.Header.MessageId, features);
                LogInteraction(request, response);
            }

            return(response);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///   Updates the state of a specified feature.
        /// </summary>
        /// <param name = "request"><see cref = "UpdateFeatureStateRequest" /> instance that defines the state necessary to update a specified Feature.</param>
        /// <returns>
        ///   <see cref = "UpdateFeatureStateResponse" /> containing the results of the request to update the state of a specified Feature.
        /// </returns>
        public UpdateFeatureStateResponse UpdateFeatureState(UpdateFeatureStateRequest request)
        {
            UpdateFeatureStateResponse response;

            using (PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.UpdateFeatureState))
            {
                Feature updatedFeature;

                try
                {
                    Feature feature = m_StorageContainer.Retrieve(request.Key);

                    if (feature == null)
                    {
                        throw new UpdateFeatureStateException(
                                  string.Format(
                                      CultureInfo.CurrentUICulture,
                                      ExceptionMessageResources.FEATURE_NOT_FOUND,
                                      request.Key.Id,
                                      request.Key.Space));
                    }

                    feature.Enabled = request.NewState;

                    updatedFeature = m_StorageContainer.Store(feature);
                }
                catch (Exception e)
                {
                    UpdateFeatureStateException updateFeatureStateException =
                        new UpdateFeatureStateException(
                            string.Format(
                                CultureInfo.CurrentUICulture,
                                ExceptionMessageResources.UPDATE_FEATURE_STATE_EXCEPTION,
                                request.Key.Id,
                                request.Key.Space),
                            e);
                    m_Logger.Error(updateFeatureStateException);

                    throw updateFeatureStateException;
                }

                response = UpdateFeatureStateResponse.Create(request.Header.MessageId, updatedFeature);
                LogInteraction(request, response);
            }

            return(response);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Asserts the performance counters recorded.
        /// </summary>
        /// <param name="reporterType">Type of the reporter.</param>
        /// <param name="checkExecutionTime">if set to <c>true</c> [check execution time].</param>
        /// <param name="expectedCount">The expected count.</param>
        /// <remarks></remarks>
        private static void AssertPerformanceCountersRecorded(PerformanceCounterReporterType reporterType,
                                                              bool checkExecutionTime, int expectedCount)
        {
            PerformanceCounterReporter counterRecorder = PerformanceCounterReporterFactory.CreateReporter(reporterType);

            Assert.AreEqual(expectedCount, counterRecorder.OperationCountValue);

            Assert.IsTrue(counterRecorder.OperationCountValue > 0);
            float executionTime = counterRecorder.ExecutionTimeValue;

            Console.WriteLine(@"The execution time was reported as " + executionTime);

            // The CheckFeatureState method smokes the millisecond barrier at these cache sizes,
            // therefore this check is disabled for that method.
            if (checkExecutionTime)
            {
                Assert.IsTrue(executionTime > 0);
            }
        }
        public void PerformanceCounterReporterFactoryCreatesInstances()
        {
            try
            {
                PerformanceCounterRegistrar.EnsureExist();

                PerformanceCounterReporter reporter =
                    PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.CreateFeature);
                Assert.IsNotNull(reporter);

                reporter =
                    PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.CheckFeatureState);
                Assert.IsNotNull(reporter);

                reporter =
                    PerformanceCounterReporterFactory.CreateReporter(PerformanceCounterReporterType.UpdateFeatureState);
                Assert.IsNotNull(reporter);
            }
            finally
            {
                PerformanceCounterRegistrar.Remove();
            }
        }