Esempio n. 1
0
        private ImmutableArray <Location> VariableLocations(InspectionContext c, TVariableSyntax variable)
        {
            var allAssignedExpressions = new List <TExpressionSyntax>();
            var parentScope            = LocalVariableScope(variable);

            if (parentScope != null)
            {
                var identText = IdentifierText(variable);
                allAssignedExpressions.AddRange(parentScope.DescendantNodes().OfType <TAssignmentExpressionSyntax>()
                                                .Select(x =>
                {
                    SplitAssignment(x, out var leftIdentifier, out var right);
                    return(new { leftIdentifier, right });
                })
                                                .Where(x => x.leftIdentifier != null && IdentifierText(x.leftIdentifier) == identText)
                                                .Select(x => x.right));
            }
            var initializer = VariableInitializer(variable);

            if (initializer != null)       //Declarator initializer is counted as (default) assignment as well
            {
                allAssignedExpressions.Add(initializer);
            }
            return(MultiExpressionSublocations(c, allAssignedExpressions));
        }
Esempio n. 2
0
        private ImmutableArray <Location> ArgumentLocations(InspectionContext c, TExpressionSyntax expression)
        {
            switch (ExtractArgumentExpressionNode(expression))
            {
            case TIdentifierNameSyntax identifier:
                var identSymbol = c.Context.SemanticModel.GetSymbolInfo(identifier).Symbol;
                if (identSymbol != null && identSymbol.DeclaringSyntaxReferences.Length == 1)
                {
                    return(IdentifierLocations(c, SyntaxFromReference(identSymbol.DeclaringSyntaxReferences.Single())));
                }
                break;

            case TLambdaSyntax lambda:
                return(LambdaLocations(c, lambda));

            case TInvocationExpressionSyntax invocation:
                var invSymbol = c.Context.SemanticModel.GetSymbolInfo(invocation).Symbol;
                if (invSymbol != null && invSymbol.DeclaringSyntaxReferences.Length == 1 && SyntaxFromReference(invSymbol.DeclaringSyntaxReferences.Single()) is TMethodSyntax syntax)
                {
                    c.VisitedMethods.Add(syntax);
                    return(InvocationLocations(c, syntax));
                }
                break;
            }
            return(ImmutableArray <Location> .Empty);
        }
Esempio n. 3
0
        internal CompilationTestData Evaluate(
            string source,
            OutputKind outputKind,
            string methodName,
            string expr,
            out ResultProperties resultProperties,
            out string error,
            int atLineNumber = -1,
            InspectionContext inspectionContext = null,
            bool includeSymbols = true)
        {
            var compilation0 = CreateCompilationWithMscorlib(
                source,
                options: (outputKind == OutputKind.DynamicallyLinkedLibrary) ? TestOptions.DebugDll : TestOptions.DebugExe);

            var runtime  = CreateRuntimeInstance(compilation0, includeSymbols);
            var context  = CreateMethodContext(runtime, methodName, atLineNumber);
            var testData = new CompilationTestData();
            ImmutableArray <AssemblyIdentity> missingAssemblyIdentities;
            var result = context.CompileExpression(
                inspectionContext ?? DefaultInspectionContext.Instance,
                expr,
                DkmEvaluationFlags.TreatAsExpression,
                DiagnosticFormatter.Instance,
                out resultProperties,
                out error,
                out missingAssemblyIdentities,
                EnsureEnglishUICulture.PreferredOrNull,
                testData);

            Assert.Empty(missingAssemblyIdentities);
            return(testData);
        }
Esempio n. 4
0
        private void GetDetails(long id)
        {
            string output = "The USDA has not made the details of this inspection public.<br/> You can request the information here: <a href=" + "\"http://www.aphis.usda.gov/foia/\"" + ">FOIA Request</a>";

            using (var insp = new InspectionContext())
            {
                var qry = from i in insp.inspectionDetails
                          where i.InspectionID == id
                          orderby i.USDACertificateNumber descending
                          select i;
                if (qry.Count() > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("<br/><br/>");
                    sb.AppendLine("<table><tr><th>AWA Section</th><th>Section Description</th></tr>");
                    foreach (var item in qry)
                    {
                        sb.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", item.CFRCitationSection, item.NCICFRCitationDescription);
                    }

                    sb.AppendLine("</table>");
                    sb.Append("<br/><br/>");
                    sb.Append("<b>For detailed information of these violations you can view the inspecting officer's notes by searching for this license on the <a href=" + "\"http://acissearch.aphis.usda.gov/LPASearch/faces/CustomerSearch.jspx \"" + ">USDA Site</a>.</b>");
                    sb.Append("<br/><br/>");

                    output = sb.ToString();
                }
            }
            lblDetails.Text = output;
        }
Esempio n. 5
0
        protected ImmutableArray <Location> ParamLocations(InspectionContext c, TParameterSyntax param)
        {
            var ret = ImmutableArray.CreateBuilder <Location>();
            var containingMethodDeclaration = param.FirstAncestorOrSelf <TMethodSyntax>();

            if (!c.VisitedMethods.Contains(containingMethodDeclaration))
            {
                c.VisitedMethods.Add(containingMethodDeclaration);
                var containingMethod = c.Context.SemanticModel.GetDeclaredSymbol(containingMethodDeclaration) as IMethodSymbol;
                var identText        = Language.Syntax.NodeIdentifier(param)?.ValueText;
                var paramSymbol      = containingMethod.Parameters.Single(x => x.Name == identText);
                if (!paramSymbol.IsParams)  // Validation for TryGetNonParamsSyntax, ParamArray/params and therefore array arguments are not inspected
                {
                    foreach (var invocation in FindInvocationList(c.Context, FindRootClassOrModule(param), containingMethod))
                    {
                        var methodParamLookup = CreateParameterLookup(invocation, containingMethod);
                        if (methodParamLookup.TryGetNonParamsSyntax(paramSymbol, out var expression))
                        {
                            ret.AddRange(CallStackSublocations(c, expression));
                        }
                    }
                }
            }
            return(ret.ToImmutable());
        }
Esempio n. 6
0
        private void GetStatusInfo(string txtLic)
        {
            lblOutput.Text = "No information about this license is in our database. <br/>You may be able to obtain more information here: <br/><br/><a href=" + "\"http://acissearch.aphis.usda.gov/LPASearch/faces/CustomerSearch.jspx \"" + ">acissearch</a>";
            using (var insp = new InspectionContext())
            {
                // Get the Customer Number for this licensee
                var qryCustNum = from ic in insp.Status
                                 where ic.USDACertificateNumber == txtLic
                                 orderby ic.USDACertificateNumber descending
                                 select ic;

                foreach (var CN in qryCustNum)
                {
                    var qry = from i in insp.Status
                              where i.CustomerNumber == CN.CustomerNumber
                              orderby i.USDACertificateNumber descending
                              select i;

                    if (qry.Count() >= 1)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.AppendLine("<br/><br/>");
                        sb.AppendLine("<table>");
                        if (qry.Count() == 1)
                        {
                            foreach (var item in qry)
                            {
                                sb.AppendFormat("<tr><td>The license {0} was issued on {1} and as of {3} has a status of {2} </td></tr>", item.USDACertificateNumber, CleanDate(item.USDACertificateBeginDate), item.USDACertificateCurrentStatus, CleanDate(item.USDACertificateCurrentStatusDate));
                            }
                        }
                        else
                        {
                            sb.AppendFormat("<tr><td>The licensee has multiple licenses.</td></tr>");
                            string strStatus = "";
                            foreach (var item in qry)
                            {
                                switch (item.USDACertificateCurrentStatus.TrimStart().TrimEnd())
                                {
                                case "CANCELLED":
                                    strStatus = "<font color=\"red\"><b>CANCELLED</b><font>";
                                    break;

                                case "REVOKED":
                                    strStatus = "<font color=\"red\"><b>REVOKED</b><font>";
                                    break;

                                default:
                                    strStatus = item.USDACertificateCurrentStatus;
                                    break;
                                }
                                sb.AppendFormat("<tr><td>The license {0} was issued on {1} and as of {3} has a status of {2} </td></tr>", item.USDACertificateNumber, item.USDACertificateBeginDate, strStatus, item.USDACertificateCurrentStatusDate);
                            }
                        }
                        sb.AppendLine("</table>");
                        lblOutput.Text = sb.ToString();
                    }
                }
            }
        }
Esempio n. 7
0
        private void TryReportLocations(InspectionContext c, Location primaryLocation, SyntaxNode expression)
        {
            var locations = ArgumentLocations(c, expression);

            if (!locations.IsEmpty)
            {
                // Report both, assignemnt as well as all implementation occurances
                c.Context.ReportDiagnosticWhenActive(Diagnostic.Create(rule, primaryLocation, additionalLocations: locations));
            }
        }
Esempio n. 8
0
 private bool IsVisited(InspectionContext c, SyntaxNode expression)
 {
     if (expression is TInvocationExpressionSyntax invocation)
     {
         var symbol = c.Context.SemanticModel.GetSymbolInfo(invocation).Symbol;
         return(symbol != null && !symbol.DeclaringSyntaxReferences.IsEmpty &&
                symbol.DeclaringSyntaxReferences.Select(x => SyntaxFromReference(x)).Any(x => x != null && c.VisitedMethods.Contains(x)));
     }
     return(false);
 }
Esempio n. 9
0
 protected override ImmutableArray <Location> LambdaLocations(InspectionContext c, ParenthesizedLambdaExpressionSyntax lambda)
 {
     if (lambda.Body is BlockSyntax block)
     {
         return(BlockLocations(c, block));
     }
     else if (lambda.Body is ExpressionSyntax expr && IsTrueLiteral(expr)) //LiteralExpressionSyntax or ParenthesizedExpressionSyntax like (((true)))
     {
         return(new[] { lambda.Body.GetLocation() }.ToImmutableArray());   //Code was found guilty for lambda (...) => true
     }
        protected override ExpressionSyntax[] FindReturnAndThrowExpressions(InspectionContext c, SyntaxNode block)
        {
            //Return value set by assignment to function variable/value
            var assignments = block.DescendantNodes().OfType <AssignmentStatementSyntax>().Where(x => c.Context.SemanticModel.GetSymbolInfo(x.Left).Symbol is ILocalSymbol local && local.IsFunctionValue);

            //And normal Return statements and throws
            return(block.DescendantNodes().OfType <ReturnStatementSyntax>().Select(x => x.Expression)
                   .Concat(block.DescendantNodes().OfType <ThrowStatementSyntax>().Select(x => x.Expression)) //Throw statements #2825. x.Expression can be NULL for standalone Throw and we need that one as well.
                   .Concat(assignments.Select(x => x.Right))
                   .ToArray());
        }
    public CategoryRepositoryTest()
    {
        var options = new DbContextOptionsBuilder <InspectionContext>()
                      .UseInMemoryDatabase(databaseName: "CategoryRepositoryTestDB")
                      .Options;

        _context = new InspectionContext(options);

        var config = new MapperConfiguration(cfg => cfg.AddProfile <AutoMapping>());

        _mapper = new Mapper(config);
    }
Esempio n. 12
0
        private ImmutableArray <Location> MultiExpressionSublocations(InspectionContext c, IEnumerable <TExpressionSyntax> expressions)
        {
            var exprSublocationsList = expressions.Distinct(CreateNodeEqualityComparer())
                                       .Select(x => CallStackSublocations(c, x))
                                       .ToArray();

            if (exprSublocationsList.Any(x => x.IsEmpty))   //If there's at leat one concurrent expression, that returns compliant delegate, then there's some logic and this scope is compliant
            {
                return(ImmutableArray <Location> .Empty);
            }
            return(exprSublocationsList.SelectMany(x => x).ToImmutableArray());      //Else every return statement is noncompliant
        }
Esempio n. 13
0
        internal override CompileResult CompileExpression(
            InspectionContext inspectionContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            DiagnosticBag diagnostics,
            out ResultProperties resultProperties,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            ReadOnlyCollection <string> formatSpecifiers;
            var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers);

            if (syntax == null)
            {
                resultProperties = default(ResultProperties);
                return(default(CompileResult));
            }

            var context = this.CreateCompilationContext(syntax);
            ResultProperties properties;
            var moduleBuilder = context.CompileExpression(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties);

            if (moduleBuilder == null)
            {
                resultProperties = default(ResultProperties);
                return(default(CompileResult));
            }

            using (var stream = new MemoryStream())
            {
                Cci.PeWriter.WritePeToStream(
                    new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
                    context.MessageProvider,
                    () => stream,
                    nativePdbWriterOpt: null,
                    pdbPathOpt: null,
                    allowMissingMethodBodies: false,
                    deterministic: false,
                    cancellationToken: default(CancellationToken));

                if (diagnostics.HasAnyErrors())
                {
                    resultProperties = default(ResultProperties);
                    return(default(CompileResult));
                }

                resultProperties = properties;
                return(new CompileResult(
                           stream.ToArray(),
                           typeName: TypeName,
                           methodName: MethodName,
                           formatSpecifiers: formatSpecifiers));
            }
        }
Esempio n. 14
0
        internal override CompileResult CompileAssignment(
            InspectionContext inspectionContext,
            string target,
            string expr,
            DiagnosticBag diagnostics,
            out ResultProperties resultProperties,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            var assignment = target.ParseAssignment(expr, diagnostics);

            if (assignment == null)
            {
                resultProperties = default(ResultProperties);
                return(default(CompileResult));
            }

            var context = this.CreateCompilationContext(assignment);
            ResultProperties properties;
            var moduleBuilder = context.CompileAssignment(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties);

            if (moduleBuilder == null)
            {
                resultProperties = default(ResultProperties);
                return(default(CompileResult));
            }

            using (var stream = new MemoryStream())
            {
                Cci.PeWriter.WritePeToStream(
                    new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
                    context.MessageProvider,
                    () => stream,
                    nativePdbWriterOpt: null,
                    pdbPathOpt: null,
                    allowMissingMethodBodies: false,
                    deterministic: false,
                    cancellationToken: default(CancellationToken));

                if (diagnostics.HasAnyErrors())
                {
                    resultProperties = default(ResultProperties);
                    return(default(CompileResult));
                }

                resultProperties = properties;
                return(new CompileResult(
                           stream.ToArray(),
                           typeName: TypeName,
                           methodName: MethodName,
                           formatSpecifiers: null));
            }
        }
Esempio n. 15
0
 internal PlaceholderLocalBinder(
     InspectionContext inspectionContext,
     TypeNameDecoder <PEModuleSymbol, TypeSymbol> typeNameDecoder,
     CSharpSyntaxNode syntax,
     MethodSymbol containingMethod,
     Binder next) :
     base(next)
 {
     _inspectionContext = inspectionContext;
     _typeNameDecoder   = typeNameDecoder;
     _syntax            = syntax;
     _containingMethod  = containingMethod;
 }
Esempio n. 16
0
        protected ImmutableArray <Location> BlockLocations(InspectionContext c, SyntaxNode block)
        {
            var ret = ImmutableArray.CreateBuilder <Location>();

            if (block != null)
            {
                var returnExpressions = FindReturnAndThrowExpressions(c, block);
                if (returnExpressions.All(x => IsTrueLiteral(x)))    //There must be at least one return, that does not return true to be compliant. There can be NULL from standalone Throw statement.
                {
                    ret.AddRange(returnExpressions.Select(x => x.GetLocation()));
                }
            }
            return(ret.ToImmutable());
        }
Esempio n. 17
0
        private ImmutableArray <Location> CallStackSublocations(InspectionContext c, TExpressionSyntax expression)
        {
            var lst = ArgumentLocations(c, expression);

            if (!lst.IsEmpty)        //There's noncompliant issue in this chain
            {
                var Loc = expression.GetLocation();
                if (!lst.Any(x => x.SourceSpan.IntersectsWith(Loc.SourceSpan)))
                {
                    //Add 2nd, 3rd, 4th etc //Secondary marker. If it is not marked already from direct Delegate name or direct Lambda occurance
                    return(lst.Concat(new[] { Loc }).ToImmutableArray());
                }
            }
            return(lst);
        }
Esempio n. 18
0
        private ImmutableArray <Location> IdentifierLocations(InspectionContext c, SyntaxNode syntax)
        {
            switch (syntax)
            {
            case TMethodSyntax method:                      //Direct delegate name
                return(BlockLocations(c, method));

            case TParameterSyntax parameter:                //Value arrived as a parameter
                return(ParamLocations(c, parameter));

            case TVariableSyntax variable:         //Value passed as variable
                return(VariableLocations(c, variable));
            }
            return(ImmutableArray <Location> .Empty);
        }
        protected override ImmutableArray <Location> LambdaLocations(InspectionContext c, LambdaExpressionSyntax lambda)
        {
            switch (lambda)
            {
            case SingleLineLambdaExpressionSyntax single:
                if (single.Body is ExpressionSyntax expr && IsTrueLiteral(expr))        //LiteralExpressionSyntax or ParenthesizedExpressionSyntax like (((true)))
                {
                    return(new[] { single.Body.GetLocation() }.ToImmutableArray());
                }
                break;

            case MultiLineLambdaExpressionSyntax multi:
                return(BlockLocations(c, multi));
            }
            return(ImmutableArray <Location> .Empty);
        }
Esempio n. 20
0
        internal override CompileResult CompileAssignment(
            InspectionContext inspectionContext,
            string target,
            string expr,
            DiagnosticFormatter formatter,
            out ResultProperties resultProperties,
            out string error,
            out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities,
            System.Globalization.CultureInfo preferredUICulture,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            var diagnostics = DiagnosticBag.GetInstance();

            try
            {
                var assignment = target.ParseAssignment(expr, diagnostics);
                if (assignment == null)
                {
                    error            = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                    resultProperties = default(ResultProperties);
                    return(default(CompileResult));
                }

                var context = this.CreateCompilationContext(assignment);
                ResultProperties properties;
                var moduleBuilder = context.CompileAssignment(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties);
                if (moduleBuilder == null)
                {
                    error            = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                    resultProperties = default(ResultProperties);
                    return(default(CompileResult));
                }

                using (var stream = new MemoryStream())
                {
                    Cci.PeWriter.WritePeToStream(
                        new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
                        context.MessageProvider,
                        stream,
                        nativePdbWriterOpt: null,
                        allowMissingMethodBodies: false,
                        deterministic: false,
                        cancellationToken: default(CancellationToken));

                    if (diagnostics.HasAnyErrors())
                    {
                        error            = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                        resultProperties = default(ResultProperties);
                        return(default(CompileResult));
                    }

                    resultProperties          = properties;
                    error                     = null;
                    missingAssemblyIdentities = ImmutableArray <AssemblyIdentity> .Empty;
                    return(new CompileResult(
                               stream.ToArray(),
                               typeName: TypeName,
                               methodName: MethodName,
                               formatSpecifiers: null));
                }
            }
            finally
            {
                diagnostics.Free();
            }
        }
Esempio n. 21
0
 public InspectionService(InspectionContext _context = null)
 {
     context = (_context != null) ? _context : getNewContext();
 }
Esempio n. 22
0
 protected override ExpressionSyntax[] FindReturnAndThrowExpressions(InspectionContext c, SyntaxNode block)
 {
     return(block.DescendantNodes().OfType <ReturnStatementSyntax>().Select(x => x.Expression)
            .Concat(block.DescendantNodes().OfType <ThrowStatementSyntax>().Select(x => x.Expression)) //Throw statements #2825. x.Expression can be NULL for standalone Throw and we need that one as well.
            .ToArray());
 }
Esempio n. 23
0
        private void GetInspectionInfo(string p)
        {
            string output = "No Inspections were found for this Licensee.<br/> <br/> Check <a href=status.aspx?id=" + p.Trim() + ">here</a> for information we may have on this licensee, or you may obtain more information here: <a href=" + "\"http://acissearch.aphis.usda.gov/LPASearch/faces/CustomerSearch.jspx \"" + ">acissearch</a>";

            using (var insp = new InspectionContext())
            {
                Response.Write(p + "<br/>");
                var qry = from i in insp.inspections
                          where i.USDACertificateNumber == p.Trim()
                          orderby i.InspectionDate descending
                          select i;
                string HTMLOut = "";
                long   inspID  = 0;
                string what    = "";
                long   howmany = 0;

                if (qry.Count() > 0)
                {
                    Response.Write("<br> COUNT: " + qry.Count().ToString() + "<br>");
                    IntroBlurb.Style.Add("display", "none");
                    Instructions.InnerText = "Results for License: " + p.Trim();
                    HTMLOut  = "<table>";
                    HTMLOut += "<tr><td>Check <a href=\"status.aspx?id=" + p.Trim() + "\">here</a> for information we may have on this licensee</td></tr>";
                    HTMLOut += "<tr><td>&nbsp;</td></tr>";
                    foreach (var item in qry)
                    {
                        //inspID = Int64.Parse(item.InspectionID.ToString());
                        if (item.CountCitations == 0)
                        {
                            HTMLOut += "<tr><td>The " + CleanDate(item.InspectionDate) + " inspection had no violations.</td></tr><br/>";
                            HTMLOut += "<tr><td>&nbsp;</td></tr>";
                        }
                        else
                        {
                            if (item.InspectionInventoryAnimalsCommonName == "")
                            {
                                HTMLOut += "<tr class=\"warn\"><td><a href=\"details.aspx?id=" + item.InspectionID.ToString() + "\">Inspection</a> was attempted on " + CleanDate(item.InspectionDate) + " but access was not possible.</td></tr>";
                                HTMLOut += "<tr><td>&nbsp;</td></tr>";
                            }
                            else
                            {
                                if (inspID != item.InspectionID)
                                {
                                    howmany  = Int64.Parse(item.CountCitations.ToString());
                                    what     = item.InspectionInventoryCount.ToString() + " " + Pluralize(Int32.Parse(item.InspectionInventoryCount.ToString()), item.InspectionInventoryAnimalsCommonName);
                                    HTMLOut += "<tr><td>The " + CleanDate(item.InspectionDate) + " <a href=\"details.aspx?id=" + item.InspectionID.ToString() + " \">Inspection</a> showed " + item.CountCitations.ToString() + " violation(s) on " + what + ".</td></tr>";
                                    HTMLOut += "<tr><td>&nbsp;</td></tr>";
                                }
                                else
                                {
                                    what    += " and " + item.InspectionInventoryCount.ToString() + " " + Pluralize(Int32.Parse(item.InspectionInventoryCount.ToString()), item.InspectionInventoryAnimalsCommonName);
                                    HTMLOut += "<tr><td>The " + CleanDate(item.InspectionDate) + " <a href=\"details.aspx?id=" + item.InspectionID.ToString() + " \">Inspection</a> showed " + item.CountCitations.ToString() + " violation(s) on " + what + ".</td></tr>";
                                    HTMLOut += "<tr><td>&nbsp;</td></tr>";
                                }
                            }
                            inspID = Int64.Parse(item.InspectionID.ToString());
                        }
                    }
                    HTMLOut += "</table>";
                    output   = HTMLOut;
                }
            }
            lblInspection.Text = output;
        }
Esempio n. 24
0
        private ImmutableArray <Location> InvocationLocations(InspectionContext c, TMethodSyntax method)
        {
            var returnExpressionSublocationsList = FindReturnAndThrowExpressions(c, method).Where(x => !IsVisited(c, x));      //Ignore all return statements with recursive call. Result depends on returns that could return compliant validator.

            return(MultiExpressionSublocations(c, returnExpressionSublocationsList));
        }
 public GenericRepository(InspectionContext context)
 {
     _context = context;
 }
Esempio n. 26
0
 protected abstract ImmutableArray <Location> LambdaLocations(InspectionContext c, TLambdaSyntax lambda);
Esempio n. 27
0
 protected abstract TExpressionSyntax[] FindReturnAndThrowExpressions(InspectionContext c, SyntaxNode block);
    public static void Seed(IServiceProvider serviceProvider)
    {
        using var context = new InspectionContext(
                  serviceProvider.GetRequiredService <DbContextOptions <InspectionContext> >());
        {
            context.Database.EnsureCreated();

            if (!context.InputTypes.Any())
            {
                context.InputTypes.AddRange(
                    new InputType {
                    InputTypeId = 1, Description = "テキスト入力"
                },
                    new InputType {
                    InputTypeId = 2, Description = "数値入力"
                },
                    new InputType {
                    InputTypeId = 3, Description = "項目選択"
                },
                    new InputType {
                    InputTypeId = 6, Description = "日付入力"
                }
                    );
                context.SaveChanges();
            }

            if (!context.ChoiceTemplates.Any())
            {
                context.ChoiceTemplates.Add(new ChoiceTemplate
                {
                    Choices = new List <Option>
                    {
                        new Option {
                            OrderIndex = 1, Description = "選択肢1"
                        },
                        new Option {
                            OrderIndex = 2, Description = "選択肢2"
                        },
                    }
                });
                context.SaveChanges();
            }

            if (!context.InspectionSheets.Any())
            {
                context.InspectionSheets.Add(new InspectionSheet
                {
                    SheetName        = "example",
                    InspectionTypeId = 1,
                    InspectionType   = new InspectionType {
                        InspectionTypeId = 1, Description = "type"
                    },
                    InspectionGroupId = 1,
                    InspectionGroup   = new InspectionGroup {
                        InspectionGroupId = 1, Description = "group"
                    },
                    Equipments = new List <Equipment>
                    {
                        new Equipment
                        {
                            OrderIndex      = 0,
                            EquipmentName   = "機器1",
                            InspectionItems = new List <InspectionItem>
                            {
                                new InspectionItem
                                {
                                    OrderIndex        = 0,
                                    InspectionContent = "テキスト入力",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("テキスト入力"))
                                },
                                new InspectionItem
                                {
                                    OrderIndex        = 1,
                                    InspectionContent = "数値入力",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("数値入力"))
                                },
                                new InspectionItem
                                {
                                    OrderIndex        = 2,
                                    InspectionContent = "項目選択",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("項目選択")),
                                    Choices           = new List <Choice>
                                    {
                                        new Choice
                                        {
                                            OrderIndex  = 0,
                                            Description = "OK"
                                        },
                                        new Choice
                                        {
                                            OrderIndex  = 1,
                                            Description = "NG"
                                        }
                                    }
                                },
                                new InspectionItem
                                {
                                    OrderIndex        = 3,
                                    InspectionContent = "日付入力",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("日付入力"))
                                }
                            }
                        },
                        new Equipment
                        {
                            OrderIndex      = 1,
                            EquipmentName   = "機器2",
                            InspectionItems = new List <InspectionItem>
                            {
                                new InspectionItem
                                {
                                    OrderIndex        = 0,
                                    InspectionContent = "テキスト入力",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("テキスト入力"))
                                },
                                new InspectionItem
                                {
                                    OrderIndex        = 1,
                                    InspectionContent = "数値入力",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("数値入力"))
                                },
                                new InspectionItem
                                {
                                    OrderIndex        = 2,
                                    InspectionContent = "項目選択",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("項目選択")),
                                    Choices           = new List <Choice>
                                    {
                                        new Choice
                                        {
                                            OrderIndex  = 0,
                                            Description = "異常あり"
                                        },
                                        new Choice
                                        {
                                            OrderIndex  = 1,
                                            Description = "異常なし"
                                        }
                                    }
                                },
                                new InspectionItem
                                {
                                    OrderIndex        = 3,
                                    InspectionContent = "日付入力",
                                    InputType         = context.InputTypes.Single(x => x.Description.Equals("日付入力"))
                                }
                            }
                        },
                    }
                });
                context.SaveChanges();
            }
        }
    }
 /// <summary>
 /// Initializes a new instance of CategoryRepository class.
 /// </summary>
 /// <param name="context">Database context</param>
 /// <param name="mapper">O/R mapper object</param>
 public CategoryRepository(InspectionContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of InspectionSheetRepository class.
 /// </summary>
 /// <param name="context">Database context</param>
 /// <param name="mapper">O/R mapper object</param>
 public InspectionSheetRepository(InspectionContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }