Example #1
0
 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
         });
     }
 }
Example #2
0
 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
         });
     }
 }
Example #3
0
 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
         });
     }
 }
Example #4
0
        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
                });
            }
        }
Example #5
0
        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
                });
            }
        }