public void FrontWindow(string windowName, CallbackContext callbackContext) { try { IntPtr ParenthWnd = new IntPtr(0); ParenthWnd = FindWindow(null, windowName); if (ParenthWnd == IntPtr.Zero) { m_Logger.Error($"[WindowUtils]FrontWindow:没有找到窗口"); callbackContext.Error(new PluginResult(PluginResult.Status.OK, false)); return; } var result = SetForegroundWindow((int)ParenthWnd); m_Logger.Error($"[WindowUtils]FrontWindow:{result}"); callbackContext.Success(new PluginResult(PluginResult.Status.OK, result)); } catch (Exception ex) { m_Logger.Error(ex); callbackContext.Error(new { type = "Exception", code = "", message = ex.Message, details = ex.StackTrace }); } }
public void GenerateQRCode(QRCodeOptions qrCodeOptions, CallbackContext callbackContext) { try { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.DisableECI = true; //设置内容编码 options.CharacterSet = "UTF-8"; //设置二维码的宽度和高度 options.Width = qrCodeOptions.QRCodeWidth; options.Height = qrCodeOptions.QRCodeHeight; //设置二维码的边距,单位不是固定像素 options.Margin = 1; writer.Options = options; Bitmap map = writer.Write(qrCodeOptions.QRCodeContent); map.Save(qrCodeOptions.QRCodePath, ImageFormat.Png); map.Dispose(); callbackContext.Success(); } catch (Exception err) { m_Logger.Error(err); callbackContext.Error(new { type = err.GetType().Name, code = "", message = err.Message, details = err.StackTrace }); } }
public async void UploadFilesAsync(FTPClientArgument[] ftpArguments, CallbackContext callbackContext) { try { Requires.NotNull(ftpArguments, nameof(ftpArguments)); var ftpArgumentGroups = ftpArguments.GroupBy(x => x.IP); foreach (var ftpArgumentGroup in ftpArgumentGroups) { var ftpClient = new FTPClient($"ftp://{ftpArgumentGroup.First().IP}"); foreach (var ftpArgument in ftpArgumentGroup) { await ftpClient.UploadFileAsync(ftpArgument.NeedCheckDirectory, ftpArgument.RemoteFilePath, ftpArgument.LocalFilePath, ftpArgument.UserName, ftpArgument.Password, ftpArgument.IsUsePassive); } } callbackContext.Success(); } catch (Exception ex) { m_Logger.Error(ex); callbackContext.Error(new { type = "Exception", code = "", message = ex.Message, details = ex.StackTrace }); } }
public void UploadAsync(FTPClientArgument ftpArgument, CallbackContext callbackContext) { try { Requires.NotNull(ftpArgument, "ftpArgument"); Requires.NotNullOrEmpty(ftpArgument.IP, "IP"); Requires.NotNullOrEmpty(ftpArgument.LocalFilePath, "LocalFilePath"); Requires.NotNullOrEmpty(ftpArgument.RemoteFilePath, "RemoteFilePath"); Requires.NotNullOrEmpty(ftpArgument.UserName, "UserName"); Requires.NotNullOrEmpty(ftpArgument.Password, "Password"); ftpArgument.LocalFilePath = Path.GetFullPath(ftpArgument.LocalFilePath);//相对路径转换成本地运行程序的绝对路径 this.UploadFileAsync(ftpArgument.NeedCheckDirectory, ftpArgument.IP, ftpArgument.RemoteFilePath, ftpArgument.LocalFilePath, ftpArgument.UserName, ftpArgument.Password, ftpArgument.IsUsePassive, callbackContext); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = "Exception", code = "", message = e.Message, details = e.StackTrace }); } }
public void RenameAsync(FTPRenameArgument renameArgument, CallbackContext callbackContext) { try { Requires.NotNull(renameArgument, "renameArgument"); Requires.NotNullOrEmpty(renameArgument.IP, "IP"); Requires.NotNullOrEmpty(renameArgument.RemoteFilePath, "RemoteFilePath"); Requires.NotNullOrEmpty(renameArgument.NewFileName, "NewFileName"); Requires.NotNullOrEmpty(renameArgument.UserName, "UserName"); Requires.NotNullOrEmpty(renameArgument.Password, "Password"); this.RenameFileAsync(renameArgument.IP, renameArgument.RemoteFilePath, renameArgument.NewFileName, renameArgument.UserName, renameArgument.Password, renameArgument.IsUsePassive, callbackContext); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = "Exception", code = "", message = e.Message, details = e.StackTrace }); } }
public void DeleteDirectoryAsync(DirectoryArgument directoryArgument, CallbackContext callbackContext) { try { Requires.NotNull(directoryArgument, "directoryArgument"); Requires.NotNullOrEmpty(directoryArgument.IP, "IP"); Requires.NotNullOrEmpty(directoryArgument.RemoteFilePath, "remoteFilePath"); Requires.NotNullOrEmpty(directoryArgument.UserName, "UserName"); Requires.NotNullOrEmpty(directoryArgument.Password, "Password"); m_Logger.Debug($"makeDirectoryArgument:{directoryArgument}"); this.DeleteFtpDirectoryAsync(directoryArgument.IP, directoryArgument.RemoteFilePath, directoryArgument.UserName, directoryArgument.Password, directoryArgument.IsUsePassive, callbackContext); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = "Exception", code = "", message = e.Message, details = e.StackTrace }); } }
public void UploadFiles(SFTPUploadArgument[] uploadArguments, string host, string username, string password, CallbackContext callbackContext) { try { Requires.NotNullOrEmpty(host, "remoteHost"); Requires.NotNullOrEmpty(username, "userName"); Requires.NotNullOrEmpty(password, "password"); foreach (SFTPUploadArgument uploadArgument in uploadArguments) { m_Logger.Debug($"uploadArgument:{uploadArgument}"); Requires.NotNull(uploadArgument, "uploadArgument"); Requires.NotNullOrEmpty(uploadArgument.LocalPathWithFileName, "localPathWithFileName"); Requires.NotNullOrEmpty(uploadArgument.BaseDirectory, "baseDirectory"); Requires.NotNullOrEmpty(uploadArgument.TargetPath, "targetPath"); } List <FtpStatusCode> result = new List <FtpStatusCode>(); _sftpClient = GetInstance(host, username, password); foreach (SFTPUploadArgument uploadArgument in uploadArguments) { var sftpResult = _sftpClient.UploadFile(uploadArgument.IsNeedCheckDirectory, uploadArgument.LocalPathWithFileName, uploadArgument.BaseDirectory, uploadArgument.TargetPath, uploadArgument.UpFileName); if (!string.IsNullOrEmpty(uploadArgument.NeedChage) && uploadArgument.NeedChage != "0") { short newPermission = Convert.ToInt16(uploadArgument.Permission); string _baseDir = uploadArgument.BaseDirectory + "/"; string[] paths = uploadArgument.TargetPath.Split('/'); foreach (string path in paths) { _baseDir = _baseDir + path + "/"; _sftpClient.changePermission(_baseDir, newPermission); } _sftpClient.changePermission(_baseDir + uploadArgument.UpFileName, newPermission); } result.Add(sftpResult); } callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } catch (Exception ex) { m_Logger.Error(ex); callbackContext.Error(new { type = "Exception", code = "", message = ex.Message, details = ex.StackTrace }); } }
public async void StartProcessAsync(string fileName, string[] arguments, bool isSystemProcess, bool isWaitForExit, CallbackContext callbackContext) { m_Logger.Debug($"[startProcessArgument]fileName:{fileName},Arguments:{arguments}"); Process startProcess = new Process(); try { await Task.Factory.StartNew(() => { startProcess.StartInfo.UseShellExecute = true; startProcess.StartInfo.FileName = Path.GetFullPath(fileName); if (isSystemProcess) { startProcess.StartInfo.FileName = fileName; } if (arguments.Length > 0 && arguments != null) { startProcess.StartInfo.Arguments = string.Join(" ", arguments); } startProcess.Start(); if (isWaitForExit) { startProcess.WaitForExit(); callbackContext.Success(startProcess.ExitCode); } else { callbackContext.Success(); } }); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = e.GetType().Name, code = "", message = e.Message, details = e.StackTrace }); } }
public void UploadFile(SFTPUploadArgument uploadArgument, CallbackContext callbackContext) { try { var sftpResult = UploadFile(uploadArgument); callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, sftpResult)); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = "Exception", code = "", message = e.Message, details = e.StackTrace }); } }
public void DownloadFiles(SFTPDownloadArgument[] downloadArguments, string host, string userName, string password, CallbackContext callbackContext) { try { Requires.NotNullOrEmpty(host, "remoteHost"); Requires.NotNullOrEmpty(userName, "userName"); Requires.NotNullOrEmpty(password, "password"); foreach (SFTPDownloadArgument downloadArgument in downloadArguments) { string[] paths = downloadArgument.RemotePathWithFileName.Split('/'); string fileName = paths[paths.Length - 1]; m_Logger.Debug($"downloadArgument:{downloadArgument}"); Requires.NotNull(downloadArgument, "downloadArgument"); Requires.NotNullOrEmpty(downloadArgument.RemotePathWithFileName, "remotePathWithFileName"); Requires.NotNullOrEmpty(downloadArgument.LocalPathWithoutFileName, "localPathWithoutFileName"); if (File.Exists(downloadArgument.LocalPathWithoutFileName + "\\" + fileName)) { File.Delete(downloadArgument.LocalPathWithoutFileName + "\\" + fileName); } } List <FtpStatusCode> result = new List <FtpStatusCode>(); _sftpClient = GetInstance(host, userName, password); foreach (SFTPDownloadArgument downloadArgument in downloadArguments) { var sftpResult = _sftpClient.DownloadFile(downloadArgument.RemotePathWithFileName, downloadArgument.LocalPathWithoutFileName); result.Add(sftpResult); } callbackContext.Success(new PluginResult(PluginResult.Status.OK, result)); } catch (Exception ex) { m_Logger.Error(ex); callbackContext.Error(new { type = "Exception", code = "", message = ex.Message, details = ex.StackTrace }); } }
public void DownloadFileLegacy(SFTPDownloadArgument downloadArgument, CallbackContext callbackContext) { try { var sftpResult = DownloadFile(downloadArgument); _sftpClient.Close(); _sftpClient = null; callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, sftpResult)); } catch (Exception ex) { m_Logger.Error(ex); callbackContext.Error(new { type = "Exception", code = "", message = ex.Message, details = ex.StackTrace }); } }
public async void ListDirectoryAsync(string ip, string remoteFilePath, string userName, string password, bool isUsePassive, CallbackContext callbackContext) { m_Logger.Debug($"ip:{ip},remoteFilePath:{remoteFilePath}"); try { FTPClient ftpClient = new FTPClient($"ftp://{ip}"); string[] ftpResult = await ftpClient.ListDirectoryAsync(remoteFilePath, userName, password, isUsePassive); callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, ftpResult)); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = "Exception", code = "", message = e.Message, details = e.StackTrace }); } }
public async void MakeSubDirectoryAsync(string ip, string remoteFilePath, string userName, string password, bool isUsePassive, CallbackContext callbackContext) { try { m_Logger.Debug($"ip:{ip},remoteFilePath:{remoteFilePath}"); FTPClient ftpClient = new FTPClient($"ftp://{ip}"); await ftpClient.CheckDirectoryAsync(remoteFilePath, userName, password, isUsePassive); callbackContext.Success(); } catch (Exception e) { m_Logger.Error(e); callbackContext.Error(new { type = "Exception", code = "", message = e.Message, details = e.StackTrace }); } }
public void ReadQRCode(string fileName, CallbackContext callbackContext) { try { m_Logger.Debug($"[QRCodeUtils]ReadRQCode=>fileName:{fileName}"); var qrCodeResult = new QRCodeResult(); List <string> textList = new List <string>(); if (!File.Exists(fileName)) { qrCodeResult.IsSuccess = false; textList.Add("文件路径不存在"); qrCodeResult.Content = textList.ToArray(); callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, qrCodeResult)); return; } using (FileStream fs = new FileStream(fileName, FileMode.Open)) { QRCodeMultiReader qc = new QRCodeMultiReader(); Image image = Image.FromStream(fs); Bitmap bitmap = new Bitmap(image); LuminanceSource source = new BitmapLuminanceSource(bitmap); BinaryBitmap binarybitmap = new BinaryBitmap(new HybridBinarizer(source)); IDictionary <DecodeHintType, object> hints = new Dictionary <DecodeHintType, object>(); hints.Add(DecodeHintType.CHARACTER_SET, "UTF-8"); hints.Add(DecodeHintType.TRY_HARDER, "3"); Result[] decodeResult = qc.decodeMultiple(binarybitmap, hints); m_Logger.Debug($"[QRCodeUtils]ReadRQCode=>decodeResult == null:{decodeResult == null}"); if (decodeResult == null || decodeResult.Length == 0) { qrCodeResult.IsSuccess = false; textList.Add("无法识别图片中的二维码"); qrCodeResult.Content = textList.ToArray(); callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, qrCodeResult)); return; } foreach (Result res in decodeResult) { if (res.Text != null) { textList.Add(res.Text); } } } qrCodeResult.Content = textList.ToArray(); m_Logger.Debug($"[QRCodeUtils]ReadRQCode=>textList.ToArray().Length:{textList.ToArray().Length}"); if (textList.ToArray().Length == 0) { qrCodeResult.IsSuccess = false; callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, qrCodeResult)); return; } qrCodeResult.IsSuccess = true; callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, qrCodeResult)); } catch (Exception err) { m_Logger.Error(err); callbackContext.Error(new { type = err.GetType().Name, code = "", message = err.Message, details = err.StackTrace }); } }