Exemplo n.º 1
0
 public static AmplitudeWrapper Initialize(string api_key, string userId)
 {
     if (instance == null)
     {
         Debug.Log((object)"AmplitudeWrapper initialized");
         instance = new AmplitudeWrapper(api_key, userId);
     }
     return(instance);
 }
Exemplo n.º 2
0
        private void UpdateServerDelayed(int delayMs, int batchSize = 10)
        {
            int num = -1;

            lock (_serverUpdateLock)
            {
                num = Mathf.Max(_serverUpdateDelayMs - (Environment.TickCount - _serverUpdateScheduledTime), 0);
                if (_serverUpdateDelayMs < 0 || delayMs < num)
                {
                    _serverUpdateScheduledTime = Environment.TickCount;
                    _serverUpdateDelayMs       = delayMs;
                }
                if (_serverUpdateBatchSize <= 0 || batchSize < _serverUpdateBatchSize)
                {
                    _serverUpdateBatchSize = batchSize;
                }
            }
            if (Interlocked.Exchange(ref isUpdateScheduled, 1) == 0)
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    AmplitudeWrapper amplitudeWrapper = this;
                    int batch = 1;
                    while (true)
                    {
                        bool flag = false;
                        lock (_serverUpdateLock)
                        {
                            flag  = (Mathf.Max(_serverUpdateDelayMs - (Environment.TickCount - _serverUpdateScheduledTime), 0) == 0);
                            batch = _serverUpdateBatchSize;
                        }
                        if (flag || _isAppExiting)
                        {
                            break;
                        }
                        Thread.Sleep(100);
                    }
                    if (!_isAppExiting)
                    {
                        lock (_serverUpdateLock)
                        {
                            _serverUpdateScheduledTime = 0;
                            _serverUpdateDelayMs       = -1;
                            _serverUpdateBatchSize     = -1;
                            isUpdateScheduled          = 0;
                        }
                        logQueue.QueueTask(delegate
                        {
                            amplitudeWrapper.UpdateServer(batch);
                        });
                    }
                });
            }
        }