public ClassPicker(CodeElements elements, string defaultNs, SelectionCollection selections) { InitializeComponent(); // Add all classes. this.defaultNs = defaultNs; IterateElements(elements); if (lstClasses.Items.Count == 1) { lstClasses.Items[0].Checked = true; } if (selections != null) { foreach (Selection sel in selections) { foreach (ListViewItem item in lstClasses.Items) { if (item.Text == sel.ClassName) { item.Checked = true; } } } } }
private void SaveSelections(SelectionCollection selections) { string key = BuildItemKey(CurrentItem); CurrentItem.ContainingProject.Globals[key] = selections.ToString(); CurrentItem.ContainingProject.Globals.set_VariablePersists(key, true); }
private SelectionCollection ShowSelectionUI(SelectionCollection selections) { ClassPicker picker = new ClassPicker(CurrentItem.FileCodeModel.CodeElements, base.FileNameSpace, selections); if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK) { selections = picker.Selections; } return(selections); }
public static SelectionCollection FromString(string serializedData) { string[] items = serializedData.Split('|'); SelectionCollection col = new SelectionCollection(); foreach (string item in items) { col.Add(Selection.FromString(item)); } return(col); }
private string[] GetTypesFromSelection(SelectionCollection selections) { string assemblyName = CurrentItem.ContainingProject.Properties.Item("AssemblyName").Value.ToString(); string[] types = new string[selections.Count]; for (int i = 0; i < selections.Count; i++) { types[i] = selections[i].ClassName + ", " + assemblyName; } return(types); }
/// <summary> /// Generates the output. /// </summary> protected override string OnGenerateCode(string inputFileName, string inputFileContent) { ThrowIfNoClassFound(); string outputPath = GetProjectOutputFullPath(); // Force compilation of the current project. We need the type in the output. CurrentItem.DTE.Solution.SolutionBuild.BuildProject( CurrentItem.DTE.Solution.SolutionBuild.ActiveConfiguration.Name, CurrentItem.ContainingProject.UniqueName, true); if (CurrentItem.DTE.Solution.SolutionBuild.LastBuildInfo == 1) { return(Properties.Resources.XGenTool_ProjectDoesNotCompile + File.ReadAllText(Path.ChangeExtension(InputFilePath, GetDefaultExtension()))); } CopyDesignToOutput(outputPath); SelectionCollection selections = GetSerializedSelection(); selections = ShowSelectionUI(selections); if (selections == null || selections.Count == 0) { return(String.Empty); } StringBuilder output = new StringBuilder(); AppDomainSetup appSetup = new AppDomainSetup(); appSetup.ApplicationName = typeof(XGenTool).Namespace; appSetup.ApplicationBase = outputPath; appSetup.ConfigurationFile = ConfigFile; string[] targetTypes = GetTypesFromSelection(selections); GetSerializationCode(appSetup, output, targetTypes); DeleteDesignFromOutput(outputPath); SaveSelections(selections); return(output.ToString()); }
private SelectionCollection GetSerializedSelection() { string key = BuildItemKey(CurrentItem); string serialized = String.Empty; if (CurrentItem.ContainingProject.Globals.get_VariableExists(key)) { serialized = (string)CurrentItem.ContainingProject.Globals[key]; } SelectionCollection selections = null; if (serialized.Length > 0) { selections = SelectionCollection.FromString(serialized); } return(selections); }