private async Task RenameAsync(string soureCode, string oldFilePath, string newFilePath, IUserNotificationServices userNotificationServices, IRoslynServices roslynServices, string language) { using (var ws = new AdhocWorkspace()) { var projectId = ProjectId.CreateNewId(); Solution solution = ws.AddSolution(InitializeWorkspace(projectId, newFilePath, soureCode, language)); Project project = (from d in solution.Projects where d.Id == projectId select d).FirstOrDefault(); var environmentOptionsFactory = IEnvironmentOptionsFactory.Implement((string category, string page, string property, bool defaultValue) => { return(true); }); var renamer = new Renamer(ws, IProjectThreadingServiceFactory.Create(), userNotificationServices, environmentOptionsFactory, roslynServices, project, oldFilePath, newFilePath); await renamer.RenameAsync(project); } }
internal async Task RenameAsync(string sourceCode, string oldFilePath, string newFilePath, IUserNotificationServices userNotificationServices, IRoslynServices roslynServices, IVsOnlineServices vsOnlineServices, string language) { using var ws = new AdhocWorkspace(); ws.AddSolution(InitializeWorkspace(ProjectId.CreateNewId(), newFilePath, sourceCode, language)); var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: $@"C:\project1.{ProjectFileExtension}"); var projectServices = IUnconfiguredProjectVsServicesFactory.Implement( threadingServiceCreator: () => IProjectThreadingServiceFactory.Create(), unconfiguredProjectCreator: () => unconfiguredProject); var unconfiguredProjectTasksService = IUnconfiguredProjectTasksServiceFactory.Create(); var environmentOptionsFactory = IEnvironmentOptionsFactory.Implement((string category, string page, string property, bool defaultValue) => { return(true); }); var waitIndicator = (new Mock <IWaitIndicator>()).Object; var refactorNotifyService = (new Mock <IRefactorNotifyService>()).Object; var dte = IVsUIServiceFactory.Create <Shell.Interop.SDTE, EnvDTE.DTE>(null !); var renamer = new Renamer(projectServices, unconfiguredProjectTasksService, ws, dte, environmentOptionsFactory, userNotificationServices, roslynServices, waitIndicator, refactorNotifyService, vsOnlineServices); await renamer.HandleRenameAsync(oldFilePath, newFilePath) .TimeoutAfter(TimeSpan.FromSeconds(1)); }
private void ScheduleRename(string oldFilePath, string newFilePath) { string codeExtension = Path.GetExtension(newFilePath); if (!oldFilePath.EndsWith(codeExtension, StringComparison.OrdinalIgnoreCase)) { return; } var myProject = _visualStudioWorkspace .CurrentSolution .Projects.Where(p => StringComparers.Paths.Equals(p.FilePath, _projectVsServices.Project.FullPath)) .FirstOrDefault(); if (myProject == null) { return; } var renamer = new Renamer(_visualStudioWorkspace, _projectVsServices.ThreadingService, _userNotificationServices, _environmentOptions, _roslynServices, myProject, oldFilePath, newFilePath); _visualStudioWorkspace.WorkspaceChanged += renamer.OnWorkspaceChangedAsync; }