Beispiel #1
0
 void ClearUpdateProcessor()
 {
     if (updateProcessor != null)
     {
         updateProcessor.Dispose();
         updateProcessor = null;
     }
 }
Beispiel #2
0
 /// <summary>
 /// Sets the factory function for creating an update processor, and attempts to connect if
 /// appropriate.
 /// </summary>
 /// <remarks>
 /// The factory function encapsulates all the information that <see cref="LdClient"/> takes into
 /// account when making a connection, i.e. whether we are in streaming or polling mode, the
 /// polling interval, and the curent user. <c>ConnectionManager</c> itself has no knowledge of
 /// those things.
 ///
 /// Besides updating the private factory function field, we do the following:
 ///
 /// If the function is null, we drop our current connection (if any), and we will not make
 /// any connections no matter what other properties are changed as long as it is still null.
 ///
 /// If it is non-null and we already have the same factory function, nothing happens.
 ///
 /// If it is non-null and we do not already have the same factory function, but other conditions
 /// disallow making a connection, nothing happens.
 ///
 /// If it is non-null and we do not already have the same factory function, and no other
 /// conditions disallow making a connection, we create an update processor and tell it to start.
 /// In this case, we also reset <see cref="Initialized"/> to false if <c>resetInitialized</c> is
 /// true.
 ///
 /// The returned task is immediately completed unless we are making a new connection, in which
 /// case it is completed when the update processor signals success or failure. The task yields
 /// a true result if we successfully made a connection <i>or</i> if we decided not to connect
 /// because we are in offline mode. In other words, the result is true if
 /// <see cref="Initialized"/> is true.
 /// </remarks>
 /// <param name="updateProcessorFactory">a factory function or null</param>
 /// <param name="resetInitialized">true if we should reset the initialized state (e.g. if we
 /// are switching users</param>
 /// <returns>a task as described above</returns>
 public Task <bool> SetUpdateProcessorFactory(Func <IMobileUpdateProcessor> updateProcessorFactory, bool resetInitialized)
 {
     return(LockUtils.WithWriteLock(_lock, () =>
     {
         if (_disposed || _updateProcessorFactory == updateProcessorFactory)
         {
             return Task.FromResult(false);
         }
         _updateProcessorFactory = updateProcessorFactory;
         _updateProcessor?.Dispose();
         _updateProcessor = null;
         if (resetInitialized)
         {
             _initialized = false;
         }
         return OpenOrCloseConnectionIfNecessary(); // not awaiting
     }));
 }
Beispiel #3
0
        public void Dispose()
        {
            IMobileUpdateProcessor processor = null;

            LockUtils.WithWriteLock(_lock, () =>
            {
                if (_disposed)
                {
                    return;
                }
                processor               = _updateProcessor;
                _updateProcessor        = null;
                _updateProcessorFactory = null;
                _disposed               = true;
            });
            processor?.Dispose();
        }