public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var expression = root.FindNode(diagnosticSpan, false, true); if (!TryGetInvocationExpression(expression, out SyntaxNode invocationExpression)) { return; } SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(); var durableVersion = SyntaxNodeUtils.GetDurableVersion(semanticModel); if (SyntaxNodeUtils.IsInsideOrchestrator(invocationExpression) && durableVersion.Equals(DurableVersion.V2)) { if (CodeFixProviderUtils.TryGetDurableOrchestrationContextVariableName(invocationExpression, out string variableName)) { var newExpression = ""; if (TryGetMillisecondsParameter(invocationExpression, out string milliseconds)) { if (TryGetCancellationTokenParameter(invocationExpression, semanticModel, out string cancellationToken)) { newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.AddMilliseconds(" + milliseconds + "), " + cancellationToken + ")"; } else { newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.AddMilliseconds(" + milliseconds + "), CancellationToken.None)"; } } else if (TryGetTimespanParameter(invocationExpression, semanticModel, out string timeSpan)) { if (TryGetCancellationTokenParameter(invocationExpression, semanticModel, out string cancellationToken)) { newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.Add(" + timeSpan + "), " + cancellationToken + ")"; } else { newExpression = variableName + ".CreateTimer(" + variableName + ".CurrentUtcDateTime.Add(" + timeSpan + "), CancellationToken.None)"; } } context.RegisterCodeFix( CodeAction.Create(FixTimerInOrchestrator.ToString(), c => ReplaceWithAwaitExpressionAsync(context.Document, expression, c, newExpression), nameof(TimerCodeFixProvider)), diagnostic); } } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var identifierNode = root.FindNode(diagnosticSpan); context.RegisterCodeFix( CodeAction.Create(FixIDurableEntityContext.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, "IDurableEntityContext"), nameof(EntityContextCodeFixProvider)), diagnostic); }
public string GetLocalizableStringValue(string localizableStringName) { var result = string.Empty; if (!string.IsNullOrEmpty(localizableStringName)) { string lsv = "LocalizableStrings." + localizableStringName + ".Value"; //###, ####### ############# ###### # Workspace CR173646 var ls = new LocalizableString(UserConnection.Workspace.ResourceStorage, "MapsTools", lsv); result = ls.ToString(); } return(result); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var identifierNode = root.FindNode(diagnosticSpan); context.RegisterCodeFix( CodeAction.Create(FixEntityFunctionStaticModifier.ToString(), cancellationToken => AddStaticModifierAsync(context.Document, identifierNode, cancellationToken), nameof(StaticFunctionCodeFixProvider)), diagnostic); }
private static void HandleCompilation(CompilationAnalysisContext context) { try { SettingsHelper.GetStyleCopSettings(context.Options, DeserializationFailureBehavior.ThrowException, context.CancellationToken); } catch (JsonException ex) { string details = ex.Message; string completeDescription = string.Format(Description.ToString(CultureInfo.CurrentCulture), details); var completeDescriptor = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, completeDescription, HelpLink); context.ReportDiagnostic(Diagnostic.Create(completeDescriptor, Location.None)); } }
private static string GetLocalizableStringValue(UserConnection userConnection, string localizableStringName) { var result = string.Empty; if (!string.IsNullOrEmpty(localizableStringName)) { string lsv = "LocalizableStrings." + localizableStringName + ".Value"; var ls = new LocalizableString( //###, ####### ############# ###### # Workspace CR172513 userConnection.Workspace.ResourceStorage, "HtmlEditHelper", lsv); result = ls.ToString(); } return(result); }
public async Task <InconsistentAccessibilityInfo> GetInconsistentAccessibilityInfoAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) { var result = new InconsistentAccessibilityInfo(); var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var methodThatRaisedError = syntaxRoot.FindNode(diagnostic.Location.SourceSpan).DescendantNodesAndSelf().OfType <MethodDeclarationSyntax>().FirstOrDefault(); if (methodThatRaisedError != null) { result.TypeToChangeAccessibility = methodThatRaisedError.ReturnType; result.CodeActionMessage = string.Format(CodeActionMessage.ToString(), methodThatRaisedError.ReturnType, methodThatRaisedError.GetIdentifier().ValueText); result.NewAccessibilityModifiers = methodThatRaisedError.Modifiers.CloneAccessibilityModifiers(); } return(result); }
public async Task <InconsistentAccessibilityInfo> GetInconsistentAccessibilityInfoAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken) { var result = new InconsistentAccessibilityInfo(); var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var indexerThatRaisedError = syntaxRoot.FindNode(diagnostic.Location.SourceSpan).AncestorsAndSelf().OfType <IndexerDeclarationSyntax>().FirstOrDefault(); if (indexerThatRaisedError != null) { result.TypeToChangeAccessibility = indexerThatRaisedError.Type; result.CodeActionMessage = string.Format(CodeActionMessage.ToString(), result.TypeToChangeAccessibility, indexerThatRaisedError.ParameterList.Parameters.ToString()); result.NewAccessibilityModifiers = indexerThatRaisedError.Modifiers.CloneAccessibilityModifiers(); } return(result); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var identifierNode = root.FindNode(diagnosticSpan); SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(); if (SyntaxNodeUtils.TryGetFunctionName(semanticModel, identifierNode, out string functionName)) { context.RegisterCodeFix( CodeAction.Create(FixDispatchEntityCall.ToString(), cancellationToken => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, identifierNode, cancellationToken, functionName), nameof(DispatchEntityNameCodeFixProvider)), diagnostic); } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var expression = root.FindNode(diagnosticSpan); if (SyntaxNodeUtils.IsInsideOrchestrationTrigger(expression)) { if (CodeFixProviderUtils.TryGetDurableOrchestrationContextVariableName(expression, out string variableName)) { context.RegisterCodeFix( CodeAction.Create(FixDateTimeInOrchestrator.ToString(), c => CodeFixProviderUtils.ReplaceWithIdentifierAsync(context.Document, expression, c, variableName + ".CurrentUtcDateTime"), nameof(DateTimeCodeFixProvider)), diagnostic); } } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var identifierNode = root.FindNode(diagnosticSpan); SemanticModel semanticModel = await context.Document.GetSemanticModelAsync(); if (SyntaxNodeUtils.TryGetClassSymbol(identifierNode, semanticModel, out INamedTypeSymbol classSymbol)) { var className = "nameof(" + classSymbol.Name.ToString() + ")"; context.RegisterCodeFix( CodeAction.Create(FixEntityFunctionName.ToString(), cancellationToken => ReplaceAttributeArgumentAsync(context.Document, identifierNode, cancellationToken, className), nameof(ClassNameCodeFixProvider)), diagnostic); } }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var result = await context.TryGetSyntaxNode <SwitchStatementSyntax>(EnumDiagnosticIdentifiers.DefaultLabelShouldBeTheLast); if (!result.success) { return; } var switchStatement = result.syntaxNode; var diagnostic = result.diagnostic; var root = result.root; var codeAction = CodeAction.Create( title: Title.ToString(), createChangedDocument: cancellationToken => MoveDefaultLabelToLastInSwitchStatement(context, root, switchStatement), equivalenceKey: EquivalenceKey); context.RegisterCodeFix(codeAction, diagnostic); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var diagnostic = context.Diagnostics.First(); var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnosticSpan = diagnostic.Location.SourceSpan; var catchStatement = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType <CatchClauseSyntax>().First(); var tryStatement = (TryStatementSyntax)catchStatement.Parent; if (tryStatement.Catches.Count > 1) { context.RegisterCodeFix(CodeAction.Create(FixRemoveEmptyCatchBlock.ToString(), c => RemoveEmptyCatchBlockAsync(context.Document, diagnostic, c), nameof(EmptyCatchBlockCodeFixProvider) + nameof(RemoveEmptyCatchBlockAsync)), diagnostic); } else { context.RegisterCodeFix(CodeAction.Create(FixRemoveTry.ToString(), c => RemoveEmptyTryBlockAsync(context.Document, diagnostic, c), nameof(EmptyCatchBlockCodeFixProvider) + nameof(RemoveEmptyCatchBlockAsync)), diagnostic); context.RegisterCodeFix(CodeAction.Create(FixRemoveEmptyCatchBlockAndPutDocumentationLink.ToString(), c => RemoveEmptyCatchBlockPutCommentAsync(context.Document, diagnostic, c), nameof(EmptyCatchBlockCodeFixProvider) + nameof(RemoveEmptyCatchBlockPutCommentAsync)), diagnostic); } context.RegisterCodeFix(CodeAction.Create(FixInsertExceptionClass.ToString(), c => InsertExceptionClassCommentAsync(context.Document, diagnostic, c), nameof(EmptyCatchBlockCodeFixProvider) + nameof(InsertExceptionClassCommentAsync)), diagnostic); }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var result = await context.TryGetSyntaxNode <AwaitExpressionSyntax>(AsyncDiagnosticIdentifiers.UseConfigureAwaitFalse); if (!result.success) { return; } var awaitExpression = result.syntaxNode; var diagnostic = result.diagnostic; var root = result.root; var codeAction = CodeAction.Create( title: Title.ToString(), createChangedDocument: cancellationToken => AddConfigureAwaitFalse(context, root, awaitExpression), equivalenceKey: EquivalenceKey); context.RegisterCodeFix(codeAction, diagnostic); }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var result = await context.TryGetSyntaxNode <MethodDeclarationSyntax>(AsyncDiagnosticIdentifiers.AvoidAsyncVoidMethods); if (!result.success) { return; } var methodDeclaration = result.syntaxNode; var diagnostic = result.diagnostic; var root = result.root; var codeAction = CodeAction.Create( title: Title.ToString(), createChangedDocument: cancellationToken => ChangeReturnTypeToTask(context, root, methodDeclaration), equivalenceKey: EquivalenceKey); context.RegisterCodeFix(codeAction, diagnostic); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; // Find the type declaration identified by the diagnostic. var declaration = root.FindToken(diagnosticSpan.Start).Parent.AncestorsAndSelf().OfType <PropertyDeclarationSyntax>().First(); // Register a code action that will invoke the fix. var title = Title.ToString(); context.RegisterCodeFix( CodeAction.Create( title: title, createChangedDocument: c => GetTransformedDocumentAsync(context.Document, root, declaration), equivalenceKey: title), diagnostic); }
public override async Task RegisterCodeFixesAsync(CodeFixContext context) { var result = await context.TryGetSyntaxNode <ClassDeclarationSyntax>(DiagnosticId); if (!result.success) { return; } var classDeclaration = result.syntaxNode; var diagnostic = result.diagnostic; var root = result.root; var codeAction = CodeAction.Create( title: Title.ToString(), createChangedDocument: cancellationToken => AddSealedModifierToClass(context, root, classDeclaration), equivalenceKey: EquivalenceKey); context.RegisterCodeFix(codeAction, diagnostic); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var usingStatement = root.FindNode(diagnosticSpan).AncestorsAndSelf().OfType <UsingStatementSyntax>().FirstOrDefault(); if (usingStatement == null) { return; } context.RegisterCodeFix( CodeAction.Create( title: Title.ToString(), createChangedDocument: ct => AddAwaitAsync(context.Document, usingStatement, ct), equivalenceKey: UsingStatementMissingAwaitAnalyzer.DiagnosticId + "-CodeFix"), diagnostic); }
public static void DownloadTemplate(UserConnection userConnection, LocalizableString fileName) { var entitySchemaManager = userConnection.EntitySchemaManager; var entitySchema = entitySchemaManager.GetInstanceByName("KnowledgeBaseFile"); var entitySchemaQuery = new EntitySchemaQuery(entitySchemaManager, entitySchema.Name); var dataColumn = entitySchemaQuery.AddColumn("Data"); entitySchemaQuery.Filters.Add( entitySchemaQuery.CreateFilterWithParameters( FilterComparisonType.Equal, "KnowledgeBase", new object[] { new Guid("edb71f06-f46b-1410-e980-20cf30b39373") })); entitySchemaQuery.Filters.Add( entitySchemaQuery.CreateFilterWithParameters( FilterComparisonType.Equal, "Name", new object[] { fileName.ToString() })); var entityCollection = entitySchemaQuery.GetEntityCollection(userConnection); if (entityCollection.Count > 0) { var data = entityCollection[0].GetBytesValue(dataColumn.Name) as byte[]; var response = HttpContext.Current.Response; Terrasoft.Configuration.PageResponse.Write(response, data, fileName, Terrasoft.Configuration.ContentType.XmlType); } }
private static void HandleCompilation(CompilationAnalysisContext context) { var firstSyntaxTree = context.Compilation.SyntaxTrees.FirstOrDefault(); if (firstSyntaxTree is null) { return; } try { SettingsHelper.GetStyleCopSettings(context.Options, firstSyntaxTree, DeserializationFailureBehavior.ThrowException, context.CancellationToken); } catch (Exception ex) when(ex is JsonParseException || ex is InvalidSettingsException) { string details = ex.Message; string completeDescription = string.Format(Description.ToString(CultureInfo.CurrentCulture), details); var completeDescriptor = new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.SpecialRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, completeDescription, HelpLink); context.ReportDiagnostic(Diagnostic.Create(completeDescriptor, Location.None)); } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var expression = root.FindNode(diagnosticSpan) as InvocationExpressionSyntax; if (expression == null) { return; } if (SyntaxNodeUtils.IsInsideOrchestrator(expression)) { if (CodeFixProviderUtils.TryGetDurableOrchestrationContextVariableName(expression, out string variableName)) { context.RegisterCodeFix( CodeAction.Create(FixGuidInOrchestrator.ToString(), c => ReplaceWithInvocationExpressionAsync(context.Document, expression, c, variableName + ".NewGuid()"), nameof(GuidCodeFixProvider)), diagnostic); } } }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); var diagnostic = context.Diagnostics.First(); var diagnosticSpan = diagnostic.Location.SourceSpan; var expression = root.FindNode(diagnosticSpan); if (SyntaxNodeUtils.IsInsideOrchestrator(expression)) { if (TryGetDurableOrchestrationContextVariableName(expression, out string variableName)) { context.RegisterCodeFix( CodeAction.Create(FixGuidInOrchestrator.ToString(), c => ReplaceWithIdentifierAsync(context.Document, expression, c, variableName + ".NewGuid()"), nameof(GuidCodeFixProvider)), diagnostic); } } else if (SyntaxNodeUtils.IsMarkedDeterministic(expression)) { context.RegisterCodeFix( CodeAction.Create(FixDeterministicAttribute.ToString(), c => RemoveDeterministicAttributeAsync(context.Document, expression, c), nameof(GuidCodeFixProvider)), diagnostic); } }
public WeakSymmetricAlgorithmReport() : base(AnalysisIds.WeakSymmetricAlgorithm, SummaryString.ToString(), DescriptionString.ToString(), CategoryString.ToString(), ExploitabilityValue, SecurityGoals, null, Remarks.ToString(), CweLink, TDesExpliot) { }
private static string EscapeTags(LocalizableString str) => Replace(str.ToString(CultureInfo.InvariantCulture), "<", @"\<");
private void Upload() { BusyStatus = HudUploadToStoreBusyStatus.Submitting; StartAsyncOperation(() => { var licenseService = ServiceLocator.Current.GetInstance <ILicenseService>(); var license = licenseService.GetHudStoreLicenseInfo(false); if (license == null) { throw new DHBusinessException(new NonLocalizableString("Couldn't find license to upload HUD to the store.")); } // update layout name in xml hudLayout.Name = Name; var serializedLayout = SerializationHelper.SerializeObject(hudLayout); var uploadInfo = new HudStoreUploadInfo { Name = Name, Description = Description, GameVariants = GameVariants.Where(x => x.IsSelected && !x.IsAll).Select(x => x.Item).ToArray(), GameTypes = GameTypes.Where(x => x.IsSelected && !x.IsAll).Select(x => x.Item).ToArray(), TableTypes = TableTypes.Where(x => x.IsSelected && !x.IsAll).Select(x => x.Item).ToArray(), Cost = Cost, Images = Images.Select(x => new HudStoreUploadImageInfo { Caption = x.Caption, Path = x.Path }).ToArray(), Serial = license.Serial, HudLayout = serializedLayout }; Model.Upload(uploadInfo); }, ex => { if (ex != null) { LogProvider.Log.Error(this, "Failed to upload HUD on the HUD store.", ex); IsSubmitButtonVisible = false; IsResetButtonVisible = false; IsRetryButtonVisible = true; IsBackButtonVisible = true; IsCancelButtonVisible = true; IsCloseButtonVisible = false; Message = LocalizableString.ToString("Common_HudUploadToStoreView_UploadingFailed", ex.Message); return; } IsSubmitButtonVisible = false; IsResetButtonVisible = false; IsRetryButtonVisible = false; IsBackButtonVisible = false; IsCancelButtonVisible = false; IsCloseButtonVisible = true; Message = CommonResourceManager.Instance.GetResourceString("Common_HudUploadToStoreView_UploadingSucceed"); }); }
private static void ForceLocalizableStringExceptions(LocalizableString localizableString, EventHandler<Exception> handler) { if (localizableString.CanThrowExceptions) { localizableString.OnException += handler; localizableString.ToString(); localizableString.OnException -= handler; } }
public NotDisposedReport() : base(DisposableAnalyzer.DiagnosticId, SummaryString.ToString(), DescriptionString.ToString(), CategoryString.ToString(), ExploitabilityValue, SecurityGoals, null, Remarks.ToString(), dispose, Cve) { }
public WeakOperationModeReport() : base(AnalysisIds.WeakOperationMode, SummaryString.ToString(), DescriptionString.ToString(), CategoryString.ToString(), ExploitabilityValue, SecurityGoals, null, Remarks.ToString(), Cbc, Ecb, Padding, Hmac) { }
public EqualKeyAndIvReport() : base(AnalysisIds.EqualKeyAndIv, SummaryString.ToString(), DescriptionString.ToString(), CategoryString.ToString(), ExploitabilityValue, SecurityGoals, null, Remarks.ToString()) { }
public NonFipsCompliantReport() : base(AnalysisIds.NonFipsCompliant, SummaryString.ToString(), DescriptionString.ToString(), CategoryString.ToString(), ExploitabilityValue, SecurityGoals, null, Remarks.ToString(), Microsoft) { }
public WeakHashingReport() : base(AnalysisIds.WeakHashing, SummaryString.ToString(), DescriptionString.ToString(), CategoryString.ToString(), ExploitabilityValue, SecurityGoals, null, Remarks.ToString(), Nist, CveLink, CveLink2, Md5Collision) { }