/// <summary> /// Print all files in specified folder /// </summary> /// <param name="ipAddress">IP Address of Printer</param> /// <param name="printProtocol"><see cref=" Printer.Printer.PrintProtocol"/></param> /// <param name="portNo">Port number for installation</param> /// <param name="testNo">Test number</param> /// <returns>true if all files printed successfully, false otherwise</returns> public bool ComplexPrinting(string ipAddress, Printer.Printer.PrintProtocol printProtocol, int portNo, int testNo) { string[] files = Directory.GetFiles(_activityData.DocumentsPath); if (null == files || 0 == files.Length) { TraceFactory.Logger.Info("Complex Printing failed. No files available."); return(false); } string hostname = string.Empty; if (Printer.Printer.PrintProtocol.IPPS.Equals(printProtocol)) { if (!CtcUtility.IPPS_Prerequisite(IPAddress.Parse(ipAddress), out hostname)) { TraceFactory.Logger.Info("Failed to perform pre-requisites for IPPS."); return(false); } } PrinterFamilies family = (PrinterFamilies)Enum.Parse(typeof(PrinterFamilies), Enum <ProductFamilies> .Value(_activityData.ProductFamily)); Printer.Printer printer = PrinterFactory.Create(family, IPAddress.Parse(ipAddress)); if (printer.Install(IPAddress.Parse(ipAddress), printProtocol, _activityData.DriverPackagePath, _activityData.DriverModel, portNo, hostname)) { printer.Print(CtcUtility.CreateFile("Test {0} started.".FormatWith(testNo))); // Subscribing for Print Queue Event printer.PrintQueueError += printer_PrintQueueError; if (!printer.Print(files)) { TraceFactory.Logger.Info("Complex Printing failed. All jobs didn't print."); return(false); } } else { TraceFactory.Logger.Info("Complex Printing failed."); return(false); } TraceFactory.Logger.Info("All jobs for Complex Printing printed successfully."); return(true); }
/// <summary> /// Check if Ftp Connection is successful /// </summary> /// <param name="ipAddress">Printer IP Address</param> /// <param name="printerFamily">Printer Family</param> /// <returns>true if connection successful, false otherwise</returns> public bool IsFtpAccessible(IPAddress ipAddress, Printer.PrinterFamilies printerFamily) { string address = string.Empty; if (ipAddress.ToString().Contains(":")) { address = string.Concat("[", ipAddress, "]"); } else { address = ipAddress.ToString(); } string ftpUri = "{0}{1}/{2}".FormatWith("ftp://", address, CtcUtility.CreateFile("temp")); Printer.Printer printer = Printer.PrinterFactory.Create(printerFamily, ipAddress); return(printer.IsFTPAccessible(ftpUri)); }
/// <summary> /// Copy file from Windows machine to Linux machine /// </summary> /// <param name="address">Linux server IP Address</param> /// <param name="fromFilePath">File path from where file needs to be fetched</param> /// <param name="toFilePath">File path to where file has to be copied</param> private static void CopyFileToLinux(IPAddress address, string fromFilePath, string toFilePath) { TraceFactory.Logger.Info("Copy file from Windows to Linux machine"); string pscpFilePath = "pscp.exe"; try { toFilePath = string.Format(CultureInfo.CurrentCulture, "{0}@{1}:{2}", USER_NAME, address, toFilePath); if (!File.Exists(pscpFilePath)) { File.WriteAllBytes(pscpFilePath, Resource.pscp); } // Command format: <pscpexe_path> -pw <linuxserver_password> <windows_filepath> <linuxserver_userid>@<linuxserver_ip>:<linux_filepath> // '< Y' is added at end for adding server's host key to registry (when command is run first time, pscp will expect user to press 'y/n' to continue) // Direct command execution throws exception hence commands are executed using batch file string command = string.Concat(pscpFilePath, " -pw {0} {1} {2} < {3}".FormatWith(PASSWORD, fromFilePath, toFilePath, CtcUtility.CreateFile("Y"))); TraceFactory.Logger.Info("Command to copy file from Windows to Linux Machine : {0}".FormatWith(command)); RunBatchFile(command); } finally { // } }