private void AddNewProblem() { var settingsErrors = _settings.Validate(); if (settingsErrors.Count > 0) { MessageBox.Show(string.Format("Incorrect settings:\r\n{0}", string.Join(Environment.NewLine, settingsErrors.ToArray()))); return; } var dialog = new NewProblemForm(_settings); if (dialog.ShowDialog() != DialogResult.OK) { return; } var sb = (SolutionBuild2)_applicationObject.Solution.SolutionBuild; var startupProjects = (Array)sb.StartupProjects; if (startupProjects.Length != 1) { MessageBox.Show("There must be exactly one startup project in the solution"); return; } var startupProject = _applicationObject.Solution.Item(startupProjects.GetValue(0)); // remove all *.cs files foreach (ProjectItem item in startupProject.ProjectItems) { if (item.Name.EndsWith(".cs", StringComparison.InvariantCultureIgnoreCase)) { item.Remove(); } } try { // add new file var projectItem = startupProject.ProjectItems.AddFromFile(dialog.SourceFileName); startupProject.Save(); var window = projectItem.Open(Constants.vsViewKindCode); window.Visible = true; window.Activate(); UpdateSettings(dialog.SourceFileName); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public ActionResult Create(NewProblemForm model) { var problem = new Problem { Contest = session.Load <Contest>(model.ContestId), ShortName = model.ShortName, Statement = new FormattedDocument { Name = model.Name }, }; session.Save(problem); return(this.RedirectToAction <ContestController>(x => x.Edit(problem.Contest.Id))); }