private void OnDocumentChanged(FileEventListener fileWatcher) { var projectItemFile = this.GetProjectItemFile(fileWatcher.FileFullPath); if (projectItemFile == null) { return; } if (projectItemFile.DeploymentType != DeploymentType.RootFile && projectItemFile.DeploymentType != DeploymentType.TemplateFile) { // Not supported type for copy this.RemoveFile(fileWatcher.FileFullPath); return; } var sourcePath = projectItemFile.FullPath; var deploymentPath = Path.Combine(projectItemFile.DeploymentRoot, projectItemFile.RelativePath); try { this.ProjectService.Logger.WriteLine($"Copy {projectItemFile.RelativePath} -> {deploymentPath}", LogCategory.Status); deploymentPath = this.ReplacePathTokens(projectItemFile.Project, deploymentPath); File.Copy(sourcePath, deploymentPath, true); } catch (Exception ex) { this.ProjectService.Logger.WriteLine($"Error: {ex.Message}", LogCategory.Error); } }
public void UnregisterListener(FileEventListener listener) { if (Eventlistener.Contains(listener)) { Eventlistener.Remove(listener); index = -1; } }
public void RegisterListener(FileEventListener listener, int index) { if (!Eventlistener.Contains(listener)) { Eventlistener.Add(listener); this.index = index; } }
public FileEventListener Create(ISolutionProject project, ActionConfiguration actionConfiguration) { var fileChangeSubscriber = new FileChangeSubscriber(this.fileChangeService); var fileMonitor = new FileMonitor(this.solutionFilesService, this.globMatcher, fileChangeSubscriber, this.outputService); var eventListener = new FileEventListener(fileMonitor, this.onChangeTaskDispatcher, this.actionFactory, fileChangeSubscriber); eventListener.Initialize(project, actionConfiguration); return eventListener; }
public void AddFile(string fileFullPath) { lock (this.updateLock) { if (!this.FileListener.ContainsKey(fileFullPath)) { var service = this.ProjectService.ServiceProvider.GetService(typeof(SVsFileChangeEx)) as IVsFileChangeEx; var fileWatcher = new FileEventListener(fileFullPath, service, this.OnDocumentChanged); this.FileListener.Add(fileFullPath, fileWatcher); } } }
private void OnDocumentChanged(FileEventListener fileWatcher) { var projectItemFile = this.GetProjectItemFile(fileWatcher.FileFullPath); if (projectItemFile == null) { return; } if (projectItemFile.DeploymentType != DeploymentType.RootFile && projectItemFile.DeploymentType != DeploymentType.TemplateFile) { // Not supported type for copy this.RemoveFile(fileWatcher.FileFullPath); return; } var deploymentPath = Path.Combine(projectItemFile.DeploymentRoot, projectItemFile.RelativePath); try { this.ProjectService.Logger.WriteLine($"Copy {projectItemFile.RelativePath} -> {deploymentPath}", LogCategory.Status); deploymentPath = this.ReplacePathTokens(projectItemFile.Project, deploymentPath); if (!Directory.Exists(Path.GetDirectoryName(deploymentPath))) { Directory.CreateDirectory(Path.GetDirectoryName(deploymentPath)); } if (this.IsFileWithTokenReplacements(projectItemFile)) { var fileContent = this.ReplaceSharePointFileTokens(projectItemFile); File.WriteAllText(deploymentPath, fileContent, Encoding.UTF8); } else { File.Copy(projectItemFile.FullPath, deploymentPath, true); } } catch (Exception ex) { this.ProjectService.Logger.WriteLine($"Error: {ex.Message}", LogCategory.Error); } }