/// <summary> /// Periodically check the status of update processes and resend the update file if necessary /// </summary> private void PendingUpdates() { while (m_IsAliveThreadPendingUpdates) { m_mutexPendingUpdates.WaitOne(); var pendingUpdatesFinal = m_pendingUpdates; foreach (CUpdaterServicePending pendingCom in m_pendingUpdates) { //Obtenemos el estado de la actualización BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); JBCUpdaterServiceClient serviceClient = new JBCUpdaterServiceClient(binding, pendingCom.endPoint); serviceClient.Open(); dc_EnumConstJBCdc_UpdateState state = serviceClient.StateUpdate(); serviceClient.Close(); // // Success operation // if (state == dc_EnumConstJBCdc_UpdateState.Finished) { pendingUpdatesFinal.Remove(pendingCom.endPoint.ToString()); // // Fail or Updating // } else { if (pendingCom.nTriesRemainingUpdate == 0) { pendingUpdatesFinal.Remove(pendingCom.endPoint.ToString()); //TODO send error message } else { pendingCom.DecrementRemainingUpdate(); pendingUpdatesFinal.Remove(pendingCom.endPoint.ToString()); pendingUpdatesFinal.Add(pendingCom, pendingCom.endPoint.ToString(), null, null); if (SendFile(pendingCom.endPoint, pendingCom.sUrlSendFile)) { SendInitUpdateCommand(pendingCom.endPoint); } else { pendingUpdatesFinal.Remove(pendingCom.endPoint.ToString()); //TODO send error message } } } } m_pendingUpdates = pendingUpdatesFinal; m_mutexPendingUpdates.Release(); Thread.Sleep(TIME_RETRY_UPDATE); } }
/// <summary> /// Wait until the windows service is ready to accept updates /// </summary> /// <param name="ep">Windows service endpoint</param> /// <returns>True if the windows service is ready to accept updates</returns> private bool WaitReadyUpdater(EndpointAddress ep) { bool bReady = false; int nTries = WAIT_READY_UPDATER_TRIES; int nTimeWait = WAIT_READY_UPDATER_TIME; BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); JBCUpdaterServiceClient serviceClient = new JBCUpdaterServiceClient(binding, ep); try { serviceClient.Open(); do { if (serviceClient.StateUpdate() == dc_EnumConstJBCdc_UpdateState.Updating) { nTries--; Thread.Sleep(nTimeWait); } else { bReady = true; } } while (nTries > 0 && !bReady); if (nTries == 0) { LoggerModule.logger.Warn(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Time exceded"); } } catch (Exception ex) { LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error: " + ex.Message); } finally { serviceClient.Close(); } return(bReady); }