コード例 #1
0
ファイル: WebFormsDocument.cs プロジェクト: ikvm/webmatrix
 internal void ProcessCompleteDocument(string text)
 {
     this._documentDirective = null;
     RegisterDirectiveCollection registerDirectives = this.RegisterDirectives;
     ArrayList miscDirectives = this.MiscDirectives;
     ArrayList scriptIncludes = this.ScriptIncludes;
     miscDirectives.Clear();
     scriptIncludes.Clear();
     registerDirectives.Clear();
     DirectiveParser parser = new DirectiveParser(text, this.DocumentDirectiveName);
     foreach (Directive directive in parser.Directives)
     {
         if (directive is Microsoft.Matrix.Packages.Web.Documents.DocumentDirective)
         {
             this._documentDirective = (Microsoft.Matrix.Packages.Web.Documents.DocumentDirective) directive;
         }
         else
         {
             if (directive is RegisterDirective)
             {
                 registerDirectives.AddParsedRegisterDirective((RegisterDirective) directive);
                 continue;
             }
             miscDirectives.Add(directive);
         }
     }
     text = text.Substring(parser.DirectiveEndIndex);
     StringBuilder builder = new StringBuilder();
     StringBuilder builder2 = new StringBuilder();
     bool flag = false;
     int startIndex = 0;
     int num2 = 0;
     foreach (Match match in scriptRegex.Matches(text))
     {
         if (match.ToString().Substring(0, 2).ToLower(CultureInfo.InvariantCulture).Equals("<s"))
         {
             if (!flag)
             {
                 GroupCollection groups = match.Groups;
                 CaptureCollection captures = groups["attrname"].Captures;
                 CaptureCollection captures2 = groups["attrval"].Captures;
                 bool flag2 = false;
                 for (int i = 0; i < captures.Count; i++)
                 {
                     string str2 = captures[i].ToString().ToLower();
                     string str3 = captures2[i].ToString().ToLower();
                     if (str2.Equals("runat") && str3.Equals("server"))
                     {
                         flag2 = true;
                     }
                     if (str2.Equals("language") && (this.DocumentDirective.Language == null))
                     {
                         this.DocumentDirective.Language = str3;
                     }
                 }
                 if (flag2)
                 {
                     if (groups["empty"].Captures.Count > 0)
                     {
                         string str4 = match.ToString().Trim();
                         scriptIncludes.Add(str4);
                         num2 = match.Index + match.Length;
                     }
                     else
                     {
                         flag = true;
                         int index = match.Index;
                         startIndex = index + match.Length;
                         string str5 = text.Substring(num2, index - num2);
                         builder2.Append(str5);
                     }
                 }
             }
             continue;
         }
         if (flag)
         {
             flag = false;
             int num5 = match.Index;
             string script = text.Substring(startIndex, num5 - startIndex);
             ScriptFormatter formatter = new ScriptFormatter();
             formatter.AddScript(script);
             builder.Append(formatter.ToString());
             builder.Append("\r\n");
             num2 = num5 + match.Length;
         }
     }
     builder2.Append(text.Substring(num2).Trim());
     CodeDocumentLanguage documentLanguage = null;
     ILanguageManager service = (ILanguageManager) this.GetService(typeof(ILanguageManager));
     if (service != null)
     {
         string name = this.DocumentDirective.Language;
         if ((name != null) && (name.Length != 0))
         {
             documentLanguage = service.GetDocumentLanguage(name) as CodeDocumentLanguage;
         }
         if (documentLanguage == null)
         {
             documentLanguage = (CodeDocumentLanguage) service.DefaultCodeLanguage;
             this.DocumentDirective.Language = documentLanguage.Name;
         }
     }
     this._codeStorage = new CodeDocumentStorage(documentLanguage);
     ((IEmbeddedDocumentStorage) this._codeStorage).SetContainerDocument(this);
     this._codeStorage.Text = builder.ToString().Trim();
     ((WebFormsDocumentStorage) base.Storage).Text = builder2.ToString().Trim();
 }
コード例 #2
0
ファイル: AspNetDocument.cs プロジェクト: ikvm/webmatrix
 protected override void OnAfterLoad(EventArgs e)
 {
     DirectiveParser parser = new DirectiveParser(this.Text, this.DocumentDirectiveName);
     foreach (Directive directive in parser.Directives)
     {
         if (directive is Microsoft.Matrix.Packages.Web.Documents.DocumentDirective)
         {
             this._documentDirective = (Microsoft.Matrix.Packages.Web.Documents.DocumentDirective) directive;
         }
         else
         {
             this.MiscDirectives.Add(directive);
         }
     }
     if (this._documentDirective == null)
     {
         this._documentDirective = this.CreateDocumentDirective();
     }
     CodeDocumentLanguage documentLanguage = null;
     ILanguageManager service = (ILanguageManager) this.GetService(typeof(ILanguageManager));
     if (service != null)
     {
         string name = this.DocumentDirective.Language;
         if ((name != null) && (name.Length != 0))
         {
             documentLanguage = service.GetDocumentLanguage(name) as CodeDocumentLanguage;
         }
         if (documentLanguage == null)
         {
             documentLanguage = (CodeDocumentLanguage) service.DefaultCodeLanguage;
             this.DocumentDirective.Language = documentLanguage.Name;
         }
     }
     this._codeStorage = new CodeDocumentStorage(documentLanguage);
     this._codeStorage.Text = this.Text.Substring(parser.DirectiveEndIndex);
     base.OnAfterLoad(e);
 }