//FRIEND internal void ModifyStatus(ConverterOperations convStatus, string convError = "", ConverterLanguagesAutodetectable convLang = ConverterLanguagesAutodetectable.Autodetect) { FOperation = convStatus; FConverterError = convError; if (convLang != ConverterLanguagesAutodetectable.Autodetect) { FConverterLanguage = convLang; } }
//CONSTRUCTOR internal ProcessedFileEventArgs(ConverterFileTypes fileType, string inFile, string inSource, string outFile, string outSource, ConverterOperations convOperation, ConverterLanguagesAutodetectable convLang, string convError) { FFileType = fileType; FInputFile = inFile; FInputSource = inSource; FOutputFile = outFile; FOutputSource = outSource; FOperation = convOperation; FConverterLanguage = convLang; FConverterError = convError; }
//SHARED #region Convert Functions /// ----------------------------------------------------------------------------- /// <summary> /// Convert ASP.NET code using language-autodetection. /// </summary> /// <param name="aspxSource">The ASPX source code.</param> /// <returns>New instance of Class ASPXConverter</returns> /// <remarks> /// Supported is only ASP.NET code with inline serverside code of the languages Visual Basic .NET or C#. /// </remarks> /// ----------------------------------------------------------------------------- public static ASPXConverter Convert(string aspxSource, ConverterLanguagesAutodetectable converterLanguage = ConverterLanguagesAutodetectable.Autodetect) { ASPXConverter RetConv = new ASPXConverter(); Int32 TmpStart; Int32 TmpEnd; Int32 TmpLastEnd; string TmpDirective; string TmpComment = ""; string TmpCodeLines; string TmpConvertCode = ""; ArrayList TmpHtmlBlocks = new ArrayList(); string TmpS; try { //set language if (converterLanguage == ConverterLanguagesAutodetectable.Autodetect) { RetConv.FConverterLanguage = SearchLanguage(aspxSource); } else { RetConv.FConverterLanguage = converterLanguage; } //get Before-Convert-Comment-Sign switch (RetConv.FConverterLanguage) { case ConverterLanguagesAutodetectable.CSharpToVBNet: TmpComment = "//"; case ConverterLanguagesAutodetectable.VBNetToCSharp: TmpComment = "'"; } //for each <%...%> block TmpStart = -1; TmpLastEnd = 0; do { //search "<%" TmpStart = aspxSource.IndexOf("<%", TmpStart + 1); if (TmpStart > -1) { //search "%>" TmpEnd = aspxSource.IndexOf("%>", TmpStart + 2); if (TmpEnd > -1) { if (aspxSource.Substring(TmpStart + 2, 1) == "@") { //if @: replace language-attribute and codebehind file extension TmpDirective = aspxSource.Substring(TmpStart, TmpEnd - TmpStart + 2); switch (RetConv.FConverterLanguage) { case ConverterLanguagesAutodetectable.CSharpToVBNet: TmpDirective = TmpDirective.Replace("\"c#\"", "\"vb\"").Replace(".cs\"", ".vb\"").Replace("=cs ", "=vb ").Replace("=c# ", "=vb ").Replace("\"cs\"", "\"vb\""); case ConverterLanguagesAutodetectable.VBNetToCSharp: TmpDirective = TmpDirective.Replace("\"vb\"", "\"c#\"").Replace(".vb\"", ".cs\"").Replace("=vb ", "=c# "); } aspxSource = aspxSource.Substring(0, TmpStart) + TmpDirective + aspxSource.Substring(TmpEnd + 2, aspxSource.Length - TmpEnd - 2); } else { //else: convert statements TmpHtmlBlocks.Add(aspxSource.Substring(TmpLastEnd, TmpStart - TmpLastEnd + 2)); TmpConvertCode += TmpComment + "HTMLBLOCK-" + TmpHtmlBlocks.Count.ToString + "." + vbCrLf; TmpCodeLines = aspxSource.Substring(TmpStart + 2, TmpEnd - TmpStart - 2); TmpS = TmpCodeLines.TrimStart(char.Parse(" "), Chr(9), Chr(10), Chr(13)); if ((TmpS != "") && (TmpS.Substring(0, 1) == "=")) { //Add Temporary Out-Variable-Prefix TmpCodeLines = "NETVERTASPNETOUT " + TmpS; } try { } catch (Exception ex) { } //if StrTrimmLeft(StrTrimmLeft(StrTrimmLeft(tmpcodelines," "), chr(9).ToString) TmpConvertCode += TmpCodeLines + vbCrLf; TmpLastEnd = TmpEnd; } } } } while (TmpStart > -1); //Append last HTML-Block if (aspxSource.Length > TmpLastEnd) { TmpHtmlBlocks.Add(aspxSource.Substring(TmpLastEnd, aspxSource.Length - TmpLastEnd)); TmpConvertCode += TmpComment + "HTMLBLOCK-" + TmpHtmlBlocks.Count.ToString + "." + vbCrLf; } //Convert Code switch (RetConv.FConverterLanguage) { case ConverterLanguagesAutodetectable.CSharpToVBNet: // ERROR: Not supported in C#: WithStatement //get After-Convert-Comment-Sign TmpComment = "'"; case ConverterLanguagesAutodetectable.VBNetToCSharp: // ERROR: Not supported in C#: WithStatement //get After-Convert-Comment-Sign TmpComment = "//"; } //Remove Temporary Out-Variable-Prefix TmpConvertCode = TmpConvertCode.Replace("NETVERTASPNETOUT ", ""); //Insert HTML-Blocks for (Int32 iBlock = 0; iBlock <= TmpHtmlBlocks.Count - 1; iBlock++) { TmpConvertCode = TmpConvertCode.Replace(TmpComment + "HTMLBLOCK-" + (iBlock + 1).ToString + ".", TmpHtmlBlocks(iBlock)); } //set result RetConv.FResultSource = TmpConvertCode; #if (DEBUG) //catch only internal exceptions } catch (NetVertException nEx) { RetConv.FHasError = true; RetConv.FErrorText = nEx.Message; #Else //catch all exceptions } catch (Exception ex) { RetConv.FHasError = true; RetConv.FErrorText = ex.Message; #endif } return(RetConv); }
//CONSTRUCTOR /// ----------------------------------------------------------------------------- /// <summary> /// Create new ASPXFileConverter instance. /// </summary> /// <param name="language">An enumeration value. Use <b>VBNetToCSharp</b> to convert from VB.NET to C# or <b>CSharpToVBNet</b> to convert from C# to VB.NET.</param> /// <remarks> /// The property <b>language</b> could not be changed on existing instances. /// </remarks> /// ----------------------------------------------------------------------------- public ASPXFileConverter(ConverterLanguagesAutodetectable language = ConverterLanguagesAutodetectable.Autodetect) { FLanguage = language; }