// Zip all the files in a folder public static string ZIPAll(string zipFileName, string sourcePath, string destPath, string password, out string ZipName) { Resco.IO.Zip.ZipArchive archive = null; ZipName = ""; try { string destFilePath = ""; string fileMask = "*.*"; // If no given Zip filename, then get the name of the first file IAPL.Transport.Transactions.ServerDetails SrvrDetails = new IAPL.Transport.Transactions.ServerDetails(); if (zipFileName.Equals("")) { ZipName = SrvrDetails.getFileNameOnly(System.IO.Directory.GetFiles(sourcePath, fileMask).GetValue(0).ToString()); ZipName = ZipName.Substring(0, ZipName.Length - 3) + "zip"; destFilePath = destPath + @"\" + ZipName; } else { destFilePath = destPath + @"\" + zipFileName; ZipName = destFilePath; } archive = new Resco.IO.Zip.ZipArchive(destFilePath, Resco.IO.Zip.ZipArchiveMode.Create, System.IO.FileShare.None); archive.AutoUpdate = true; archive.Add(sourcePath, @"\", password, true, null); return(destFilePath); } catch (Exception ex) { throw ex; } finally { archive.Close(); } }
// Picks up files extracted from zip and move it to root folder public static bool GetFilesOnlyInExtractedZip(string SourcePath) { bool success = false; try { IAPL.Transport.Transactions.ServerDetails SrvrDetails = new IAPL.Transport.Transactions.ServerDetails(); int FileExist = System.IO.Directory.GetFiles(SourcePath).Length; System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(SourcePath); if (FileExist.Equals(0)) { foreach (System.IO.DirectoryInfo g in dir.GetDirectories()) { string FolderInZip = SourcePath + @"\" + g.ToString(); foreach (string file in System.IO.Directory.GetFiles(FolderInZip)) { string FileInsideFolderInZip = file.ToString(); string DestinationFilePath = SourcePath + @"\" + SrvrDetails.getFileNameOnly(file.ToString()); File.Copy(FileInsideFolderInZip, DestinationFilePath); File.Delete(FileInsideFolderInZip); } if (!FolderInZip.Equals("")) { System.IO.Directory.Delete(FolderInZip, true); } } } success = true; } catch (Exception ex) { throw ex; } return(success); }
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Get the list of IMS files to process public System.Collections.Hashtable GetIMSFiles(System.Collections.Hashtable IMSFiles, out System.Collections.Hashtable IMSListOfZipFiles, out System.Collections.Hashtable IMSIncompleteFiles, out System.Collections.Hashtable IMSCompleteCountriesName, out System.Collections.Hashtable IMSIncompleteCountriesName) { string Filename = ""; string ExtName = ""; int TerminatorCtr = 0; int LogCtr = 0; int IMSCtr = 0; System.Collections.Hashtable ListOfTerminator = new System.Collections.Hashtable(); System.Collections.Hashtable ListOfLogs = new System.Collections.Hashtable(); System.Collections.Hashtable ZipFiles = new System.Collections.Hashtable(); //ListOfZipFiles = null; foreach (System.Collections.DictionaryEntry file in IMSFiles) { Filename = SDetails.getFileNameOnly(file.Value.ToString()); ExtName = Filename.Substring(Filename.LastIndexOf(".") + 1); Filename = Filename.ToLower(); ExtName = ExtName.ToLower(); // Get list of Terminator //OLD CODE SR#33117 Ccenriquez -- December 2, 2009 - Fix FITE send to Destination //if (ExtName.Equals(IMSTerminatorExt.ToLower())) //NEW CODE SR#33117 Ccenriquez -- December 2, 2009 - Fix FITE send to Destination if (string.Equals(ExtName, IMSTerminatorExt, StringComparison.OrdinalIgnoreCase)) { TerminatorCtr++; ListOfTerminator.Add("file" + TerminatorCtr.ToString(), Filename); } // Get list of Logs //OLD CODE SR#33117 Ccenriquez -- December 2, 2009 - Fix FITE send to Destination //if (ExtName.Equals(IMSLogExt.ToLower())) //NEW CODE SR#33117 Ccenriquez -- December 2, 2009 - Fix FITE send to Destination if (string.Equals(ExtName, IMSLogExt, StringComparison.OrdinalIgnoreCase)) { LogCtr++; ListOfLogs.Add("file" + LogCtr.ToString(), Filename); } // Get list of IMS Zip files //OLD CODE SR#33117 Ccenriquez -- December 2, 2009 - Fix FITE send to Destination //if (ExtName.Equals(IMSFileExt.ToLower())) //NEW CODE SR#33117 Ccenriquez -- December 2, 2009 - Fix FITE send to Destination if (string.Equals(ExtName, IMSFileExt, StringComparison.OrdinalIgnoreCase)) { IMSCtr++; ZipFiles.Add("file" + IMSCtr.ToString(), Filename); } } // ------------------------------------------------------------------------------------------ // Filter files int CompleteFileCtr = 0; int IncompleteFileCtr = 0; int ZipFileCtr = 0; int CompleteCountriesNameCtr = 0; int IncompleteCountriesNameCtr = 0; System.Collections.Hashtable ValidZipFiles = new System.Collections.Hashtable(); System.Collections.Hashtable CompleteFiles = new System.Collections.Hashtable(); System.Collections.Hashtable IncompleteFiles = new System.Collections.Hashtable(); System.Collections.Hashtable CompleteCountriesName = new System.Collections.Hashtable(); System.Collections.Hashtable IncompleteCountriesName = new System.Collections.Hashtable(); foreach (System.Collections.DictionaryEntry TerminatorFile in ListOfTerminator) { string terminatorfile = TerminatorFile.Value.ToString(); string TermFilename = terminatorfile.Substring(0, terminatorfile.LastIndexOf(".")); // Check if Terminator filename is found in Log list bool LogFound = false; foreach (System.Collections.DictionaryEntry LogFile in ListOfLogs) { string logfile = LogFile.Value.ToString(); string VerifyLogFilename = TermFilename + "." + IMSLogExt; if (logfile.ToUpper() == VerifyLogFilename.ToUpper()) { LogFound = true; break; } } // Check if Terminator filename is found in Zip list bool ZipFound = false; if (LogFound) { foreach (System.Collections.DictionaryEntry ZipFile in ZipFiles) { string zipfile = ZipFile.Value.ToString(); string VerifyZipFilename = TermFilename + "." + IMSFileExt; if (zipfile.ToUpper() == VerifyZipFilename.ToUpper()) { ZipFound = true; break; } } } Filename = terminatorfile; string ThisFilename = Filename.Substring(0, 7); string CountryCode = Filename.Substring(0, 2); string VersionNo = Filename.Substring(3, 7); if (LogFound && ZipFound) { // Add to list of files to pull from source (Complete) CompleteFileCtr++; CompleteFiles.Add("file" + CompleteFileCtr.ToString(), Filename); CompleteFileCtr++; CompleteFiles.Add("file" + CompleteFileCtr.ToString(), Filename.Replace(IMSTerminatorExt, IMSLogExt)); CompleteFileCtr++; CompleteFiles.Add("file" + CompleteFileCtr.ToString(), Filename.Replace(IMSTerminatorExt, IMSFileExt)); // List Valid Zip files ZipFileCtr++; ValidZipFiles.Add("file" + ZipFileCtr.ToString(), Filename.Replace(IMSTerminatorExt, IMSFileExt)); // Get filename and put to list of CompleteCountriesName CompleteCountriesNameCtr++; CompleteCountriesName.Add("file" + ZipFileCtr.ToString(), Filename.Substring(0, 7)); } else { // List down Incomplete files IncompleteFileCtr++; IncompleteFiles.Add("file" + IncompleteFileCtr.ToString(), Filename); if (LogFound) { IncompleteFileCtr++; IncompleteFiles.Add("file" + IncompleteFileCtr.ToString(), Filename.Replace(IMSTerminatorExt, IMSLogExt)); } if (ZipFound) { IncompleteFileCtr++; IncompleteFiles.Add("file" + IncompleteFileCtr.ToString(), Filename.Replace(IMSTerminatorExt, IMSFileExt)); } // Get filename and put to list of IncompleteCountriesName IncompleteCountriesNameCtr++; IncompleteCountriesName.Add("file" + (IncompleteCountriesName.Count + 1), Filename.Substring(0, 7)); } } IMSListOfZipFiles = ValidZipFiles; IMSIncompleteFiles = IncompleteFiles; IMSCompleteCountriesName = CompleteCountriesName; IMSIncompleteCountriesName = IncompleteCountriesName; return(CompleteFiles); }