Beispiel #1
0
 public CompilationResult CompileWorkspace(bool compileModified = false)
 {
     if (UserConnection.DBSecurityEngine.GetCanExecuteOperation("CanManageSolution"))
     {
         WorkspaceBuilder        workspaceBuilder = WorkspaceBuilderUtility.CreateWorkspaceBuilder(AppConnection);
         CompilerErrorCollection compilerErrors   = workspaceBuilder.Rebuild(AppConnection.Workspace,
                                                                             out var buildResultType);
         var configurationBuilder = ClassFactory.Get <IAppConfigurationBuilder>();
         if (compileModified)
         {
             configurationBuilder.BuildChanged();
         }
         else
         {
             configurationBuilder.BuildAll();
         }
         return(new CompilationResult {
             Status = buildResultType,
             CompilerErrors = compilerErrors
         });
     }
     else
     {
         throw new Exception("You don't have permission for operation CanManageSolution");
     }
 }
Beispiel #2
0
        public ConfigurationServiceResponse InstallFromStorage(string source)
        {
            var response = new ConfigurationServiceResponse();

            try {
                if (!CheckLicense(source))
                {
                    throw new LicException();
                }
                bool canExecuteOperation = GetInstallPackageRights();
                if (!canExecuteOperation)
                {
                    throw new SecurityException(
                              string.Format(
                                  new LocalizableString("Terrasoft.Core", "DBSecurityEngine.Exception.Admin.UnitCannotExecuteAdminOperation"),
                                  "CanManageSolution"));
                }
                InstallStorage(source);
                WorkspaceBuilder        workspaceBuilder = WorkspaceBuilderUtility.CreateWorkspaceBuilder(UserConnection.AppConnection);
                CompilerErrorCollection compilerErrors   = workspaceBuilder.Build(UserConnection.Workspace);
                if (GetIsError(compilerErrors))
                {
                    throw new Exception(new LocalizableString("Terrasoft.WebApp", "CompilationErrors.Caption"));
                }
                WorkspaceUtilities.ForceGetCustomPackageUId(UserConnection);
            } catch (Exception exception) {
                response.Exception = exception;
            }
            return(response);
        }
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A multi-level repeater test")
                            .AddAggregate("x", 8, "1..size(x)")
                            .WithConstraintExpression("$x[i] <> $x[j] | i,j in size(x),i")
                            .Build();

            return(workspace.Model);
        }
Beispiel #4
0
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A simple repeater test")
                            .AddAggregate("x", 10, "1..10")
                            .WithConstraintExpression("$x[0] <> $x[i] | i in 1..9")
                            .Build();

            return(workspace.Model);
        }
        protected override ModelModel CreateModel()
        {
            var workspace = new WorkspaceBuilder("Model with a variable with an inline domain with an invalid table reference")
                            .AddAggregate("x", 10, "missingtable!Names:Names")
                            .WithConstraintAllDifferent("x")
                            .Build();

            return(workspace.Model);
        }
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A test using an all different constraint on an aggregate variable")
                            .AddAggregate("x", 3, "1..size(x)")
                            .WithConstraintAllDifferent("x")
                            .Build();

            return(workspace.Model);
        }
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A multi-level repeater test")
                            .AddAggregate("x", 10, "1..10")
                            .WithConstraintExpression("$x[i] <> $x[j] + 1 | i,j in 0..9,0..i")
                            .Build();

            return(workspace.Model);
        }
        protected override ModelModel CreateModel()
        {
            var workspace = new WorkspaceBuilder("Model with shared domain that has a missing table referenced")
                            .AddSingleton("y", "$z")
                            .WithSharedDomain("z", "missingtable!Names:Names")
                            .WithConstraintExpression("$x > 1")
                            .Build();

            return(workspace.Model);
        }
        protected override ModelModel CreateModel()
        {
            var workspace = new WorkspaceBuilder("Model with missing variable $z")
                            .AddSingleton("x", "1..9")
                            .AddSingleton("y", "1..9")
                            .WithConstraintExpression("$x > $z")
                            .Build();

            return(workspace.Model);
        }
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("An aggregate test")
                            .AddAggregate("c", 10, "1..9")
                            .WithConstraintExpression("$c[0] < $c[9]")
                            .WithConstraintExpression("$c[1] > $c[8]")
                            .Build();

            return(workspace.Model);
        }
Beispiel #11
0
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A test")
                            .WithSharedDomain("a", "1..9")
                            .AddAggregate("x", 10, "1..10")
                            .WithConstraintAllDifferent("x")
                            .Build();

            return(workspace.Model);
        }
            public void Invokes_WorkspaceBuilder_On_Project()
            {
                var project = new Project();

                DomainRoot.Arrange(dr => dr.GetRoot()).Returns(project);

                Target.BuildWorkspace(new Project());

                WorkspaceBuilder.Assert(wsb => wsb.BuildWorkspaceForProject(project), Occurs.Once());
            }
Beispiel #13
0
        public void Create_Workspace_With_Name_Returns_Model_With_Expected_Name()
        {
            const string ExpectedModelName = "The expected model name";
            var          sut = new WorkspaceBuilder(ExpectedModelName)
                               .AddSingleton("x", "1..10")
                               .WithConstraintExpression("x > 1")
                               .Build();

            Assert.That(sut.Model.Name.Text, Is.EqualTo(ExpectedModelName));
        }
        private static ModelModel MakeValidModel()
        {
            var workspace = new WorkspaceBuilder("A valid model")
                            .AddSingleton("x", "1..9")
                            .AddAggregate("y", 10, "1..9")
                            .WithConstraintExpression("x > y")
                            .Build();

            return(workspace.Model);
        }
Beispiel #15
0
        private WorkspaceModel CreateWorkspace()
        {
            var a = new WorkspaceBuilder("Simple model with ternary operator that can be solved")
                    .WithSharedDomain("D", "\"red\", \"blue\"")
                    .AddSingleton("x", "$D")
                    .AddSingleton("y", "$D")
                    .WithConstraintExpression("$x <> $y")
                    .Build();

            return(a);
        }
        protected override ModelModel CreateModel()
        {
            var workspace = new WorkspaceBuilder("Model with missing shared domain $a")
                            .AddSingleton("x", "$a")
                            .AddSingleton("y", "$z")
                            .WithSharedDomain("z", "1..10")
                            .WithConstraintExpression("$x > $y")
                            .Build();

            return(workspace.Model);
        }
Beispiel #17
0
        private static WorkspaceModel CreateWorkspace()
        {
            var workspace = new WorkspaceBuilder("A made up character range test")
                            .AddAggregate("a", 26, "'a'..'z'")
                            .AddSingleton("b", "'a'..'z'")
                            .WithConstraintAllDifferent("a")
                            .WithConstraintExpression("$b <> 'a'")
                            .Build();

            return(workspace);
        }
Beispiel #18
0
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A test")
                            .AddSingleton("x", "1..9")
                            .AddSingleton("y", "1..9")
                            .AddAggregate("z", 1, "1..9")
                            .WithConstraintExpression("$x < $y")
                            .WithConstraintExpression("$y > $z[0]")
                            .Build();

            return(workspace.Model);
        }
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A test to reproduce a solver bug")
                            .AddSingleton("x", "1..3")
                            .AddSingleton("y", "1..3")
                            .AddSingleton("z", "1..3")
                            .WithConstraintExpression("$x <> $y")
                            .WithConstraintExpression("$x <> $z")
                            .WithConstraintExpression("$y <> $z")
                            .Build();

            return(workspace.Model);
        }
        private static ModelModel MakeModel()
        {
            var workspace = new WorkspaceBuilder("A test")
                            .WithSharedDomain("a", "1..9")
                            .AddSingleton("x", "$a")
                            .AddSingleton("y", "$a")
                            .AddSingleton("z", "$a")
                            .WithConstraintExpression("$x + 1 != $y - 1")
                            .WithConstraintExpression("$x <= $y")
                            .WithConstraintExpression("$y = $z")
                            .Build();

            return(workspace.Model);
        }
        private static WorkspaceModel CreateWorkspace()
        {
            var workspace = new WorkspaceBuilder($"{ExpectedQueens} Queens Model")
                            .AddAggregate("cols", ExpectedQueens, "1..size(cols)")
                            .WithConstraintAllDifferent("cols")
                            .WithConstraintExpression("$cols[i] <> $cols[j] | i,j in size(cols),i")
                            .WithConstraintExpression("$cols[i] + i <> $cols[j] + j | i,j in size(cols),i")
                            .WithConstraintExpression("$cols[i] - i <> $cols[j] - j | i,j in size(cols),i")
                            .WithBinding("for x,y in 1..size(cols),1..size(cols): if <cols,x> = %y: board(x:x,y:y,side:white,piece:Queen)")
                            .WithChessboard("board")
                            .Build();

            return(workspace);
        }
        protected string GetScriptText()
        {
            ControllerBuilder.Commit();

            // Kind of annoying... but eh
            WorkspaceBuilder.ProcessorSettings.NamingStrategy = NamingStrategy.Create(ConfigOptions.NameCasingConverter);

            var packageTester = WorkspaceBuilder.GetPackageTester();
            var context       = CreateContext(packageTester);

            var    templateFactory = new ScriptTemplateFactory(ConfigOptions);
            string scriptText      = templateFactory.CreateControllerTextTemplate(context).GetText();

            return(scriptText);
        }
        public void Actions_WhenWorkspaceHasMixedActions_ContainsOnlyInboxActions()
        {
            IAction inboxAction = AnAction.In(State.Inbox).Build();

            WorkspaceBuilder stubWorkspace =
                AWorkspace
                .With(AnAction.In(State.Committed))
                .With(inboxAction)
                .With(AnAction.In(State.Hold))
                .With(AnAction.In(State.SomedayMaybe));

            var test = new InboxActionsFilter(stubWorkspace.Build());

            Assert.Contains(inboxAction, test.Actions);
            Assert.Equal(1, test.Actions.Count);
        }
Beispiel #24
0
        private async IAsyncEnumerable <AnalyzerResult> AnalyzeGeneratorAsync(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path);
            }

            List <ProjectWorkspace> workspaceResults = new List <ProjectWorkspace>();

            WorkspaceBuilder builder = new WorkspaceBuilder(Logger, path, AnalyzerConfiguration);


            var projectBuildResultEnumerator = builder.BuildProject().GetAsyncEnumerator();

            try
            {
                while (await projectBuildResultEnumerator.MoveNextAsync().ConfigureAwait(false))
                {
                    var projectBuildResult = projectBuildResultEnumerator.Current;
                    var workspaceResult    = AnalyzeProject(projectBuildResult);
                    workspaceResult.ProjectGuid = projectBuildResult.ProjectGuid;
                    workspaceResult.ProjectType = projectBuildResult.ProjectType;
                    workspaceResults.Add(workspaceResult);

                    if (AnalyzerConfiguration.MetaDataSettings.LoadBuildData)
                    {
                        yield return(new AnalyzerResult()
                        {
                            ProjectResult = workspaceResult, ProjectBuildResult = projectBuildResult
                        });
                    }
                    else
                    {
                        yield return(new AnalyzerResult()
                        {
                            ProjectResult = workspaceResult
                        });
                    }
                }
            }
            finally
            {
                await projectBuildResultEnumerator.DisposeAsync();
            }
        }
Beispiel #25
0
        private async Task <List <AnalyzerResult> > AnalyzeWithReferences(string path, Dictionary <string, List <string> > oldReferences, Dictionary <string, List <string> > references)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path);
            }

            List <ProjectWorkspace> workspaceResults = new List <ProjectWorkspace>();
            var analyzerResults = new List <AnalyzerResult>();

            WorkspaceBuilder builder = new WorkspaceBuilder(Logger, path, AnalyzerConfiguration);

            var projectBuildResults = builder.GenerateNoBuildAnalysis(oldReferences, references);

            foreach (var projectBuildResult in projectBuildResults)
            {
                var workspaceResult = await Task.Run(() => AnalyzeProject(projectBuildResult));

                workspaceResult.ProjectGuid = projectBuildResult.ProjectGuid;
                workspaceResult.ProjectType = projectBuildResult.ProjectType;
                workspaceResults.Add(workspaceResult);

                //Generate Output result
                if (AnalyzerConfiguration.MetaDataSettings.LoadBuildData)
                {
                    analyzerResults.Add(new AnalyzerResult()
                    {
                        ProjectResult = workspaceResult, ProjectBuildResult = projectBuildResult
                    });
                }
                else
                {
                    analyzerResults.Add(new AnalyzerResult()
                    {
                        ProjectResult = workspaceResult
                    });
                }
            }

            await GenerateOptionalOutput(analyzerResults);

            return(analyzerResults);
        }
        /// <summary>
        /// Create a simple workspace model.
        /// </summary>
        /// <returns>A simple workspace model.</returns>
        internal WorkspaceModel Create()
        {
            var newWorkspace = new WorkspaceBuilder("An example model for no particular purpose.")
                               .AddSingleton("x", "z")
                               .AddAggregate("y", 10, "1..9")
                               .WithConstraintExpression("x > 1")
                               .WithSharedDomain("z", "1..10")
                               .Build();
            var xVariable = newWorkspace.Model.GetVariableByName("x");
            var valueOfX  = new SingletonVariableLabelModel((SingletonVariableModel)xVariable, new ValueModel(1));
            var snapshot  = new SolutionSnapshot(new List <SingletonVariableLabelModel> {
                valueOfX
            },
                                                 Enumerable.Empty <AggregateVariableLabelModel>(),
                                                 Enumerable.Empty <BucketLabelModel>());

            newWorkspace.Solution = new SolutionModel(newWorkspace.Model, snapshot, TimeSpan.Zero);

            return(newWorkspace);
        }
Beispiel #27
0
        private Workspace GetUpdatedWorkspace(ParsedModule parsedModule, ModuleDefinition moduleDefinition, AbsolutePath path)
        {
            // Need to use both 'ParsedModule' and 'ModuleDefinition' in case if the 'path' is newly added
            // file and was not parsed yet.

            // All already parsed modules are good to go
            var unchangedModules = m_workspace.SpecModules;

            // We build a module under construction that has all specs but the one that changed
            var moduleUnderConstruction = new ModuleUnderConstruction(moduleDefinition);

            foreach (var spec in parsedModule.Specs)
            {
                if (spec.Key != path)
                {
                    moduleUnderConstruction.AddParsedSpec(spec.Key, spec.Value);
                }
            }

            // Update parsing failures so the ones coming from the changed spec are removed
            var filteredFailures = m_workspace.Failures.Where(
                failure => (failure is ParsingFailure parsingFailure && parsingFailure.SourceFile.Path.AbsolutePath != path.ToString(m_pathTable)));

            var updatedWorkspace =
                m_workspace.WorkspaceProvider.CreateIncrementalWorkspaceForAllKnownModulesAsync(
                    unchangedModules,
                    moduleUnderConstruction,
                    filteredFailures,
                    m_workspace.PreludeModule)
                .GetAwaiter()
                .GetResult();

            var semanticWorkspaceProvider = new SemanticWorkspaceProvider(new WorkspaceStatistics(), m_workspace.WorkspaceConfiguration);
            var semanticWorkspace         =
                semanticWorkspaceProvider.ComputeSemanticWorkspaceAsync(m_pathTable, updatedWorkspace, m_workspace.GetSemanticModel(), incrementalMode: true)
                .GetAwaiter()
                .GetResult();

            // Get all the potentially new specs. Old ones, besides the one that changed, were aready linted
            var newPathToSpecs =
                updatedWorkspace.GetAllSpecFiles()
                .Except(m_workspace.GetAllSpecFiles())
                .Concat(new[] { path });

            // The changed spec always needs linting. Plus all the new ones the changed spec may have introduced.
            var preludeModule = updatedWorkspace.PreludeModule;
            var specsToLint   = new HashSet <ISourceFile>();

            foreach (var pathToSpec in newPathToSpecs)
            {
                // Need to exclude prelude files from liinting.
                // Need to keep config files. They should be linted.
                if (preludeModule == null || !preludeModule.Specs.ContainsKey(pathToSpec))
                {
                    specsToLint.Add(updatedWorkspace.GetSourceFile(pathToSpec));
                }
            }

            var lintedWorkspace = WorkspaceBuilder.CreateLintedWorkspaceForChangedSpecs(
                semanticWorkspace,
                specsToLint,
                m_controller.FrontEndContext.LoggingContext,
                m_controller.FrontEndConfiguration,
                m_controller.FrontEndContext.PathTable);

            return(lintedWorkspace);
        }
Beispiel #28
0
        protected EnumTester AssertThatTheDefaultEnumType()
        {
            var packageTester = WorkspaceBuilder.GetPackageTester();

            return(packageTester.TestEnumWithName(TestTypeName));
        }
Beispiel #29
0
        protected ReferenceTypeTester AssertThatTheReferenceTypeWithName(string name, int?typeArgCnt = null)
        {
            var packageTester = WorkspaceBuilder.GetPackageTester();

            return(packageTester.TestReferenceTypeWithName(name, typeArgCnt));
        }
Beispiel #30
0
        private void AssertScriptTextIs(string expected)
        {
            var packageTester = WorkspaceBuilder.GetPackageTester();

            packageTester.AssertScriptText(expected);
        }