示例#1
0
            private bool AnalyzeAndReportDiagnostic(IMethodSymbol symbol, InvocationExpressionSyntax node)
            {
                var semanticModel = GetSemanticModel(node.SyntaxTree);
                SaveOperationKind saveOperationKind = SaveOperationHelper.GetSaveOperationKind(
                    symbol, node, semanticModel, _pxContext);

                if (saveOperationKind != SaveOperationKind.None)
                {
                    if (_eventType == EventType.RowPersisting)
                    {
                        if (saveOperationKind != SaveOperationKind.CachePersist)
                        {
                            ReportDiagnostic(_context.ReportDiagnostic, Descriptors.PX1043_SavingChangesInRowPerstisting, node);
                            return(true);
                        }
                    }
                    else
                    {
                        ReportDiagnostic(_context.ReportDiagnostic, Descriptors.PX1043_SavingChangesInEventHandlers, node);
                        return(true);
                    }
                }

                return(false);
            }
示例#2
0
            public override void VisitInvocationExpression(InvocationExpressionSyntax node)
            {
                _context.CancellationToken.ThrowIfCancellationRequested();

                IMethodSymbol symbol        = GetSymbol <IMethodSymbol>(node);
                SemanticModel semanticModel = GetSemanticModel(node.SyntaxTree);

                if (symbol != null && SaveOperationHelper.GetSaveOperationKind(symbol, node, semanticModel, _pxContext) != SaveOperationKind.None)
                {
                    ReportDiagnostic(_context.ReportDiagnostic, _descriptor, node);
                }
                else
                {
                    base.VisitInvocationExpression(node);
                }
            }
            private bool AnalyzeAndReportDiagnostic(IMethodSymbol symbol, InvocationExpressionSyntax node)
            {
                var semanticModel = GetSemanticModel(node.SyntaxTree);
                SaveOperationKind saveOperationKind = SaveOperationHelper.GetSaveOperationKind(
                    symbol, node, semanticModel, _pxContext);

                PXDBOperationKind saveDatabaseKind = SaveOperationHelper.GetPXDatabaseSaveOperationKind(symbol, _pxContext);

                if (saveOperationKind != SaveOperationKind.None ||
                    saveDatabaseKind != PXDBOperationKind.None)
                {
                    if (_eventType == EventType.RowPersisting)
                    {
                        if (saveOperationKind != SaveOperationKind.CachePersist)
                        {
                            ReportDiagnostic(_context.ReportDiagnostic, Descriptors.PX1043_SavingChangesInRowPerstisting, node);
                            return(true);
                        }
                    }
                    else if (_eventType == EventType.RowPersisted)
                    {
                        if (IsTransactionOpened)
                        {
                            return(false);
                        }

                        ReportDiagnostic(_context.ReportDiagnostic,
                                         _pxContext.CodeAnalysisSettings.IsvSpecificAnalyzersEnabled
                                                                ? Descriptors.PX1043_SavingChangesInEventHandlers
                                                                : Descriptors.PX1043_SavingChangesInRowPerstistedNonISV, node);
                        return(true);
                    }
                    else
                    {
                        ReportDiagnostic(_context.ReportDiagnostic, Descriptors.PX1043_SavingChangesInEventHandlers, node);
                        return(true);
                    }
                }

                return(false);
            }