/// <summary>
        /// Download a file from JBC's server or from a user folder
        /// </summary>
        /// <param name="fileName">File name to download</param>
        /// <returns>Full path of the downloaded file</returns>
        public string DownloadFile(string fileName)
        {
            var    sReturn        = "";
            string downloadFolder = m_localData.GetSystemFilesFolderLocation();

            //Download from Remote Server
            if (m_localData.IsAvailableRemoteServerDownload())
            {
                sReturn = m_comRemoteServer.DownloadFileFromRemoteServer(fileName, downloadFolder);

                //Local file
            }
            else
            {
                sReturn = Path.Combine(downloadFolder, fileName);
            }

            return(sReturn);
        }
示例#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);
                }
            }
        }
示例#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);
        }