private static DatabaseAccessingMethodCallExtractor <FakeORMToolType> GetDDAccessingMethodCallExtractorReturningOneMethodCall()
        {
            //Create fake database query for db accessing method call
            var dbEntityDeclaration = new DatabaseEntityDeclaration <FakeORMToolType>("Employee", null);
            var dbEntityDeclarationsReturnedByDbQuery = new HashSet <DatabaseEntityDeclaration <FakeORMToolType> >()
            {
                dbEntityDeclaration
            };
            var dbQueryVariable = new DatabaseQueryVariable <FakeORMToolType>("", null);

            //Create fake CompilationInfo for db accessing method call
            var methodDeclarationCompilationInfo = new CompilationInfo(null, null);
            // var methodDeclarationContainingDbAccessingMethodCall = new MethodDeclaration("GetEmployee", methodDeclarationCompilationInfo);

            var dbAccessingMethodCallCompilationInfo = new CompilationInfo(null, null);

            //Create fake db accessing method call
            DatabaseAccessingMethodCallStatement <FakeORMToolType> dbAccessingMethodCall = new DatabaseAccessingMethodCallStatement <FakeORMToolType>("", dbEntityDeclarationsReturnedByDbQuery, dbAccessingMethodCallCompilationInfo);

            dbAccessingMethodCall.SetDatabaseQueryVariable(dbQueryVariable);

            var fakeDbAccessingMethodCallExt   = new Mock <DatabaseAccessingMethodCallExtractor <FakeORMToolType> >();
            var dbAccessingMethodCallsToReturn = new HashSet <DatabaseAccessingMethodCallStatement <FakeORMToolType> >()
            {
                dbAccessingMethodCall
            };

            fakeDbAccessingMethodCallExt.Setup(f => f.DatabaseAccessingMethodCalls).Returns(dbAccessingMethodCallsToReturn);
            return(fakeDbAccessingMethodCallExt.Object);
        }
 public ExplorationState(CompilationInfo info, BasicBlock programLocation, IDictionary <ISymbol, Mutator> parameters, Expr[] boundVariables)
     : base(info)
 {
     PathConstraint      = new List <BoolExpr>();
     _pendingConstraints = new List <BoolExpr>();
     _locals             = new Dictionary <ISymbol, Mutator>(parameters);
     _boundVariables     = boundVariables;
     SetProgramLocation(programLocation);
 }
        public DatabaseAccessingMethodCallStatement(string queryTextInCSharp
                                                    , HashSet <DatabaseEntityDeclaration <T> > entityDeclarations
                                                    , CompilationInfo compilationInfo)
            : base(compilationInfo)
        {
            this.QueryTextInCSharp             = queryTextInCSharp;
            this.EntityDeclarationsUsedInQuery = entityDeclarations;

            this.LoadedEntityDeclarations = new List <DatabaseEntityDeclaration <T> >();
        }
Example #4
0
 public DatabaseQuery(string queryTextInCSharp
                      , HashSet <DatabaseEntityDeclaration <T> > entityDeclarations
                      , DatabaseQueryVariableDeclaration <T> databaseQueryVariable
                      , CompilationInfo compilationInfo)
     : base(compilationInfo)
 {
     this.QueryTextInCSharp             = queryTextInCSharp;
     this.EntityDeclarationsUsedInQuery = entityDeclarations;
     this.DatabaseQueryVariable         = databaseQueryVariable;
 }
Example #5
0
        void ProcessReceivedAcceptedHello_UpdateHelloLevelFields(ConnectedPeer connectedPeer, ConnectedPeerStream stream, PeerHelloPacket helloPacket)
        {
            stream.LatestHelloRtt           = TimeSpan.FromTicks(unchecked (_localPeer.Time32 - helloPacket.RequestTime32));
            stream.LastTimeReceivedAccepted = _localPeer.DateTimeNowUtc;
            connectedPeer.ProtocolVersion   = helloPacket.ProtocolVersion;
            connectedPeer.LibraryVersion    = CompilationInfo.ToDateTime(helloPacket.LibraryVersion);
            connectedPeer.TotalHelloAcceptedPacketsReceived++;
            stream.TotalHelloAcceptedPacketsReceived++;
            stream.RemotePeerRoleIsUser = helloPacket.RoleFlagIsUser;

            if (helloPacket.ExtensionIds != null && helloPacket.ExtensionIds.Length != 0)
            {
                connectedPeer.LatestReceivedRemoteExtensionIds = new HashSet <string>(helloPacket.ExtensionIds.Distinct());
            }
        }
Example #6
0
        static string TestType(Compilation c, INamedTypeSymbol x)
        {
            var nfo  = ClassInfo.FromSymbol(x);
            var cNfo = CompilationInfo.FromCompilation(c);

            var attr = nfo.Attributes.First();

            Debug.Assert(
                ((CodeGeneration.CSharp.TypeInfo.TypeInfo)attr.PassedArguments[0]).FullName ==
                "System.IEquatable<Aikixd.CodeGeneration.Test.CSharp.Target.Standard.DecorationWithType>");

            var eqNfo = ((CodeGeneration.CSharp.TypeInfo.TypeInfo)attr.PassedArguments[0]).AsInterface();

            return(getText(nfo));

            string getText(ClassInfo i)
            {
                return($"// Attribute array argument test. Class name: {i.Name}. TypeArg: {((CodeGeneration.CSharp.TypeInfo.TypeInfo)attr.PassedArguments[0]).FullName}");
            }
        }
        public async Task SetsSyntaxNodeCorrectly()
        {
            //Arrange
            string textToPlaceInMainMethod = @" 
									NorthWindDataClassesDataContext dc = new NorthWindDataClassesDataContext();
                                    var query = (from e in dc.Employees
											where (e.EmployeeID == empId)
											select e);
									return query.SingleOrDefault<Employee>();"                                    ;

            var        solGenerator = new RoslynSimpleSolutionGenerator(textToPlaceInMainMethod);
            SyntaxNode rootNode     = await solGenerator.GetRootNodeForMainDocument();

            var dataContextVariableDecSyntaxNode = rootNode.DescendantNodes().OfType <VariableDeclarationSyntax>().First();

            //Act
            CompilationInfo result = dataContextVariableDecSyntaxNode.GetCompilationInfo(null);

            //Assert
            Assert.IsTrue(result.SyntaxNode == dataContextVariableDecSyntaxNode);
        }
        protected override async Task ExtractDatabaseEntityDeclarationsAsync(Solution solution, IProgress <ExtractionProgress> progress)
        {
            string extractionNote = "Extracting Database Entity Declarations by finding all IQueryable<T> properties in Data Context Declarations";

            progress.Report(new ExtractionProgress(extractionNote));
            int totalAmountOfDataContextClasses = GetTotalAmountOfDataContextClasses();

            int counter = 0;

            foreach (var dataContextClassDeclarationSyntax in Context.DataContextDeclarations)
            {
                counter++;
                progress.Report(GetExtractionProgress(totalAmountOfDataContextClasses, counter));

                CompilationInfo compInfo = dataContextClassDeclarationSyntax.CompilationInfo;
                foreach (var propertyDeclarationSyntax in compInfo.SyntaxNode.DescendantNodes().OfType <PropertyDeclarationSyntax>())
                {
                    SemanticModel model = compInfo.SemanticModel;
                    if (model.IsOfType <IQueryable>(propertyDeclarationSyntax))
                    {
                        TypeSyntax propertyType = propertyDeclarationSyntax.Type;
                        //Get T from DbSet<T> or IQueryable<T>
                        string entityClassName = (propertyType as GenericNameSyntax).TypeArgumentList.Arguments[0].ToFullString();

                        Dictionary <ClassDeclarationSyntax, SemanticModel> entityClass = await solution.GetClassesOfType(entityClassName);

                        if (entityClass.Keys.Count > 0)
                        {
                            ClassDeclarationSyntax entityClassDeclarationSyntax = entityClass.Keys.First();
                            SemanticModel          modelForEntityClass          = entityClass[entityClassDeclarationSyntax];
                            DatabaseEntityDeclarations.Add(new DatabaseEntityDeclaration <EntityFramework>(entityClassName,
                                                                                                           entityClassDeclarationSyntax.GetCompilationInfo(modelForEntityClass)));
                        }
                    }
                }
            }
        }
Example #9
0
 public ExpressionEvaluator(ExpressionEvaluator toClone)
 {
     _info = toClone._info;
 }
Example #10
0
 public ExpressionEvaluator(CompilationInfo info)
 {
     _info = info;
 }
Example #11
0
 public DatabaseEntityVariableRelatedEntityCallStatement(DatabaseEntityVariableDeclaration <T> databaseEntityObject, CompilationInfo compilationUnit)
     : base(databaseEntityObject, compilationUnit)
 {
 }
Example #12
0
        public static CompilationInfo GetCompilationInfo(this SyntaxNode node, SemanticModel model)
        {
            var compilationInfo = new CompilationInfo(node, model);

            return(compilationInfo);
        }
Example #13
0
 private static bool RelevantCompilationInfo(CompilationInfo c)
 {
     return((c.IsError() || c.IsWarning()) && !string.IsNullOrEmpty(c.Info) && !string.IsNullOrEmpty(c.FileName));
 }
Example #14
0
 public MethodLifter(CompilationInfo info)
 {
     _info = info;
 }
 public DatabaseAccessingDeleteStatement(string queryTextInCSharp
                                         , HashSet <DatabaseEntityDeclaration <T> > entityDeclarations
                                         , CompilationInfo compilationInfo)
     : base(queryTextInCSharp, entityDeclarations, compilationInfo)
 {
 }
 public MainExplorationState(CompilationInfo info, BasicBlock programLocation, Mutator register, IDictionary <ISymbol, Mutator> parameters, Expr[] boundVariables)
     : base(info, programLocation, parameters, boundVariables)
 {
     Outputs  = new List <Expr>();
     Register = register;
 }
 public DatabaseQueryVariableDeclaration(string variableName, CompilationInfo compilationInfo)
 {
     this.VariableName    = variableName;
     this.CompilationInfo = compilationInfo;
 }
Example #18
0
 public DeclarationBase(string name, CompilationInfo compilationInfo)
     : base(compilationInfo)
 {
     Name = name;
 }
Example #19
0
 public DataContextDeclaration(string name, CompilationInfo compilationInfo)
     : base(name, compilationInfo)
 {
 }
Example #20
0
 public DataContextInitializationStatement(DataContextDeclaration <T> dataContextDeclarationUsed, CompilationInfo compilationUnit)
 {
     this.DataContextDeclarationUsed = dataContextDeclarationUsed;
     this.CompilationInfo            = compilationUnit;
 }
 public DatabaseEntityDeclaration(string name, CompilationInfo compilationInfo)
     : base(name, compilationInfo)
 {
 }
 public MethodCall(MethodDeclarationSyntax calledMethod, CompilationInfo compilationInfo)
 {
     CalledMethod    = calledMethod;
     CompilationInfo = compilationInfo;
 }
 public InvocationExplorer(CompilationInfo info)
 {
     _info = info;
 }
 public VariableDeclaration(string variableName, CompilationInfo compilationInfo)
     : base(variableName, compilationInfo)
 {
 }
 /// <summary> Check if CompilationInfo has severity warning. </summary>
 /// <param name="c"> The CompilationInfo. </param>
 /// <returns> The <see cref="bool"/>. </returns>
 public static bool IsWarning(this CompilationInfo c)
 {
     return("Warning".Equals(c?.Severity, StringComparison.CurrentCultureIgnoreCase));
 }
Example #26
0
 public DatabaseEntityObjectCallStatement(DatabaseEntityVariableDeclaration <T> calledDatabaseEntityVariable, CompilationInfo compilationUnit)
 {
     this.CompilationInfo = compilationUnit;
     this.CalledDatabaseEntityVariable = calledDatabaseEntityVariable;
 }
 public PureExplorationState(CompilationInfo info, BasicBlock programLocation, SortMapping returnType, IDictionary <ISymbol, Mutator> parameters, Expr[] boundVariables = null)
     : base(info, programLocation, parameters, boundVariables == null ? new Expr[0] : boundVariables)
 {
     _returnType = returnType;
 }
Example #28
0
        /// <summary>
        /// Creates the service assembly for a service
        /// </summary>
        /// <param name="org">The Organization code for the service owner</param>
        /// <param name="service">The service code for the current service</param>
        /// <param name="edition">The edition code for the current service</param>
        /// <param name="outputLocation">The directory where the resulting assembly should be saved</param>
        /// <param name="loadAssemblyContext">Defines if assembly should be loaded in context</param>
        /// <returns>The assembly name</returns>
        public CodeCompilationResult CreateServiceAssembly(string org, string service, string edition, string outputLocation = null, bool loadAssemblyContext = true)
        {
            CodeCompilationResult compilationResult = new CodeCompilationResult()
            {
                CompileStarted = DateTime.Now
            };
            string assemblykey = org + "_" + service + "_" + edition;

            List <AltinnCoreFile> implementationFiles = _repository.GetImplementationFiles(org, service, edition);

            DateTime lastChanged = new DateTime(2000, 01, 01);

            foreach (AltinnCoreFile file in implementationFiles)
            {
                if (file.LastChanged > lastChanged)
                {
                    lastChanged = file.LastChanged;
                }
            }

            if (_assemblyNames.ContainsKey(assemblykey) && _assemblyNames[assemblykey].CompileStarted > lastChanged && string.IsNullOrWhiteSpace(outputLocation))
            {
                compilationResult = _assemblyNames[assemblykey];
                return(compilationResult);
            }

            SyntaxTree[]             syntaxTrees = GetSyntaxTrees(org, service, edition);
            List <MetadataReference> references  = new List <MetadataReference>();
            Assembly root = Assembly.GetEntryAssembly();

            string assemblyName = Path.GetRandomFileName();

            MetadataReferenceFeature referenceFeature = new MetadataReferenceFeature();

            _partManager.PopulateFeature(referenceFeature);

            CSharpCompilation compilation = CSharpCompilation.Create(
                assemblyName,
                syntaxTrees: syntaxTrees,
                references: referenceFeature.MetadataReferences,
                options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

            using (var pdbMs = new MemoryStream())
                using (var ms = new MemoryStream())
                {
                    EmitResult result;
                    Stopwatch  stopWatch = new Stopwatch();
                    stopWatch.Start();
                    if (!string.IsNullOrEmpty(outputLocation))
                    {
                        result = compilation.Emit(outputLocation + assemblyName + ".dll", outputLocation + assemblyName + ".pdb");
                    }
                    else
                    {
                        result = compilation.Emit(ms, pdbMs);
                    }

                    stopWatch.Stop();
                    compilationResult.TimeUsed = stopWatch.Elapsed;

                    compilationResult.CompilationInfo = new List <CompilationInfo>();
                    foreach (Diagnostic diag in result.Diagnostics)
                    {
                        // TODO: Decide how to handle this special CS1701 we get
                        if (!diag.Id.Equals("CS1701"))
                        {
                            var compInfo = new CompilationInfo
                            {
                                Info         = diag.GetMessage(),
                                FilePath     = diag.Location.SourceTree.FilePath,
                                FileName     = System.IO.Path.GetFileName(diag.Location.SourceTree.FilePath),
                                Severity     = diag.Severity.ToString(),
                                Code         = diag.Id,
                                WarningLevel = diag.WarningLevel,
                                LineNumber   = diag.Location.GetLineSpan().StartLinePosition.Line + 1
                            };

                            if (diag.Severity.Equals(DiagnosticSeverity.Warning))
                            {
                                compilationResult.Warnings++;
                            }
                            else if (diag.Severity.Equals(DiagnosticSeverity.Error))
                            {
                                compilationResult.Errors++;
                            }

                            compilationResult.CompilationInfo.Add(compInfo);
                        }
                    }

                    if (!result.Success)
                    {
                        LogEmitResult(result);
                    }
                    else
                    {
                        compilationResult.AssemblyName = compilation.AssemblyName;
                        compilationResult.Succeeded    = true;

                        if (string.IsNullOrEmpty(outputLocation) && loadAssemblyContext)
                        {
                            ms.Seek(0, SeekOrigin.Begin);
                            pdbMs.Seek(0, SeekOrigin.Begin);
                            AssemblyLoadContext.Default.LoadFromStream(ms, pdbMs);
                            ms.Seek(0, SeekOrigin.Begin);
                            MetadataReference newReference = MetadataReference.CreateFromStream(ms);
                            if (_roslynCompilation.ServiceReferences.ContainsKey(assemblykey))
                            {
                                _roslynCompilation.ServiceReferences.Remove(assemblykey);
                            }

                            _roslynCompilation.ServiceReferences.Add(assemblykey, newReference);

                            if (_assemblyNames.ContainsKey(assemblykey))
                            {
                                _assemblyNames.Remove(assemblykey);
                            }

                            _assemblyNames.Add(assemblykey, compilationResult);
                        }

                        return(compilationResult);
                    }
                }

            return(compilationResult);
        }
Example #29
0
 public ModelBase(CompilationInfo compilationInfo)
 {
     CompilationInfo = compilationInfo;
 }