Esempio n. 1
0
        OpenRazorDocument GetDocument(string fileName)
        {
            lock (this) {
                DisposeDocuments(documentsPendingDispose);

                OpenRazorDocument currentDocument = openDocuments.FirstOrDefault(d => d != null && d.FileName == fileName);
                // We need document and project to be loaded to correctly initialize Razor Host.
                if (currentDocument == null && !TryAddDocument(fileName, out currentDocument))
                {
                    return(null);
                }

                return(currentDocument);
            }
        }
Esempio n. 2
0
        public override System.Threading.Tasks.Task <ParsedDocument> Parse(MonoDevelop.Ide.TypeSystem.ParseOptions parseOptions, CancellationToken cancellationToken)
        {
            OpenRazorDocument currentDocument = GetDocument(parseOptions.FileName);

            if (currentDocument == null)
            {
                return(System.Threading.Tasks.Task.FromResult((ParsedDocument) new RazorCSharpParsedDocument(parseOptions.FileName, new RazorCSharpPageInfo())));
            }

            var context = new RazorCSharpParserContext(parseOptions, currentDocument);

            lock (currentDocument) {
                return(Parse(context, cancellationToken));
            }
        }
Esempio n. 3
0
 void TryDisposingDocument(OpenRazorDocument document)
 {
     if (Monitor.TryEnter(document))
     {
         try {
             document.Dispose();
         } finally {
             Monitor.Exit(document);
         }
     }
     else
     {
         lock (this) {
             documentsPendingDispose.Add(document);
         }
     }
 }
Esempio n. 4
0
        bool TryAddDocument(string fileName, out OpenRazorDocument currentDocument)
        {
            currentDocument = null;
            if (string.IsNullOrEmpty(fileName))
            {
                return(false);
            }

            var guiDoc = IdeApp.Workbench.GetDocument(fileName);

            if (guiDoc != null && guiDoc.Editor != null)
            {
                currentDocument = new OpenRazorDocument(guiDoc.Editor);
                lock (this) {
                    var newDocs = new List <OpenRazorDocument> (openDocuments);
                    newDocs.Add(currentDocument);
                    openDocuments = newDocs;
                }
                var closedDocument = currentDocument;
                guiDoc.Closed += (sender, args) =>
                {
                    var doc = (Ide.Gui.Document)sender;
                    if (doc.Editor != null)
                    {
                        lock (this) {
                            openDocuments = new List <OpenRazorDocument> (openDocuments.Where(d => d.FileName != doc.Editor.FileName));
                        }
                    }

                    TryDisposingDocument(closedDocument);
                    closedDocument = null;
                };
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
		void TryDisposingDocument (OpenRazorDocument document)
		{
			if (Monitor.TryEnter (document)) {
				try {
					document.Dispose ();
				} finally {
					Monitor.Exit (document);
				}
			} else {
				lock (this) {
					documentsPendingDispose.Add (document);
				}
			}
		}
Esempio n. 6
0
		bool TryAddDocument (string fileName, out OpenRazorDocument currentDocument)
		{
			currentDocument = null;
			if (string.IsNullOrEmpty (fileName))
				return false;

			var guiDoc = IdeApp.Workbench.GetDocument (fileName);
			if (guiDoc != null && guiDoc.Editor != null) {
				currentDocument = new OpenRazorDocument (guiDoc.Editor);
				lock (this) {
					var newDocs = new List<OpenRazorDocument> (openDocuments);
					newDocs.Add (currentDocument);
					openDocuments = newDocs;
				}
				var closedDocument = currentDocument;
				guiDoc.Closed += (sender, args) =>
				{
					var doc = sender as MonoDevelop.Ide.Gui.Document;
					if (doc.Editor != null && doc.Editor != null) {
						lock (this) {
							openDocuments = new List<OpenRazorDocument> (openDocuments.Where (d => d.FileName != doc.Editor.FileName));
						}
					}

					TryDisposingDocument (closedDocument);
					closedDocument = null;
				};
				return true;
			}
			return false;
		}
 public RazorCSharpParserContext(MonoDevelop.Ide.TypeSystem.ParseOptions parseOptions, OpenRazorDocument razorDocument)
 {
     this.parseOptions  = parseOptions;
     this.razorDocument = razorDocument;
 }
		public RazorCSharpParserContext (MonoDevelop.Ide.TypeSystem.ParseOptions parseOptions, OpenRazorDocument razorDocument)
		{
			this.parseOptions = parseOptions;
			this.razorDocument = razorDocument;
		}