/// <summary> /// 日志 /// </summary> public static void WriteLog(toolpars Toolpars, ListBox listDATA) { string txtNewTypeKey = Toolpars.formEntity.txtNewTypeKey; string LogStr = txtNewTypeKey + Environment.NewLine; string varAppPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "log"; Directory.CreateDirectory(varAppPath); string head = DateTime.Now.ToString("hh:mm:ss:fff"); for (int s = 0; s < listDATA.Items.Count; s++) { LogStr += listDATA.Items[s].ToString() + "\r\n"; } string logMessage = head + Environment.NewLine + LogStr + System.Environment.NewLine; string strDate = System.DateTime.Now.ToString("yyyyMMdd"); string strFile = varAppPath + "\\" + strDate + ".log"; using (StreamWriter SW = new StreamWriter(strFile, true)) { SW.WriteLine(logMessage); SW.Flush(); SW.Close(); } ; }
public static void copyDll(toolpars Toolpars) { var PathEntity = Toolpars.PathEntity; if (PathEntity != null) { string serverPath = PathEntity.ServerPath; string clientPath = PathEntity.DeployServerPath; string businessDllFullPath = PathEntity.ExportPath + PathEntity.BusinessDllName; string ImplementDllFullPath = PathEntity.ExportPath + PathEntity.ImplementDllName; string UIDllFullPath = PathEntity.ExportPath + PathEntity.UIDllName; string UIImplementDllFullPath = PathEntity.ExportPath + PathEntity.UIImplementDllName; //Path.GetDirectoryName() string toPath = string.Empty; if (File.Exists(businessDllFullPath)) { if (Directory.Exists(serverPath)) { toPath = serverPath + PathEntity.BusinessDllName; File.Copy(businessDllFullPath, toPath, true); } if (Directory.Exists(clientPath)) { toPath = clientPath + PathEntity.BusinessDllName; File.Copy(businessDllFullPath, toPath, true); } } if (File.Exists(ImplementDllFullPath)) { if (Directory.Exists(serverPath)) { File.Copy(ImplementDllFullPath, serverPath + PathEntity.ImplementDllName, true); } } if (File.Exists(UIDllFullPath)) { if (Directory.Exists(clientPath)) { File.Copy(UIDllFullPath, clientPath + PathEntity.UIDllName, true); } } if (File.Exists(UIImplementDllFullPath)) { if (Directory.Exists(clientPath)) { File.Copy(UIImplementDllFullPath, clientPath + PathEntity.UIImplementDllName, true); } } } }
/// <summary> /// 獲取各種路徑 /// </summary> /// <param name="name"></param> /// <returns></returns> public static PathEntity getPathEntity(toolpars Toolpars) { var SettingPathEntity = Toolpars.SettingPathEntity; string serverProgramsPath = CombineStr(new[] { Toolpars.Mplatform, SettingPathEntity.ServerDir, SettingPathEntity.Programs }); string clientProgramsPath = CombineStr(new[] { Toolpars.Mplatform, SettingPathEntity.DeployServerDir, SettingPathEntity.Programs }); string ExportPath = CombineStr(new[] { Toolpars.formEntity.txtToPath, SettingPathEntity.ExportDir }); string txtNewTypeKey = Toolpars.formEntity.txtNewTypeKey; string rootDir = CombineStr(new[] { SettingPathEntity.PackageBaseName, txtNewTypeKey }); string businessDir = CombineStr(new[] { rootDir, SettingPathEntity.BusinessDirExtention }); string ImplementDir = CombineStr(new[] { businessDir, SettingPathEntity.ImplementDirExtention }); string UIDir = CombineStr(new[] { rootDir, SettingPathEntity.UIDirExtention }); string UIImplementDir = CombineStr(new[] { UIDir, SettingPathEntity.ImplementDirExtention }); string businessDllName = CombineStr(new[] { businessDir, SettingPathEntity.DllExtention }); string ImplementDllName = CombineStr(new[] { ImplementDir, SettingPathEntity.DllExtention }); string UIDllName = CombineStr(new[] { UIDir, SettingPathEntity.DllExtention }); string UIImplementDllName = CombineStr(new[] { UIImplementDir, SettingPathEntity.DllExtention }); if (Toolpars.MIndustry) { serverProgramsPath = CombineStr(new[] { Toolpars.Mplatform, SettingPathEntity.IndustryServerDir, SettingPathEntity.Programs }); clientProgramsPath = CombineStr(new[] { Toolpars.Mplatform, SettingPathEntity.IndustryDeployDir, SettingPathEntity.Programs }); } PathEntity pathEntity = new PathEntity() { ServerProgramsPath = serverProgramsPath, DeployProgramsPath = clientProgramsPath, ExportPath = ExportPath, RootDir = rootDir, BusinessDir = businessDir, ImplementDir = ImplementDir, UIDir = UIDir, UIImplementDir = UIImplementDir, BusinessDllName = businessDllName, ImplementDllName = ImplementDllName, UIDllName = UIDllName, UIImplementDllName = UIImplementDllName }; return(pathEntity); }
/// <summary> /// 把文件拷入指定的文件夹 /// </summary> /// <param name="fromDir"></param> /// <param name="toDir"></param> /// <param name="filterName"></param> public static void copyTo(toolpars Toolpars, string fromDir, string toDir, List <string> fileNames, string fromTypeKey, string ToTypeKey) { var formFiles = GetFilePath(fromDir); foreach (var file in formFiles) { if (!File.Exists(file)) { continue; } FileInfo fileinfo = new FileInfo(file); string file_name = Path.GetFileNameWithoutExtension(file); if (!fileNames.Contains(file_name)) { continue; } string absolutedir = fileinfo.Directory.FullName.Replace(fromDir, string.Empty); string absolutePath = file.Replace(fromDir, string.Empty); string newFilePath = Path.Combine(toDir, absolutePath); string newFileDir = Path.Combine(toDir, absolutedir).Replace(fromTypeKey, ToTypeKey); if (!Directory.Exists(newFileDir)) { Directory.CreateDirectory(newFileDir); } if (File.Exists(newFilePath)) { if (MessageBox.Show("文件已存在,是否覆盖?", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning) != DialogResult.OK) { return; } } fileinfo.CopyTo(newFilePath); changeText(newFilePath, fromTypeKey, ToTypeKey); FileInfo newfileinfo = new FileInfo(newFilePath); var dir = newfileinfo.Directory; //dir.Parent //Tools.ModiCS(mpaths + @"\" + StrYY + ".Business.Implement\\" + StrYY + // ".Business.Implement.csproj", "Interceptor\\DetailInterceptorS" + ra + ".cs"); } ; }
/// <summary> /// 獲取各種路徑 /// </summary> /// <param name="name"></param> /// <returns></returns> public static PathEntity getPathEntity(toolpars Toolpars) { string serverPath = Toolpars.Mplatform + "\\Server\\Application\\Customization\\Programs\\"; string clientPath = Toolpars.Mplatform + "\\DeployServer\\Shared\\Customization\\Programs\\"; string ExportPath = Toolpars.formEntity.txtToPath + "\\Export\\"; string txtNewTypeKey = Toolpars.formEntity.txtNewTypeKey; string businessDllName = "Digiwin.ERP." + txtNewTypeKey + ".Business.dll"; string ImplementDllName = "Digiwin.ERP." + txtNewTypeKey + ".Business.Implement.dll"; string UIDllName = "Digiwin.ERP." + txtNewTypeKey + ".UI.dll"; string UIImplementDllName = "Digiwin.ERP." + txtNewTypeKey + ".UI.Implement.dll"; string businessDir = "Digiwin.ERP." + txtNewTypeKey; string ImplementDir = "Digiwin.ERP." + txtNewTypeKey + ".Business.Implement"; string UIDir = "Digiwin.ERP." + txtNewTypeKey + ".UI"; string UIImplementDir = "Digiwin.ERP." + txtNewTypeKey + ".UI.Implement"; if (Toolpars.MIndustry) { serverPath = Toolpars.Mplatform + "\\Server\\Application\\Industry\\Programs\\"; clientPath = Toolpars.Mplatform + "\\DeployServer\\Shared\\Industry\\Programs\\"; } PathEntity pathEntity = new PathEntity() { ServerPath = serverPath, DeployServerPath = clientPath, ExportPath = ExportPath, BusinessDllName = businessDllName, ImplementDllName = ImplementDllName, UIDllName = UIDllName, UIImplementDllName = UIImplementDllName }; return(pathEntity); // Toolpars.PathEntity = pathEntity; }
public static void CopyFileCS(string mfileN, string mtos, string mfrom, toolpars Toolpars) { string txtNewTypeKey = Toolpars.formEntity.txtNewTypeKey; if (Directory.Exists(mfileN)) { if (!Directory.Exists(mtos.Substring(0, mtos.LastIndexOf("\\")))) { Directory.CreateDirectory(mtos.Substring(0, mtos.LastIndexOf("\\"))); } System.IO.File.Copy(mfrom, mtos, true); } else { string mresult = mfileN.Substring(mfileN.LastIndexOf("\\") + 1); mresult = mresult.Substring(mresult.IndexOf(".") + 1); mresult = mresult.Substring(mresult.IndexOf(".") + 1); mresult = mresult.Substring(mresult.IndexOf(".") + 1); DialogResult result = MessageBox.Show("路径" + mfileN + "\r\n目錄不存在,是否建立??", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { CopyAll(Toolpars.MVSToolpath + "Digiwin.ERP.XTEST\\Digiwin.ERP.XTEST." + mresult, mfileN); #region 修改文件名 DirectoryInfo tDes = new DirectoryInfo(mfileN + @"\"); List <string> tSearchPatternList = new List <string>(); tSearchPatternList.Add("*xml"); tSearchPatternList.Add("*.sln"); tSearchPatternList.Add("*.repx"); tSearchPatternList.Add("*proj"); tSearchPatternList.Add("*.complete"); tSearchPatternList.Add("*.cs"); foreach (System.IO.DirectoryInfo d in tDes.GetDirectories("*", SearchOption.AllDirectories)) { if (d.Name.IndexOf(txtNewTypeKey) == -1) { if (d.Name.IndexOf(Toolpars.OldTypekey) != -1) { if ( File.Exists(d.Parent.FullName + "\\" + d.Name.Replace(Toolpars.OldTypekey, txtNewTypeKey))) { File.SetAttributes( d.Parent.FullName + "\\" + d.Name.Replace(Toolpars.OldTypekey, txtNewTypeKey), FileAttributes.Normal); File.Delete(d.Parent.FullName + "\\" + d.Name.Replace(Toolpars.OldTypekey, txtNewTypeKey)); } if ( Directory.Exists(d.Parent.FullName + "\\" + d.Name.Replace(Toolpars.OldTypekey, txtNewTypeKey)) == false) { d.MoveTo(d.Parent.FullName + "\\" + d.Name.Replace(Toolpars.OldTypekey, txtNewTypeKey)); } Application.DoEvents(); } } } foreach (FileInfo f in tDes.GetFiles("*", SearchOption.AllDirectories)) { if (f.Name.IndexOf(txtNewTypeKey) == -1) { if (f.Name.IndexOf(Toolpars.OldTypekey) != -1) { if (File.Exists(f.FullName)) { if ( File.Exists(f.Directory.FullName + "\\" + f.Name.Replace(Toolpars.OldTypekey, txtNewTypeKey)) == false) { f.MoveTo(f.Directory.FullName + "\\" + f.Name.Replace(Toolpars.OldTypekey, txtNewTypeKey)); } Application.DoEvents(); } } } } for (int i = 0; i < tSearchPatternList.Count; i++) { foreach ( FileInfo f in tDes.GetFiles(tSearchPatternList[i], SearchOption.AllDirectories)) { if (File.Exists(f.FullName)) { string text = File.ReadAllText(f.FullName); text = text.Replace(Toolpars.OldTypekey, txtNewTypeKey); File.SetAttributes(f.FullName, FileAttributes.Normal); File.Delete(f.FullName); File.WriteAllText(f.FullName, text, Encoding.UTF8); //^_^ 20160802 by 05485 for 编码方式修改 Application.DoEvents(); } } } #endregion if (!Directory.Exists(mtos.Substring(0, mtos.LastIndexOf("\\")))) { Directory.CreateDirectory(mtos.Substring(0, mtos.LastIndexOf("\\"))); } File.Copy(mfrom, mtos, true); } else { return; } } }
/// <summary> /// /// </summary> /// <param name="Toolpars"></param> public static void ModiName(toolpars Toolpars) { string txtNewTypeKey = Toolpars.formEntity.txtNewTypeKey; string DirectoryPath = string.Format(@"{0}\Digiwin.ERP.{1}\", Toolpars.GToIni, txtNewTypeKey); DirectoryInfo tDes = new DirectoryInfo(DirectoryPath); List <string> tSearchPatternList = new List <string>(); tSearchPatternList.AddRange(new[] { "*xml", "*.sln", "*.repx", "*proj", "*.complete", "*.cs" }); foreach (System.IO.DirectoryInfo d in tDes.GetDirectories("*", SearchOption.AllDirectories)) { if (d.Name.IndexOf(txtNewTypeKey) == -1) { if (d.Name.IndexOf(txtNewTypeKey.Substring(1)) != -1) { if ( File.Exists(d.Parent.FullName + "\\" + d.Name.Replace(txtNewTypeKey.Substring(1), txtNewTypeKey))) { File.SetAttributes( d.Parent.FullName + "\\" + d.Name.Replace(txtNewTypeKey.Substring(1), txtNewTypeKey), FileAttributes.Normal); File.Delete(d.Parent.FullName + "\\" + d.Name.Replace(txtNewTypeKey.Substring(1), txtNewTypeKey)); } if ( Directory.Exists(d.Parent.FullName + "\\" + d.Name.Replace(txtNewTypeKey.Substring(1), txtNewTypeKey)) == false) { d.MoveTo(d.Parent.FullName + "\\" + d.Name.Replace(txtNewTypeKey.Substring(1), txtNewTypeKey)); } Application.DoEvents(); } } } foreach (System.IO.FileInfo f in tDes.GetFiles("*", SearchOption.AllDirectories)) { if (f.Name.IndexOf(txtNewTypeKey) == -1) { if (f.Name.IndexOf(txtNewTypeKey.Substring(1)) != -1) { if (File.Exists(f.FullName)) { if ( File.Exists(f.Directory.FullName + "\\" + f.Name.Replace("Digiwin.ERP." + txtNewTypeKey.Substring(1), "Digiwin.ERP." + txtNewTypeKey)) == false) { f.MoveTo(f.Directory.FullName + "\\" + f.Name.Replace("Digiwin.ERP." + txtNewTypeKey.Substring(1), "Digiwin.ERP." + txtNewTypeKey)); } Application.DoEvents(); } } } } for (int i = 0; i < tSearchPatternList.Count; i++) { foreach (System.IO.FileInfo f in tDes.GetFiles(tSearchPatternList[i], SearchOption.AllDirectories)) { if (File.Exists(f.FullName)) { string text = File.ReadAllText(f.FullName); text = text.Replace("Digiwin.ERP." + txtNewTypeKey.Substring(1), "Digiwin.ERP." + txtNewTypeKey); text = text.Replace(@"<HintPath>..\..\", @"<HintPath>..\..\..\..\..\WD_PR\SRC\"); File.SetAttributes(f.FullName, FileAttributes.Normal); File.Delete(f.FullName); File.WriteAllText(f.FullName, text, System.Text.UTF8Encoding.UTF8); Application.DoEvents(); } } } }