/// <summary> /// Gets the IDE version. /// </summary> /// <returns>Returns the IDE version of the file we're working with.</returns> protected IdeVersion GetIdeVersion() { IdeVersion ideVer = IdeVersion.Default; TextReader reader = new StreamReader(this.solutionPath); string sln = reader.ReadToEnd(); reader.Close(); // Here we loop through the possible visual studio versions. // Trying to determine the IDE version. foreach (IdeVersion version in Enum.GetValues(typeof(IdeVersion))) { if (sln.Contains(version.GetStringValue())) { ideVer = version; } } return(ideVer); }
/// <summary> /// Converts to the specified <paramref name="solutionVersion"/>. /// </summary> /// <param name="solutionVersion">The solution version.</param> /// <param name="ideVersion">The IDE version.</param> /// <returns><c>true</c> if successful; <c>false</c> otherwise.</returns> public ConversionResult ConvertTo(VisualStudioVersion solutionVersion, IdeVersion ideVersion) { ConversionResult result = new ConversionResult(); result.ConverterReference = this; if (!this.IsReady) { result.ConversionStatus = ConversionStatus.NotReady; return(result); } bool success = true; StreamReader reader = new StreamReader(this.solutionPath); FileStream stream = null; TextWriter writer = null; string sln = reader.ReadToEnd(); reader.Close(); // Replace the solution version. sln = sln.Replace(this.VisualStudioVersion.GetStringValue(), solutionVersion.GetStringValue()); // If possible, also update the Ide version as well. if (ideVersion != IdeVersion.Default && this.IdeVersion != IdeVersion.Default) { string oldVersion, newVersion; oldVersion = this.IdeVersion.GetStringValue() + " " + ((int)this.VisualStudioVersion).ToString(); newVersion = ideVersion.GetStringValue() + " " + ((int)solutionVersion).ToString(); sln = sln.Replace(oldVersion, newVersion); } // Now write the file back to the hard drive. try { stream = File.OpenWrite(this.solutionPath); writer = new StreamWriter(stream, Encoding.UTF8); writer.Write(sln); } catch (Exception) { success = false; } finally { this.IsReady = false; if (stream != null) { writer.Close(); } } result.ConversionStatus = ConversionStatus.Failed; result.ConverterReference = this; if (success) { this.ConvertProjects(solutionVersion); result.ConversionStatus = ConversionStatus.Succeeded; if (this.projectConversionResults != null) { foreach (ConversionResult ret in this.projectConversionResults) { if (ret.ConversionStatus != ConversionStatus.Succeeded) { result.ConversionStatus = ConversionStatus.Partial; break; } } } } return(result); }
/// <summary> /// Converts the solution or project to another version. /// </summary> /// <param name="visualStudioVersion">The Visual Studio version.</param> /// <param name="ideVersion">The IDE version.</param> /// <returns><c>true</c> if the conversion succeeded; otherwise, <c>false</c>.</returns> public ConversionResult ConvertTo(VisualStudioVersion visualStudioVersion, IdeVersion ideVersion) { return this.ConvertTo(visualStudioVersion, SolutionConverterLib.IdeVersion.Default); }
/// <summary> /// Handles the Click event of the ConvertBtn control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void ConvertBtn_Click(object sender, EventArgs e) { VisualStudioVersion solVer = VisualStudioVersion.Unknown; IdeVersion ideVer = IdeVersion.Default; if (this.rdoCsExp.Checked == true) { ideVer = IdeVersion.CSExpress; } else if (this.rdoVbExp.Checked == true) { ideVer = IdeVersion.VBExpress; } else if (this.rdoVS.Checked == true) { ideVer = IdeVersion.VisualStudio; } if (this.rdoVS2002.Checked == true) { solVer = VisualStudioVersion.VisualStudio2002; } else if (this.rdoVS2003.Checked == true) { solVer = VisualStudioVersion.VisualStudio2003; } else if (this.rdoVS2005.Checked == true) { solVer = VisualStudioVersion.VisualStudio2005; } else if (this.rdoVS2008.Checked == true) { solVer = VisualStudioVersion.VisualStudio2008; } else if (this.rdoVS2010.Checked == true) { solVer = VisualStudioVersion.VisualStudio2010; } ConversionResult result = this.solutionConverter.ConvertTo(solVer, ideVer); if (result.ConversionStatus == ConversionStatus.Succeeded) { MessageBox.Show(ConversionStatus.Succeeded.GetStringValue(), "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.ResetForm(); } else if (result.ConversionStatus == ConversionStatus.Partial) { StringBuilder message = new StringBuilder(); message.AppendLine(ConversionStatus.Partial.GetStringValue()); this.solutionConverter.ProjectConversionResults.ForEach(delegate(ConversionResult conversionResult) { message.AppendLine(conversionResult.ConverterReference.Name + ": " + conversionResult.ConversionStatus.GetStringValue()); }); MessageBox.Show(message.ToString(), "Partial success!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(ConversionStatus.Failed.GetStringValue(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Converts the solution or project to another version. /// </summary> /// <param name="visualStudioVersion">The Visual Studio version.</param> /// <param name="ideVersion">The IDE version.</param> /// <returns><c>true</c> if the conversion succeeded; otherwise, <c>false</c>.</returns> public ConversionResult ConvertTo(VisualStudioVersion visualStudioVersion, IdeVersion ideVersion) { return(this.ConvertTo(visualStudioVersion, SolutionConverterLib.IdeVersion.Default)); }