/// <summary>
 /// Checks if one callback is active
 /// </summary>
 /// <param name="paramCallbackToCheck">Callback to check</param>
 /// <returns></returns>
 private async Task <bool> sentAsyncSignalToCallback(IServicioCallback paramCallbackToCheck)
 {
     try {
         // Checks if the callback is null
         if (paramCallbackToCheck != null)
         {
             // Checks on async method with timeout if the operator is alive
             bool isActive = await(Task.Run <bool>(() =>
             {
                 try {
                     return(paramCallbackToCheck.IsActive());
                 }
                 catch (Exception ex) {
                     Log.Error(_operatorClassName, "details: " + ex.Message);
                     return(false);
                 }
             })).TimeoutAfter(_dblOperatorTimeoutAwaitResponse);
             return(isActive);
         }
     }
     catch (TimeoutException) {
         return(false);
     }
     catch (Exception ex) {
         Log.Error(_operatorClassName, "error awaiting response: " + ex.Message);
         return(false);
     }
     throw new Exception("callback is null.");
 }
 /// <summary>
 /// Checks a client callback
 /// </summary>
 /// <param name="prmClientToCheck"></param>
 private void CheckAndUpdateCallbackOperator(Client prmClientToCheck, IServicioCallback prmLastCallback)
 {
     // if the callback is not the same on saved in service, update them
     if (prmClientToCheck.Callback != prmLastCallback)
     {
         prmClientToCheck.Callback = prmLastCallback;
     }
 }
Пример #3
0
 /// <summary>
 /// Checks if the callback of the client related is active
 /// </summary>
 /// <returns>true if is active, false</returns>
 private async Task <bool> isCallbackActive(IServicioCallback paramCallbackToCheck)
 {
     try {
         return(await Task.Run(() => { return paramCallbackToCheck.IsActive(); }));
     }
     catch (Exception ex) {
         throw ex;
     }
 }
Пример #4
0
 /// <summary>
 /// Process a connection request to the service
 /// </summary>
 /// <param name="oper"></param>
 /// <returns></returns>
 public bool Conectar(Operador oper)
 {
     // guarantees exclusive petition
     lock (syncObject) {
         // Checks if the operator is correct
         if (oper == null)
         {
             return(false);
         }
         if (isConsoleAdmin(oper))
         {
             // If is a console admin the connection has suceess and saves console admin callback
             ConsoleAdminCallback = CurrentCallback;
             return(true);
         }
         // if the connection is valid
         if (SQL.Operador.ValidarIngreso(oper))
         {
             // search on list of working operators for username
             Client operatorClient = lstOperatorMustConnected.First((operConn) => operConn.Operator.UserName == oper.UserName);
             // if the username is on the list
             if (operatorClient != null)
             {
                 // save current callback with this value
                 operatorClient.Callback = CurrentCallback;
             }
             // if the username is not on list, this means the operator is not programmed to log in today.
             else
             {
                 // Creates new client
                 operatorClient = new Client()
                 {
                     Callback = CurrentCallback, Operator = oper
                 };
                 // Add new operator to the list.
                 addClient(operatorClient);
             }
             // Set status for new client connected to readytoreceive.
             operatorClient.Operator.Status = AvailabiltyStatus.ReadyToReceive;
             // if backoffice is connected to the service, sent a signal to refresh list
             if (connectedBackoffice != null)
             {
                 SentRefreshForConnectedBackoffice();
             }
             // validate successfull the login
             return(true);
         }
         // if the operators credentials are invalid return false
         return(false);
     }
 }
 /// <summary>
 /// Removes operator from client connected list
 /// </summary>
 /// <param name="paramCallback">Callback to remove</param>
 private void removeOperator(IServicioCallback paramCallback)
 {
     try {
         // Get connected client
         Client clientToRemove = lstOperatorMustConnected.First((client) => client.Callback == paramCallback);
         if (clientToRemove != null)
         {
             // Remove client from the list
             disconnectClient(clientToRemove);
         }
     } catch (Exception ex) {
         Log.Error(_operatorClassName, string.Format("error removing operator from caLLback : {1}", paramCallback, ex.Message));
     }
 }
        /// <summary>
        /// check if the operator callback is already active
        /// </summary>
        /// <param name="paramOperator"></param>
        /// <returns></returns>
        private async Task <bool> checkOperatorActivity(Operador paramOperator)
        {
            try {
                // Gets callback related to operator
                IServicioCallback callbackRelated = getCallback(paramOperator);
                // Sent a signal to check if the operator callback is live
                bool isAlive = await sentAsyncSignalToCallback(callbackRelated);

                // Sent the result of checking
                return(isAlive);
            } catch (Exception ex) {
                Log.Error(_operatorClassName, ex.Message);
                return(false);
            }
        }
 /// <summary>
 /// Get operator related to callback
 /// </summary>
 /// <param name="paramCallback">Callback to find</param>
 /// <returns></returns>
 private Operador getOperator(IServicioCallback paramCallback)
 {
     try {
         // Instance a new operator object
         Operador newOper = lstOperatorMustConnected.First((clientToFind) => clientToFind.Callback == paramCallback).Operator;
         // Checks if the operator is null
         if (newOper != null)
         {
             return(newOper);
         }
         else
         {
             return(null);
         }
     } catch (Exception ex) {
         throw ex;
     }
 }
 /// <summary>
 /// Gets operator callback from the list of connected
 /// </summary>
 /// <param name="paramOperator">operator to find</param>
 /// <returns></returns>
 private IServicioCallback getCallback(Operador paramOperator)
 {
     // Check if the operator have data
     if (paramOperator != null)
     {
         // Gets a save on variable the callback
         IServicioCallback callbackOfOperator = lstOperatorMustConnected.First((client) => client.Operator.UserName == paramOperator.UserName).Callback;
         // Finds in the client connect list a operator related with a callback
         if (callbackOfOperator != null)
         {
             return(callbackOfOperator);
         }
         else
         {
             throw new Exception(string.Format("callback related to operator {0} not found.", paramOperator));
         }
     }
     throw new Exception("operator parameter is empty");
 }
Пример #9
0
 private async void _tmrCheckActiveService_Elapsed(object sender, ElapsedEventArgs e)
 {
     // Gets Client's Interface for a easy calls multiple methods from explicit interface
     IServicioCallback UIInteraction = this;
     try {
         // Configure timeout for wait response
         await runAsyncTimeoutMethod(() => { return proxy.IsServiceActiveAsync(isBackoffice, operatorLogged); }, defaultGeneralTimeout);                 
     }
     catch (Exception) {
         // Sent status message to the UI
         UIInteraction.Mensaje("Se ha perdido conexión con el servicio. Se procede a detener la conexión.");
         // Change the UI graphic status
         UIInteraction.ServiceChangeStatusRequest(AvailabiltyStatus.Disconnected);
         // Sets proxy to null
         proxy = null;
         // Stop timer activity
         stopCheckStatusOfConnectionWithService();
     }
 }
 /// <summary>
 /// Add operator to list of connected clients
 /// </summary>
 /// <param name="paramOperator"></param>
 /// <param name="paramCallback"></param>
 private void addOperator(Operador paramOperator, IServicioCallback paramCallback)
 {
     try {
         // If operator to log is already logged in
         if (isOperatorLogged(paramOperator))
         {
             // Remove from client connected
             disconnectOperator(paramOperator);
         }
         // Implement a new client object
         Client newClient = new Client()
         {
             Operator = paramOperator, Callback = paramCallback
         };
         // Add client to list of connected clients
         lstOperatorMustConnected.Add(newClient);
     } catch (Exception ex) {
         throw ex;
     }
 }
 /// <summary>
 /// Check backoffice logged in and validates if callback is the same
 /// </summary>
 /// <param name="prmOperatorBackoffice"></param>
 /// <param name="prmCallback"></param>
 private void CheckAndUpdateCallbackBackoffice(Operador prmOperatorBackoffice, IServicioCallback prmCallback)
 {
     // Checks if operator is the same and callback if different
     if (connectedBackoffice.Operator.UserName == prmOperatorBackoffice.UserName && connectedBackoffice.Callback != prmCallback)
     {
         connectedBackoffice.Callback = prmCallback;
     }
 }
Пример #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="iscOperatorRelated"></param>
 /// <returns></returns>
 internal Entidades.Operador getOperator(IServicioCallback iscOperatorRelated)
 {
     return(lstConnectedClients.First((client) => client.Callback == iscOperatorRelated).Operator);
 }