public List <string> DeployArtifacts(FileTransferPacket packet) { if (packet.Content == null) { return(new List <string>()); } //store file into a temp folder string directoryName = Path.Combine(Information.TempDirectoryTempData, DateTime.Now.ToString("yyyyMMddHHmmss") + "_d"); Directory.CreateDirectory(directoryName); string fileName = Path.Combine(directoryName, DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip"); SaveFileStream(fileName, new MemoryStream(packet.Content)); List <string> files = ZipFileHandler.UnZip(fileName, directoryName); File.Delete(fileName); //pass over to batch file string batchFile = ExtractBatchFile(directoryName); Trace.TraceInformation("The system is going to update. Waiting for stop signal..."); Trace.Flush(); Eyedia.Core.Windows.Utilities.WindowsUtility.ExecuteBatchFile(batchFile, true); //List<string> output = new List<string>(); //List<string> error = new List<string>(); //Eyedia.Core.Windows.Utilities.WindowsUtility.ExecuteDosCommand(batchFile, true, ref output, ref error); //Trace.TraceInformation("srecmd: Batch file '{0}' was exeucted, output was:{1},{2}Error:{3}{4}", // batchFile, output.ToLine(), Environment.NewLine, error.ToLine(), Environment.NewLine); return(files); }
internal string Handle() { ExtensionMethods.TraceInformation("Handling a zip file '{0}', processing by '{1}' of data source '{2}'.", ZipFileName, ProcessingBy, DataSourceId); string unzipLocation = Path.Combine(EyediaCoreConfigurationSection.CurrentConfig.TempDirectory, Constants.IdpeBaseFolderName); unzipLocation = Path.Combine(unzipLocation, "TempZip"); unzipLocation = Path.Combine(unzipLocation, ZipUniqueId); UnZippedFileNames = ZipFileHandler.UnZip(ZipFileName, unzipLocation).ToArray(); Array.Sort(UnZippedFileNames, (f1, f2) => Path.GetExtension(f1).CompareTo(Path.GetExtension(f2))); //todo if (UnZippedFileNames.Length == 0) { //2nd attempt. Reason - Sometimes unzip returns 0 files. Thread.Sleep(500); UnZippedFileNames = ZipFileHandler.UnZip(ZipFileName, unzipLocation).ToArray(); } string validationErrorMessage = string.Format("The zip file '{0}' processing has beeen aborted as validation process failed", ZipFileName); if (DataSourceSpecificZipFileWatcher != null) { DataSourceSpecificZipFileWatcher.UnZippedFileNames = UnZippedFileNames; DataSourceSpecificZipFileWatcher.ZipUniqueId = ZipUniqueId; DataSourceSpecificZipFileWatcher.ZipFileName = ZipFileName; if (!DataSourceSpecificZipFileWatcher.Prepare(ref validationErrorMessage)) { throw new BusinessException(validationErrorMessage); } } else { if (!Prepare(ref validationErrorMessage)) { throw new BusinessException(validationErrorMessage); } } UnZippedFileNames = AddUniqueIdToFiles(UnZippedFileNames, ZipUniqueId); SetZipFileInfo(this.ZipUniqueId, UnZippedFileNames.Length); ExtensionMethods.TraceInformation("There are {0} files.", UnZippedFileNames.Length); foreach (string unZippedFileName in UnZippedFileNames) { string onlyFileName = Path.GetFileName(unZippedFileName); if (DataSourceSpecificZipFileWatcher != null) { ExtensionMethods.TraceInformation("'{0}' will be processed with specific handler '{1}'", onlyFileName, DataSourceSpecificZipFileWatcher.ToString()); DataSourceSpecificZipFileWatcher.Handle(unZippedFileName, onlyFileName, Path.GetExtension(unZippedFileName), FileStatus.Process); } else { ExtensionMethods.TraceInformation("'{0}' will be processed with default handler", onlyFileName); string fileExt = Path.GetExtension(unZippedFileName).ToLower(); //if (fileExt == ".txt") // Debugger.Break(); FileStatus fileProposedStatus = FileStatus.Process; if (IsInIgnoreList(fileExt)) { fileProposedStatus = FileStatus.Ignore; } if (IsInIgnoreListButCopy(fileExt)) { fileProposedStatus = FileStatus.IgnoreMoveToOutput; } Handle(unZippedFileName, Path.GetFileName(unZippedFileName), fileExt, fileProposedStatus); } ExtensionMethods.TraceInformation("'{0}' handled.", onlyFileName); } ExtensionMethods.TraceInformation("All files handled."); Trace.Flush(); return(ZipUniqueId); }