// This method is called while _lock is being held. If we're starting up a new connection, we do // *not* wait for it to succeed; we return a Task that will be completed once it succeeds. In all // other cases we return an immediately-completed Task. private Task <bool> OpenOrCloseConnectionIfNecessary(bool mustReinitializeDataSource) { if (!_started) { return(Task.FromResult(false)); } // Analytics event sending is enabled as long as we're allowed to do any network things. // (If the SDK is configured not to send events, then this is a no-op because _eventProcessor // will be a no-op implementation). _eventProcessor.SetOffline(_forceOffline || !_networkEnabled); // Diagnostic events are disabled if we're in the background. _diagnosticDisabler?.SetDisabled(_forceOffline || !_networkEnabled || _inBackground); if (mustReinitializeDataSource && _dataSource != null) { _dataSource?.Dispose(); _dataSource = null; } if (_networkEnabled && !_forceOffline) { if (_inBackground && !_enableBackgroundUpdating) { _log.Debug("Background updating is disabled"); _updateSink.UpdateStatus(DataSourceState.BackgroundDisabled, null); return(Task.FromResult(true)); } if (_dataSource is null) { // Set the state to Initializing when there's a new data source that has not yet // started. The state will then be updated as appropriate by the data source either // calling UpdateStatus, or Init which implies UpdateStatus(Valid). _updateSink.UpdateStatus(DataSourceState.Initializing, null); _dataSource = _dataSourceFactory.CreateDataSource(_clientContext, _updateSink, _user, _inBackground); return(_dataSource.Start() .ContinueWith(SetInitializedIfUpdateProcessorStartedSuccessfully)); } } else { // Either we've been explicitly set to be offline (in which case the state is always // SetOffline regardless of any other conditions), or we're offline because the network // is unavailable. If either of those things changes, we'll end up calling this method // again and the state will be updated if appropriate. _dataSource?.Dispose(); _dataSource = null; _initialized = true; _updateSink.UpdateStatus( _forceOffline ? DataSourceState.SetOffline : DataSourceState.NetworkUnavailable, null ); return(Task.FromResult(true)); } return(Task.FromResult(false)); }
/// <summary> /// Class constructor from specific diff options (rather than using defaults) /// </summary> /// <param name="args"></param> /// <param name="dataSourceFactory"></param> public AppViewModel(DirDiffArgs args, IDataSourceFactory dataSourceFactory) : this() { _Args = args; // Get a data object provider for browsing directories and files _DataSource = dataSourceFactory.CreateDataSource(); // Update redundant copy of file diff mode viewmodel selection in this viewmodel // This enables the user to change this property within the document view _FileDiffMode.DiffFileModeSelected = _FileDiffMode.DiffFileModes.ToList().First(i => i.Key == (uint)args.CompareDirFileMode); _LeftDirPath = args.LeftDir; _RightDirPath = args.RightDir; }
/// <summary> /// Creates a new client to connect to LaunchDarkly with a custom configuration. /// </summary> /// <remarks> /// <para> /// Applications should instantiate a single instance for the lifetime of the application. In /// unusual cases where an application needs to evaluate feature flags from different LaunchDarkly /// projects or environments, you may create multiple clients, but they should still be retained /// for the lifetime of the application rather than created per request or per thread. /// </para> /// <para> /// Normally, the client will begin attempting to connect to LaunchDarkly as soon as you call the /// constructor. The constructor returns as soon as any of the following things has happened: /// </para> /// <list type="number"> /// <item><description> It has successfully connected to LaunchDarkly and received feature flag data. In this /// case, <see cref="Initialized"/> will be true, and the <see cref="DataSourceStatusProvider"/> /// will return a state of <see cref="DataSourceState.Valid"/>. </description></item> /// <item><description> It has not succeeded in connecting within the <see cref="ConfigurationBuilder.StartWaitTime(TimeSpan)"/> /// timeout (the default for this is 5 seconds). This could happen due to a network problem or a /// temporary service outage. In this case, <see cref="Initialized"/> will be false, and the /// <see cref="DataSourceStatusProvider"/> will return a state of <see cref="DataSourceState.Initializing"/>, /// indicating that the SDK will still continue trying to connect in the background. </description></item> /// <item><description> It has encountered an unrecoverable error: for instance, LaunchDarkly has rejected the /// SDK key. Since an invalid key will not become valid, the SDK will not retry in this case. /// <see cref="Initialized"/> will be false, and the <see cref="DataSourceStatusProvider"/> will /// return a state of <see cref="DataSourceState.Off"/>. </description></item> /// </list> /// <para> /// If you have specified <see cref="ConfigurationBuilder.Offline"/> mode or /// <see cref="Components.ExternalUpdatesOnly"/>, the constructor returns immediately without /// trying to connect to LaunchDarkly. /// </para> /// <para> /// Failure to connect to LaunchDarkly will never cause the constructor to throw an exception. /// Under any circumstance where it is not able to get feature flag data from LaunchDarkly (and /// therefore <see cref="Initialized"/> is false), if it does not have any other source of data /// (such as a persistent data store) then feature flag evaluations will behave the same as if /// the flags were not found: that is, they will return whatever default value is specified in /// your code. /// </para> /// </remarks> /// <param name="config">a client configuration object (which includes an SDK key)</param> /// <example> /// <code> /// var config = Configuration.Builder("my-sdk-key") /// .AllAttributesPrivate(true) /// .EventCapacity(1000) /// .Build(); /// var client = new LDClient(config); /// </code> /// </example> /// <seealso cref="LdClient.LdClient(string)"/> public LdClient(Configuration config) { _configuration = config; var logConfig = (config.LoggingConfigurationFactory ?? Components.Logging()) .CreateLoggingConfiguration(); _log = logConfig.LogAdapter.Logger(logConfig.BaseLoggerName ?? LogNames.DefaultBase); _log.Info("Starting LaunchDarkly client {0}", AssemblyVersions.GetAssemblyVersionStringForType(typeof(LdClient))); _evalLog = _log.SubLogger(LogNames.EvaluationSubLog); var basicConfig = new BasicConfiguration(config, _log); var httpConfig = (config.HttpConfigurationFactory ?? Components.HttpConfiguration()) .CreateHttpConfiguration(basicConfig); ServerDiagnosticStore diagnosticStore = _configuration.DiagnosticOptOut ? null : new ServerDiagnosticStore(_configuration, basicConfig, httpConfig); var taskExecutor = new TaskExecutor(this, _log); var clientContext = new LdClientContext(basicConfig, httpConfig, diagnosticStore, taskExecutor); var dataStoreUpdates = new DataStoreUpdatesImpl(taskExecutor, _log.SubLogger(LogNames.DataStoreSubLog)); _dataStore = (_configuration.DataStoreFactory ?? Components.InMemoryDataStore) .CreateDataStore(clientContext, dataStoreUpdates); _dataStoreStatusProvider = new DataStoreStatusProviderImpl(_dataStore, dataStoreUpdates); var bigSegmentsConfig = (_configuration.BigSegmentsConfigurationFactory ?? Components.BigSegments(null)) .CreateBigSegmentsConfiguration(clientContext); _bigSegmentStoreWrapper = bigSegmentsConfig.Store is null ? null : new BigSegmentStoreWrapper( bigSegmentsConfig, taskExecutor, _log.SubLogger(LogNames.BigSegmentsSubLog) ); _bigSegmentStoreStatusProvider = new BigSegmentStoreStatusProviderImpl(_bigSegmentStoreWrapper); _evaluator = new Evaluator( GetFlag, GetSegment, _bigSegmentStoreWrapper == null ? (Func <string, BigSegmentsInternalTypes.BigSegmentsQueryResult>)null : _bigSegmentStoreWrapper.GetUserMembership, _log ); var eventProcessorFactory = config.Offline ? Components.NoEvents : (_configuration.EventProcessorFactory ?? Components.SendEvents()); _eventProcessor = eventProcessorFactory.CreateEventProcessor(clientContext); var dataSourceUpdates = new DataSourceUpdatesImpl(_dataStore, _dataStoreStatusProvider, taskExecutor, _log, logConfig.LogDataSourceOutageAsErrorAfter); IDataSourceFactory dataSourceFactory = config.Offline ? Components.ExternalUpdatesOnly : (_configuration.DataSourceFactory ?? Components.StreamingDataSource()); _dataSource = dataSourceFactory.CreateDataSource(clientContext, dataSourceUpdates); _dataSourceStatusProvider = new DataSourceStatusProviderImpl(dataSourceUpdates); _flagTracker = new FlagTrackerImpl(dataSourceUpdates, (string key, User user) => JsonVariation(key, user, LdValue.Null)); var initTask = _dataSource.Start(); if (!(_dataSource is ComponentsImpl.NullDataSource)) { _log.Info("Waiting up to {0} milliseconds for LaunchDarkly client to start...", _configuration.StartWaitTime.TotalMilliseconds); } try { var success = initTask.Wait(_configuration.StartWaitTime); if (!success) { _log.Warn("Timeout encountered waiting for LaunchDarkly client initialization"); } } catch (AggregateException) { // StreamProcessor may throw an exception if initialization fails, because we want that behavior // in the Xamarin client. However, for backward compatibility we do not want to throw exceptions // from the LdClient constructor in the .NET client, so we'll just swallow this. } }
public PageBehaviourRepository(IDataSourceFactory dataSourceFactory) { _dataSourceFactory = dataSourceFactory; _sqlDataSource = _dataSourceFactory.CreateDataSource <PageBehaviour>("SQLServer"); }
/// <summary> /// 创建数据源 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createDataSourceToolStripButton_Click(object sender, EventArgs e) { CreateDataSourceForm dsForm = new CreateDataSourceForm(true); if (dsForm.ShowDialog() != DialogResult.OK) { return; } IConnectionInfo ci = new ConnectionInfo(); switch (dsForm.ConnectionType) { case "gviConnectionMySql5x": ci.ConnectionType = gviConnectionType.gviConnectionMySql5x; break; case "gviConnectionFireBird2x": ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; break; case "gviConnectionSQLite3": ci.ConnectionType = gviConnectionType.gviConnectionSQLite3; break; } ci.Server = dsForm.Server; ci.Port = dsForm.Port; ci.Database = dsForm.Database; ci.UserName = dsForm.UserName; ci.Password = dsForm.Password; IDataSource ds = null; try { if (!dsFactory.HasDataSource(ci)) { ds = dsFactory.CreateDataSource(ci, null); if (ds != null && CreateLogicTreeTable(ds)) { myTreeNode sourceNode = null; if (ci.ConnectionType == gviConnectionType.gviConnectionMySql5x) { sourceNode = new myTreeNode(ci.Database + "@" + ci.Server, ci); } else { sourceNode = new myTreeNode(ci.Database, ci); } this.treeView1.Nodes.Add(sourceNode); sourceNode.ContextMenuStrip = this.contextMenuStrip1; } } else { MessageBox.Show("数据源已存在"); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (ds != null) { //Marshal.ReleaseComObject(ds); ds = null; } } }