public static BuildContext CurrentOrCreate(BuildCmdlet cmdlet) { if (_current == null) { _current = new BuildContext(cmdlet); } return(_current); }
private string askUserForStage(BuildCmdlet cmdlet) { ConsoleListBox box = new ConsoleListBox(); var cC = Console.BackgroundColor; var fC = Console.ForegroundColor; string[] Choices = _app.StageNames(); string result = ""; try { int check = Console.CursorTop; Console.WriteLine("Select Stage"); Console.ForegroundColor = ConsoleColor.Green; int before = Console.CursorTop; int choice = ConsoleListBox.ChooseListBoxItem(Choices, 10, before, ConsoleColor.Blue, ConsoleColor.White); result = Choices[choice - 1]; Console.SetCursorPosition(0, before + Choices.Length + 2); Console.BackgroundColor = cC; Console.ForegroundColor = fC; } catch (IOException) { cmdlet.Host.UI.WriteLine("Select Stage"); int i = 1; foreach (string choice in Choices) { cmdlet.Host.UI.WriteLine(i + ") " + choice); i++; } cmdlet.Host.UI.WriteLine(); bool invalid = true; while (invalid) { cmdlet.Host.UI.Write(">"); string data = cmdlet.Host.UI.ReadLine(); try { if (data == null || data.Length == 0) { invalid = false; cmdlet.Host.UI.WriteErrorLine("User Aborting"); } int d = Convert.ToInt32(data); if (d > 0 && d <= i) { result = Choices[d - 1]; invalid = false; } } catch (Exception ex) { cmdlet.Host.UI.WriteLine(ex.Message); } } } return(result); }
private string getStageName(BuildCmdlet cmdlet) { string envvalue = Environment.GetEnvironmentVariable(@"powerbuild_stage"); if (envvalue != null && _app.getStage(envvalue) != null) { return(envvalue); } return(askUserForStage(cmdlet)); }
public static BuildContext LoadFromFile(string filename, BuildCmdlet cmdlet) { XmlSerializer serializer = new XmlSerializer(typeof(Application)); TextReader reader = new StreamReader(filename); object obj = serializer.Deserialize(reader); Application app = (Application)obj; reader.Close(); _current = new BuildContext(cmdlet, app); return(_current); }
public BuildContext(BuildCmdlet cmdlet, Application application = null) { if (application == null) { _app = buildRecursive(cmdlet.CurrentPath); if (_app == null) { _app = new Application(); } String f = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), _configfilename); if (File.Exists(f)) { XmlSerializer serializer = new XmlSerializer(typeof(Application)); TextReader reader = new StreamReader(f); object obj = serializer.Deserialize(reader); Application other = (Application)obj; reader.Close(); _app.Add(other); } } else { _app = application; } this._stage = _app.getStage(getStageName(cmdlet)); this._variables = new Variables(_app.Variables); foreach (string key in _stage.Variables.Keys) { this.Set(key, _stage.Variables[key]); } this.Set("pb_stage", this._stage.Name); this.Set("pb_osuser", Environment.UserName); /* * XmlSerializer serializer = new XmlSerializer(typeof(Application)); * using (TextWriter writer = new StreamWriter(@"D:\Xml.xml")) * { * serializer.Serialize(writer, _app); * } * */ }