Example #1
0
        private static void WriteToFileQueue(object source, ElapsedEventArgs e, bool shuttingDown = false)
        {
            if (!shuttingDown)
            {
                ChangeFileName();
            }
            ChangeFileNameWaitHandle.WaitOne(); // wait when the file name is being changed
            var bufferedData = new RoomInfoWrapper[JsonDataQueue.Count];

            lock (JsonDataQueue)
            {
                JsonDataQueue.CopyTo(bufferedData, 0);
                JsonDataQueue.Clear();
            }

            var utf8Text = JsonConvert.SerializeObject(bufferedData);
            var byteText = Encoding.ASCII.GetBytes(utf8Text);

            var b = SevenZipHelper.Compress(byteText);

            _sw.Write(Encoding.UTF8.GetString(b));

            /*Console.WriteLine(
             * Encoding.ASCII.GetString(
             *  SevenZipHelper.Decompress(
             *      b)).Substring(0,400));*/
        }
Example #2
0
        public InputState ConsumeLast()
        {
            ConsoleKeyInfo lastKeyInfo;
            bool           hasKey = _keyInputs.TryTake(out lastKeyInfo);

            _keyInputs.Clear();
            return(new InputState(hasKey, lastKeyInfo));
        }
Example #3
0
        public void CommitEvents(long committedVersion)
        {
            if (committedVersion != Version + 1)
            {
                throw new ArgumentException($"版本提交失败,与当前版本不匹配。 [AggregateRootType = {GetType()}, AggregateRootId = {Id}, CurrentVerion = {Version}, CommittedVersion = {committedVersion}]", nameof(committedVersion));
            }

            Version = committedVersion;
            uncommittedEvents.Clear();
        }
Example #4
0
        // clear for each test
        private void ClearTest()
        {
            WaitControlQueue?.Clear();
            WaitControlQueue = null;

            ControlChannel?.Teardown();
            ControlChannel = null;

            InfoToServer = null;
        }
Example #5
0
 internal void ClearResult()
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         try
         {
             _parseResult.Clear();
         }
         catch (Exception ex)
         {
             Logger.Error(ex);
         }
     });
 }
Example #6
0
        protected override void DoImport()
        {
            try
            {
                ProcessBuffer();
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(this, $"Failed to process imported data. [{SiteString}]", e);
            }

            packetBuffer.Clear();

            RaiseProcessStopped();
        }
Example #7
0
        /// <summary>
        /// Protocol starts to listen interface and respond
        /// </summary>
        public void Start()
        {
            Action <string> com = Comunication;

            Task.Factory.StartNew(ProcessQueue);//start new thread for consume commands
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "?") //if it is stop command, immediately stop engine without put it into queue
                {
                    engine.Exit = true;
                    commandConsumer.Clear();
                    continue;
                }
                commandConsumer.Add(input);
            }
        }
Example #8
0
        public static void Remove <T>(this BlockingCollection <T> collection, T item)
        {
            BlockingCollection <T> temp = new BlockingCollection <T>();

            foreach (T value in collection)
            {
                if (!value.Equals(item))
                {
                    temp.Add(value);
                }
            }

            collection.Clear();
            foreach (T value in temp)
            {
                collection.Add(value);
            }
        }
Example #9
0
        /// <summary>
        /// Main importer task, executes in the background thread
        /// </summary>
        protected override void DoImport()
        {
            try
            {
                InitializeLogger();
                InitializeSettings();
                ProcessBuffer();
            }
            catch (Exception e)
            {
                LogProvider.Log.Error(Logger, $"Failed importing.", e);
            }

            packetBuffer.Clear();

            protectedLogger.StopLogging();

            RaiseProcessStopped();
        }
        public void ClearDecompressItems()
        {
            bool restart = _decompressPool.Active;

            _decompressPool.Stop(false);

            List <IFrameReference> remaining;

            _framesToDecompress.Clear(out remaining);
            foreach (IFrameReference reference in remaining)
            {
                reference.Dispose();
            }

            if (restart)
            {
                _decompressPool.Start();
            }

            NotifyPropertyChanged("NumberOfDecompressItems");
        }
        public void ClearRetrieveItems()
        {
            _performanceInfo.Clear();

            bool restart = _retrievePool.Active;

            _retrievePool.Stop(false);

            List <IFrameReference> remaining;

            _framesToRetrieve.Clear(out remaining);
            foreach (IFrameReference reference in remaining)
            {
                reference.Dispose();
            }

            if (restart)
            {
                _retrievePool.Start();
            }

            NotifyPropertyChanged("NumberOfRetrieveItems");
        }
 protected override void ClearInternal()
 {
     _queue.Clear();
 }
Example #13
0
        public DotNetBrowserService(
            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider,
            IEventAggregator eventAggregator)
        {
            _serviceProvider = serviceProvider;
            _eventAggregator = eventAggregator;

            try {
                _messageQueue     = new BlockingCollection <string>(new ConcurrentQueue <string>());
                _manualResetEvent = new ManualResetEvent(false);
                _disposables      = new List <IDisposable>()
                {
                    _eventAggregator.GetEvent <WebviewDidInitializeEvent>().Subscribe(_ => {
                        Log.Debug($"{nameof(WebviewDidInitializeEvent)} Message QueueCount={QueueCount}");
                        _manualResetEvent.Set();

                        _disposable = _eventAggregator.GetEvent <SessionReadyEvent>().Subscribe(nested => {
                            Log.Debug($"{nameof(SessionReadyEvent)} Message QueueCount={QueueCount}");
                            if (!_manualResetEvent.WaitOne(0))
                            {
                                _manualResetEvent.Set();
                            }
                        });
                    }),
                    _eventAggregator.GetEvent <SessionLogoutEvent>().Subscribe(_ => {
                        Log.Debug($"{nameof(SessionLogoutEvent)} Message QueueCount={QueueCount}");
                        _queueTokenSource?.Cancel();
                        _messageQueue.Clear();
                        _manualResetEvent.Reset();
                    })
                };

                //https://stackoverflow.com/questions/9106419/how-to-cancel-getconsumingenumerable-on-blockingcollection
                _processorTokenSource = new CancellationTokenSource();
                var processorToken = _processorTokenSource.Token;

                _processor = System.Threading.Tasks.Task.Factory.StartNew(() => {
                    try {
                        while (_manualResetEvent.WaitOne())
                        {
                            if (processorToken.IsCancellationRequested)
                            {
                                break;
                            }

                            _queueTokenSource = new CancellationTokenSource();
                            var queueToken    = _queueTokenSource.Token;
                            try {
                                foreach (var value in _messageQueue.GetConsumingEnumerable(_queueTokenSource.Token))
                                {
                                    if (queueToken.IsCancellationRequested)
                                    {
                                        break;
                                    }

                                    if (_messageQueue.Count > QueueLimit)
                                    {
                                        _messageQueue.Clear();
                                        _manualResetEvent.Reset();
#pragma warning disable VSTHRD010
                                        ReloadWebView();
#pragma warning restore VSTHRD010
                                        break;
                                    }

                                    Send(value);
                                }
                            }
                            catch (OperationCanceledException ex) {
                                //no need to pass the error, this exception is expected
                                Log.Verbose(ex.Message);
                            }
                            catch (Exception ex) {
                                Log.Error(ex, ex.Message);
                            }
                        }
                    }
                    catch (Exception ex) {
                        Log.Error(ex.Message);
                    }
                }, processorToken, TaskCreationOptions.None, TaskScheduler.Default);
            }
            catch (Exception ex) {
                Log.Fatal(ex, nameof(DotNetBrowserService));
            }
        }
Example #14
0
 /// <inheritdoc />
 public void Clear()
 {
     _blockingCollection.Clear();
 }
 public void Clear()
 {
     queue.Clear();
     Stop();
 }
Example #16
0
 /// <summary>
 /// Clears all elements from the queue.
 /// </summary>
 public void Clear()
 {
     _queue.Clear();
 }