Пример #1
0
 private void LusterkoWyslij_Click(object sender, EventArgs e)
 {
     readTimer.Stop();
     try
     {
         lock (commLock)
         {
             spektrometr.SetUstawionyKatLusterko(Convert.ToByte(LusterkoKat.Value));
         }
     }
     catch (TimeoutException)
     {
         ConnectionErrors.Invoke(new Action(CountErrors));
     }
     readTimer.Start();
 }
Пример #2
0
 private void Wyslij2_Click(object sender, EventArgs e)
 {
     readTimer.Stop();
     try
     {
         lock (commLock)
         {
             spektrometr.SetUstawioneImpulsy2(Convert.ToInt32(UstawioneImpulsy2.Value));
         }
     }
     catch (TimeoutException)
     {
         ConnectionErrors.Invoke(new Action(CountErrors));
     }
     readTimer.Start();
 }
Пример #3
0
        private void notifyStatus(ConnectionStatus status, ConnectionErrors error, string errorMsg)
        {
            connectionStatus = status;
            if (this.onStatus != null)
            {
                HStatus hstatus = new HStatus();
                hstatus.SetStatus(status);
                hstatus.SetErrorCode(error);
                hstatus.SetErrorMsg(errorMsg);

                IAsyncAction threadPoolWorkItem = ThreadPool.RunAsync(
                    (source) =>
                {
                    this.onStatus(hstatus);
                }
                    );
            }
        }
Пример #4
0
        private void WyslijVMax_Click(object sender, EventArgs e)
        {
            readTimer.Stop();
            try
            {
                byte[] predkosci = new byte[]
                {
                    Convert.ToByte(VMax1.Value),
                    Convert.ToByte(VMax2.Value)
                };

                lock (commLock)
                {
                    spektrometr.SetPredkosciMax(predkosci);
                }
            }
            catch (TimeoutException)
            {
                ConnectionErrors.Invoke(new Action(CountErrors));
            }
            readTimer.Start();
        }
Пример #5
0
        private void ReadVariables(object sender, EventArgs e)
        {
            SpektrometrStatus status;

            readTimer.Stop();

            try
            {
                lock (commLock)
                {
                    status = spektrometr.GetAllVariables();
                }
                Invoke(new Action(() => UpdateValues(status)));
            }
            catch (FormatException)
            {
                ConnectionErrors.Invoke(new Action(CountErrors));
            }
            catch (System.IO.InvalidDataException)
            {
                ConnectionErrors.Invoke(new Action(CountErrors));
            }
            readTimer.Start();
        }
        void Transport_onStatus(ConnectionStatus status, ConnectionErrors error, string errorMsg)
        {
            this.connStatus = status;
            if (onStatus != null)
            {

                if (WebErrorStatus.ConnectionAborted.ToString().Equals(errorMsg))
                {
                    if (this.shouldConnect)
                        onStatus(status, error, errorMsg + " " + ErrorMessage.reconnIn5s);
                    else
                        onStatus(status, error, errorMsg);
                    ThreadPoolTimer timer = ThreadPoolTimer.CreateTimer(
                       async (obj) =>
                       {
                           await ThreadPool.RunAsync(TryToConnectDisconnect, WorkItemPriority.High);
                       }, new TimeSpan(0, 0, 0, 0, 5000));

                }
                else
                {
                    onStatus(status, error, errorMsg);
                    if (error == ConnectionErrors.AUTH_FAILED)
                    {
                        this.shouldConnect = false;
                    }
                }
            }
            else
                throw new ArgumentNullException("Error: " + this.GetType() + " require a StatusEventHandler onStatus");
        }
 public void updateStatus(ConnectionStatus status, ConnectionErrors error, string errorMsg)
 {
     this.connStatus = status;
     if (onStatus != null)
         onStatus(status, error, errorMsg);
     else
         throw new ArgumentNullException("Error: " + this.GetType() + " require a StatusEventHandler onStatus");
 }
Пример #8
0
 private void transport_onStatus(ConnectionStatus status, ConnectionErrors error, string errrorMsg)
 {
     notifyStatus(status, error, errrorMsg);
 }
Пример #9
0
        private void notifyStatus(ConnectionStatus status, ConnectionErrors error, string errorMsg)
        {
            connectionStatus = status;
            if (this.onStatus != null)
            {
                HStatus hstatus = new HStatus();
                hstatus.SetStatus(status);
                hstatus.SetErrorCode(error);
                hstatus.SetErrorMsg(errorMsg);

                IAsyncAction threadPoolWorkItem = ThreadPool.RunAsync(
                    (source) =>
                    {
                        this.onStatus(hstatus);
                    }
                    );
            }
        }
Пример #10
0
 public void SetErrorCode(ConnectionErrors? errorCode)
 {
     try
     {
         if (errorCode == null)
             this.Remove("errorCode");
         else
             this["errorCode"] = (int)errorCode;
     }
     catch (Exception e)
     {
         Debug.WriteLine("{0} : Can not update the errorCode attribute : ",e);
     }
 }
Пример #11
0
		public ErrorReceivedEventArgs(ConnectionErrors error)
		{
			this.Error = error;
		}
Пример #12
0
 private void transport_onStatus(ConnectionStatus status, ConnectionErrors error, string errrorMsg)
 {
     notifyStatus(status, error, errrorMsg);
 }
Пример #13
0
        override public async Task <bool> ProcessUpdatesAsync(CancellationToken cts)
        {
            try
            {
                #region SHUTDOWN
                if (Manager.ShutdownRequested())
                {
                    foreach (var client in GetClientsAsList())
                    {
                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.PreDisconnect,
                            Origin = client,
                            Owner  = this,
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        await e.WaitAsync();
                    }

                    foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins)
                    {
                        await plugin.OnUnloadAsync();
                    }

                    return(true);
                }
                #endregion

                try
                {
                    var polledClients = await PollPlayersAsync();

                    var waiterList = new List <GameEvent>();

                    foreach (var disconnectingClient in polledClients[1])
                    {
                        if (disconnectingClient.State == ClientState.Disconnecting)
                        {
                            continue;
                        }

                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.PreDisconnect,
                            Origin = disconnectingClient,
                            Owner  = this
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        // wait until the disconnect event is complete
                        // because we don't want to try to fill up a slot that's not empty yet
                        waiterList.Add(e);
                    }
                    // wait for all the disconnect tasks to finish
                    await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));

                    waiterList.Clear();
                    // this are our new connecting clients
                    foreach (var client in polledClients[0])
                    {
                        // note: this prevents players in ZMBI state from being registered with no name
                        if (string.IsNullOrEmpty(client.Name))
                        {
                            continue;
                        }

                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.PreConnect,
                            Origin = client,
                            Owner  = this
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        waiterList.Add(e);
                    }

                    // wait for all the connect tasks to finish
                    await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));

                    waiterList.Clear();
                    // these are the clients that have updated
                    foreach (var client in polledClients[2])
                    {
                        var e = new GameEvent()
                        {
                            Type   = GameEvent.EventType.Update,
                            Origin = client,
                            Owner  = this
                        };

                        Manager.GetEventHandler().AddEvent(e);
                        waiterList.Add(e);
                    }

                    await Task.WhenAll(waiterList.Select(e => e.WaitAsync(10 * 1000)));

                    if (ConnectionErrors > 0)
                    {
                        var _event = new GameEvent()
                        {
                            Type   = GameEvent.EventType.ConnectionRestored,
                            Owner  = this,
                            Origin = Utilities.IW4MAdminClient(this),
                            Target = Utilities.IW4MAdminClient(this)
                        };

                        Manager.GetEventHandler().AddEvent(_event);
                    }

                    ConnectionErrors = 0;
                    LastPoll         = DateTime.Now;
                }

                catch (NetworkException e)
                {
                    ConnectionErrors++;
                    if (ConnectionErrors == 3)
                    {
                        var _event = new GameEvent()
                        {
                            Type   = GameEvent.EventType.ConnectionLost,
                            Owner  = this,
                            Origin = Utilities.IW4MAdminClient(this),
                            Target = Utilities.IW4MAdminClient(this),
                            Extra  = e,
                            Data   = ConnectionErrors.ToString()
                        };

                        Manager.GetEventHandler().AddEvent(_event);
                    }
                    return(true);
                }

                LastMessage = DateTime.Now - start;
                lastCount   = DateTime.Now;

                // update the player history
                if ((lastCount - playerCountStart).TotalMinutes >= SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval)
                {
                    while (ClientHistory.Count > ((60 / SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours
                    {
                        ClientHistory.Dequeue();
                    }

                    ClientHistory.Enqueue(new SharedLibraryCore.Helpers.PlayerHistory(ClientNum));
                    playerCountStart = DateTime.Now;
                }

                // send out broadcast messages
                if (LastMessage.TotalSeconds > Manager.GetApplicationSettings().Configuration().AutoMessagePeriod &&
                    BroadcastMessages.Count > 0 &&
                    ClientNum > 0)
                {
                    string[] messages = (await this.ProcessMessageToken(Manager.GetMessageTokens(), BroadcastMessages[NextMessage])).Split(Environment.NewLine);

                    foreach (string message in messages)
                    {
                        Broadcast(message);
                    }

                    NextMessage = NextMessage == (BroadcastMessages.Count - 1) ? 0 : NextMessage + 1;
                    start       = DateTime.Now;
                }

                return(true);
            }

            // this one is ok
            catch (ServerException e)
            {
                if (e is NetworkException && !Throttled)
                {
                    Logger.WriteError(loc["SERVER_ERROR_COMMUNICATION"].FormatExt($"{IP}:{Port}"));
                    Logger.WriteDebug(e.GetExceptionInfo());
                }

                return(false);
            }

            catch (Exception E)
            {
                Logger.WriteError(loc["SERVER_ERROR_EXCEPTION"].FormatExt($"[{IP}:{Port}]"));
                Logger.WriteDebug(E.GetExceptionInfo());
                return(false);
            }
        }
Пример #14
0
 public ErrorHandler(int id, ConnectionErrors code, string message, object param, ConnectionErrorDelegate handler)
 {
     this.id = id;
     this.error = code;
     this.message = message;
     this.param = param;
     this.handler = handler;
 }
Пример #15
0
 private void fireErrorHandlers(ConnectionErrors error, string message, object param)
 {
     if (errorHandlers.Count > 0)
     {
         foreach (KeyValuePair<int, ConnectionErrorDelegate> i in errorHandlers)
         {
             ErrorHandler handler = new ErrorHandler(i.Key, error, message, param, i.Value);
             Handler.getInstance().postAction(handleError, handler);
         }
     }
 }