コード例 #1
0
        public HttpResponseMessage Get(EnvironmentEnum environment, PlatformEnum platform, string application = "ALL")
        {
            log.DebugFormat("GetAllForPlatform: {0}", platform.ToString());

            HttpResponseMessage response;

            try
            {
                var validationResult = VerifyProperties(platform, environment);

                if (validationResult.Errors.Count > 0)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, validationResult);
                    return(response);
                }

                var features = _jsonTogglerService.GetAllFeatureTogglesForPlatformAndApplication(platform, application);

                var ftResults = new List <FeatureToggleResult>();
                foreach (var feature in features)
                {
                    var ftResult = new FeatureToggleResult();
                    ftResult.Name         = feature.Name;
                    ftResult.IsEnabled    = feature.Platform.Has <PlatformEnum>(platform) && feature.Environment.Has <EnvironmentEnum>(environment);
                    ftResult.FilterValues = feature.FilterValues;
                    ftResult.CommandType  = feature.CommandType.HasValue ? (int)feature.CommandType.Value : 0;
                    ftResult.Command      = feature.Command;

                    if (feature.SubFeatureToggles != null && feature.SubFeatureToggles.Count > 0)
                    {
                        var subFeatures = new List <SubFeatureToggleResult>();
                        foreach (var subFeature in feature.SubFeatureToggles)
                        {
                            var subft = new SubFeatureToggleResult();

                            subft.Name         = subFeature.Name;
                            subft.IsEnabled    = subFeature.Platform.Has <PlatformEnum>(platform) && subFeature.Environment.Has <EnvironmentEnum>(environment);
                            subft.FilterValues = subFeature.FilterValues;
                            subft.CommandType  = subFeature.CommandType.HasValue ? (int)subFeature.CommandType.Value : 0;
                            subft.Command      = subFeature.Command;

                            subFeatures.Add(subft);
                        }

                        ftResult.SubFeatures = subFeatures;
                    }

                    ftResults.Add(ftResult);
                }

                response = Request.CreateResponse(HttpStatusCode.OK, ftResults);
            }
            catch (Exception ex)
            {
                log.Error("Error occurred", ex);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(response);
        }
コード例 #2
0
        public HttpResponseMessage Disabled()
        {
            log.Debug("Get Disabled features called.");

            HttpResponseMessage response;

            try
            {
                var features = _jsonTogglerService.GetAllFeatureToggles();

                var ftResults = new List <FeatureToggleResult>();
                foreach (var feature in features)
                {
                    if (feature.Environment == EnvironmentEnum.NONE)
                    {
                        var ftResult = new FeatureToggleResult();
                        ftResult.Name         = feature.Name;
                        ftResult.IsEnabled    = false;
                        ftResult.FilterValues = feature.FilterValues;
                        ftResult.CommandType  = feature.CommandType.HasValue ? (int)feature.CommandType.Value : 0;
                        ftResult.Command      = feature.Command;

                        if (feature.SubFeatureToggles != null && feature.SubFeatureToggles.Count > 0)
                        {
                            var subFeatures = new List <SubFeatureToggleResult>();
                            foreach (var subFeature in feature.SubFeatureToggles)
                            {
                                var subft = new SubFeatureToggleResult();

                                subft.Name         = subFeature.Name;
                                subft.IsEnabled    = false;
                                subft.FilterValues = subFeature.FilterValues;
                                subft.CommandType  = subFeature.CommandType.HasValue ? (int)subFeature.CommandType.Value : 0;
                                subft.Command      = subFeature.Command;

                                subFeatures.Add(subft);
                            }

                            ftResult.SubFeatures = subFeatures;
                        }

                        ftResults.Add(ftResult);
                    }
                }

                response = Request.CreateResponse(HttpStatusCode.OK, ftResults.OrderBy(o => o.Name));
            }
            catch (Exception ex)
            {
                log.Error("Error occurred", ex);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(response);
        }