Exemplo n.º 1
0
		private void menuFileOpenSolution_Click (object sender, System.EventArgs e)
		{
			if (project.IsDirty)
			{
				DialogResult result = PromptToSave();
				switch (result)
				{
					case DialogResult.Yes:
						SaveOrSaveAs();
						break;
					case DialogResult.No:
						break;
					case DialogResult.Cancel:
						return;
				}
			}
			OpenFileDialog openFileDlg = new OpenFileDialog();
			openFileDlg.InitialDirectory = Directory.GetCurrentDirectory();
			openFileDlg.Filter = "Visual Studio Solution files (*.sln)|*.sln|All files (*.*)|*.*" ;

			if(openFileDlg.ShowDialog() == DialogResult.OK)
			{
				VS.Solution sol = new VS.Solution(openFileDlg.FileName);

				try
				{
					this.Cursor = Cursors.WaitCursor;

					string warningMessages=String.Empty;

					if (sol.ProjectCount==0)
					{
						warningMessages = "There are no projects in this solution that NDoc can import.\n\n";
						warningMessages += "Either the solution is blank, or the projects contained within\n";
						warningMessages += "the solution are not of a type NDoc can import.\n"; 
						WarningForm warningForm = new WarningForm("VS Solution Import Warnings", warningMessages);
						warningForm.ShowDialog(this);
						return;
					}

					SolutionForm sf = new SolutionForm();
					sf.Text = "Solution " + sol.Name;

					sf.ConfigList.Items.Clear();
					foreach (string configkey in sol.GetConfigurations())
					{
						sf.ConfigList.Items.Add(configkey);
					}

					sf.ShowDialog(this);
					if (sf.ConfigList.SelectedIndex < 0)
						return;

					string solconfig = (string)sf.ConfigList.SelectedItem;

					//clear current ndoc project settings
					Clear();

					foreach (VS.Project p in sol.GetProjects())
					{
						string projid = p.ID.ToString();
						string projconfig = sol.GetProjectConfigName(solconfig, projid);

						if (projconfig == null)
						{
							warningMessages += String.Format("VS Project {0} could not be imported.\n- There are no settings in the project file for configuration '{1}'\n\n",p.Name,solconfig);
							continue;
						}

						string apath = p.GetRelativeOutputPathForConfiguration(projconfig);
						string xpath = p.GetRelativePathToDocumentationFile(projconfig);
						string spath = sol.Directory;

						AssemblySlashDoc asd = new AssemblySlashDoc();
						asd.Assembly.Path=Path.Combine(spath, apath);

						if (!File.Exists(asd.Assembly.Path))
						{
							warningMessages += String.Format("VS Project '{0}' has been imported, but the specified assembly does not exist.\n- You will not be able to build documentation for this project until its assembly has been successfully compiled...\n\n",p.Name);
						}

						if (xpath!=null && xpath.Length>0)
						{
							asd.SlashDoc.Path=Path.Combine(spath, xpath);
							if (!File.Exists(asd.SlashDoc.Path))
							{
							warningMessages += String.Format("VS Project '{0}' has been imported, but the XML documentation file specified in the project cannot be found.\n- This can occur if the project is set to do 'incremental' compiles.\n- NDoc output will be very limited until the VS project is rebuilt with XML documntation...\n",p.Name);
						
							}
						}
						else
						{
							warningMessages += String.Format("VS Project '{0}' has been imported, but the project is not set to produce XML documentation.\n- NDoc output for this assembly will be very limited...\n\n",p.Name);
						}

						project.AssemblySlashDocs.Add(asd);
						AddRowToListView(asd);
					}

					EnableMenuItems(true);
					EnableAssemblyItems();

					projectFilename =  Path.Combine(sol.Directory, sol.Name + ".ndoc");

					if (warningMessages.Length>0)
					{
						WarningForm warningForm = new WarningForm("VS Solution Import Warnings", warningMessages);
						warningForm.ShowDialog(this);
					}
				}
				finally
				{
					this.Cursor = Cursors.Arrow;
				}
			}
		}
Exemplo n.º 2
0
		private void menuFileOpenSolution_Click (object sender, System.EventArgs e)
		{
			if ( QueryContinueDiscardProject() )
			{
				using ( OpenFileDialog openFileDlg = new OpenFileDialog() )
				{
					openFileDlg.InitialDirectory = Directory.GetCurrentDirectory();
					openFileDlg.Filter = "Visual Studio Solution files (*.sln)|*.sln|All files (*.*)|*.*" ;

					if( openFileDlg.ShowDialog() == DialogResult.OK )
					{
						VS.Solution sol = new VS.Solution( openFileDlg.FileName );

						string warningMessages = String.Empty;

						if ( sol.ProjectCount != 0 )
						{
							using( SolutionForm sf = new SolutionForm() )
							{
								sf.Text = "Solution " + sol.Name;

								sf.ConfigList.Items.Clear();

								foreach (string configkey in sol.GetConfigurations())
									sf.ConfigList.Items.Add(configkey);

								sf.ShowDialog(this);
								if (sf.ConfigList.SelectedIndex < 0)
									return;

								//clear current ndoc project settings
								Clear();

								warningMessages = LoadFromSolution( sol, (string)sf.ConfigList.SelectedItem );

								EnableMenuItems(true);
								EnableAssemblyItems();

								projectFilename =  Path.Combine(sol.Directory, sol.Name + ".ndoc");
							}
						}
						else
						{
							warningMessages = "There are no projects in this solution that NDoc can import.\n\n";
							warningMessages += "Either the solution is blank, or the projects contained within\n";
							warningMessages += "the solution are not of a type NDoc can import.\n"; 
						}

						if ( warningMessages.Length > 0 )
							WarningForm.ShowWarning( "VS Solution Import Warnings", warningMessages, this );
					}
				}
			}
		}