Esempio n. 1
0
        private void SendFirstInternal()
        {
            if (PackageQueue.Count == 0)
            {
                return;
            }

            if (IsPaused)
            {
                Logger.Debug("Package handler is paused");
                return;
            }

            // no need to lock InternalWaitHandle between WaitOne(0) call and Reset()
            // because all Internal methods of PackageHandler can be only executed by 1 thread at a time

            if (InternalWaitHandle.WaitOne(0)) // check if the door is open without waiting (waiting 0 seconds)
            {
                InternalWaitHandle.Reset();    // close the door (non-signals the wait handle)
                RequestHandler.SendPackage(PackageQueue.First());
            }
            else
            {
                Logger.Verbose("Package handler is already sending");
            }
        }
Esempio n. 2
0
 private void SendNextInternal()
 {
     try
     {
         PackageQueue.RemoveAt(0);
         WritePackageQueue();
     }
     finally
     // preventing an exception not signaling the WaitHandle
     {
         InternalWaitHandle.Set(); // open the door (signals the wait handle)
     }
     SendFirstInternal();
 }
Esempio n. 3
0
        /// <summary>
        /// 运行相关任务
        /// </summary>
        public void Execute()
        {
            Report("开始分析目录");
            DoAnalyze(this.LocalBaseDir);

            int total = PackageQueue.Count;

            Report("开始处理缓存");
            for (int i = 1; i <= total; i++)
            {
                PackageFile(PackageQueue.Dequeue());
                ReportProgress((float)i / (float)total);
            }
            PackageQueue.Clear();
            Report("操作完成");
        }
Esempio n. 4
0
        private void AddInternal(ActivityPackage activityPackage)
        {
            if (activityPackage.ActivityKind.Equals(ActivityKind.Click) && PackageQueue.Count > 0)
            {
                PackageQueue.Insert(1, activityPackage);
            }
            else
            {
                PackageQueue.Add(activityPackage);
            }

            Logger.Debug("Added package {0} ({1})", PackageQueue.Count, activityPackage);
            Logger.Verbose("{0}", activityPackage.GetExtendedString());

            WritePackageQueue();
        }
        public Server(ServerActions actionHandler, ServerInfo serverInfo, StateMachine stateMachine,
                      ValidationSystem validationSystem, ClientDisconnection disconnectionHandler)
        {
            _stateMachine = stateMachine;
            var bwStateMachine = new BackgroundWorker();

            bwStateMachine.DoWork += (obj, ea) => _stateMachine.Start();
            bwStateMachine.RunWorkerAsync();

            _validationSystem = validationSystem;
            var bwValidationSystem = new BackgroundWorker();

            bwValidationSystem.DoWork += (obj, ea) => _validationSystem.Start();
            bwValidationSystem.RunWorkerAsync();

            _serverInfo           = serverInfo;
            _actionsHandler       = actionHandler;
            _disconnectionHandler = disconnectionHandler;

            _queue   = new PackageQueue();
            _process = new PackageProcessing(_queue, _actionsHandler);

            _listener = new TcpListener(_serverInfo.ServerIPAdress, 8080);
        }