static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            LoginForm loginForm = new LoginForm();

            loginForm.AdminUser = true;
            if (loginForm.ShowDialog() == DialogResult.OK)
            {
                // Show project loaded / recent file form
                RecentFilesForm recentFilesForm = new RecentFilesForm();
                if (recentFilesForm.ShowDialog() == DialogResult.OK)
                {
                    MainForm mainForm = new MainForm(recentFilesForm.SelectedPath);
                    Application.Run(mainForm);
                }
            }
        }
Example #2
0
        private void RecentFilesDialog()
        {
            var dialog = new RecentFilesForm(_settings);

            if (dialog.ShowDialog() != DialogResult.OK || string.IsNullOrEmpty(dialog.SelectedFile))
            {
                return;
            }
            if (!File.Exists(dialog.SelectedFile))
            {
                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;
            }

            // remove all *.cs files from project
            bool fileExists     = false;
            var  startupProject = _applicationObject.Solution.Item(startupProjects.GetValue(0));

            foreach (ProjectItem item in startupProject.ProjectItems)
            {
                if (item.Name.EndsWith(".cs", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (item.FileCount == 1 && item.FileNames[0] == dialog.SelectedFile)
                    {
                        // the file we selected is already added
                        fileExists = true;
                    }
                    else
                    {
                        item.Remove();
                    }
                }
            }

            if (fileExists)
            {
                return;
            }

            // add selected file

            try
            {
                var projectItem = startupProject.ProjectItems.AddFromFile(dialog.SelectedFile);
                startupProject.Save();
                var window = projectItem.Open(Constants.vsViewKindCode);
                window.Visible = true;
                window.Activate();

                UpdateSettings(dialog.SelectedFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }