Пример #1
0
        public ServerOfflineFileInfoPair(DIFileInfo serverFileInfo, DIFileInfo offlineFileInfo)
        {
            this._ServerFileInfo = serverFileInfo;

            this._OfflineFileInfo = offlineFileInfo;
        }
Пример #2
0
        /// <summary>
        /// Gets the list of FileInfo of Server Files. Each FileInfo object is for each file's information in DI_AppDirInfo.xml
        /// </summary>
        /// <param name="xmlFileName">DI_AppDirInfo.xml file path</param>
        /// <returns></returns>
        private List<DIFileInfo> GetFileListFromXML(string xmlFileName)
        {
            List<DIFileInfo> RetVal = new List<DIFileInfo>();
            XmlDocument ManifestXmlDoc = new XmlDocument();
            XmlNodeList FileNodesList = null;
            DIFileInfo ServerFileInfo;

            if (File.Exists(xmlFileName))
            {
                //-- Load Manifest xml file.
                ManifestXmlDoc.Load(xmlFileName);

                //-- Get all XmlNode <File> in  xml document.
                FileNodesList = ManifestXmlDoc.DocumentElement.SelectNodes(@"//" + DILiveUpdate.FILE_NODE);

                if (FileNodesList != null && FileNodesList.Count > 0)
                {
                    for (int i = 0; i < FileNodesList.Count; i++)
                    {
                        if (FileNodesList[i].HasChildNodes)
                        {
                            try
                            {
                                ServerFileInfo = new DIFileInfo();
                                //-- Get FileName, FilePath, FileVersion, FileType, ModifiedDateTimeStamp from xmlNode,
                                //-- and assign into FileInfo variable.

                                ServerFileInfo.FileName = FileNodesList[i].ChildNodes[0].InnerText;
                                ServerFileInfo.FilePath = FileNodesList[i].ChildNodes[1].InnerText;
                                ServerFileInfo.Version = FileNodesList[i].ChildNodes[2].InnerText;
                                ServerFileInfo.FileType = FileNodesList[i].ChildNodes[3].InnerText;
                                ServerFileInfo.ModifiedDateTimeStamp = FileNodesList[i].ChildNodes[4].InnerText;

                                // Convert this Date Time to local System DateTime Format
                                // Server Date Time Format = mm/dd/yyyy hh:mm:ss
                                // STEP 1: Get Date Time Format according to the current Culture
                                // STEP 2: Convert the server Date Modified into the current cilture format
                                string sDate = FileNodesList[i].ChildNodes[4].InnerText.Split(' ')[0];
                                string sTime = FileNodesList[i].ChildNodes[4].InnerText.Split(' ')[1];
                                string sCurrentDateMM = sDate.Split('/')[0];
                                string sCurrentDateDD = sDate.Split('/')[1];
                                string sCurrentDateYY = sDate.Split('/')[2];

                                string sCurrentDateHH = sTime.Split(':')[0];
                                string sCurrentDateMIN = sTime.Split(':')[1];
                                string sCurrentDateSEC = sTime.Split(':')[2];

                                DateTime dDateTime = new DateTime(Convert.ToInt32(sCurrentDateYY), Convert.ToInt32(sCurrentDateMM), Convert.ToInt32(sCurrentDateDD), Convert.ToInt32(sCurrentDateHH), Convert.ToInt32(sCurrentDateMIN), Convert.ToInt32(sCurrentDateSEC));

                                ServerFileInfo.ModifiedDateTimeStamp = dDateTime.ToString();

                                ServerFileInfo.FileSize = FileNodesList[i].ChildNodes[6].InnerText;
                                ServerFileInfo.ForceUpdate = FileNodesList[i].ChildNodes[7].InnerText;

                                RetVal.Add(ServerFileInfo);
                            }
                            catch (Exception)
                            {
                                //If XMl text is unreadable, then display message on interface. But Do not abort the process.
                                //TODO: handling of displaying message.
                            }
                        }
                    }
                }

            }
            return RetVal;
        }
Пример #3
0
        public bool DownloadFile(DIFileInfo fileInfo, string updateFolderPath)
        {
            bool RetVal = false;

            string FileToDownload = string.Empty;
            string TempFileName = string.Empty;
            string FtpDirectory = string.Empty;
            string LocalFileName = string.Empty;

            try
            {

                FileToDownload = Path.GetFileName(fileInfo.FileName) + ".zip";

                //-- If this file belongs to current Adaptation, then handle Adaptation Folder name in downloaded path.
                if (fileInfo.ApplicationName.ToLower() == this.Adaptation.ToLower())
                {
                    TempFileName = Path.Combine(Path.Combine(updateFolderPath, fileInfo.ApplicationName), Path.GetDirectoryName(fileInfo.FilePath)) + "\\" + Path.GetFileNameWithoutExtension(fileInfo.FileName) + ".zip";
                }
                else
                {
                    if (fileInfo.FileName.ToLower() == "diLiveUpdate.exe".ToLower())
                    {
                        //-- NOTE: Special handling for "diLiveUpdate.exe" .
                        // as "diLiveUpdate.exe" needs to be udpated directly into root application Path folder
                        // instead of Temp Liveupdate Folder.
                        TempFileName = Path.Combine(this.AppInstallationPath, Path.GetFileNameWithoutExtension(fileInfo.FileName) + ".zip");
                    }
                    else
                    {
                        //-- normal files.
                        TempFileName = Path.Combine(updateFolderPath, Path.GetDirectoryName(fileInfo.FilePath)) + "\\" + Path.GetFileNameWithoutExtension(fileInfo.FileName) + ".zip";
                    }
                }

                // -- Concatenate Server root FTP path with file's parent folder path.
                FtpDirectory = this.FTPDirectoryName + "/" + fileInfo.ApplicationName + "/" + this.GetFTPFileReferencePath(fileInfo.FilePath);

                // --Download it from location specified in the same xml element
                // --and save in temp folder
                RetVal = this.DownloadFileThroughFTP(FileToDownload, FtpDirectory, TempFileName);

                //-- Change ModifiedDateTime of downloaded file to server's file Modified datatime.
                //-- because when file are unzipped, then creation time becomes current system time
                string downloadedFile = Path.Combine(Path.GetDirectoryName(TempFileName), fileInfo.FileName);
                File.SetLastWriteTime(downloadedFile, Convert.ToDateTime(fileInfo.ModifiedDateTimeStamp));

                //-- Unzip "Zipdi" files as Special handling
                if (Path.GetExtension(fileInfo.FileName).ToLower() == ".zipdi")
                {
                    //-- unzip file again (because .zipdi files were zipped twice at server
                    FTPClient oftp = new FTPClient();
                    TempFileName = Path.Combine(Path.GetDirectoryName(TempFileName), fileInfo.FileName);
                    oftp.ExtractArchive(TempFileName, Path.GetDirectoryName(TempFileName), false);
                }
            }
            catch (Exception ex)
            {
                RetVal = false;
                ExceptionHandler.ExceptionFacade.ThrowException(ex);
                //MessageBoxControl.ShowMsg(DIMessage.CONNECTION_FAILED, Msg_IconType.INFORMATION, Msg_ButtonType.OK, true);
            }

            return RetVal;
        }
Пример #4
0
        /// <summary>
        /// Fetches file information of specified fileName required for comparison with server file info..
        /// </summary>
        /// <param name="fileNameWPath">file Name with path.</param>
        /// <returns>FileInfo object.</returns>
        public DIFileInfo FetchFileInformation(string fileNameWPath)
        {
            DIFileInfo RetVal = new DIFileInfo();
            System.IO.FileInfo fileInfo;
            if (File.Exists(fileNameWPath))
            {
                fileInfo = new System.IO.FileInfo(fileNameWPath);

                // Filename
                RetVal.FileName = Path.GetFileName(fileNameWPath);

                // File Type
                // get fileType on the basis of file extention.
                // NOTE: Special handling of LanguageType if .xml file is in LanguageFolder (..Language\")
                RetVal.FileType = this.GetFileType(fileNameWPath);

                //- Modified Date-Time stamp.
                //- Get Modified DateTime in desired format which is kept similar as Server's format.
                RetVal.ModifiedDateTimeStamp = fileInfo.LastWriteTime.ToString();

                // File Size
                RetVal.FileSize = fileInfo.Length.ToString();

                // Version of file
                RetVal.Version = this.GetVersion(fileNameWPath);

                fileInfo = null;
            }

            return RetVal;
        }
Пример #5
0
        /// <summary>
        /// Compares Server's file infomration with local counterpart.
        /// </summary>
        /// <param name="serverFileInfo">FileInfo variable of server file.</param>
        /// <returns>false, if server FileInfo is different from local one.</returns>
        public bool CompareServerFileWithLocal(DIFileInfo serverFileInfo, DIFileInfo localFileInfo)
        {
            bool RetVal = false;

            string FilePath = string.Empty;

            if (string.IsNullOrEmpty(serverFileInfo.FileName) == false)
            {
                if (Convert.ToBoolean(serverFileInfo.ForceUpdate))
                {
                    RetVal = false;
                }
                else
                {
                    if (string.IsNullOrEmpty(localFileInfo.FileName) == false)
                    {
                        //-- Compare two ServerFileInfo with localFileInfo
                        // -- Compare FileName, FileType, FileVersion, ModifiedDateTimeStamp
                        if ((serverFileInfo.FileName.ToLower() == localFileInfo.FileName.ToLower()))
                        {
                            //-- compare version
                            if (this.CheckVersionDiffrence(serverFileInfo.Version, localFileInfo.Version) == false)              //serverFileInfo.Version == localFileInfo.Version)
                            {
                                try
                                {
                                    DateTime ServerFileDateTime = Convert.ToDateTime(serverFileInfo.ModifiedDateTimeStamp);
                                    DateTime LocalFileDateTime = Convert.ToDateTime(localFileInfo.ModifiedDateTimeStamp);

                                    //-- Compare modified DateTimeStamp of two fileInfo.
                                    if (ServerFileDateTime.CompareTo(LocalFileDateTime) <= 0)
                                    {
                                        RetVal = true;
                                    }
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                        }
                    }
                }
            }

            return RetVal;
        }