private void CallClientTimer(Queue queue) { var context = GlobalHost.ConnectionManager.GetHubContext <QueueHub>(); string connectionIdEmployee = _hub.GetConnectionIdByLogin(queue.Employee.Login); context.Clients.Client(connectionIdEmployee).callFromEmployee(queue.Client.Name, queue.Operation.Name); string connectionIdClient = _hub.GetConnectionIdByLogin(queue.Client.Login); if (!string.IsNullOrEmpty(connectionIdClient)) { context.Clients.Client(connectionIdClient).callToClient(queue.Employee.Name); } ; TimerObjClass StateObj = new TimerObjClass() { TimerCanceled = false, NumberCall = 0, Queue = queue, Context = context }; TimerCallback TimerDelegate = new TimerCallback(TimerTask); Timer TimerItem = new Timer(TimerDelegate, StateObj, 500, queue.TimeCall * 1000); StateObj.TimerReference = TimerItem; }
private void TimerTask(object StateObj) { TimerObjClass State = (TimerObjClass)StateObj; Interlocked.Increment(ref State.NumberCall); StatesClient stateClient = _queueRepository.GetStateClient(State.Queue.Id); if (stateClient != StatesClient.Welcom) { State.TimerReference.Dispose(); } else { if (State.NumberCall > State.Queue.MaxNumberCall) { State.TimerReference.Dispose(); _queueRepository.GetOut(State.Queue.Id, StatesClient.GetOut); string connectionIdEmployee = _hub.GetConnectionIdByLogin(State.Queue.Employee.Login); if (!string.IsNullOrEmpty(connectionIdEmployee)) { State.Context.Clients.Client(connectionIdEmployee).addMessageEmployee("Клиент не принял приглашение"); } ; string connectionIdClient = _hub.GetConnectionIdByLogin(State.Queue.Client.Login); if (!string.IsNullOrEmpty(connectionIdClient)) { State.Context.Clients.Client(connectionIdClient).addMessageClient("Вы исключены из очереди"); State.Context.Clients.Client(connectionIdClient).changeClass("#BtnAccept", "noVisible"); } ; State.Context.Clients.All.removeClientFromQueue(State.Queue.Id); } else { string connectionIdEmployee = _hub.GetConnectionIdByLogin(State.Queue.Employee.Login); if (!string.IsNullOrEmpty(connectionIdEmployee)) { State.Context.Clients.Client(connectionIdEmployee).changeNumberCall(State.NumberCall, State.Queue.MaxNumberCall, State.Queue.TimeCall); } ; string connectionIdClient = _hub.GetConnectionIdByLogin(State.Queue.Client.Login); if (!string.IsNullOrEmpty(connectionIdClient)) { State.Context.Clients.Client(connectionIdClient).changeNumberCall(State.NumberCall, State.Queue.MaxNumberCall, State.Queue.TimeCall); } ; } } }