// Internal for testing internal void Publish(OmniSharpProjectSnapshot projectSnapshot) { if (projectSnapshot == null) { throw new ArgumentNullException(nameof(projectSnapshot)); } lock (_publishLock) { string publishFilePath = null; try { if (!_publishFilePathMappings.TryGetValue(projectSnapshot.FilePath, out publishFilePath)) { return; } SerializeToFile(projectSnapshot, publishFilePath); } catch (Exception ex) { _logger.LogWarning($@"Could not update Razor project configuration file '{publishFilePath}': {ex}"); } } }
// Virtual for testing protected virtual void SerializeToFile(OmniSharpProjectSnapshot projectSnapshot, string publishFilePath) { // We need to avoid having an incomplete file at any point, but our // project.razor.json is large enough that it will be written as multiple operations. var tempFilePath = string.Concat(publishFilePath, TempFileExt); var tempFileInfo = new FileInfo(tempFilePath); if (tempFileInfo.Exists) { // This could be caused by failures during serialization or early process termination. tempFileInfo.Delete(); } // This needs to be in explicit brackets because the operation needs to be completed // by the time we move the tempfile into its place using (var writer = tempFileInfo.CreateText()) { _serializer.Serialize(writer, projectSnapshot); } var fileInfo = new FileInfo(publishFilePath); if (fileInfo.Exists) { fileInfo.Delete(); } File.Move(tempFileInfo.FullName, publishFilePath); }
public override OmniSharpProjectSnapshot GetLoadedProject(string filePath) { var projectSnapshot = InternalProjectSnapshotManager.GetLoadedProject(filePath); var converted = OmniSharpProjectSnapshot.Convert(projectSnapshot); return(converted); }
internal OmniSharpProjectChangeEventArgs(ProjectChangeEventArgs args) : this( OmniSharpProjectSnapshot.Convert(args.Older), OmniSharpProjectSnapshot.Convert(args.Newer), (OmniSharpProjectChangeKind)args.Kind) { InternalProjectChangeEventArgs = args; }
// Virtual for testing protected virtual void SerializeToFile(OmniSharpProjectSnapshot projectSnapshot, string publishFilePath) { var fileInfo = new FileInfo(publishFilePath); using var writer = fileInfo.CreateText(); _serializer.Serialize(writer, projectSnapshot); }
private bool TryGetProjectSnapshot(string projectFilePath, out OmniSharpProjectSnapshot projectSnapshot) { if (projectFilePath == null) { projectSnapshot = null; return(false); } projectSnapshot = _projectManager.GetLoadedProject(projectFilePath); return(projectSnapshot != null); }
// Internal for testing internal void EnqueuePublish(OmniSharpProjectSnapshot projectSnapshot) { // A race is not possible here because we use the main thread to synchronize the updates // by capturing the sync context. _pendingProjectPublishes[projectSnapshot.FilePath] = projectSnapshot; if (!_deferredPublishTasks.TryGetValue(projectSnapshot.FilePath, out var update) || update.IsCompleted) { _deferredPublishTasks[projectSnapshot.FilePath] = PublishAfterDelay(projectSnapshot.FilePath); } }
// Internal for testing internal void EnqueuePublish(OmniSharpProjectSnapshot projectSnapshot) { lock (_publishLock) { _pendingProjectPublishes[projectSnapshot.FilePath] = projectSnapshot; if (!_deferredPublishTasks.TryGetValue(projectSnapshot.FilePath, out var update) || update.IsCompleted) { _deferredPublishTasks[projectSnapshot.FilePath] = PublishAfterDelayAsync(projectSnapshot.FilePath); } } }
private OmniSharpProjectChangeEventArgs(OmniSharpProjectSnapshot older, OmniSharpProjectSnapshot newer, OmniSharpProjectChangeKind kind) { if (older == null && newer == null) { throw new ArgumentException("Both projects cannot be null."); } Older = older; Newer = newer; Kind = kind; ProjectFilePath = older?.FilePath ?? newer.FilePath; }
internal void RemovePublishingData(OmniSharpProjectSnapshot projectSnapshot) { lock (_publishLock) { var oldProjectFilePath = projectSnapshot.FilePath; if (!_publishFilePathMappings.TryGetValue(oldProjectFilePath, out var configurationFilePath)) { // If we don't track the value in PublishFilePathMappings that means it's already been removed, do nothing. return; } if (_pendingProjectPublishes.TryGetValue(oldProjectFilePath, out _)) { // Project was removed while a delayed publish was in flight. Clear the in-flight publish so it noops. _pendingProjectPublishes.Remove(oldProjectFilePath); } } }
public static OmniSharpProjectChangeEventArgs CreateTestInstance(OmniSharpProjectSnapshot older, OmniSharpProjectSnapshot newer, string documentFilePath, OmniSharpProjectChangeKind kind) => new OmniSharpProjectChangeEventArgs(older, newer, documentFilePath, kind);
private Project GetRoslynProject(OmniSharpProjectSnapshot project) { var roslynProject = _workspace.CurrentSolution.Projects.FirstOrDefault(roslynProject => string.Equals(roslynProject.FilePath, project.FilePath, FilePathComparison.Instance)); return(roslynProject); }
protected override void SerializeToFile(OmniSharpProjectSnapshot projectSnapshot, string publishFilePath) => _onSerializeToFile?.Invoke(projectSnapshot, publishFilePath);
public static OmniSharpProjectChangeEventArgs CreateTestInstance(OmniSharpProjectSnapshot older, OmniSharpProjectSnapshot newer, OmniSharpProjectChangeKind kind) => new OmniSharpProjectChangeEventArgs(older, newer, kind);