Example #1
0
        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
                });
            }
        }
Example #2
0
 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
         });
     }
 }
Example #3
0
        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
                });
            }
        }
Example #4
0
        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
                });
            }
        }
Example #5
0
 public void Disconnect(CallbackContext callbackContext)
 {
     if (_sftpClient != null)
     {
         _host     = "";
         _username = "";
         _password = "";
         _sftpClient.Close();
     }
     callbackContext.Success();
 }
Example #6
0
 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
         });
     }
 }
Example #7
0
        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
                });
            }
        }
Example #8
0
 public bool GetFlag(CallbackContext callback) {
     
     callback.Success(this.flag);
     
     return this.flag;
 }
 public override bool Execute(String action, CordovaArgs args, CallbackContext context)
 {
     counter++;
     context.Success(counter.ToString());
     return(true);
 }
Example #10
0
 public override bool Execute(String action, CordovaArgs args, CallbackContext context)
 {
     counter++;
     context.Success(counter.ToString());
     return true;
 }