Exemple #1
0
        private void ExecuteConversion(NetVertVsProject.NetVertExecutionEnum excuteFilter)
        {
            List <NetVertVsProject> TmpProjs;

            TmpProjs = GetEnabledProjects(excuteFilter);
            if (TmpProjs.Count > 0)
            {
                FOutputPane.Clear();
                FOutputPane.Activate();
                FOutputPane.OutputString("==== Start Conversion of " + TmpProjs.Count.ToString() + " Projects ====" + vbCrLf);
                //create new converters
                FConverterVBCS = new VSProjectFileConverter(ConverterLanguages.VBNetToCSharp);
                FConverterCSVB = new VSProjectFileConverter(ConverterLanguages.CSharpToVBNet);
                FConverterVBCS.AfterFileProcessed += NetVertConverter_AfterFileProcessed;
                FConverterCSVB.AfterFileProcessed += NetVertConverter_AfterFileProcessed;
                //convert all projects
                foreach (NetVertVsProject nvp in TmpProjs)
                {
                    ConvertProject(nvp);
                }
                //output summary
                if (FConverterVBCS.TotalProjectsCount > 0)
                {
                    FOutputPane.OutputString("--------------------------------------" + vbCrLf);
                    FOutputPane.OutputString("Summary VB.NET -> C#" + vbCrLf);
                    FOutputPane.OutputString(FConverterVBCS.SummaryText + vbCrLf);
                }
                if (FConverterCSVB.TotalProjectsCount > 0)
                {
                    FOutputPane.OutputString("--------------------------------------" + vbCrLf);
                    FOutputPane.OutputString("Summary C# -> VB.NET" + vbCrLf);
                    FOutputPane.OutputString(FConverterCSVB.SummaryText + vbCrLf);
                }
                FOutputPane.OutputString("==== Finish ====" + vbCrLf);
            }
            else
            {
                if (excuteFilter == NetVertVsProject.NetVertExecutionEnum.OnlyManual)
                {
                    FOutputPane.Clear();
                    FOutputPane.Activate();
                    FOutputPane.OutputString("==== No Projects are Enabled for Conversion ====" + vbCrLf);
                }
            }
        }
Exemple #2
0
        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();
        }