internal static bool IsXSharpDocument(this ITextDocumentFactoryService factory, ITextBuffer buffer) { string path = ""; if (buffer.Properties.ContainsProperty(typeof(XFile))) { return(buffer.GetFile() != null); } // When not found then locate the file in the XSolution by its name if (factory != null) { ITextDocument doc = null; if (factory.TryGetTextDocument(buffer, out doc)) { path = doc.FilePath; } } // Find and attach the X# document when we have it, or a null to indicate that we have searched // and not found it var file = XSolution.FindFile(path); if (file == null) { var type = XFileTypeHelpers.GetFileType(path); switch (type) { case XFileType.SourceCode: case XFileType.Header: file = XSolution.AddOrphan(path); break; default: if (type.IsVOBinary()) { file = XSolution.AddOrphan(path); } break; } } if (file != null) { file.Interactive = true; buffer.Properties.AddProperty(typeof(XFile), file); } return(file != null); }
internal static XFile CreateFileForSystemType(XPETypeSymbol petype, XPESymbol element) { asmName = petype.Assembly; bool mustCreate = false; if (Semaphore == null) { // we create a semaphore file in the workfolder to make sure that if 2 copies of VS are running // that we will not delete the files from the other copy var tempFolder = Path.GetTempPath(); tempFolder = Path.Combine(tempFolder, folderName); var semFile = Path.Combine(tempFolder, semName); // clean up files from previous run if (Directory.Exists(tempFolder)) { if (File.Exists(semFile)) { try { File.Delete(semFile); DeleteFolderRecursively(new DirectoryInfo(tempFolder)); } catch { // if deletion fails, other copy of VS is running, so do not delete the folder } } } if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } WorkFolder = tempFolder; if (!File.Exists(semFile)) { Semaphore = File.Create(semFile); } } var ns = petype.Namespace + "." + petype.Assembly.Version; var name = petype.Name; var nspath = Path.Combine(WorkFolder, ns); if (!Directory.Exists(nspath)) { Directory.CreateDirectory(nspath); } var temp = Path.Combine(nspath, petype.Name) + ".prg"; mustCreate = !File.Exists(temp); if (mustCreate) { VS.StatusBar.ShowMessageAsync("Generating reference source for " + petype.FullName).FireAndForget(); VS.StatusBar.StartAnimationAsync(StatusAnimation.General).FireAndForget(); var aLines = XClassCreator.Create(petype, LookupXml); File.WriteAllLines(temp, aLines, System.Text.Encoding.UTF8); File.SetAttributes(temp, FileAttributes.ReadOnly); VS.StatusBar.ClearAsync().FireAndForget(); VS.StatusBar.EndAnimationAsync(StatusAnimation.General).FireAndForget(); } var xFile = XSolution.AddOrphan(temp); return(xFile); }