public FileConverter Build(FileInfo document) { // NOTE // Existing Type: FileInfo = System.IO.FileInfo // Our New Type: FileInformation = CTA.WebForms.FileInformationModel.FileInformation // Add logic to determine the type of FileInformation // object to create, likely using the file type specified // in the FileInfo object string extension = document.Extension; FileConverter fc; try { if (extension.Equals(Constants.CSharpCodeFileExtension)) { fc = new CodeFileConverter(_sourceProjectPath, document.FullName, _blazorWorkspaceManager, _webFormsProjectAnalyzer, _classConverterFactory, _taskManagerService, _metricsContext); } else if (extension.Equals(Constants.WebFormsConfigFileExtension)) { fc = new ConfigFileConverter(_sourceProjectPath, document.FullName, _taskManagerService, _metricsContext); } else if (extension.Equals(Constants.WebFormsPageMarkupFileExtension) || extension.Equals(Constants.WebFormsControlMarkupFileExtenion) || extension.Equals(Constants.WebFormsMasterPageMarkupFileExtension) || extension.Equals(Constants.WebFormsGlobalMarkupFileExtension)) { fc = new ViewFileConverter(_sourceProjectPath, document.FullName, _viewImportService, _taskManagerService, _metricsContext); } else if (extension.Equals(Constants.CSharpProjectFileExtension)) { fc = new ProjectFileConverter(_sourceProjectPath, document.FullName, _blazorWorkspaceManager, _webFormsProjectAnalyzer, _taskManagerService, _metricsContext); } else if (StaticResourceExtensions.Contains(extension)) { fc = new StaticResourceFileConverter(_sourceProjectPath, document.FullName, _hostPageService, _taskManagerService, _metricsContext); } else { fc = new StaticFileConverter(_sourceProjectPath, document.FullName, _taskManagerService, _metricsContext); } return(fc); } catch (Exception e) { LogHelper.LogError(e, $"{Rules.Config.Constants.WebFormsErrorTag}Could not build appropriate file converter for {document.FullName}."); return(null); } }
private void WriteCodeFile(CodeFileConverter codeFileConverter) { var directoryPath = Path.Combine(options.RootDirectory, codeFileConverter.CodeFile.RelativeNamespace); var filePath = Path.Combine(directoryPath, $"{codeFileConverter.CodeFile.FileName}.cs"); CreateDirectoryIfNotExist(directoryPath); var codeWriter = new CodeFileWriter(filePath, codeFileConverter.CodeFile, options); codeFileConverter.WriteTo(codeWriter, options); codeWriter.Flush(); }
public void StartConversion(bool appendConversion = false) { CodeFileConverter TmpConvVBCS; CodeFileConverter TmpConvCSVB; VSProjectFileConverter TmpProjConvVBCS; VSProjectFileConverter TmpProjConvCSVB; ASPXFileConverter TmpAspxConv; CodeFileConverter TmpConv; VSProjectFileConverter TmpProjConv; string TmpSrcFile; string TmpTargetFile; Int32 TmpErrCount = 0; if (!appendConversion) { //clear output-TextBox TxtStatus.Text = ""; } OutputMessage("Converting..." + vbCrLf); //create all converts TmpConvVBCS = new CodeFileConverter(ConverterLanguages.VBNetToCSharp); TmpConvCSVB = new CodeFileConverter(ConverterLanguages.CSharpToVBNet); TmpProjConvVBCS = new VSProjectFileConverter(ConverterLanguages.VBNetToCSharp); TmpProjConvCSVB = new VSProjectFileConverter(ConverterLanguages.CSharpToVBNet); TmpAspxConv = new ASPXFileConverter(ConverterLanguagesAutodetectable.Autodetect); //add event-handlers TmpConvVBCS.AfterFileProcessed += Converter_AfterFileProcessed; TmpConvCSVB.AfterFileProcessed += Converter_AfterFileProcessed; TmpProjConvVBCS.AfterFileProcessed += Converter_AfterFileProcessed; TmpProjConvCSVB.AfterFileProcessed += Converter_AfterFileProcessed; TmpAspxConv.AfterFileProcessed += Converter_AfterFileProcessed; //wait for all events System.Windows.Forms.Application.DoEvents(); //start execution-loop while (FFileList.Count > 0) { if (!FProcessing) { //user-abort FTargetRoot = ""; OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("Abort by user!" + vbCrLf); if (SettingsManager.AutoCloseStatusDialogs) { System.Windows.Forms.Application.DoEvents(); //wait 2 seconds System.Threading.Thread.Sleep(2000); System.Environment.Exit(0); } else { BtnRestart.Visible = true; BtnCancel.Text = "Close"; this.AcceptButton = BtnCancel; BtnCancel.Focus(); } return; } //reset previous converter TmpConv = null; TmpProjConv = null; //get next file of queue TmpSrcFile = FFileList.Dequeue; switch (Path.GetExtension(TmpSrcFile).ToLower) { case ".vb": TmpTargetFile = Path.ChangeExtension(TmpSrcFile, "cs"); TmpConv = TmpConvVBCS; OutputMessage("Converting Codefile '" + Path.GetFileName(TmpSrcFile) + "' from VB.NET to C#..." + vbCrLf); case ".cs": TmpTargetFile = Path.ChangeExtension(TmpSrcFile, "vb"); TmpConv = TmpConvCSVB; OutputMessage("Converting Codefile '" + Path.GetFileName(TmpSrcFile) + "' from C# to VB.NET..." + vbCrLf); case ".vbproj": TmpTargetFile = Path.ChangeExtension(TmpSrcFile, "csproj"); TmpProjConv = TmpProjConvVBCS; OutputMessage("Converting Visual Studio Project '" + Path.GetFileName(TmpSrcFile) + "' from VB.NET to C#..." + vbCrLf); case ".csproj": TmpTargetFile = Path.ChangeExtension(TmpSrcFile, "vbproj"); TmpProjConv = TmpProjConvCSVB; OutputMessage("Converting Visual Studio Project '" + Path.GetFileName(TmpSrcFile) + "' from C# to VB.NET..." + vbCrLf); case ".aspx": case ".ascx": case "*.asmx": TmpTargetFile = TmpSrcFile; OutputMessage("Converting ASP.NET File '" + Path.GetFileName(TmpSrcFile) + "'..." + vbCrLf); default: //not supported extension TmpTargetFile = ""; } if (TmpTargetFile != "") { if (FTargetRoot != "") { //set manual destination path TmpTargetFile = Path.Combine(FTargetRoot, Path.GetFileName(TmpTargetFile)); } if (TmpTargetFile == TmpSrcFile) { //destination equals source, add ".converted" to filename TmpTargetFile = Path.ChangeExtension(TmpSrcFile, "converted" + Path.GetExtension(TmpSrcFile)); } if (!TmpConv == null) { //convert CodeFile TmpConv.ConvertFile(TmpSrcFile, TmpTargetFile, true, true); } else if (!TmpProjConv == null) { //convert VSProject TmpProjConv.ConvertProject(TmpSrcFile, TmpTargetFile, true, true); } else { //convert ASPXFile TmpAspxConv.ConvertFile(TmpSrcFile, TmpTargetFile, true); } } //wait for all events System.Windows.Forms.Application.DoEvents(); } //conversion finished FTargetRoot = ""; FProcessing = false; if (TmpConvVBCS.TotalFilesCount > 0) { OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("Summary for Code Files: VB.NET -> C#" + vbCrLf); OutputMessage(TmpConvVBCS.SummaryText); TmpErrCount += TmpConvVBCS.FailedFilesCount; } if (TmpConvCSVB.TotalFilesCount > 0) { OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("Summary for Code Files: C# -> VB.NET" + vbCrLf); OutputMessage(TmpConvCSVB.SummaryText); TmpErrCount += TmpConvCSVB.FailedFilesCount; } if (TmpProjConvVBCS.TotalProjectsCount > 0) { OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("Summary for VS Projects: VB.NET -> C#" + vbCrLf); OutputMessage(TmpProjConvVBCS.SummaryText); TmpErrCount += TmpProjConvVBCS.FailedCodeFilesCount; } if (TmpProjConvCSVB.TotalProjectsCount > 0) { OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("Summary for VS Projects: C# -> VB.NET" + vbCrLf); OutputMessage(TmpProjConvCSVB.SummaryText); TmpErrCount += TmpProjConvCSVB.FailedCodeFilesCount; } if (TmpAspxConv.TotalFilesCount > 0) { OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("Summary for ASP.NET Files" + vbCrLf); OutputMessage(TmpAspxConv.SummaryText); TmpErrCount += TmpAspxConv.FailedFilesCount; } if (TmpErrCount == 0) { OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("All Conversions Successfull" + vbCrLf); if (SettingsManager.AutoCloseStatusDialogs) { System.Windows.Forms.Application.DoEvents(); //wait 2 seconds System.Threading.Thread.Sleep(2000); System.Environment.Exit(0); } } else { OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("--------------------------------------" + vbCrLf); OutputMessage("Conversionerror in " + TmpErrCount.ToString + " files" + vbCrLf); BtnRestart.Visible = true; } BtnCancel.Text = "Close"; this.AcceptButton = BtnCancel; BtnCancel.Focus(); }