Beispiel #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            Microsoft.Extensions.Logging.ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name = name ?? data?.name;

            var clientConfiguration = new LazyLoadConfiguration
            {
                SdkKey = "f3vYCGwC00OC4a_P2E5x4w/U6mbty2Tq0aCDCws85-xvw", // <-- This is the actual SDK Key for your Production environment
                CacheTimeToLiveSeconds = 1
            };
            IConfigCatClient client = new ConfigCatClient(clientConfiguration);

            User user = new User("returning"); // Unique identifier is required. Could be UserID, Email address or SessionID.

            var costumerflag            = client.GetValue("costumerflag", false, user);
            var isAwesomeFeatureEnabled = client.GetValue("isAwesomeFeatureEnabled", false, user);

            Console.WriteLine("costumerflag's value from ConfigCat: " + costumerflag);
            Console.WriteLine("isAwesomeFeatureEnabled's value from ConfigCat: " + isAwesomeFeatureEnabled);

            string responseMessage = costumerflag
                ? $"Welcome back, {name}!"
                : $"Welcome {name}!";

            return(new OkObjectResult(responseMessage));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Creating the ConfigCat client instance using the SDK Key
            var client = new ConfigCatClient("PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ");

            // Setting log level to Info to show detailed feature flag evaluation
            client.LogLevel = LogLevel.Info;

            // Creating a user object to identify the user (optional)
            User user = new User("<SOME USERID>")
            {
                Country = "US",
                Email   = "*****@*****.**",
                Custom  =
                {
                    { "SubscriptionType", "Pro"   },
                    { "Role",             "Admin" },
                    { "version",          "1.0.0" }
                }
            };

            // Accessing feature flag or setting value
            var value = client.GetValue("isPOCFeatureEnabled", false, user);

            Console.WriteLine($"isPOCFeatureEnabled: {value}");
        }
        public IActionResult Index()
        {
            var userEmail = HttpContext.User.Claims.Where(claim => claim.Type == "email").Select(claim => claim.Value).FirstOrDefault();
            var user      = new User(userEmail)
            {
                Email = userEmail
            };
            var client             = new ConfigCatClient("tNHYCC8Nm0OPXt2LxXT4zQ/k-5ZmLLd10isguXVF6PrTw");
            var twitterFeedVisible = client.GetValue("twitterFeedVisible", false, user);

            return(View(twitterFeedVisible));
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            string   filePath = System.IO.Path.Combine(Environment.CurrentDirectory, "configcat.log");
            LogLevel logLevel = LogLevel.Warning; // I would like to log only WARNING and higher entires (Warnings and Errors).

            var clientConfiguration = new AutoPollConfiguration
            {
                SdkKey = "YOUR-SDK-KEY",
                Logger = new MyFileLogger(filePath, logLevel),
                PollIntervalSeconds = 5
            };

            IConfigCatClient client = new ConfigCatClient(clientConfiguration);

            var feature = client.GetValue("keyNotExists", "N/A");

            Console.ReadKey();
        }
        public void GetValue_EvaluateServiceThrowException_ShouldReturnDefaultValue()
        {
            // Arrange

            const string defaultValue = "Victory for the Firstborn!";

            evaluatorMock
            .Setup(m => m.Evaluate(It.IsAny <ProjectConfig>(), It.IsAny <string>(), defaultValue, null))
            .Throws <Exception>();

            var client = new ConfigCatClient(configServiceMock.Object, loggerMock.Object, evaluatorMock.Object, configDeserializerMock.Object);

            // Act

            var actual = client.GetValue(null, defaultValue);

            // Assert

            Assert.AreEqual(defaultValue, actual);
        }
        public void GetValue_ConfigServiceThrowException_ShouldReturnDefaultValue()
        {
            // Arrange

            const string defaultValue = "Victory for the Firstborn!";

            configService
            .Setup(m => m.GetConfigAsync())
            .Throws <Exception>();

            var client = new ConfigCatClient(configService.Object, loggerMock.Object, evaluateMock.Object);

            // Act

            var actual = client.GetValue(null, defaultValue);

            // Assert

            Assert.AreEqual(defaultValue, actual);
        }
Beispiel #7
0
        private void ExecuteManualCommand()
        {
            client_manual.ForceRefresh();

            ToggleB = client_manual.GetValue("toggleb", false);
        }
Beispiel #8
0
 private void ExecuteAutoCommand()
 {
     ToggleB = client_auto.GetValue("toggleb", false);
 }
Beispiel #9
0
 private void ExecuteVerificarCommand()
 {
     ToggleA = client_verificar.GetValue("togglea", false);
 }
 public T GetSetting <T>(string settingName, T defaultValue)
 {
     return(_configClient.GetValue(settingName, defaultValue));
 }