Exemplo n.º 1
0
        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 HandleBuild(object sender, VisualStudioBuildEventArgs e)
        {
            if (e.BuildAction == vsBuildAction.vsBuildActionClean ||
                e.BuildAction == vsBuildAction.vsBuildActionDeploy)
            {
                _log.InfoFormat("Build Action is Clean or Deploy.  No Code Generation will occur");
                return;
            }

            var sw = Stopwatch.StartNew();

            try
            {
                _log.InfoFormat("HandleBuild started.");

                _visualStudioCodeGenerator
                .GenerateCode(
                    _codeGeneratorContextFactory.GenerateContext(s => s.GetValidPMixinFiles()))
                .MapParallel(_responseFileWriter.WriteCodeGeneratorResponse);
            }
            catch (Exception exc)
            {
                _log.Error("Exception in HandleBuild", exc);
            }
            finally
            {
                _log.InfoFormat("HandleBuild Completed in [{0}] ms", sw.ElapsedMilliseconds);
            }
        }
        private void WarmUpCodeGeneratorDependencyManager()
        {
            if (null != OnSolutionOpeningTask)
            {
                return;
            }

            lock (_lock)
            {
                if (null != OnSolutionOpeningTask)
                {
                    return;
                }

                OnSolutionOpeningTask =
                    _taskFactory.StartNew(
                        () =>
                {
                    using (new LoggingActivity("HandleSolutionOpening"))
                        try
                        {
                            _visualStudioCodeGenerator.GenerateCode(
                                _codeGeneratorContextFactory
                                .GenerateContext(s => s.GetValidPMixinFiles()))
                            .MapParallel(_responseFileWriter.WriteCodeGeneratorResponse);
                        }
                        catch (Exception exc)
                        {
                            _log.Error("Exception in WarmUpCodeGeneratorDependencyManager",
                                       exc);
                        }
                });
            }
        }
 public IEnumerable <CodeGeneratorResponse> GenerateCode(IEnumerable <RawSourceFile> rawSourceFiles)
 {
     return(GenerateCode(_codeGeneratorContextFactory.GenerateContext(rawSourceFiles.ToList())));
 }