private void GenerateCode(FilePath classFullPath, string eventName) { _taskFactory.StartNew(() => { pMixinsOnSolutionOpenCodeGenerator.OnSolutionOpeningTask.Wait(); using (new LoggingActivity("GenerateCode - " + eventName + " -- " + classFullPath)) try { //Generate code for the file saved var currentFileContext = _codeGeneratorContextFactory.GenerateContext( s => s.GetValidPMixinFiles() .Where(f => f.FileName.Equals(classFullPath))) .ToArray(); if (currentFileContext.Length == 0) { _log.InfoFormat("No code will be genereated for [{0}]", classFullPath); _responseFileWriter.ClearCodeBehindForSourceFile(classFullPath); } else { _visualStudioCodeGenerator .GenerateCode(currentFileContext) .Map(_responseFileWriter.WriteCodeGeneratorResponse); } //Generate code for dependencies var filesToUpdate = _codeGeneratorDependencyManager.GetFilesThatDependOn(classFullPath); if (_log.IsDebugEnabled) { _log.DebugFormat("Will update [{0}]", string.Join(Environment.NewLine, filesToUpdate.Select(x => x.FileName))); } _visualStudioCodeGenerator .GenerateCode( _codeGeneratorContextFactory.GenerateContext(filesToUpdate)) .MapParallel(_responseFileWriter.WriteCodeGeneratorResponse); } catch (Exception exc) { _log.Error("Exception in HandleProjectItemSaved", exc); } }); }
private void WireUpVisualStudioEvents(IVisualStudioEventProxy visualStudioEventProxy, ICodeGeneratorDependencyManager codeGeneratorDependencyManager, ISolutionContext solutionContext) { visualStudioEventProxy.OnSolutionClosing += (sender, args) => { _log.Info("Solution closing. Firing OnClearCache"); OnClearCache(this, new EventArgs()); }; visualStudioEventProxy.OnProjectAdded += (sender, args) => { _log.InfoFormat("OnProjectAdded - Evict [{0}]", solutionContext.SolutionFileName); OnEvictFromCache(this, new EvictFromCacheEventArgs(solutionContext.SolutionFileName)); }; visualStudioEventProxy.OnProjectRemoved += (sender, args) => { _log.InfoFormat("OnProjectRemoved - Evict [{0}]", args.ProjectFullPath); OnEvictFromCache(this, new EvictFromCacheEventArgs(args.ProjectFullPath)); _log.InfoFormat("OnProjectRemoved - Evict [{0}]", solutionContext.SolutionFileName); OnEvictFromCache(this, new EvictFromCacheEventArgs(solutionContext.SolutionFileName)); }; visualStudioEventProxy.OnProjectReferenceAdded += (sender, args) => { _log.InfoFormat("OnProjectReferenceAdded - Evict [{0}]", args.ProjectFullPath); OnEvictFromCache(this, new EvictFromCacheEventArgs(args.ProjectFullPath)); //TODO - Evict Project Items - Compilation needs to be updated? }; visualStudioEventProxy.OnProjectReferenceRemoved += (sender, args) => { _log.InfoFormat("OnProjectReferenceRemoved - Evict [{0}]", args.ProjectFullPath); OnEvictFromCache(this, new EvictFromCacheEventArgs(args.ProjectFullPath)); //TODO - Evict Project Items - Compilation needs to be updated? }; visualStudioEventProxy.OnProjectItemSaved += (sender, args) => { _log.InfoFormat("OnProjectItemSaved - Evict [{0}]", args.ClassFullPath); OnEvictFromCache(this, new EvictFromCacheEventArgs(args.ClassFullPath)); codeGeneratorDependencyManager .GetFilesThatDependOn(args.ClassFullPath) .Map(f => { _log.InfoFormat("OnProjectItemSaved - Evict Dependency [{0}]", f.FileName); OnEvictFromCache(this, new EvictFromCacheEventArgs(f.FileName) { FileOnDiskHasChanged = false }); }); }; visualStudioEventProxy.OnProjectItemRemoved += (sender, args) => { _log.InfoFormat("OnProjectItemRemoved - Evict [{0}]", args.ClassFullPath); OnEvictFromCache(this, new EvictFromCacheEventArgs(args.ClassFullPath)); }; visualStudioEventProxy.OnProjectItemRenamed += (sender, args) => { _log.InfoFormat("OnProjectItemRemoved - Evict [{0}]", args.OldClassFileName); OnEvictFromCache(this, new EvictFromCacheEventArgs(args.OldClassFileName)); }; }