public List <dc_FirmwareStation> GetInfoUpdateFirmware(dc_FirmwareStation infoUpdateFirmware) { List <dc_FirmwareStation> listInfoUpdateFirmware = new List <dc_FirmwareStation>(); try { m_mutexHostControllerEndpoints.WaitOne(); foreach (EndpointAddress ep in m_hostControllerEndpoints) { BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); JBCHostControllerServiceClient serviceClient = new JBCHostControllerServiceClient(binding, ep); serviceClient.Open(); listInfoUpdateFirmware.AddRange(serviceClient.GetInfoUpdateFirmware(infoUpdateFirmware)); serviceClient.Close(); } } catch (Exception ex) { LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error: " + ex.Message); } finally { m_mutexHostControllerEndpoints.ReleaseMutex(); } return(listInfoUpdateFirmware); }
public void GetUpdateFirmware(ref System.Collections.Generic.List <CFirmwareStation> versionMicros) { List <CFirmwareStation> versionMicrosHostController = new List <CFirmwareStation>(); try { //Carpeta donde guardar la descarga string firmwareFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles), "JBC\\JBC Station Controller Service\\Firmwares"); //Crear carpeta temporal if (!(new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.DirectoryExists(firmwareFolder)) { Directory.CreateDirectory(firmwareFolder); } //Endpoint HostController EndpointAddress ep = null; m_mutexHostControllerEndpoints.WaitOne(); if (m_hostControllerEndpoints.Count > 0) { ep = m_hostControllerEndpoints.First(); } m_mutexHostControllerEndpoints.ReleaseMutex(); if (ep != null) { //Open connection BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); JBCHostControllerServiceClient serviceClient = new JBCHostControllerServiceClient(binding, ep); serviceClient.Open(); //Recorrer todos los micros for (int i = 0; i <= versionMicros.Count - 1; i++) { //Obtener información del firmware HostControllerServiceReference.dc_FirmwareStation infoUpdateFirmware = new HostControllerServiceReference.dc_FirmwareStation(); infoUpdateFirmware.model = System.Convert.ToString(versionMicros.ElementAt(i).Model); infoUpdateFirmware.hardwareVersion = System.Convert.ToString(versionMicros.ElementAt(i).HardwareVersion); List <HostControllerServiceReference.dc_FirmwareStation> listNewInfoUpdateFirmware = new List <HostControllerServiceReference.dc_FirmwareStation>(); listNewInfoUpdateFirmware.AddRange(serviceClient.GetInfoUpdateFirmware(infoUpdateFirmware)); foreach (HostControllerServiceReference.dc_FirmwareStation dc_firmware in listNewInfoUpdateFirmware) { CFirmwareStation firmware = new CFirmwareStation(); firmware.Model = dc_firmware.model; firmware.ModelVersion = dc_firmware.modelVersion; firmware.ProtocolVersion = dc_firmware.protocolVersion; firmware.HardwareVersion = dc_firmware.hardwareVersion; firmware.SoftwareVersion = dc_firmware.softwareVersion; firmware.FileName = Path.Combine(firmwareFolder, dc_firmware.fileName); versionMicrosHostController.Add(firmware); //Si no existe el archivo de firmware if (!File.Exists(firmware.FileName)) { bool bOk = false; bool bContinue = false; int nSequence = 1; //Download firmware update do { int nTries = 3; bOk = false; dc_UpdateFirmware updateFirmware = new dc_UpdateFirmware(); while (nTries > 0 && !bOk) { updateFirmware = serviceClient.GetFileUpdateFirmware(nSequence, dc_firmware.fileName); bOk = updateFirmware.sequence == nSequence; bContinue = !updateFirmware.final; nTries--; } if (!bOk) { break; } nSequence++; (new Microsoft.VisualBasic.Devices.ServerComputer()).FileSystem.WriteAllBytes(firmware.FileName, updateFirmware.bytes, true); } while (bContinue); } } } serviceClient.Close(); } } catch (Exception ex) { LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error: " + ex.Message); } versionMicros = versionMicrosHostController; }