private string TransFile(string userName, string pwd, string ip, string fromPath, string toPath) { string mess = ""; using (SharedTool tool = new SharedTool(userName, pwd, ip)) { if (System.IO.File.Exists(fromPath)) { try { System.IO.File.Copy(fromPath, toPath, true);//从客户端拷贝文件到服务端(覆盖式拷贝) mess = string.Format("结果:true;此IP({0})的终端下({1})数据库处理成功", ip, fromPath); } catch (Exception ex) { mess = string.Format("结果:false;此IP({0})的终端下({1})备份文件传输失败", ip, fromPath); } } else { mess = string.Format("结果:false;此IP({0})的终端下此文件路径不存在({1})", ip, fromPath); } return(mess); } }
private List <lhh_LoginList_info> Local_IP1() { string[] ob = Regex.Split(ZFCEPath, @"\\", RegexOptions.IgnoreCase); //bool status = SharedTool.connectState(@"\\192.168.1.2", @"administrator", "333333"); string ipadd = "\\\\" + ob[2]; bool status = SharedTool.connectState(ipadd, @netuser, netpassword); if (!File.Exists(ZFCEPath) && status != true) { MessageBox.Show("没有找到此路径或此文件,请保证共享文件存在或权限共享机登录账户密码配置正确!"); System.Environment.Exit(0); return(null); } InfoList = new List <lhh_LoginList_info>(); //string A_Path = AppDomain.CurrentDomain.BaseDirectory + "辣皇后\\user control.txt"; try { if (File.Exists(ZFCEPath)) { string[] fileText = File.ReadAllLines(ZFCEPath); if (fileText.Length > 0 && fileText[0] != null && fileText[0] != "") { for (int i = 1; i < fileText.Length; i++) { string[] texttemp = System.Text.RegularExpressions.Regex.Split(fileText[i], "\t"); lhh_LoginList_info temp = new lhh_LoginList_info(); if (texttemp[0] != null) { temp.loginid = texttemp[0].ToString().Trim(); } if (texttemp[1] != null) { temp.pwd = texttemp[1].ToString().Trim(); } if (texttemp[2] != null) { temp.startTime = texttemp[2].ToString().Trim(); } if (texttemp[3] != null) { temp.endTime = Convert.ToDateTime(texttemp[3].ToString()); } InfoList.Add(temp); } } } } catch (Exception ex) { MessageBox.Show("异常,请参照使用说明修改:" + ex.Message); return(null); throw; } return(InfoList); }
public async Task <string> UploadFile(byte[] bytes, string extra, string type = "") { //bool status = false; ////链接 //status = TransportConnectHelper.connectState(mapDirPath, "waveaccess", "waveaccessxxx"); Logger.Info("进入本地上传文件"); //uint state = 0; //if (!Directory.Exists(mapDirPath)) //{ // Logger.Info("不存在该地址"); // try // { // state = WNetHelper.WNetAddConnection(mapDirUserName, mapDirPwd, mapDirRemotingName, mapDirPath); // } // catch (Exception e) // { // WNetHelper.WNetCancelConnection(mapDirUserName, 1, true); // Logger.Error($"网络地址错误:{e.Message}"); // throw e; // } //} //if (state.Equals(0)) using (SharedTool tool = new SharedTool(mapDirUserName, mapDirPwd, mapDirRemotingIP)) { var typepath = string.IsNullOrEmpty(type) ? "" : $"{type}/"; if (!Directory.Exists($"{filePath}/{typepath}{DateTime.Now.ToString("yyyy-MM-dd")}")) { Logger.Info($"创建地址:{filePath}/{typepath}{DateTime.Now.ToString("yyyy-MM-dd")}"); Directory.CreateDirectory($"{filePath}/{typepath}{DateTime.Now.ToString("yyyy-MM-dd")}"); } string tmplname = $"{typepath}{DateTime.Now.ToString("yyyy-MM-dd")}/{GuidHelper.CreateTimeGuid()}.{extra}"; var path = Path.Combine(filePath, tmplname); Logger.Info($"文件存储物理地址{path}"); //using (FileStream fs = File.Create($"{_appFolders.TempFileDownloadFolder}/{tmplname}")) using (FileStream fs = File.Create(path)) { await fs.WriteAsync(bytes, 0, bytes.Length); } //return _webUrlService.GetServerRootAddress() + $@"Temp/Downloads/{tmplname}"; var result = fileDownloadUrl + $@"{tmplname}"; Logger.Info($"文件虚拟地址{result}"); return(result); } //else //{ // WNetHelper.WNetCancelConnection(mapDirUserName, 1, true); // Logger.Info($"添加网络驱动器错误,错误号:{state.ToString()}"); // throw new UserFriendlyException($"添加网络驱动器错误,错误号:{state.ToString()}"); //} }
public frmquanshengcailiao(string password) { try { //bat_dsoframer(); InitializeComponent(); pass = password; Local_IP(); int ssd = 0; #region test tabControl1.TabPages[2].Parent = null; //调用的是 AxDSOFramer 也好用,但是打开保存后共享Excel就变位只读了 tabControl1.TabPages[2].Parent = null; //统计表wb 按钮好用 toolStripButton5.Visible = false; #endregion // ZFCEPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "全晟新材料\\jxc.xlsx"); // ZFCEPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "加气砖统计表\\2019年加气砖统计表.xlsx"); //ssd = 1; if (ssd == 0) { string[] ob = Regex.Split(ZFCEPath, @"\\", RegexOptions.IgnoreCase); //bool status = SharedTool.connectState(@"\\192.168.1.2", @"administrator", "333333"); string ipadd = "\\\\" + ob[2]; if (!ZFCEPath.Contains("D:\\Devlop\\报价单\\ewm\\Excel_baojiadan\\QCAuto\\bin\\Debug")) { bool status = SharedTool.connectState(ipadd, @netuser, netpassword); if (!File.Exists(ZFCEPath) && status != true) { MessageBox.Show("没有找到此路径或此文件,请保证共享文件存在!"); System.Environment.Exit(0); return; } } } #region 好用但是弹窗有结果 //string cmd = @"regsvr32 C:\Windows\SysWOW64\dsoframer.ocx"; //string output = ""; //RunCmd(cmd, out output); #endregion } catch (Exception ex) { MessageBox.Show("" + ex); throw; } }
private void RemoteDesktop(ExCommandParameter param) { try { //先切换网口 int no = 0; Camera camera = null; if (param.Sender is Button) { var sender = param.Sender as Button; no = int.Parse(sender.Tag.ToString()); camera = this.Cameras.SingleOrDefault(c => c.Id == no); } else if (param.Sender is MenuItem) { var sender = param.Sender as MenuItem; no = int.Parse(sender.Tag.ToString()); if (this.currentPad == null) { return; } camera = this.currentPad.Cameras.SingleOrDefault(c => c.Id == no); } if (camera == null) { return; } Task.Run(() => { camera.IsSwitching = true; SwitchCameraNetPort(camera); System.Threading.Thread.Sleep(3000); camera.IsSwitching = false; Task.Run(() => { try { //从下位机获取图片 string root = "\\\\" + camera.IP + "\\Alarm_Pic"; DateTime now = DateTime.Now; DateTime yesterday = now.AddDays(-1); yesterday = now; string picDir = Path.Combine(root, "pic_" + yesterday.ToString("yyyy_MM_dd")); using (SharedTool tool = new SharedTool("Admin", "", camera.IP)) { //采集图片 camera.IsDownloadingImage = true; string[] dirs = Directory.GetDirectories(picDir); foreach (var dir in dirs) { if (Path.GetFileName(dir).StartsWith("下位机") && dir.EndsWith("报警截图")) { camera.IsDownloadingImage = true; while (true) { string[] images = Directory.GetFiles(dir, "*.jpg"); foreach (var img in images) { string parentDir = Path.GetDirectoryName(img); string rootDir = Path.GetPathRoot(parentDir); picDir = parentDir.Substring(parentDir.IndexOf(rootDir) + 1 + rootDir.Length); string localPath = Path.Combine(this.copyImagePath, picDir); if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } string localImg = Path.Combine(localPath, Path.GetFileName(img)); if (!File.Exists(localImg)) { File.Copy(img, localImg); } } Thread.Sleep(2000); } } } } } catch (Exception ex) { //App.Current.Dispatcher.Invoke(() => //{ // ModernDialog.ShowMessage(ex.Message+",图片采集已中止!", "提示", MessageBoxButton.OK); //}); } finally { camera.IsDownloadingImage = false; } }); //启动远程桌面,使用mstsc命令读取rdp文件 string rdpFile = camera.Name + ".rdp"; if (!File.Exists(rdpFile)) { ExecuteCmd($"mstsc /admin"); } else { ExecuteCmd($"mstsc /admin \"{rdpFile}\""); } }); } catch (Exception ex) { App.Current.Dispatcher.Invoke(() => { ModernDialog.ShowMessage(ex.Message, "提示", MessageBoxButton.OK); }); } }