protected override ProjectConfig Poll() { var datafile = GetRemoteDatafileResponse(); if (datafile == null) { return(null); } return(DatafileProjectConfig.Create(datafile, Logger, ErrorHandler)); }
/// <summary> /// HttpProjectConfigManager.Builder that builds and starts a HttpProjectConfigManager. /// </summary> /// <param name="defer">When true, we will not wait for the configuration to be available /// before returning the HttpProjectConfigManager instance.</param> /// <returns>HttpProjectConfigManager instance</returns> public HttpProjectConfigManager Build(bool defer) { HttpProjectConfigManager configManager = null; if (Logger == null) { Logger = new DefaultLogger(); } if (ErrorHandler == null) { ErrorHandler = new DefaultErrorHandler(Logger, false); } if (string.IsNullOrEmpty(Format)) { if (string.IsNullOrEmpty(DatafileAccessToken)) { Format = DEFAULT_FORMAT; } else { Format = DEFAULT_AUTHENTICATED_DATAFILE_FORMAT; } } if (string.IsNullOrEmpty(Url)) { if (string.IsNullOrEmpty(SdkKey)) { ErrorHandler.HandleError(new Exception("SdkKey cannot be null")); } Url = string.Format(Format, SdkKey); } if (IsPollingIntervalProvided && (Period.TotalMilliseconds <= 0 || Period.TotalMilliseconds > MAX_MILLISECONDS_LIMIT)) { Logger.Log(LogLevel.DEBUG, $"Polling interval is not valid for periodic calls, using default period {DEFAULT_PERIOD.TotalMilliseconds}ms"); Period = DEFAULT_PERIOD; } else if (!IsPollingIntervalProvided) { Logger.Log(LogLevel.DEBUG, $"No polling interval provided, using default period {DEFAULT_PERIOD.TotalMilliseconds}ms"); Period = DEFAULT_PERIOD; } if (IsBlockingTimeoutProvided && (BlockingTimeoutSpan.TotalMilliseconds <= 0 || BlockingTimeoutSpan.TotalMilliseconds > MAX_MILLISECONDS_LIMIT)) { Logger.Log(LogLevel.DEBUG, $"Blocking timeout is not valid, using default blocking timeout {DEFAULT_BLOCKINGOUT_PERIOD.TotalMilliseconds}ms"); BlockingTimeoutSpan = DEFAULT_BLOCKINGOUT_PERIOD; } else if (!IsBlockingTimeoutProvided) { Logger.Log(LogLevel.DEBUG, $"No Blocking timeout provided, using default blocking timeout {DEFAULT_BLOCKINGOUT_PERIOD.TotalMilliseconds}ms"); BlockingTimeoutSpan = DEFAULT_BLOCKINGOUT_PERIOD; } configManager = new HttpProjectConfigManager(Period, Url, BlockingTimeoutSpan, AutoUpdate, Logger, ErrorHandler, DatafileAccessToken); if (Datafile != null) { try { var config = DatafileProjectConfig.Create(Datafile, Logger, ErrorHandler); configManager.SetConfig(config); } catch (Exception ex) { Logger.Log(LogLevel.WARN, "Error parsing fallback datafile." + ex.Message); } } configManager.NotifyOnProjectConfigUpdate += () => { NotificationCenter?.SendNotifications(NotificationCenter.NotificationType.OptimizelyConfigUpdate); }; if (StartByDefault) { configManager.Start(); } // Optionally block until config is available. if (!defer) { configManager.GetConfig(); } return(configManager); }