private bool GenWinSolution(WinClientParam winParam, ClientParam cParam) { Solution sln = _dte2.Solution; string BaseFormName = GetBaseWinForm(cbIsMasterDetails.Checked); FTemplatePath = Path.GetDirectoryName(_addIn.Object.GetType().Assembly.Location) + "\\Templates\\"; string CurrentSln = _dte2.Solution.FileName; String lan = GetLanguage(); string BaseFormProj = BaseFormName + "\\" + BaseFormName + lan + "proj"; string FilePath = winParam.OutputPath + "\\" + winParam.PackageName; if (System.IO.Directory.Exists(FilePath)) { if (FilePath == "\\") throw new Exception("Unknown Output Path: " + "\\"); DialogResult dr = MessageBox.Show("There is another File which name is " + winParam.PackageName + " existed! Do you want to delete it first", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.Yes) { try { System.IO.Directory.Delete(FilePath, true); } catch { System.IO.Directory.Delete(FilePath, true); } } else { return false; } } Project P = sln.AddFromTemplate(FTemplatePath + BaseFormProj, FilePath, winParam.PackageName, true); P.Name = winParam.PackageName; string FileName = FilePath + "\\" + winParam.PackageName + lan + "proj"; P.Save(FileName); sln.Open(CurrentSln); int I; P = null; for (I = 1; I <= sln.Projects.Count; I++) { P = sln.Projects.Item(I); if (string.Compare(P.Name, winParam.PackageName) == 0) break; else P = null; } if (P != null) sln.Remove(P); P = sln.AddFromFile(FilePath + "\\" + winParam.PackageName + lan + "proj", false); P.Properties.Item("RootNamespace").Value = winParam.PackageName; P.Properties.Item("AssemblyName").Value = winParam.PackageName; sln.SaveAs(sln.FileName); sln.SolutionBuild.StartupProjects = P; sln.SolutionBuild.BuildProject(sln.SolutionBuild.ActiveConfiguration.Name, P.FullName, true); GlobalProject = P; if (winParam.AssemblyOutputPath != null && winParam.AssemblyOutputPath != "") GlobalProject.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value = winParam.AssemblyOutputPath; return true; }
private void GenWinForm(WinClientParam winParam, ClientParam cParam) { Solution Sln = _dte2.Solution; Project P = null; int I; for (I = 1; I <= Sln.Projects.Count; I++) { P = Sln.Projects.Item(I); if (string.Compare(winParam.PackageName, P.Name) == 0) break; P = null; } if (P == null) throw new Exception("Can not find project " + winParam.PackageName + " in solution"); ProjectItem PI; String lan = GetLanguage(); for (I = P.ProjectItems.Count; I >= 1; I--) { PI = P.ProjectItems.Item(I); if (string.Compare(PI.Name, "Form1" + lan) == 0) { string Path = PI.get_FileNames(0); Path = System.IO.Path.GetDirectoryName(Path); RenameNameSpace(Path + "\\Form1" + lan, winParam.PackageName, cParam.FormName); RenameNameSpace(Path + "\\Form1.Designer" + lan, winParam.PackageName, cParam.FormName); Window W = PI.Open("{00000000-0000-0000-0000-000000000000}"); W.Activate(); GlobalPI = PI; GlobalWindow = W; if (string.Compare(cParam.FormName, "Form1") != 0) { PI.Name = cParam.FormName + lan; W.Close(vsSaveChanges.vsSaveChangesYes); W = PI.Open("{00000000-0000-0000-0000-000000000000}"); W.Activate(); } FDesignerHost = (IDesignerHost)W.Object; FRootForm = (System.Windows.Forms.Form)FDesignerHost.RootComponent; FRootForm.Name = cParam.FormName; FRootForm.Text = cParam.FormTitle; IComponentChangeService FComponentChangeService = (IComponentChangeService)FDesignerHost.RootComponent.Site.GetService(typeof(IComponentChangeService)); } if (string.Compare(PI.Name, "Program" + lan) == 0) { RenameNameSpace(PI.get_FileNames(0), winParam.PackageName, cParam.FormName); } } }
public static void WinCreateXSD(Project GlobalProject, InfoDataSet FDataSet, ClientParam cParam, WinClientParam winParam) { string filePath = winParam.OutputPath + "\\" + winParam.PackageName + "\\"; bool CreateFileSucess = true; string fileName = ""; try { fileName = filePath + FDataSet.Site.Name + ".xsd"; FDataSet.RealDataSet.WriteXmlSchema(fileName); } catch { CreateFileSucess = false; MessageBox.Show("Failed to create xsd file!"); } finally { if (CreateFileSucess && File.Exists(fileName)) { GlobalProject.ProjectItems.AddFromFile(fileName); } } }
private WinClientParam GetWinClientParams() { WinClientParam winParam = new WinClientParam(); winParam.PackageName = tbPackageName.Text; winParam.OutputPath = tbOutputPath.Text; winParam.AssemblyOutputPath = tbAssemblyOutputPath.Text; return winParam; }
public static void GenDataSet(Project GlobalProject, ClientParam cParam, WinClientParam winParam, IDesignerHost FDesignerHost) { InfoDataSet FDataSet = FDesignerHost.CreateComponent(typeof(InfoDataSet), "id" + cParam.TableName) as InfoDataSet; FDataSet.RemoteName = cParam.ProviderName; FDataSet.Active = true; FDataSet.AlwaysClose = true; InfoBindingSource MainBindingSource = FDesignerHost.CreateComponent(typeof(InfoBindingSource), "ibs" + cParam.TableName) as InfoBindingSource; MainBindingSource.DataSource = FDataSet; MainBindingSource.DataMember = FDataSet.RealDataSet.Tables[0].TableName; WinCreateXSD(GlobalProject, FDataSet, cParam, winParam); }