public SourceCodeService(
            ISourceFileRepository sourceFilesRepository,
            ILogger logger,
            ICalculationsRepository calculationsRepository,
            ISourceFileGeneratorProvider sourceFileGeneratorProvider,
            ICompilerFactory compilerFactory,
            ICodeMetadataGeneratorService codeMetadataGenerator,
            ICalcsResiliencePolicies resiliencePolicies)
        {
            Guard.ArgumentNotNull(sourceFilesRepository, nameof(sourceFilesRepository));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(calculationsRepository, nameof(calculationsRepository));
            Guard.ArgumentNotNull(sourceFileGeneratorProvider, nameof(sourceFileGeneratorProvider));
            Guard.ArgumentNotNull(compilerFactory, nameof(compilerFactory));
            Guard.ArgumentNotNull(codeMetadataGenerator, nameof(codeMetadataGenerator));
            Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies));
            Guard.ArgumentNotNull(resiliencePolicies?.SourceFilesRepository, nameof(resiliencePolicies.SourceFilesRepository));
            Guard.ArgumentNotNull(resiliencePolicies?.CalculationsRepository, nameof(resiliencePolicies.CalculationsRepository));

            _sourceFilesRepository = sourceFilesRepository;
            _logger = logger;
            _calculationsRepository       = calculationsRepository;
            _sourceFileGeneratorProvider  = sourceFileGeneratorProvider;
            _compilerFactory              = compilerFactory;
            _sourceFileGenerator          = sourceFileGeneratorProvider.CreateSourceFileGenerator(TargetLanguage.VisualBasic);
            _codeMetadataGenerator        = codeMetadataGenerator;
            _sourceFilesRepositoryPolicy  = resiliencePolicies.SourceFilesRepository;
            _calculationsRepositoryPolicy = resiliencePolicies.CalculationsRepository;
        }
Exemple #2
0
        public FileProcessor(IProgress <ProgressToken> reporter, ICompilerFactory factory)
        {
            _factory   = factory ?? throw new ArgumentNullException(nameof(factory));
            _reporter  = reporter;
            _compilers = new Hashtable();

            Receive <ICompilierOptions>(HandleMessage, ((x) => !string.IsNullOrEmpty(x.SourceFile)));
        }
Exemple #3
0
        private static ICompilerFactory CreateCompilerFactory(ICompiler compiler = null, IEnumerable <SourceFile> sourceFiles = null)
        {
            ICompilerFactory compilerFactory = Substitute.For <ICompilerFactory>();

            compilerFactory
            .GetCompiler(Arg.Is(sourceFiles))
            .Returns(compiler);

            return(compilerFactory);
        }
Exemple #4
0
        CompilerData CreateExecutable(InputData input)
        {
            CompilerData cdata = new CompilerData();
            string       ext   = "";
            string       rand  = Utils.RandomString();

            cdata.Rand = rand;
            string dir = rand + @"\";

            switch (input.Lang)
            {
            case Languages.VCPP:
                ext = ".cpp";
                break;

            case Languages.VC:
                ext = ".c";
                break;

            default:
                ext = ".unknown";
                break;
            }
            string PathToSource = RootPath + dir + rand + ext;

            input.PathToSource = PathToSource;
            input.BaseDir      = RootPath + dir;
            input.Rand         = rand;
            Directory.CreateDirectory(RootPath + dir);

            Directory.SetCurrentDirectory(RootPath + dir);
            //DirectorySecurity sec = Directory.GetAccessControl(RootPath + dir);
            //SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            //sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
            //Directory.SetAccessControl(RootPath + dir, sec);

            using (TextWriter sw = new StreamWriter(PathToSource))
            {
                sw.Write(input.Program);
            }

            cdata.CleanThis = RootPath + dir;

            var comp = ICompilerFactory.GetICompiler(input.Lang);

            if (comp != null)
            {
                return(comp.Compile(input, cdata));
            }

            cdata.Success = false;
            return(cdata);
        }
Exemple #5
0
 public ProjectService(
     IRegistryService registryService,
     ITemplateService templateService,
     IFileUtil fileUtil,
     IGitService gitService,
     ICompilerFactory compilerFactory,
     IProjectValidator projectValidator
     )
 {
     _registryService  = registryService;
     _templateService  = templateService;
     _fileUtil         = fileUtil;
     _gitService       = gitService;
     _compilerFactory  = compilerFactory;
     _projectValidator = projectValidator;
 }
Exemple #6
0
 private static SourceCodeService CreateSourceCodeService(
     ISourceFileRepository sourceFilesRepository = null,
     ILogger logger = null,
     ICalculationsRepository calculationsRepository           = null,
     ISourceFileGeneratorProvider sourceFileGeneratorProvider = null,
     ICompilerFactory compilerFactory = null,
     ICodeMetadataGeneratorService codeMetadataGenerator = null,
     ICalcsResiliencePolicies resiliencePolicies         = null)
 {
     return(new SourceCodeService(
                sourceFilesRepository ?? CreateSourceFileRepository(),
                logger ?? CreateLogger(),
                calculationsRepository ?? CreateCalculationsRepository(),
                sourceFileGeneratorProvider ?? CreateSourceFileGeneratorProvider(),
                compilerFactory ?? CreateCompilerFactory(),
                codeMetadataGenerator ?? CreateCodeMetadataGeneratorService(),
                resiliencePolicies ?? CreatePolicies()));
 }
Exemple #7
0
 public ActionScriptImplementation(ActionScriptClassTemplate scriptClassTemplate, ICompilerFactory compilerFactory)
     : base(scriptClassTemplate, compilerFactory.CreateCompiler())
 {
     SourcePreprocessors.Add(new UsingsPreprocessor());
 }
 public ReportBuilderService(ICompilerFactory compilerFactory, IIntervalHelper intervalHelper)
 {
     _compilerFactory = compilerFactory;
     _intervalHelper = intervalHelper;
 }
Exemple #9
0
        public void Compile_GivenStringCompareInCodeAndAggregatesIsEnabledAndCalculationAggregateFunctionsFound_CompilesCodeAndReturnsOk()
        {
            //Arrange
            string stringCompareCode = "Public Class TestClass\nPublic Property E1 As ExampleClass\nPublic Function TestFunction As String\nIf E1.ProviderType = \"goodbye\" Then\nReturn Sum(Calc1)\nElse Return \"no\"\nEnd If\nEnd Function\nEnd Class";

            Calculation calculation = new Calculation
            {
                Id              = calculationId,
                BuildProjectId  = buildProjectId,
                Current         = new CalculationVersion(),
                SpecificationId = specificationId,
                Name            = "TestFunction"
            };

            IEnumerable <Calculation> calculations = new List <Calculation>()
            {
                calculation
            };

            BuildProject buildProject = new BuildProject
            {
                SpecificationId = specificationId
            };

            ILogger logger = CreateLogger();

            List <SourceFile> sourceFiles = new List <SourceFile>
            {
                new SourceFile {
                    FileName = "project.vbproj", SourceCode = "<Project Sdk=\"Microsoft.NET.Sdk\"><PropertyGroup><TargetFramework>netcoreapp2.0</TargetFramework></PropertyGroup></Project>"
                },
                new SourceFile {
                    FileName = "ExampleClass.vb", SourceCode = "Public Class ExampleClass\nPublic Property ProviderType() As String\nEnd Class"
                },
                new SourceFile {
                    FileName = "Calculation.vb", SourceCode = stringCompareCode
                }
            };

            Build build = new Build
            {
                Success     = true,
                SourceFiles = sourceFiles
            };

            Dictionary <string, string> sourceCodes = new Dictionary <string, string>()
            {
                { "TestFunction", stringCompareCode },
                { "Calc1", "return 1" }
            };

            CompilerOptions compilerOptions = new CompilerOptions();

            ISourceFileGenerator sourceFileGenerator = Substitute.For <ISourceFileGenerator>();

            sourceFileGenerator
            .GenerateCode(Arg.Is(buildProject), Arg.Is(calculations), compilerOptions)
            .Returns(sourceFiles);

            ISourceFileGeneratorProvider sourceFileGeneratorProvider = CreateSourceFileGeneratorProvider();

            sourceFileGeneratorProvider
            .CreateSourceFileGenerator(Arg.Any <TargetLanguage>())
            .Returns(sourceFileGenerator);

            ICompiler compiler = CreateCompiler();

            ICompilerFactory compilerFactory = CreateCompilerFactory(compiler, sourceFiles);

            SourceCodeService sourceCodeService = CreateSourceCodeService(sourceFileGeneratorProvider: sourceFileGeneratorProvider, compilerFactory: compilerFactory);

            //Act
            Build buildResult = sourceCodeService.Compile(buildProject, calculations, compilerOptions);

            //Assert
            compiler
            .Received(1)
            .GenerateCode(Arg.Is <List <SourceFile> >(m => m.Count == 3));
        }
Exemple #10
0
        public async Task GetAssembly_GivenAssemblyDoesNotExist_CompilesNewAssembly()
        {
            //Arrange
            BuildProject buildProject = new BuildProject
            {
                SpecificationId = specificationId,
            };

            Calculation calculation = new Calculation
            {
                Id              = calculationId,
                BuildProjectId  = buildProjectId,
                Current         = new CalculationVersion(),
                SpecificationId = specificationId,
                Name            = "TestFunction"
            };

            IEnumerable <Calculation> calculations = new List <Calculation>()
            {
                calculation
            };

            ISourceFileRepository sourceFileRepository = CreateSourceFileRepository();

            sourceFileRepository
            .DoesAssemblyExist(Arg.Is(specificationId))
            .Returns(false);

            List <SourceFile> sourceFiles = new List <SourceFile>
            {
                new SourceFile {
                    FileName = "project.vbproj", SourceCode = "<Project Sdk=\"Microsoft.NET.Sdk\"><PropertyGroup><TargetFramework>netcoreapp2.0</TargetFramework></PropertyGroup></Project>"
                },
                new SourceFile {
                    FileName = "ExampleClass.vb", SourceCode = "Public Class ExampleClass\nPublic Property ProviderType() As String\nEnd Class"
                },
                new SourceFile {
                    FileName = "Calculation.vb", SourceCode = "code"
                }
            };

            buildProject.Build = new Build
            {
                SourceFiles = sourceFiles,
            };

            Build newBuild = new Build
            {
                SourceFiles = sourceFiles,
                Assembly    = new byte[100]
            };

            ISourceFileGenerator sourceFileGenerator = Substitute.For <ISourceFileGenerator>();

            sourceFileGenerator
            .GenerateCode(Arg.Is(buildProject), Arg.Any <IEnumerable <Calculation> >(), Arg.Any <CompilerOptions>())
            .Returns(sourceFiles);

            ISourceFileGeneratorProvider sourceFileGeneratorProvider = CreateSourceFileGeneratorProvider();

            sourceFileGeneratorProvider
            .CreateSourceFileGenerator(Arg.Any <TargetLanguage>())
            .Returns(sourceFileGenerator);

            ICompiler compiler = CreateCompiler();

            compiler
            .GenerateCode(Arg.Any <List <SourceFile> >())
            .Returns(newBuild);

            ICompilerFactory compilerFactory = CreateCompilerFactory(compiler, sourceFiles);

            SourceCodeService sourceCodeService = CreateSourceCodeService(sourceFileGeneratorProvider: sourceFileGeneratorProvider, compilerFactory: compilerFactory);

            //Act
            byte[] assembly = await sourceCodeService.GetAssembly(buildProject);

            //Assert
            assembly
            .Should()
            .NotBeNull();

            assembly
            .Length
            .Should()
            .Be(100);
        }
Exemple #11
0
 public ReportBuilderService(ICompilerFactory compilerFactory, IIntervalHelper intervalHelper)
 {
     _compilerFactory = compilerFactory;
     _intervalHelper  = intervalHelper;
 }