Esempio n. 1
0
        /// <summary>
        /// Check if an update is available on the remote server
        /// </summary>
        /// <returns>Update information</returns>
        public dc_InfoUpdateSoftware CheckUpdate()
        {
            dc_InfoUpdateSoftware dcInfoUpdateSw = new dc_InfoUpdateSoftware();
            stSwVersion           infoUpdateSw   = m_updatesManager.GetInfoNewUpdate();

            dcInfoUpdateSw.lastUpdateDate = infoUpdateSw.lastUpdateDate;
            //Station Controller
            dcInfoUpdateSw.stationControllerSwAvailable = infoUpdateSw.stationControllerSwAvailable;
            dcInfoUpdateSw.stationControllerSwDate      = infoUpdateSw.stationControllerSwDate;
            dcInfoUpdateSw.stationControllerSwVersion   = infoUpdateSw.stationControllerSwVersion;
            //Remote Manager
            dcInfoUpdateSw.remoteManagerSwAvailable = infoUpdateSw.remoteManagerSwAvailable;
            dcInfoUpdateSw.remoteManagerSwDate      = infoUpdateSw.remoteManagerSwDate;
            dcInfoUpdateSw.remoteManagerSwVersion   = infoUpdateSw.remoteManagerSwVersion;
            //Host Controller
            dcInfoUpdateSw.hostControllerSwAvailable = infoUpdateSw.hostControllerSwAvailable;
            dcInfoUpdateSw.hostControllerSwDate      = infoUpdateSw.hostControllerSwDate;
            dcInfoUpdateSw.hostControllerSwVersion   = infoUpdateSw.hostControllerSwVersion;
            //Web Manager
            dcInfoUpdateSw.webManagerSwAvailable = infoUpdateSw.webManagerSwAvailable;
            dcInfoUpdateSw.webManagerSwDate      = infoUpdateSw.webManagerSwDate;
            dcInfoUpdateSw.webManagerSwVersion   = infoUpdateSw.webManagerSwVersion;

            return(dcInfoUpdateSw);
        }
Esempio n. 2
0
        /// <summary>
        /// Check if the latest update software version is downloaded and downloaded it otherwise
        /// </summary>
        public void DownloadSwUpdate()
        {
            stSwVersion currentSwVersion           = m_localData.GetSwInfo(); //obtener la información de las versiones instaladas en la red local
            bool        bDownloadStationController = !File.Exists(Path.Combine(m_localData.GetSystemFilesFolderLocation(), currentSwVersion.stationControllerSwUrl));
            bool        bDownloadRemoteManager     = !File.Exists(Path.Combine(m_localData.GetSystemFilesFolderLocation(), currentSwVersion.remoteManagerSwUrl));
            bool        bDownloadHostController    = !File.Exists(Path.Combine(m_localData.GetSystemFilesFolderLocation(), currentSwVersion.hostControllerSwUrl));
            bool        bDownloadWebManager        = !File.Exists(Path.Combine(m_localData.GetSystemFilesFolderLocation(), currentSwVersion.webManagerSwUrl));

            if (bDownloadStationController || bDownloadRemoteManager || bDownloadHostController || bDownloadWebManager)
            {
                m_systemFilesManager.DownloadFile(System.Convert.ToString(My.Settings.Default.VersionFileName));

                if (bDownloadStationController)
                {
                    string stationControllerSwUrl = m_versionFileParser.GetStationControllerSwUrl(currentSwVersion.stationControllerSwVersion);
                    string sFilePath = m_systemFilesManager.DownloadFile(stationControllerSwUrl);
                    LoggerModule.logger.Info(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". StationController downloaded software url:" + sFilePath);
                    m_localData.SetStationControllerSwUrl(stationControllerSwUrl);
                }

                if (bDownloadRemoteManager)
                {
                    string remoteManagerSwUrl = m_versionFileParser.GetRemoteManagerSwUrl(currentSwVersion.remoteManagerSwVersion);
                    string sFilePath          = m_systemFilesManager.DownloadFile(remoteManagerSwUrl);
                    LoggerModule.logger.Info(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". RemoteManager downloaded software url:" + sFilePath);
                    m_localData.SetRemoteManagerSwUrl(remoteManagerSwUrl);
                }

                if (bDownloadHostController)
                {
                    string hostControllerSwUrl = m_versionFileParser.GetHostControllerSwUrl(currentSwVersion.hostControllerSwVersion);
                    string sFilePath           = m_systemFilesManager.DownloadFile(hostControllerSwUrl);
                    LoggerModule.logger.Info(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". HostController downloaded software url:" + sFilePath);
                    m_localData.SetHostControllerSwUrl(hostControllerSwUrl);
                }

                if (bDownloadWebManager)
                {
                    string webManagerSwUrl = m_versionFileParser.GetWebManagerSwUrl(currentSwVersion.webManagerSwVersion);
                    string sFilePath       = m_systemFilesManager.DownloadFile(webManagerSwUrl);
                    LoggerModule.logger.Info(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". WebManager downloaded software url:" + sFilePath);
                    m_localData.SetWebManagerSwUrl(webManagerSwUrl);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Get the last software version from info file
        /// </summary>
        /// <returns>StationController, RemoteManager, HostController and WebManager update information</returns>
        public stSwVersion GetInfoLastSwVersion()
        {
            stSwVersion swVersion = new stSwVersion();

            swVersion.stationControllerSwVersion = "";
            swVersion.stationControllerSwDate    = DateTime.Parse("1/1/1900");
            swVersion.stationControllerSwUrl     = "";
            swVersion.remoteManagerSwVersion     = "";
            swVersion.remoteManagerSwDate        = DateTime.Parse("1/1/1900");
            swVersion.remoteManagerSwUrl         = "";
            swVersion.hostControllerSwVersion    = "";
            swVersion.hostControllerSwDate       = DateTime.Parse("1/1/1900");
            swVersion.hostControllerSwUrl        = "";
            swVersion.webManagerSwVersion        = "";
            swVersion.webManagerSwDate           = DateTime.Parse("1/1/1900");
            swVersion.webManagerSwUrl            = "";


            if (File.Exists(Path.Combine(m_localData.GetSystemFilesFolderLocation(), System.Convert.ToString(My.Settings.Default.VersionFileName))))
            {
                bool bBlockStationController = false; //para saber si estamos en un bloque de datos del StationController
                bool bBlockRemoteManager     = false; //para saber si estamos en un bloque de datos del RemoteManager
                bool bBlockHostController    = false; //para saber si estamos en un bloque de datos del HostController
                bool bBlockWebManager        = false; //para saber si estamos en un bloque de datos del WebManager

                //Decrypt
                byte[] fileReader = File.ReadAllBytes(Path.Combine(m_localData.GetSystemFilesFolderLocation(), System.Convert.ToString(My.Settings.Default.VersionFileName)));
                byte[] Key        = JBC_encryption.JBC_ENCRYPTION_KEY;
                byte[] IV         = JBC_encryption.JBC_ENCRYPTION_IV;
                string decrypted  = System.Convert.ToString(RoutinesLibrary.Security.AES.DecryptStringFromBytes_AES(fileReader, Key, IV));

                //Carriage Return (0x0D AKA Char 13) and Line Feed (0x0A AKA Char 10)
                string[] sTextLines = decrypted.Replace("\r", "").Split('\n');

                //Leemos el documento line by line
                foreach (string sTextLine in sTextLines)
                {
                    //Empieza un bloque de StationController
                    if (sTextLine == STATION_CONTROLLER_MARK)
                    {
                        bBlockStationController = true;
                        bBlockRemoteManager     = false;
                        bBlockHostController    = false;
                        bBlockWebManager        = false;

                        //Empieza un bloque de RemoteManager
                    }
                    else if (sTextLine == REMOTE_MANAGER_MARK)
                    {
                        bBlockStationController = false;
                        bBlockRemoteManager     = true;
                        bBlockHostController    = false;
                        bBlockWebManager        = false;

                        //Empieza un bloque de HostController
                    }
                    else if (sTextLine == HOST_CONTROLLER_MARK)
                    {
                        bBlockStationController = false;
                        bBlockRemoteManager     = false;
                        bBlockHostController    = true;
                        bBlockWebManager        = false;

                        //Empieza un bloque de WebManager
                    }
                    else if (sTextLine == WEB_MANAGER_MARK)
                    {
                        bBlockStationController = false;
                        bBlockRemoteManager     = false;
                        bBlockHostController    = false;
                        bBlockWebManager        = true;

                        //Estamos leyendo un bloque de datos
                    }
                    else if (bBlockStationController || bBlockRemoteManager || bBlockHostController || bBlockWebManager)
                    {
                        string[] lineArray = Strings.Split(sTextLine, SEPARATOR, LINE_ARGS);

                        //Comprobar el numero de campos de una linea
                        if (lineArray.Length == LINE_ARGS)
                        {
                            DateTime candidateDate = default(DateTime);

                            if (DateTime.TryParseExact(lineArray[1].Trim(), "yyyy/MM/dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out candidateDate))
                            {
                                //Pertenece a un StationController
                                if (bBlockStationController)
                                {
                                    //La nueva version leida es mas reciente
                                    if (candidateDate > swVersion.stationControllerSwDate)
                                    {
                                        swVersion.stationControllerSwVersion = lineArray[0].Trim();
                                        swVersion.stationControllerSwDate    = candidateDate;
                                        swVersion.stationControllerSwUrl     = lineArray[2].Trim();
                                    }

                                    //Pertenece a un RemoteManager
                                }
                                else if (bBlockRemoteManager)
                                {
                                    //La nueva version leida es mas reciente
                                    if (candidateDate > swVersion.remoteManagerSwDate)
                                    {
                                        swVersion.remoteManagerSwVersion = lineArray[0].Trim();
                                        swVersion.remoteManagerSwDate    = candidateDate;
                                        swVersion.remoteManagerSwUrl     = lineArray[2].Trim();
                                    }

                                    //Pertenece a un HostController
                                }
                                else if (bBlockHostController)
                                {
                                    //La nueva version leida es mas reciente
                                    if (candidateDate > swVersion.hostControllerSwDate)
                                    {
                                        swVersion.hostControllerSwVersion = lineArray[0].Trim();
                                        swVersion.hostControllerSwDate    = candidateDate;
                                        swVersion.hostControllerSwUrl     = lineArray[2].Trim();
                                    }

                                    //Pertenece a un WebManager
                                }
                                else if (bBlockWebManager)
                                {
                                    //La nueva version leida es mas reciente
                                    if (candidateDate > swVersion.webManagerSwDate)
                                    {
                                        swVersion.webManagerSwVersion = lineArray[0].Trim();
                                        swVersion.webManagerSwDate    = candidateDate;
                                        swVersion.webManagerSwUrl     = lineArray[2].Trim();
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(swVersion);
        }
Esempio n. 4
0
        /// <summary>
        /// Get software information installed in the local network
        /// </summary>
        /// <returns>Software information installed in the local network</returns>
        public stSwVersion GetSwInfo()
        {
            stSwVersion swVersion = new stSwVersion();

            swVersion.stationControllerSwVersion = "";
            swVersion.stationControllerSwDate    = DateTime.Parse("1/1/1900");
            swVersion.stationControllerSwUrl     = "";

            swVersion.remoteManagerSwVersion = "";
            swVersion.remoteManagerSwDate    = DateTime.Parse("1/1/1900");
            swVersion.remoteManagerSwUrl     = "";

            swVersion.hostControllerSwVersion = "";
            swVersion.hostControllerSwDate    = DateTime.Parse("1/1/1900");
            swVersion.hostControllerSwUrl     = "";

            swVersion.webManagerSwVersion = "";
            swVersion.webManagerSwDate    = DateTime.Parse("1/1/1900");
            swVersion.webManagerSwUrl     = "";

            string table = "versionInfo";

            string[] keyList = new string[8];
            keyList[0] = "stationControllerSwVersion";
            keyList[1] = "remoteManagerSwVersion";
            keyList[2] = "hostControllerSwVersion";
            keyList[3] = "webManagerSwVersion";
            keyList[4] = "stationControllerSwDate";
            keyList[5] = "remoteManagerSwDate";
            keyList[6] = "hostControllerSwDate";
            keyList[7] = "webManagerSwDate";
            string[] valueList = new string[1];

            try
            {
                m_semaphoreData.WaitOne();
                if (m_DBConnection.SelectQuery(keyList, table, ref valueList))
                {
                    swVersion.stationControllerSwVersion = valueList[0];
                    swVersion.remoteManagerSwVersion     = valueList[1];
                    swVersion.hostControllerSwVersion    = valueList[2];
                    swVersion.webManagerSwVersion        = valueList[3];
                    swVersion.stationControllerSwDate    = DateTime.Parse(valueList[4]);
                    swVersion.remoteManagerSwDate        = DateTime.Parse(valueList[5]);
                    swVersion.hostControllerSwDate       = DateTime.Parse(valueList[6]);
                    swVersion.webManagerSwDate           = DateTime.Parse(valueList[7]);
                }
                else
                {
                    LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error with DB Select Query");
                }
            }
            catch (Exception ex)
            {
                LoggerModule.logger.Error(System.Reflection.MethodInfo.GetCurrentMethod().Name + ". Error: " + ex.Message);
            }
            finally
            {
                m_semaphoreData.Release();
            }

            return(swVersion);
        }
Esempio n. 5
0
        /// <summary>
        /// Checks if exists an update form JBC's server
        /// </summary>
        /// <returns>Update information</returns>
        public stSwVersion GetInfoNewUpdate()
        {
            stSwVersion infoUpdateSw = new stSwVersion();

            //descargar el archivo de versiones del remote server
            m_systemFilesManager.DownloadFile(System.Convert.ToString(My.Settings.Default.VersionFileName));

            //obtener la información del archivo de versiones
            stSwVersion remoteSwVersion = m_versionFileParser.GetInfoLastSwVersion();

            //obtener la información de las versiones instaladas en la red local
            stSwVersion currentSwVersion = m_localData.GetSwInfo();

            //obtiene la fecha de la última actualización
            infoUpdateSw.lastUpdateDate = m_localData.GetLastUpdateDate();

            //Comprobar si hay actualizacion software del StationController
            if (remoteSwVersion.stationControllerSwDate > currentSwVersion.stationControllerSwDate)
            {
                infoUpdateSw.stationControllerSwAvailable = true;
                infoUpdateSw.stationControllerSwDate      = remoteSwVersion.stationControllerSwDate;
                infoUpdateSw.stationControllerSwVersion   = remoteSwVersion.stationControllerSwVersion;
                infoUpdateSw.stationControllerSwUrl       = remoteSwVersion.stationControllerSwUrl;
            }
            else
            {
                infoUpdateSw.stationControllerSwAvailable = false;
            }

            //Comprobar si hay actualizacion software del RemoteManager
            if (remoteSwVersion.remoteManagerSwDate > currentSwVersion.remoteManagerSwDate)
            {
                infoUpdateSw.remoteManagerSwAvailable = true;
                infoUpdateSw.remoteManagerSwDate      = remoteSwVersion.remoteManagerSwDate;
                infoUpdateSw.remoteManagerSwVersion   = remoteSwVersion.remoteManagerSwVersion;
                infoUpdateSw.remoteManagerSwUrl       = remoteSwVersion.remoteManagerSwUrl;
            }
            else
            {
                infoUpdateSw.remoteManagerSwAvailable = false;
            }

            //Comprobar si hay actualizacion software del HostController
            if (remoteSwVersion.hostControllerSwDate > currentSwVersion.hostControllerSwDate)
            {
                infoUpdateSw.hostControllerSwAvailable = true;
                infoUpdateSw.hostControllerSwDate      = remoteSwVersion.hostControllerSwDate;
                infoUpdateSw.hostControllerSwVersion   = remoteSwVersion.hostControllerSwVersion;
                infoUpdateSw.hostControllerSwUrl       = remoteSwVersion.hostControllerSwUrl;
            }
            else
            {
                infoUpdateSw.hostControllerSwAvailable = false;
            }

            //Comprobar si hay actualizacion software del WebManager
            if (remoteSwVersion.webManagerSwDate > currentSwVersion.webManagerSwDate)
            {
                infoUpdateSw.webManagerSwAvailable = true;
                infoUpdateSw.webManagerSwDate      = remoteSwVersion.webManagerSwDate;
                infoUpdateSw.webManagerSwVersion   = remoteSwVersion.webManagerSwVersion;
                infoUpdateSw.webManagerSwUrl       = remoteSwVersion.webManagerSwUrl;
            }
            else
            {
                infoUpdateSw.webManagerSwAvailable = false;
            }

            return(infoUpdateSw);
        }
Esempio n. 6
0
        /// <summary>
        /// Updates the system with the latest software version from the JBC's server
        /// </summary>
        public void UpdateSystem()
        {
            //Si está actualizando no recibir peticiones
            if (m_isUpdating)
            {
                return;
            }
            m_isUpdating = true;

            //Actualiza la fecha de la última actualización del software
            m_localData.SetLastUpdateDate();

            stSwVersion infoUpdateSw = GetInfoNewUpdate();

            //Comprobar si hay actualizacion software del StationController
            if (infoUpdateSw.stationControllerSwAvailable)
            {
                //Descargar la versión de software y actualizar DB
                m_systemFilesManager.DownloadFile(infoUpdateSw.stationControllerSwUrl);
                m_localData.SetStationControllerSwInfo(infoUpdateSw.stationControllerSwVersion, infoUpdateSw.stationControllerSwDate, infoUpdateSw.stationControllerSwUrl);
            }

            //Comprobar si hay actualizacion software del RemoteManager
            if (infoUpdateSw.remoteManagerSwAvailable)
            {
                //Descargar la versión de software y actualizar DB
                m_systemFilesManager.DownloadFile(infoUpdateSw.remoteManagerSwUrl);
                m_localData.SetRemoteManagerSwInfo(infoUpdateSw.remoteManagerSwVersion, infoUpdateSw.remoteManagerSwDate, infoUpdateSw.remoteManagerSwUrl);
            }

            //Comprobar si hay actualizacion software del WebManager
            if (infoUpdateSw.webManagerSwAvailable)
            {
                //Descargar la versión de software y actualizar DB
                m_systemFilesManager.DownloadFile(infoUpdateSw.webManagerSwUrl);
                m_localData.SetWebManagerSwInfo(infoUpdateSw.webManagerSwVersion, infoUpdateSw.webManagerSwDate, infoUpdateSw.webManagerSwUrl);
            }

            //Si hay actualización del WebManager pero no del HostController
            //Ya que si hay actualización del HostController, éste se reiniciará y comprobará si se tiene que actualizar
            if (infoUpdateSw.webManagerSwAvailable && !infoUpdateSw.hostControllerSwAvailable)
            {
                //Descargar la versión de software y actualizar DB
                m_systemFilesManager.DownloadFile(infoUpdateSw.webManagerSwUrl);
                m_localData.SetWebManagerSwInfo(infoUpdateSw.webManagerSwVersion, infoUpdateSw.webManagerSwDate, infoUpdateSw.webManagerSwUrl);

                //Enviar comprobación de actualización al Web Manager
                string ipWebManager = m_localData.GetWebManagerUri().ToString();
                if (!string.IsNullOrEmpty(ipWebManager))
                {
                    m_comWebManager.StartUpdate(ipWebManager);
                }
            }

            //Comprobar si hay actualizacion software del HostController
            if (infoUpdateSw.hostControllerSwAvailable)
            {
                //Descargar la versión de software, no actualiza ls DB para que al reiniciar el HostController ejecute los scripts sql de actualización
                string hostControllerSwUpdatePath = m_systemFilesManager.DownloadFile(infoUpdateSw.hostControllerSwUrl);

                //Actualizar el HostController
                m_comUpdaterService.SendUpdateSw(hostControllerSwUpdatePath, System.Net.Dns.GetHostName());
            }

            m_isUpdating = false;
        }