Here are the examples of the csharp api Microsoft.Extensions.Logging.ILogger.LogWarning(string, params object[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
690 Examples
19
View Source File : SubOrchestrationFanOutFanIn.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[FunctionName("StartSubOrchestrationFanOutFanIn")]
public static async Task<IActionResult> Start(
[HttpTrigger(AuthorizationLevel.Function, methods: "post", Route = "StartSubOrchestrationFanOutFanIn")] HttpRequest req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
if (!int.TryParse(req.Query["count"], out int count) || count < 1)
{
return new BadRequestObjectResult("A 'count' query string parameter is required and it must contain a positive number.");
}
string instanceId = await starter.StartNewAsync<object>("FanOutFanInOrchestration", count);
log.LogWarning("Started FanOutFanInOrchestration orchestration with ID = '" + instanceId + "'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}
19
View Source File : GitHubService.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private async Task<string> GetCodeownersFileImpl(Uri repoUrl)
{
// Gets the repo path from the URL
var relevantPathParts = repoUrl.Segments.Skip(1).Take(2);
var repoPath = string.Join("", relevantPathParts);
var codeOwnersUrl = $"https://raw.githubusercontent.com/{repoPath}/main/.github/CODEOWNERS";
var result = await httpClient.GetAsync(codeOwnersUrl);
if (result.IsSuccessStatusCode)
{
logger.LogInformation("Retrieved CODEOWNERS file URL = {0}", codeOwnersUrl);
return await result.Content.ReadreplacedtringAsync();
}
logger.LogWarning("Could not retrieve CODEOWNERS file URL = {0} ResponseCode = {1}", codeOwnersUrl, result.StatusCode);
return default;
}
19
View Source File : PluginModelComponentProvider.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public IApplicationModelProvider FindModelProvider()
{
_logger.LogInformation(InformationMessages.FindingModelProvider);
if (_options.FindPath != null && _options.FindPath.Any())
{
FileInfo providerreplacedembly = null;
foreach (var path in _options.FindPath)
{
// Find plugin replacedembly locations
var replacedemblies = _pluginFinder.FindPluginreplacedemblies(path.FullName, _sharedTypes);
// Remove duplicates (based on filename, without path), if any
var distinctreplacedemblies = replacedemblies.Select(a => new FileInfo(a)).GroupBy(f => f.Name).Select(f => f.First());
if (distinctreplacedemblies.Any())
{
_logger.LogInformation(InformationMessages.replacedemblyCountInPath, distinctreplacedemblies.Count(), path.FullName);
// There should be only one, so break after the first one found
providerreplacedembly = distinctreplacedemblies.First();
break;
}
else
{
_logger.LogDebug(TraceMessages.ModelProviderreplacedemblyNotFoundInPath, path.FullName);
}
}
if (providerreplacedembly != null)
{
// Load provider into separate plugin host
_pluginHost.LoadPlugins(new string[1] { providerreplacedembly.FullName }, _sharedTypes);
return _pluginHost.GetPlugins().Where(p => p is IApplicationModelProvider).Select(p => (IApplicationModelProvider)p).First();
}
else
{
_logger.LogWarning(WarningMessages.ModelProviderreplacedemblyNotFound);
}
}
return null;
}
19
View Source File : EndToEndTraceHelper.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public void FunctionAborted(
string hubName,
string functionName,
string instanceId,
string reason,
FunctionType functionType)
{
EtwEventSource.Instance.FunctionAborted(
hubName,
LocalAppName,
LocalSlotName,
functionName,
instanceId,
reason,
functionType.ToString(),
ExtensionVersion,
IsReplay: false);
this.logger.LogWarning(
"{instanceId}: Function '{functionName} ({functionType})' was aborted. Reason: {reason}. IsReplay: {isReplay}. HubName: {hubName}. AppName: {appName}. SlotName: {slotName}. ExtensionVersion: {extensionVersion}. SequenceNumber: {sequenceNumber}.",
instanceId, functionName, functionType, reason, false /*isReplay*/, hubName,
LocalAppName, LocalSlotName, ExtensionVersion, this.sequenceNumber++);
}
19
View Source File : Utils.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public static async Task<IReadOnlyDictionary<string, IReadOnlyList<Dictionary<string, string>>>> PopulateDoreplacedentsAsync(
CTLConfig config,
ILogger logger,
IEnumerable<Container> containers)
{
Dictionary<string, IReadOnlyList<Dictionary<string, string>>> createdDoreplacedents = new Dictionary<string, IReadOnlyList<Dictionary<string, string>>>();
foreach (Container container in containers)
{
long successes = 0;
long failures = 0;
ConcurrentBag<Dictionary<string, string>> createdDoreplacedentsInContainer = new ConcurrentBag<Dictionary<string, string>>();
IEnumerable<Dictionary<string, string>> doreplacedentsToCreate = GenerateDoreplacedents(config.PreCreatedDoreplacedents, config.CollectionParreplacedionKey);
await Utils.ForEachAsync(doreplacedentsToCreate, (Dictionary<string, string> doc)
=> container.CreateItemAsync(doc).ContinueWith(task =>
{
if (task.IsCompletedSuccessfully)
{
createdDoreplacedentsInContainer.Add(doc);
Interlocked.Increment(ref successes);
}
else
{
Utils.LogError(logger, $"Pre-populating {container.Id}", task.Exception);
Interlocked.Increment(ref failures);
}
}), config.Concurrency);
if (successes > 0)
{
logger.LogInformation("Completed pre-populating {0} doreplacedents in container {1}.", successes, container.Id);
}
if (failures > 0)
{
logger.LogWarning("Failed pre-populating {0} doreplacedents in container {1}.", failures, container.Id);
}
createdDoreplacedents.Add(container.Id, createdDoreplacedentsInContainer.ToList());
}
return createdDoreplacedents;
}
19
View Source File : BindingFileParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[System.Diagnostics.Codereplacedysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "By design as the exception messages are collated in an error object.")]
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
// Null check
_ = context ?? throw new ArgumentNullException(nameof(context));
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(BindingFileParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(BindingFileParser));
foreach (var application in group.Applications)
{
try
{
// Defensive check
if (application.Application.Bindings == null)
{
_logger.LogWarning(WarningMessages.BindingInfoNotFound, application.Application.Name);
continue;
}
_logger.LogDebug(TraceMessages.ParsingBizTalkBindingFileFromResourceContainer, application.Application.Bindings.ResourceContainerKey);
var bindingResourceDefinition = model.FindResourceDefinitionByKey(application.Application.Bindings.ResourceDefinitionKey, ModelConstants.ResourceDefinitionBindings);
if (bindingResourceDefinition != null)
{
var bindingInfo = BindingInfo.FromXml((string)bindingResourceDefinition.ResourceContent);
application.Application.Bindings.BindingInfo = bindingInfo;
ParseServiceBindings(bindingInfo, bindingResourceDefinition);
}
else
{
var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceDefinition, ModelConstants.ResourceDefinitionBindings, application.Application.Bindings.ResourceDefinitionKey);
_logger.LogError(error);
context.Errors.Add(new ErrorMessage(error));
}
}
catch (Exception ex)
{
var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorReadingBindingInfo, application.Application.Name, ex.Message);
context.Errors.Add(new ErrorMessage(message));
_logger.LogError(message);
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(BindingFileParser));
}
}
19
View Source File : GitHubNameResolver.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public async Task<string> GetInternalUserPrincipalImpl(string githubUserName)
{
var query = $"{kustoTable} | where githubUserName == '{githubUserName}' | project aadUpn | limit 1;";
// TODO: Figure out how to make this async
using (var reader = client.ExecuteQuery(query))
{
if (reader.Read())
{
return reader.GetString(0);
}
logger.LogWarning("Could Not Resolve GitHub User Username = {0}", githubUserName);
return default;
}
}
19
View Source File : SC001DocumentSchemaGenerator.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[System.Diagnostics.Codereplacedysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "The folder paths are lowercased, so must use a lowercase function.")]
protected override async Task ConvertInternalAsync(CancellationToken token)
{
if (Model.MigrationTarget.MessageBus?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(SC001DoreplacedentSchemaGenerator));
}
else
{
_logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(SC001DoreplacedentSchemaGenerator));
var conversionPath = Context.ConversionFolder;
foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications)
{
foreach (var message in targetApplication.Messages)
{
// Key the resource for the schema (message definition from the model).
var messageResource = Model.FindResourceByKey(message.MessageSchema?.ResourceKeyRef);
if (messageResource == null)
{
_logger.LogWarning(WarningMessages.ResourceNotFoundByKey, message.MessageSchema?.ResourceKeyRef);
}
else
{
// Get the schema resource (which is a parent of the message definition) from the model.
var schemaResource = Model.FindResourceByRefId(messageResource.ParentRefId);
if (schemaResource == null)
{
_logger.LogWarning(WarningMessages.ResourceNotFoundByRefId, messageResource.ParentRefId);
}
else
{
// Get the schema resource definition which is the parent of the schema resource. This is required for the schema resource definition content.
var schemaResourceDefinition = Model.FindResourceDefinitionByRefId(schemaResource.ParentRefId);
if (schemaResourceDefinition == null)
{
_logger.LogWarning(WarningMessages.ResourceDefinitionNotFound, schemaResource.ParentRefId);
}
else
{
var schemaXmlResources = message.Resources.Where(r => r.ResourceType == ModelConstants.ResourceTypeXml);
if (schemaXmlResources != null && schemaXmlResources.Count() > 0)
{
foreach (var schemaXmlResource in schemaXmlResources)
{
var fileName = $"{targetApplication.Name}.{message.MessageSchema.Name}".Replace(" ", string.Empty);
var outputPath = new FileInfo(Path.Combine(conversionPath, Path.Combine(schemaXmlResource.OutputPath, $"{fileName}.xsd")));
_fileRepository.WriteXmlFile(outputPath.FullName, schemaResourceDefinition.ResourceContent.ToString());
_logger.LogDebug(TraceMessages.SavingArtifact, outputPath.FullName);
}
}
else
{
var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceTemplateForMessagingObject, ModelConstants.ResourceTypeXml, message.Name);
_logger.LogError(error);
Context.Errors.Add(new ErrorMessage(error));
}
}
}
}
}
}
_logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(SC001DoreplacedentSchemaGenerator));
}
await Task.CompletedTask.ConfigureAwait(false);
}
19
View Source File : PipelineConvention.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private async Task<BuildDefinition> CreateDefinitionAsync(string definitionName, SdkComponent component, CancellationToken cancellationToken)
{
var sourceRepository = await Context.GetSourceRepositoryAsync(cancellationToken);
var buildRepository = new BuildRepository()
{
DefaultBranch = Context.Branch,
Id = sourceRepository.Id,
Name = sourceRepository.FullName,
Type = "GitHub",
Url = new Uri(sourceRepository.Properties["cloneUrl"]),
};
buildRepository.Properties.AddRangeIfRangeNotNull(sourceRepository.Properties);
var projectReference = await Context.GetProjectReferenceAsync(cancellationToken);
var agentPoolQueue = await Context.GetAgentPoolQueue(cancellationToken);
var normalizedRelativeYamlPath = component.RelativeYamlPath.Replace("\\", "/");
var definition = new BuildDefinition()
{
Name = definitionName,
Project = projectReference,
Path = Context.DevOpsPath,
Repository = buildRepository,
Process = new YamlProcess()
{
YamlFilename = normalizedRelativeYamlPath
},
Queue = agentPoolQueue
};
if (!Context.WhatIf)
{
Logger.LogDebug("Creating definition named '{0}'.", definitionName);
var buildClient = await Context.GetBuildHttpClientAsync(cancellationToken);
definition = await buildClient.CreateDefinitionAsync(
definition: definition,
cancellationToken: cancellationToken
);
Logger.LogInformation("Created definition '{0}' at: {1}", definitionName, definition.GetWebUrl());
}
else
{
Logger.LogWarning("Skipping creating definition '{0}' (--whatif).", definitionName);
}
return definition;
}
19
View Source File : TemplateRendererConverter.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private async Task<int> GenerateFilesAsync(MessagingObject messagingObject, IEnumerable<DirectoryInfo> templatePaths, DirectoryInfo conversionPathRoot)
{
var generatedFiles = 0;
if (messagingObject.Resources.Any())
{
foreach (var resourceTemplate in messagingObject.Resources)
{
foreach (var templateFile in resourceTemplate.ResourceTemplateFiles)
{
var foundTemplate = await GenerateFileAsync(messagingObject, resourceTemplate, templatePaths, templateFile, resourceTemplate.OutputPath, conversionPathRoot).ConfigureAwait(false);
if (!foundTemplate)
{
_logger.LogWarning(WarningMessages.TemplateFileNotFound, templateFile);
}
else
{
generatedFiles++;
}
}
}
}
return generatedFiles;
}
19
View Source File : EndToEndTraceHelper.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public void FunctionTerminated(
string hubName,
string functionName,
string instanceId,
string reason)
{
FunctionType functionType = FunctionType.Orchestrator;
EtwEventSource.Instance.FunctionTerminated(
hubName,
LocalAppName,
LocalSlotName,
functionName,
instanceId,
reason,
functionType.ToString(),
ExtensionVersion,
IsReplay: false);
this.logger.LogWarning(
"{instanceId}: Function '{functionName} ({functionType})' was terminated. Reason: {reason}. State: {state}. HubName: {hubName}. AppName: {appName}. SlotName: {slotName}. ExtensionVersion: {extensionVersion}. SequenceNumber: {sequenceNumber}.",
instanceId, functionName, functionType, reason, FunctionState.Terminated, hubName, LocalAppName,
LocalSlotName, ExtensionVersion, this.sequenceNumber++);
}
19
View Source File : SubOrchestrationFanOutFanIn.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[FunctionName("StartSubOrchestrationFanOutFanIn")]
public static async Task<HttpResponseMessage> Start(
[HttpTrigger(AuthorizationLevel.Function, methods: "post", Route = "StartSubOrchestrationFanOutFanIn")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
if (!int.TryParse(req.GetQueryNameValuePairs().First(q => q.Key == "count").Value, out int count) || count < 1)
{
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.BadRequest,
ReasonPhrase = "A 'count' query string parameter is required and it must contain a positive number."
};
}
string instanceId = await starter.StartNewAsync<object>("FanOutFanInOrchestration", count);
log.LogWarning("Started FanOutFanInOrchestration orchestration with ID = '" + instanceId + "'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}
19
View Source File : SendPortPipelineDataParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(SendPortPipelineDataParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(SendPortPipelineDataParser));
foreach (var application in group.Applications)
{
// Defensive check
if (application.Application.Bindings == null)
{
_logger.LogWarning(WarningMessages.BindingInfoNotFound, application.Application.Name);
continue;
}
_logger.LogDebug(TraceMessages.ParsingBizTalkSendPipelineDataInApplication, application.Application.Name);
if (application.Application.Bindings.BindingInfo.SendPortCollection != null)
{
foreach (var sendPort in application.Application.Bindings.BindingInfo.SendPortCollection)
{
_logger.LogDebug(TraceMessages.ParsingBizTalkSendPortPipelineDataForSendPort, sendPort.Name);
sendPort.SendPipelineCustomConfiguration = ParsePipelineData(application, sendPort.Name, sendPort.SendPipelineData, PipelineDirection.Send, context.Errors);
sendPort.ReceivePipelineCustomConfiguration = ParsePipelineData(application, sendPort.Name, sendPort.ReceivePipelineData, PipelineDirection.Receive, context.Errors);
}
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(SendPortPipelineDataParser));
}
}
19
View Source File : GraphWebhookSubscriptionAsyncCollector.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private async Task RefreshSubscription(IGraphServiceClient client, string id)
{
try
{
var subscription = new Subscription
{
ExpirationDateTime = DateTime.UtcNow + _options.WebhookExpirationTimeSpan,
};
var result = await client.Subscriptions[id].Request().UpdateAsync(subscription);
_log.LogInformation($"Successfully renewed MS Graph subscription {id}. \n Active until {subscription.ExpirationDateTime}");
}
catch (Exception ex)
{
// If the subscription is expired, it can no longer be renewed, so delete the file
var subscriptionEntry = await _subscriptionStore.GetSubscriptionEntryAsync(id);
if (subscriptionEntry != null)
{
if(subscriptionEntry.Subscription.ExpirationDateTime < DateTime.UtcNow)
{
await _subscriptionStore.DeleteAsync(id);
} else
{
_log.LogError(ex, "A non-expired subscription failed to renew");
}
} else
{
_log.LogWarning("The subscription with id " + id + " was not present in the local subscription store.");
}
}
}
19
View Source File : DP005DistributionListDependencyAnalyzer.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
protected override async Task replacedyzeInternalAsync(CancellationToken token)
{
// Get parsed BizTalk model from the application model
var resources = Model.FindAllResources();
if (resources == null || !resources.Any())
{
_logger.LogDebug(TraceMessages.SkippingRulereplacedourceModelMissing, RuleName, nameof(DP005DistributionListDependencyreplacedyzer));
}
else
{
_logger.LogDebug(TraceMessages.RunningRule, RuleName, nameof(DP005DistributionListDependencyreplacedyzer));
// Get a list of all the send port groups
var distributionLists = resources.Where(r => r.Type == ModelConstants.ResourceDistributionList);
foreach (var distributionList in distributionLists)
{
if (distributionList.SourceObject == null || !(distributionList.SourceObject.GetType() == typeof(DistributionList)))
{
// Source model corrupt
_logger.LogError(ErrorMessages.UnableToFindreplacedociatedResource, distributionList.Type, distributionList.Name, distributionList.Key);
distributionList.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Error, Message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindreplacedociatedResource, distributionList.Type, distributionList.Name, distributionList.Key) });
continue;
}
// Look up the send ports in the send port group.
var dl = (DistributionList)distributionList.SourceObject;
foreach (var sendPortRef in dl.SendPorts)
{
var matchingSendPorts = resources.Where(r => r.Type == ModelConstants.ResourceSendPort && r.SourceObject != null && r.SourceObject.GetType() == typeof(SendPort) && ((SendPort)r.SourceObject).Name == sendPortRef.Name);
if (matchingSendPorts == null || !matchingSendPorts.Any())
{
// No send ports found matching the one referenced in the DL
_logger.LogWarning(WarningMessages.DistributionListSendPortNotFound, sendPortRef.Name, distributionList.Name, distributionList.Key);
distributionList.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Warning, Message = string.Format(CultureInfo.CurrentCulture, WarningMessages.DistributionListSendPortNotFound, sendPortRef.Name, distributionList.Name, distributionList.Key) });
}
else if (matchingSendPorts.Count() > 1)
{
// There are multiple send ports found, for example when two apps being replacedyzed use the same name
_logger.LogWarning(WarningMessages.DistributionListSendPortMultipleMatches, sendPortRef.Name, distributionList.Name, distributionList.Key);
distributionList.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Warning, Message = string.Format(CultureInfo.CurrentCulture, WarningMessages.DistributionListSendPortMultipleMatches, sendPortRef.Name, distributionList.Name, distributionList.Key) });
}
else
{
// All good. A send port has been found.
var sendPort = matchingSendPorts.Single();
distributionList.AddRelationship(new ResourceRelationship(sendPort.RefId, ResourceRelationshipType.CallsTo));
sendPort.AddRelationship(new ResourceRelationship(distributionList.RefId, ResourceRelationshipType.CalledBy));
}
}
}
_logger.LogDebug(TraceMessages.RuleCompleted, RuleName, nameof(DP005DistributionListDependencyreplacedyzer));
}
await Task.CompletedTask.ConfigureAwait(false);
}
19
View Source File : OptionsSetup.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public void Configure(ServiceManagerOptions options)
{
options.ConnectionString = configuration.GetConnectionString(connectionStringKey) ?? configuration[connectionStringKey];
var endpoints = configuration.GetSection(Constants.AzureSignalREndpoints).GetEndpoints(_azureComponentFactory);
// Fall back to use a section to configure Azure idenreplacedy
if (options.ConnectionString == null && configuration.GetSection(connectionStringKey).TryGetNamedEndpointFromIdenreplacedy(_azureComponentFactory, out var endpoint))
{
endpoint.Name = string.Empty;
endpoints = endpoints.Append(endpoint);
}
options.ServiceEndpoints = endpoints.ToArray();
var serviceTransportTypeStr = configuration[Constants.ServiceTransportTypeName];
if (Enum.TryParse<ServiceTransportType>(serviceTransportTypeStr, out var transport))
{
options.ServiceTransportType = transport;
}
else if (string.IsNullOrWhiteSpace(serviceTransportTypeStr))
{
options.ServiceTransportType = ServiceTransportType.Transient;
logger.LogInformation($"{Constants.ServiceTransportTypeName} not set, using default {ServiceTransportType.Transient} instead.");
}
else
{
options.ServiceTransportType = ServiceTransportType.Transient;
logger.LogWarning($"Unsupported service transport type: {serviceTransportTypeStr}. Use default {ServiceTransportType.Transient} instead.");
}
//make connection more stable
options.ConnectionCount = 3;
options.ProductInfo = GetProductInfo();
}
19
View Source File : DistributionListParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[System.Diagnostics.Codereplacedysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "By design as the exception messages are collated in an error object.")]
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(DistributionListParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(DistributionListParser));
foreach (var application in group.Applications)
{
// Defensive check
if (application.Application.Bindings == null)
{
_logger.LogWarning(WarningMessages.BindingInfoNotFound, application.Application.Name);
continue;
}
_logger.LogDebug(TraceMessages.ParsingBizTalkSendPortGroupFilterForApplication, application.Application.Name);
var bindingFileDefinition = model.FindResourceDefinitionByKey(application.Application.Bindings.ResourceDefinitionKey, ModelConstants.ResourceDefinitionBindings);
var applicationResource = model.FindResourceByKey(application.Application?.ApplicationDefinition?.ResourceKey);
foreach (var distributionList in application.Application.Bindings.BindingInfo.DistributionListCollection)
{
_logger.LogDebug(TraceMessages.ParsingBizTalkSendPortGroupFilterForDistributionList, distributionList.Name);
// Set the resource key for the distribution list.
distributionList.ResourceKey = string.Concat(application.Application.Bindings.ResourceDefinitionKey, ":", distributionList.Name);
// Create the resource under the application.
var distributionListResource = new ResourceItem
{
Key = distributionList.ResourceKey,
Name = distributionList.Name,
Description = distributionList.Description,
Type = ModelConstants.ResourceDistributionList,
ParentRefId = bindingFileDefinition.RefId,
Rating = ConversionRating.NotSupported
};
distributionList.Resource = distributionListResource; // Maintain pointer to the resource.
distributionListResource.SourceObject = distributionList; // Maintain backward pointer.
bindingFileDefinition.Resources.Add(distributionListResource);
if (applicationResource != null)
{
applicationResource.AddRelationship(new ResourceRelationship(distributionListResource.RefId, ResourceRelationshipType.Child));
distributionListResource.AddRelationship(new ResourceRelationship(applicationResource.RefId, ResourceRelationshipType.Parent));
}
else
{
var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceDefinition, ModelConstants.ResourceApplication, application.Application?.ApplicationDefinition?.ResourceKey);
_logger.LogError(error);
context.Errors.Add(new ErrorMessage(error));
}
try
{
if (!string.IsNullOrEmpty(distributionList.Filter))
{
distributionList.FilterExpression = Filter.FromXml(distributionList.Filter);
distributionList.FilterExpression.ResourceKey = string.Concat(distributionList.Name, ":", "filter");
// Create the distribution filter resource.
var filterReportResource = new ResourceItem
{
Key = distributionList.FilterExpression.ResourceKey,
Name = distributionListResource.Name + " filter expression",
Type = ModelConstants.ResourceFilterExpression,
ParentRefId = distributionListResource.RefId,
Rating = ConversionRating.NotSupported
};
distributionList.FilterExpression.Resource = filterReportResource; // Maintain pointer to the resource.
filterReportResource.SourceObject = distributionList.FilterExpression; // Maintain backward pointer.
distributionListResource.Resources.Add(filterReportResource);
}
}
catch (Exception ex)
{
var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorParsingDistributionListFilter, distributionList.Name, application.Application.Name, ex.Message);
context.Errors.Add(new ErrorMessage(message));
_logger.LogError(message);
}
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(DistributionListParser));
}
}
19
View Source File : BaseReport.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
protected async Task ExecuteWithRetryAsync(int retryCount, Func<Task> action)
{
await Policy
.Handle<AbuseException>()
.Or<RateLimitExceededException>()
.RetryAsync(10, async (ex, retryCount) =>
{
TimeSpan retryDelay = TimeSpan.FromSeconds(10); // Default.
switch (ex)
{
case AbuseException abuseException:
retryDelay = TimeSpan.FromSeconds((double)abuseException.RetryAfterSeconds);
Logger.LogWarning("Abuse exception detected. Retry after seconds is: {retrySeconds}",
abuseException.RetryAfterSeconds
);
break;
case RateLimitExceededException rateLimitExceededException:
retryDelay = rateLimitExceededException.GetRetryAfterTimeSpan();
Logger.LogWarning(
"Rate limit exception detected. Limit is: {limit}, reset is: {reset}, retry seconds is: {retrySeconds}",
rateLimitExceededException.Limit,
rateLimitExceededException.Reset,
retryDelay.TotalSeconds
);
break;
default:
Logger.LogError(
"Fall through case invoked, this should never happen!"
);
break;
}
await Task.Delay(retryDelay);
})
.ExecuteAsync(async () =>
{
try
{
await action();
}
catch (AggregateException ex) when (ex.InnerException! is AbuseException || ex.InnerException! is RateLimitExceededException)
{
throw ex.InnerException;
}
}
19
View Source File : DefaultProjectChangePublisher.cs
License : Apache License 2.0
Project Creator : aspnet
License : Apache License 2.0
Project Creator : aspnet
protected virtual void DeleteFile(string publishFilePath)
{
var info = new FileInfo(publishFilePath);
if (info.Exists)
{
try
{
// Try catch around the delete in case it was deleted between the Exists and this delete call. This also
// protects against unauthorized access issues.
info.Delete();
}
catch (Exception ex)
{
_logger.LogWarning([email protected]"Failed to delete Razor configuration file '{publishFilePath}':
{ex}");
}
}
}
19
View Source File : PipelineConvention.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public async Task<BuildDefinition> DeleteDefinitionAsync(SdkComponent component, CancellationToken cancellationToken)
{
var definitionName = GetDefinitionName(component);
Logger.LogDebug("Checking to see if definition '{0}' exists prior to deleting.", definitionName);
var definition = await GetExistingDefinitionAsync(definitionName, cancellationToken);
if (definition != null)
{
Logger.LogDebug("Found definition called '{0}' at '{1}'.", definitionName, definition.GetWebUrl());
if (!Context.WhatIf)
{
Logger.LogWarning("Deleting definition '{0}'.", definitionName);
var projectReference = await Context.GetProjectReferenceAsync(cancellationToken);
var buildClient = await Context.GetBuildHttpClientAsync(cancellationToken);
await buildClient.DeleteDefinitionAsync(
project: projectReference.Id,
definitionId: definition.Id,
cancellationToken: cancellationToken
);
}
else
{
Logger.LogWarning("Skipping deleting definition '{0}' (--whatif).", definitionName);
}
return definition;
}
else
{
Logger.LogDebug("No definition called '{0}' existed.", definitionName);
return null;
}
}
19
View Source File : AzureAppConfigurationProvider.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public async Task<bool> TryRefreshAsync(CancellationToken cancellationToken)
{
try
{
await RefreshAsync(cancellationToken).ConfigureAwait(false);
}
catch (RequestFailedException e)
{
if (IsAuthenticationError(e))
{
_logger?.LogWarning(e, LoggingConstants.RefreshFailedDueToAuthenticationError);
}
else
{
_logger?.LogWarning(e, LoggingConstants.RefreshFailedError);
}
return false;
}
catch (AggregateException e) when (e?.InnerExceptions?.All(e => e is RequestFailedException) ?? false)
{
if (IsAuthenticationError(e))
{
_logger?.LogWarning(e, LoggingConstants.RefreshFailedDueToAuthenticationError);
}
else
{
_logger?.LogWarning(e, LoggingConstants.RefreshFailedError);
}
return false;
}
catch (KeyVaultReferenceException e)
{
_logger?.LogWarning(e, LoggingConstants.RefreshFailedDueToKeyVaultError);
return false;
}
catch (OperationCanceledException)
{
_logger?.LogWarning(LoggingConstants.RefreshCanceledError);
return false;
}
return true;
}
19
View Source File : SendPortParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[System.Diagnostics.Codereplacedysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "By design as the exception messages are collated in an error object.")]
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(SendPortParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(SendPortParser));
foreach (var application in group.Applications)
{
// Defensive check
if (application.Application.Bindings == null)
{
_logger.LogWarning(WarningMessages.BindingInfoNotFound, application.Application.Name);
continue;
}
_logger.LogDebug(TraceMessages.ParsingBizTalkSendPortFiltersInApplication, application.Application.Name);
var bindingFileDefinition = model.FindResourceDefinitionByKey(application.Application.Bindings.ResourceDefinitionKey, ModelConstants.ResourceDefinitionBindings);
var applicationResource = model.FindResourceByKey(application.Application?.ApplicationDefinition?.ResourceKey);
foreach (var sendPort in application.Application.Bindings.BindingInfo.SendPortCollection)
{
try
{
sendPort.ResourceKey = string.Concat(application.Application.Bindings.ResourceDefinitionKey, ":", sendPort.Name);
// Create the resource under the binding file.
var sendPortResource = new ResourceItem
{
Key = sendPort.ResourceKey,
Name = sendPort.Name,
Description = sendPort.Description,
Type = ModelConstants.ResourceSendPort,
ParentRefId = bindingFileDefinition.RefId,
Rating = ConversionRating.NotSupported
};
sendPort.Resource = sendPortResource; // Maintain pointer to the resource.
sendPortResource.SourceObject = sendPort; // Maintain backward pointer.
// Static or dynamic port?
if (sendPort.IsStatic)
{
// Static port
sendPortResource.Properties.Add(ResourceItemProperties.SendPortTypeProperty, ResourceItemProperties.StaticSendPortType);
sendPortResource.Properties.Add(ResourceItemProperties.SendPortPrimaryTransportTypeProperty, sendPort.PrimaryTransport.TransportType?.Name);
sendPortResource.Properties.Add(ResourceItemProperties.SendPortPrimaryAddressProperty, sendPort.PrimaryTransport.Address);
if (sendPort.SecondaryTransport != null && !string.IsNullOrEmpty(sendPort.SecondaryTransport.Address))
{
sendPortResource.Properties.Add(ResourceItemProperties.SendPortSecondaryTransportTypeProperty, sendPort.SecondaryTransport.TransportType?.Name);
sendPortResource.Properties.Add(ResourceItemProperties.SendPortSecondaryAddressProperty, sendPort.SecondaryTransport.Address);
}
}
else
{
// Dynamic port
sendPortResource.Properties.Add(ResourceItemProperties.SendPortTypeProperty, ResourceItemProperties.DynamicSendPortType);
}
sendPortResource.Properties.Add(ResourceItemProperties.PortDirectionProperty, sendPort.IsTwoWay ? ResourceItemProperties.PortDirectionTwoWay : ResourceItemProperties.PortDirectionOneWay);
bindingFileDefinition.Resources.Add(sendPortResource);
if (applicationResource != null)
{
applicationResource.AddRelationship(new ResourceRelationship(sendPortResource.RefId, ResourceRelationshipType.Child));
sendPortResource.AddRelationship(new ResourceRelationship(applicationResource.RefId, ResourceRelationshipType.Parent));
}
else
{
var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceDefinition, ModelConstants.ResourceApplication, application.Application?.ApplicationDefinition?.ResourceKey);
_logger.LogError(error);
context.Errors.Add(new ErrorMessage(error));
}
if (!string.IsNullOrEmpty(sendPort.Filter))
{
sendPort.FilterExpression = Filter.FromXml(sendPort.Filter);
sendPort.FilterExpression.ResourceKey = string.Concat(sendPort.Name, ":", "filter");
var filterResource = new ResourceItem
{
Key = sendPort.FilterExpression.ResourceKey,
Name = sendPortResource.Name + " filter expression",
Type = ModelConstants.ResourceFilterExpression,
ParentRefId = sendPortResource.RefId,
Rating = ConversionRating.NotSupported
};
sendPort.FilterExpression.Resource = filterResource; // Maintain pointer to the resource.
filterResource.SourceObject = sendPort.FilterExpression; // Maintain backward pointer.
sendPortResource.Resources.Add(filterResource);
_logger.LogDebug(TraceMessages.ParsedBizTalkSendPortFilterExpression, sendPort.Name);
}
}
catch (Exception ex)
{
var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorParsingSendPort, sendPort.Name, application.Application.Name, ex.Message);
context.Errors.Add(new ErrorMessage(message));
_logger.LogError(message);
}
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(SendPortParser));
}
}
19
View Source File : DefaultProjectChangePublisher.cs
License : Apache License 2.0
Project Creator : aspnet
License : Apache License 2.0
Project Creator : aspnet
internal void Publish(OmniSharpProjectSnapshot projectSnapshot)
{
if (projectSnapshot == null)
{
throw new ArgumentNullException(nameof(projectSnapshot));
}
lock (_publishLock)
{
string publishFilePath = null;
try
{
if (!_publishFilePathMappings.TryGetValue(projectSnapshot.FilePath, out publishFilePath))
{
return;
}
SerializeToFile(projectSnapshot, publishFilePath);
}
catch (Exception ex)
{
_logger.LogWarning([email protected]"Could not update Razor project configuration file '{publishFilePath}':
{ex}");
}
}
}
19
View Source File : DurableTaskScaleMonitor.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public async Task<DurableTaskTriggerMetrics> GetMetricsAsync()
{
DurableTaskTriggerMetrics metrics = new DurableTaskTriggerMetrics();
// Durable stores its own metrics, so we just collect them here
PerformanceHeartbeat heartbeat = null;
try
{
DisconnectedPerformanceMonitor performanceMonitor = this.GetPerformanceMonitor();
heartbeat = await performanceMonitor.PulseAsync();
}
catch (StorageException e)
{
this.logger.LogWarning("{details}. Function: {functionName}. HubName: {hubName}.", e.ToString(), this.functionName, this.hubName);
}
if (heartbeat != null)
{
metrics.ParreplacedionCount = heartbeat.ParreplacedionCount;
metrics.ControlQueueLengths = JsonConvert.SerializeObject(heartbeat.ControlQueueLengths);
metrics.ControlQueueLatencies = JsonConvert.SerializeObject(heartbeat.ControlQueueLatencies);
metrics.WorkItemQueueLength = heartbeat.WorkItemQueueLength;
if (heartbeat.WorkItemQueueLatency != null)
{
metrics.WorkItemQueueLatency = heartbeat.WorkItemQueueLatency.ToString();
}
}
return metrics;
}
19
View Source File : BizTalkApplicationParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[System.Diagnostics.Codereplacedysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "By design as the exception messages are collated in an error object.")]
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(BizTalkApplicationParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(BizTalkApplicationParser));
foreach (var application in group.Applications)
{
try
{
// Defensive check
if (application.Application.ApplicationDefinition == null)
{
_logger.LogWarning(WarningMessages.ApplicationDefinitionNotFound, application.Application.Name);
continue;
}
_logger.LogDebug(TraceMessages.ParsingBizTalkApplicationFromResourceContainer, application.Application.ApplicationDefinition.ResourceContainerKey);
var adf = from resourceContainer in model.MigrationSource.ResourceContainers
from resourceDefinition in resourceContainer.ResourceDefinitions
where resourceContainer.Key == application.ResourceContainerKey &&
application.Application.ApplicationDefinition.ResourceContainerKey == resourceContainer.Key &&
application.Application.ApplicationDefinition.ResourceDefinitionKey == resourceDefinition.Key &&
resourceDefinition.Type == ModelConstants.ResourceDefinitionApplicationDefinition
select resourceDefinition;
var applicationResourceDefinition = adf.SingleOrDefault();
if (applicationResourceDefinition == null)
{
_logger.LogWarning(WarningMessages.ApplicationDefinitionNotFound, application.Application.Name);
continue;
}
var applicationDefinition = application.Application.ApplicationDefinition.ApplicationDefinition ?? ApplicationDefinition.FromXml((string)applicationResourceDefinition.ResourceContent); // Only parse if not already deserialized.
var applicationName = applicationDefinition.Properties.Where(p => p.Name == BizTalkApplicationParser.ApplicationDisplayNameProperty).SingleOrDefault();
if (applicationName != null && !string.IsNullOrWhiteSpace(applicationName.Value))
{
// Check to see if there is already an application in the source with this name (duplicate names can occur is preplaceding multiple unrelated
// MSI files).
var duplicateApplication = model.FindResourcesByType(ModelConstants.ResourceApplication).Any(a => a.Name == applicationName.Value);
// Set application name
application.Application.Name = applicationName.Value;
if (duplicateApplication)
{
application.Application.Name = $"{application.Application.Name} {ResourceItemProperties.Duplicate}";
}
// Define resource key for application.
var resourceKey = string.Concat(applicationResourceDefinition.Key, ":", applicationName);
application.Application.ApplicationDefinition.ResourceKey = resourceKey;
// Create the application resource under the application definition resource.
var applicationResource = new ResourceItem
{
Name = applicationName.Value,
Description = applicationDefinition.Properties.Where(p => p.Name == BizTalkApplicationParser.ApplicationDescriptionProperty).SingleOrDefault()?.Value,
Key = resourceKey,
Type = ModelConstants.ResourceApplication,
ParentRefId = applicationResourceDefinition.RefId,
Rating = ConversionRating.NotSupported
};
application.Application.ApplicationDefinition.Resource = applicationResource; // Maintain pointer to the resource.
applicationResource.SourceObject = applicationDefinition; // Maintain backward pointer.
applicationResourceDefinition.Resources.Add(applicationResource);
_logger.LogTrace(TraceMessages.ResourceCreated, nameof(BizTalkApplicationParser), applicationResource.Key, applicationResource.Name, applicationResource.Type, applicationResource.Key);
// If this does not exist then update on the source model.
if (application.Application.ApplicationDefinition.ApplicationDefinition == null)
{
application.Application.ApplicationDefinition.ApplicationDefinition = applicationDefinition;
}
_logger.LogDebug(TraceMessages.ParsedTheBizTalkApplicationWithName, application.Application.Name);
// Raise an error if this was a duplicate application
if (duplicateApplication)
{
// Raise an error that there is already an application with this name
var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.DuplicateApplicationFound, applicationName.Value);
context.Errors.Add(new ErrorMessage(message));
_logger.LogError(message);
}
}
else
{
var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ApplicationNameNotFound, applicationResourceDefinition.Key);
context.Errors.Add(new ErrorMessage(message));
_logger.LogError(message);
}
}
catch (Exception ex)
{
var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorReadingApplicationFromAdf, application.Application.ApplicationDefinition.ResourceDefinitionKey, ex.Message);
context.Errors.Add(new ErrorMessage(message));
_logger.LogError(message);
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(BizTalkApplicationParser));
}
}
19
View Source File : KafkaListener.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private ConsumerConfig GetConsumerConfiguration()
{
ConsumerConfig conf = new ConsumerConfig()
{
// enable auto-commit
EnableAutoCommit = true,
// disable auto storing read offsets since we need to store them after calling the trigger function
EnableAutoOffsetStore = false,
// Interval in which commits stored in memory will be saved
AutoCommitIntervalMs = this.options.AutoCommitIntervalMs,
// Librdkafka debug options
Debug = this.options.LibkafkaDebug,
// start from earliest if no checkpoint has been committed
AutoOffsetReset = AutoOffsetReset.Earliest,
// Secure communication/authentication
SaslMechanism = this.listenerConfiguration.SaslMechanism,
SaslUsername = this.listenerConfiguration.SaslUsername,
SaslPreplacedword = this.listenerConfiguration.SaslPreplacedword,
SecurityProtocol = this.listenerConfiguration.SecurityProtocol,
SslCaLocation = this.listenerConfiguration.SslCaLocation,
SslCertificateLocation = this.listenerConfiguration.SslCertificateLocation,
SslKeyLocation = this.listenerConfiguration.SslKeyLocation,
SslKeyPreplacedword = this.listenerConfiguration.SslKeyPreplacedword,
// Values from host configuration
StatisticsIntervalMs = this.options.StatisticsIntervalMs,
ReconnectBackoffMs = this.options.ReconnectBackoffMs,
ReconnectBackoffMaxMs = this.options.ReconnectBackoffMaxMs,
SessionTimeoutMs = this.options.SessionTimeoutMs,
MaxPollIntervalMs = this.options.MaxPollIntervalMs,
QueuedMinMessages = this.options.QueuedMinMessages,
QueuedMaxMessagesKbytes = this.options.QueuedMaxMessagesKbytes,
MaxParreplacedionFetchBytes = this.options.MaxParreplacedionFetchBytes,
FetchMaxBytes = this.options.FetchMaxBytes,
MetadataMaxAgeMs = this.options.MetadataMaxAgeMs,
SocketKeepaliveEnable = this.options.SocketKeepaliveEnable
};
if (string.IsNullOrEmpty(this.listenerConfiguration.EventHubConnectionString))
{
// Setup native kafka configuration
conf.BootstrapServers = this.listenerConfiguration.BrokerList;
conf.GroupId = this.listenerConfiguration.ConsumerGroup;
if (!string.IsNullOrWhiteSpace(conf.SslCaLocation))
{
if (AzureFunctionsFileHelper.TryGetValidFilePath(conf.SslCaLocation, out var resolvedSslCaLocation))
{
this.logger.LogDebug("Found SslCaLocation in {filePath}", resolvedSslCaLocation);
conf.SslCaLocation = resolvedSslCaLocation;
}
else
{
this.logger.LogWarning("Could not find valid file path for SslCaLocation {filePath}", conf.SslCaLocation);
}
}
}
else
{
// Setup eventhubs kafka head configuration
var ehBrokerList = this.listenerConfiguration.BrokerList;
if (!ehBrokerList.Contains(EventHubsBrokerListDns))
{
ehBrokerList = $"{this.listenerConfiguration.BrokerList}{EventHubsBrokerListDns}:{EventHubsBrokerListPort}";
}
var consumerGroupToUse = string.IsNullOrEmpty(this.listenerConfiguration.ConsumerGroup) ? "$Default" : this.listenerConfiguration.ConsumerGroup;
conf.BootstrapServers = ehBrokerList;
conf.SecurityProtocol = SecurityProtocol.SaslSsl;
conf.SaslMechanism = SaslMechanism.Plain;
conf.SaslUsername = EventHubsSaslUsername;
conf.SaslPreplacedword = this.listenerConfiguration.EventHubConnectionString;
conf.SslCaLocation= this.EnsureValidEventHubsCertificateLocation(this.listenerConfiguration.SslCaLocation);
conf.GroupId = consumerGroupToUse;
conf.BrokerVersionFallback = EventHubsBrokerVersionFallback;
}
return conf;
}
19
View Source File : AzureStorageOptions.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public void Validate(ILogger logger)
{
if (this.ControlQueueBatchSize <= 0)
{
throw new InvalidOperationException($"{nameof(this.ControlQueueBatchSize)} must be a non-negative integer.");
}
if (this.ParreplacedionCount < 1 || this.ParreplacedionCount > 16)
{
throw new InvalidOperationException($"{nameof(this.ParreplacedionCount)} must be an integer value between 1 and 16.");
}
if (this.ControlQueueVisibilityTimeout < TimeSpan.FromMinutes(1) ||
this.ControlQueueVisibilityTimeout > TimeSpan.FromMinutes(60))
{
throw new InvalidOperationException($"{nameof(this.ControlQueueVisibilityTimeout)} must be between 1 and 60 minutes.");
}
if (this.MaxQueuePollingInterval <= TimeSpan.Zero)
{
throw new InvalidOperationException($"{nameof(this.MaxQueuePollingInterval)} must be non-negative.");
}
if (this.ControlQueueBufferThreshold < 1 || this.ControlQueueBufferThreshold > 1000)
{
throw new InvalidOperationException($"{nameof(this.ControlQueueBufferThreshold)} must be between 1 and 1000.");
}
if (this.ControlQueueBatchSize > this.ControlQueueBufferThreshold)
{
logger.LogWarning($"{nameof(this.ControlQueueBatchSize)} cannot be larger than {nameof(this.ControlQueueBufferThreshold)}. Please adjust these values in your `host.json` settings for predictable performance");
}
}
19
View Source File : ReceivePortPipelineDataParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(ReceivePortPipelineDataParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(ReceivePortPipelineDataParser));
foreach (var application in group.Applications)
{
// Defensive check
if (application.Application.Bindings == null)
{
_logger.LogWarning(WarningMessages.BindingInfoNotFound, application.Application.Name);
continue;
}
if (application.Application.Bindings.BindingInfo.ReceivePortCollection != null)
{
foreach (var receivePort in application.Application.Bindings.BindingInfo.ReceivePortCollection)
{
_logger.LogDebug(TraceMessages.ParsingBizTalkSendPipelineCustomConfigurationForReceivePort, receivePort.Name);
receivePort.SendPipelineCustomConfiguration = ParsePipelineData(application, receivePort.Name, receivePort.SendPipelineData, PipelineDirection.Send, context.Errors);
}
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(ReceivePortPipelineDataParser));
}
}
19
View Source File : EndToEndTraceHelper.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public void FunctionRewound(
string hubName,
string functionName,
string instanceId,
string reason)
{
FunctionType functionType = FunctionType.Orchestrator;
EtwEventSource.Instance.FunctionRewound(
hubName,
LocalAppName,
LocalSlotName,
functionName,
instanceId,
reason,
functionType.ToString(),
ExtensionVersion,
IsReplay: false);
this.logger.LogWarning(
"{instanceId}: Function '{functionName} ({functionType})' was rewound. Reason: {reason}. State: {state}. HubName: {hubName}. AppName: {appName}. SlotName: {slotName}. ExtensionVersion: {extensionVersion}. SequenceNumber: {sequenceNumber}.",
instanceId, functionName, functionType, reason, FunctionState.Rewound, hubName, LocalAppName,
LocalSlotName, ExtensionVersion, this.sequenceNumber++);
}
19
View Source File : DP004ApplicationDependencyAnalyzer.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
protected override async Task replacedyzeInternalAsync(CancellationToken token)
{
// Get parsed BizTalk model from the application model
var parsedApplicationGroup = Model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (parsedApplicationGroup?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingRulereplacedourceModelMissing, RuleName, nameof(DP004ApplicationDependencyreplacedyzer));
}
else
{
_logger.LogDebug(TraceMessages.RunningRule, RuleName, nameof(DP004ApplicationDependencyreplacedyzer));
// Find all application definitions in source model
var applicationDefinitionFiles = parsedApplicationGroup.Applications.Select(a => a.Application.ApplicationDefinition).Where(ad => ad != null);
if (applicationDefinitionFiles != null && applicationDefinitionFiles.Any())
{
foreach (var applicationDefinitionFile in applicationDefinitionFiles)
{
if (applicationDefinitionFile.ApplicationDefinition != null)
{
// Get application name
var applicationName = applicationDefinitionFile.ApplicationDefinition.GetPropertyValue(ApplicationDefinitionConstants.PropertyKeyDisplayName);
// Defensive check
if (applicationDefinitionFile.Resource == null)
{
_logger.LogError(ErrorMessages.UnableToFindreplacedociatedResource, applicationDefinitionFile.GetType(), applicationName, applicationDefinitionFile.ResourceKey);
Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindreplacedociatedResource, applicationDefinitionFile.GetType(), applicationName, applicationDefinitionFile.ResourceKey)));
continue;
}
// Get application references
var applicationRefs = applicationDefinitionFile?.ApplicationDefinition?.References?.Where(r => r.Name != "BizTalk.System");
if (applicationRefs != null && applicationRefs.Any())
{
foreach (var applicationRef in applicationRefs)
{
var foundReference = false;
// Search all application definitions in source model for related applications
var relatedApplicationDefinitionFiles = parsedApplicationGroup.Applications.Select(a => a.Application.ApplicationDefinition).Where(a => a != null && a.ApplicationDefinition != null);
if (relatedApplicationDefinitionFiles != null && relatedApplicationDefinitionFiles.Any())
{
foreach (var relatedApplicationDefinitionFile in applicationDefinitionFiles)
{
// Get application name
var relatedApplicationName = relatedApplicationDefinitionFile.ApplicationDefinition.GetPropertyValue(ApplicationDefinitionConstants.PropertyKeyDisplayName);
// Defensive check
if (relatedApplicationDefinitionFile.Resource == null)
{
_logger.LogError(ErrorMessages.UnableToFindreplacedociatedResource, relatedApplicationDefinitionFile.GetType(), relatedApplicationName, relatedApplicationDefinitionFile.ResourceKey);
Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindreplacedociatedResource, relatedApplicationDefinitionFile.GetType(), relatedApplicationName, relatedApplicationDefinitionFile.ResourceKey)));
continue;
}
if (relatedApplicationName == applicationRef.Name)
{
// Add relationships between application resource and related application resource
applicationDefinitionFile.Resource.ResourceRelationships.Add(new ResourceRelationship(relatedApplicationDefinitionFile.Resource.RefId, ResourceRelationshipType.ReferencesTo));
_logger.LogDebug(TraceMessages.RelationshipCreated, RuleName, applicationDefinitionFile.ResourceKey, relatedApplicationDefinitionFile.ResourceKey, ResourceRelationshipType.ReferencesTo);
// Add reverse relationship between schema resource and transform resource
relatedApplicationDefinitionFile.Resource.ResourceRelationships.Add(new ResourceRelationship(applicationDefinitionFile.Resource.RefId, ResourceRelationshipType.ReferencedBy));
_logger.LogDebug(TraceMessages.RelationshipCreated, RuleName, relatedApplicationDefinitionFile.ResourceKey, applicationDefinitionFile.ResourceKey, ResourceRelationshipType.ReferencedBy);
foundReference = true;
}
}
}
if (!foundReference)
{
// Add unresolved dependency message to application resource
_logger.LogWarning(WarningMessages.ApplicationReferencedByApplicationIsMissing, applicationRef.Name, applicationName);
var warning = string.Format(CultureInfo.CurrentCulture, WarningMessages.ApplicationReferencedByApplicationIsMissing, applicationRef.Name, applicationName);
applicationDefinitionFile.Resource.ReportMessages.Add(new ReportMessage() { Severity = MessageSeverity.Warning, Message = warning });
}
}
}
}
else
{
_logger.LogError(ErrorMessages.NoApplicationDefinition, applicationDefinitionFile.ResourceDefinitionKey);
var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.NoApplicationDefinition, applicationDefinitionFile.ResourceDefinitionKey);
Context.Errors.Add(new ErrorMessage(error));
}
}
}
_logger.LogDebug(TraceMessages.RuleCompleted, RuleName, nameof(DP004ApplicationDependencyreplacedyzer));
}
await Task.CompletedTask.ConfigureAwait(false);
}
19
View Source File : KafkaEventDataConvertManager.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private Task<object> ConvertToByteArray(object src, Attribute attribute, ValueBindingContext context)
{
object result = null;
var value = ((IKafkaEventData)src).Value;
if (value is byte[] bytes)
{
result = bytes;
}
else if (value is string stringValue)
{
result = Encoding.UTF8.GetBytes(stringValue);
}
else
{
logger.LogWarning([email protected]"Unable to convert incoming data to byte[] as underlying data stream was not byte[]. Returning [null]");
}
return Task.FromResult(result);
}
19
View Source File : ApplicationDefinitionParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[System.Diagnostics.Codereplacedysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "By design as the exception messages are collated in an error object.")]
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(ApplicationDefinitionParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(ApplicationDefinitionParser));
foreach (var application in group.Applications)
{
try
{
// Defensive check
if (application.Application.ApplicationDefinition == null)
{
_logger.LogWarning(WarningMessages.ApplicationDefinitionNotFound, application.Application.Name);
continue;
}
_logger.LogDebug(TraceMessages.ParsingBizTalkApplicationDefinitionFileFromResourceContainer, application.Application.ApplicationDefinition.ResourceContainerKey);
var adf = from resourceContainer in model.MigrationSource.ResourceContainers
from resourceDefinition in resourceContainer.ResourceDefinitions
where resourceContainer.Key == application.ResourceContainerKey &&
application.Application.ApplicationDefinition.ResourceContainerKey == resourceContainer.Key &&
application.Application.ApplicationDefinition.ResourceDefinitionKey == resourceDefinition.Key &&
resourceDefinition.Type == ModelConstants.ResourceDefinitionApplicationDefinition
select resourceDefinition;
var adfResourceDefinition = adf.Single();
var applicationDefinition = ApplicationDefinition.FromXml((string)adfResourceDefinition.ResourceContent);
application.Application.ApplicationDefinition.ApplicationDefinition = applicationDefinition;
}
catch (Exception ex)
{
var message = string.Format(CultureInfo.CurrentCulture, ErrorMessages.ErrorReadingApplicationDefinition, application.Application.Name, ex.Message);
context.Errors.Add(new ErrorMessage(message));
_logger.LogError(message);
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(ApplicationDefinitionParser));
}
}
19
View Source File : GraphWebhookSubscriptionAsyncCollector.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private async Task DeleteSubscription(IGraphServiceClient client, string id)
{
try
{
await client.Subscriptions[id].Request().DeleteAsync();
_log.LogInformation($"Successfully deleted MS Graph subscription {id}.");
}
catch
{
_log.LogWarning($"Failed to delete MS Graph subscription {id}.\n Either it never existed or it has already expired.");
}
finally
{
// Regardless of whether or not deleting the Graph subscription succeeded, delete the file
await _subscriptionStore.DeleteAsync(id);
}
}
19
View Source File : Login.cshtml.cs
License : Apache License 2.0
Project Creator : aspnet
License : Apache License 2.0
Project Creator : aspnet
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
ReturnUrl = returnUrl;
if (ModelState.IsValid)
{
// This doesn't count login failures towards account lockout
// To enable preplacedword failures to trigger account lockout, set lockoutOnFailure: true
var result = await _signInManager.PreplacedwordSignInAsync(Input.Email, Input.Preplacedword, Input.RememberMe, lockoutOnFailure: true);
if (result.Succeeded)
{
_logger.LogInformation("User logged in.");
return LocalRedirect(Url.GetLocalUrl(returnUrl));
}
if (result.RequiresTwoFactor)
{
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
}
if (result.IsLockedOut)
{
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout");
}
else
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}
// If we got this far, something failed, redisplay form
return Page();
}
19
View Source File : AzureFunctionsFileHelper.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
internal static void InitializeLibrdKafka(ILogger logger)
{
lock (librdkafkaInitializationLock)
{
if (librdkafkaInitialized)
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Librdkafka initialization: skipping as the initialization already happened");
}
return;
}
librdkafkaInitialized = true;
var userSpecifiedLibrdKafkaLocation = Environment.GetEnvironmentVariable(LibrdKafkaLocationEnvVarName);
if (!string.IsNullOrWhiteSpace(userSpecifiedLibrdKafkaLocation))
{
logger.LogDebug("Librdkafka initialization: loading librdkafka from user specified location: {librdkafkaPath}", userSpecifiedLibrdKafkaLocation);
Confluent.Kafka.Library.Load(userSpecifiedLibrdKafkaLocation);
return;
}
if (!IsRunningAsFunctionInAzureOrContainer())
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("Librdkafka initialization: skipping as we are not running in Azure or a container");
}
return;
}
var possibleLibrdKafkaLibraryPaths = new List<string>();
var os = Environment.GetEnvironmentVariable(OSEnvVarName, EnvironmentVariableTarget.Process) ?? string.Empty;
var isWindows = os.IndexOf("windows", 0, StringComparison.InvariantCultureIgnoreCase) != -1;
if (isWindows)
{
var websiteBitness = Environment.GetEnvironmentVariable(SiteBitnessEnvVarName) ?? string.Empty;
var is32 = websiteBitness.Equals(ProcessArchitecturex86Value, StringComparison.InvariantCultureIgnoreCase);
var architectureFolderName = is32 ? Windows32ArchFolderName : Windows64ArchFolderName;
var functionBaseFolder = GetFunctionBaseFolder();
// Functions v2 have the runtime under 'D:\home\site\wwwroot\runtimes'
possibleLibrdKafkaLibraryPaths.Add(Path.Combine(functionBaseFolder, RuntimesFolderName, architectureFolderName, NativeFolderName, LibrdKafkaWindowsFileName));
// Functions v3 have the runtime under 'D:\home\site\wwwroot\bin\runtimes'
possibleLibrdKafkaLibraryPaths.Add(Path.Combine(functionBaseFolder, BinFolderName, RuntimesFolderName, architectureFolderName, NativeFolderName, LibrdKafkaWindowsFileName));
}
else
{
logger.LogInformation("Librdkafka initialization: running in non-Windows OS, expecting librdkafka to be there");
}
if (possibleLibrdKafkaLibraryPaths.Count > 0)
{
foreach (var librdKafkaLibraryPath in possibleLibrdKafkaLibraryPaths)
{
if (File.Exists(librdKafkaLibraryPath))
{
logger.LogDebug("Librdkafka initialization: loading librdkafka from {librdkafkaPath}", librdKafkaLibraryPath);
Confluent.Kafka.Library.Load(librdKafkaLibraryPath);
return;
}
}
logger.LogWarning("Librdkafka initialization: did not attempt to load librdkafka because the desired file(s) does not exist: '{searchedPaths}' You can ignore this warning when you use extension bundle.", string.Join(",", possibleLibrdKafkaLibraryPaths));
}
else
{
logger.LogInformation("Librdkafka initialization: could not find dll location");
}
}
}
19
View Source File : App.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private void PrintExecutionStats(IRunState runState)
{
if (runState != null && runState.ExecutionState != null)
{
if (!_options.Options.Verbose)
{
// Find and print any stage runners that didn't complete
if (runState.ExecutionState.Values.Any(s => s.ExecutionState.Any(r => r.State != State.Completed && r.State != State.Skipped)))
{
foreach (var stageState in runState.ExecutionState.Values)
{
foreach (var runnerState in stageState.ExecutionState)
{
if (runnerState.State != State.Completed && runnerState.State != State.Skipped)
{
var runnerName = runnerState.StageRunner.Name ?? runnerState.StageRunner.GetType().FullName;
switch (runnerState.State)
{
case State.Failed:
_logger.LogError(ErrorMessages.StageRunnerFailed, runnerName, runnerState.Error.Message);
break;
default:
_logger.LogWarning(WarningMessages.StageRunnerDidNotCompleteSuccessfully, runnerName, runnerState.State);
break;
}
}
}
}
}
}
else
{
// Print detailed execution stats
var firstStageState = runState.ExecutionState.Values.Where(s => s.Stage == Stages.Discover).FirstOrDefault();
if (firstStageState != null)
{
var startTime = firstStageState.Started;
foreach (var stageState in runState.ExecutionState.Values)
{
_logger.LogDebug(TraceMessages.StageExecutionStats, stageState.Stage, stageState.State, (stageState.Started - startTime).TotalMilliseconds, (stageState.Completed - startTime).TotalMilliseconds);
foreach (var runnerState in stageState.ExecutionState)
{
var runnerName = runnerState.StageRunner.Name ?? runnerState.StageRunner.GetType().FullName;
switch (runnerState.State)
{
case State.Failed:
_logger.LogDebug(TraceMessages.StageRunnerExecutionStatsWithError, runnerName, stageState.Stage, runnerState.State, (runnerState.Started - startTime).TotalMilliseconds, (runnerState.Completed - startTime).TotalMilliseconds, runnerState.Error.Message);
break;
default:
_logger.LogDebug(TraceMessages.StageRunnerExecutionStats, runnerName, stageState.Stage, runnerState.State, (runnerState.Started - startTime).TotalMilliseconds, (runnerState.Completed - startTime).TotalMilliseconds);
break;
}
}
}
}
}
}
}
19
View Source File : BackgroundDeploymentHost.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private async Task ExecuteMessage(ActiveDeployment activeDeployment)
{
if (activeDeployment.DequeueCount > 10)
{
_logger.LogWarning(
$"Deleting background task for {activeDeployment.StorageName} as it has exceeded the " +
$"maximum dequeue count.");
await _deploymentQueue.Delete(activeDeployment.MessageId, activeDeployment.PopReceipt);
}
else if (activeDeployment.Action == "DeleteVM")
{
await DeleteDeployment(activeDeployment);
}
else
{
await MonitorDeployment(activeDeployment);
}
}
19
View Source File : MA001TransformGenerator.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
[System.Diagnostics.Codereplacedysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "The folder paths are lowercased, so must use a lowercase function.")]
protected override async Task ConvertInternalAsync(CancellationToken token)
{
if (Model.MigrationTarget.MessageBus?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingRuleAsMigrationTargetMessageBusMissing, RuleName, nameof(MA001TransformGenerator));
}
else
{
_logger.LogDebug(TraceMessages.RunningGenerator, RuleName, nameof(MA001TransformGenerator));
var conversionPath = Context.ConversionFolder;
foreach (var targetApplication in Model.MigrationTarget.MessageBus.Applications)
{
foreach (var message in targetApplication.Messages)
{
foreach (var messageTransform in message.MessageTransforms)
{
var messageResource = Model.FindResourceByKey(messageTransform.ResourceKeyRef);
if (messageResource == null)
{
_logger.LogWarning(WarningMessages.ResourceNotFoundByKey, messageTransform.ResourceKeyRef);
}
else
{
var mapResourceDefinition = Model.FindResourceDefinitionByRefId(messageResource.ParentRefId);
if (mapResourceDefinition == null)
{
_logger.LogError(ErrorMessages.UnableToFindResourceDefinition, mapResourceDefinition.ParentRefId);
Context.Errors.Add(new ErrorMessage(string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceDefinition, mapResourceDefinition.ParentRefId)));
}
else
{
var xmlTransformResources = message.Resources.Where(r => r.ResourceType == ModelConstants.ResourceTypeXslt);
foreach (var xmlTransformResource in xmlTransformResources)
{
var fileName = $"{targetApplication.Name}.{messageResource.Name}".Replace(" ", string.Empty);
var outputPath = new FileInfo(Path.Combine(conversionPath, Path.Combine(xmlTransformResource.OutputPath, $"{fileName}.xslt")));
_fileRepository.WriteXmlFile(outputPath.FullName, mapResourceDefinition.ResourceContent.ToString());
_logger.LogDebug(TraceMessages.SavingArtifact, outputPath.FullName);
}
}
}
}
}
}
_logger.LogDebug(TraceMessages.GeneratorCompleted, RuleName, nameof(MA001TransformGenerator));
}
await Task.CompletedTask.ConfigureAwait(false);
}
19
View Source File : GitHubNameResolver.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public async Task<IdenreplacedyDetail> GetMappingInformationFromAADUpn(string aadUpn)
{
var query = $"{kustoTable} | where aadUpn == '{aadUpn}' | project githubUserName, aadId, aadName, aadAlias, aadUpn | limit 1;";
// TODO: Figure out how to make this async
using (var reader = client.ExecuteQuery(query))
{
if (reader.Read())
{
return new IdenreplacedyDetail(){
GithubUserName = reader.GetString(0),
AadId = reader.GetString(1),
Name = reader.GetString(2),
Alias = reader.GetString(3),
AadUpn = reader.GetString(4)
};
}
logger.LogWarning("Could Not Resolve Idenreplacedy of User = {0}", aadUpn);
return default;
}
}
19
View Source File : AppOptionsService.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public void MergeConfig()
{
if (_config != null)
{
// Working path
if (_options.Value.WorkingPath == null && !string.IsNullOrWhiteSpace(_config.WorkingPath))
{
_options.Value.WorkingPath = new DirectoryInfo(_config.WorkingPath);
}
// State path
if (_options.Value.StatePath == null && !string.IsNullOrWhiteSpace(_config.StatePath))
{
_options.Value.StatePath = new DirectoryInfo(_config.StatePath).FullName;
}
// Find paths
if (_config.FindPaths != null && _config.FindPaths.Any())
{
// Merge existing paths if they exist
var findPaths = new List<DirectoryInfo>();
if (_options.Value.FindPath != null && _options.Value.FindPath.Any())
{
findPaths.AddRange(_options.Value.FindPath);
}
// Add new paths
findPaths.AddRange(_config.FindPaths.Where(p => !string.IsNullOrWhiteSpace(p)).Select(p => new DirectoryInfo(p)));
// Replace with new appended collection
_options.Value.FindPath = findPaths;
}
// Find pattern
if (string.IsNullOrWhiteSpace(_options.Value.FindPattern) && !string.IsNullOrWhiteSpace(_config.FindPattern))
{
_options.Value.FindPattern = _config.FindPattern;
}
// Template config path
if (_options.Value.TemplateConfigPath == null && !string.IsNullOrWhiteSpace(_config.TemplateConfigPath))
{
_options.Value.TemplateConfigPath = new DirectoryInfo(_config.TemplateConfigPath);
}
// Template path
if (_config.TemplatePaths != null && _config.TemplatePaths.Any())
{
// Merge existing paths if they exist
var templatePaths = new List<DirectoryInfo>();
if (_options.Value.TemplatePath != null && _options.Value.TemplatePath.Any())
{
templatePaths.AddRange(_options.Value.TemplatePath);
}
// Add new paths
templatePaths.AddRange(_config.TemplatePaths.Where(p => !string.IsNullOrWhiteSpace(p)).Select(p => new DirectoryInfo(p)));
// Replace with new appended collection
_options.Value.TemplatePath = templatePaths;
}
// Primary region
if (!string.IsNullOrWhiteSpace(_options.Value.PrimaryRegion))
{
_userProvidedPrimaryRegion = true;
}
if (string.IsNullOrWhiteSpace(_options.Value.PrimaryRegion) && !string.IsNullOrWhiteSpace(_config.PrimaryRegion))
{
_options.Value.PrimaryRegion = _config.PrimaryRegion;
}
// Secondary region
if (!string.IsNullOrWhiteSpace(_options.Value.SecondaryRegion))
{
_userProvidedSecondaryRegion = true;
}
if (string.IsNullOrWhiteSpace(_options.Value.SecondaryRegion) && !string.IsNullOrWhiteSpace(_config.SecondaryRegion))
{
_options.Value.SecondaryRegion = _config.SecondaryRegion;
}
// Check paired regions
if (_userProvidedPrimaryRegion && !_userProvidedSecondaryRegion)
{
var pairedRegion = _regionProvider.GetPairedRegion(_options.Value.PrimaryRegion);
if (pairedRegion != null && _options.Value.SecondaryRegion != pairedRegion)
{
// Secondary region not specified on command line but isn't the paired region for the primary region, replace it
_logger.LogInformation(InformationMessages.SecondaryRegionChangedToMatchPairedRegionOfPrimary, _options.Value.SecondaryRegion, _options.Value.PrimaryRegion, pairedRegion);
_options.Value.SecondaryRegion = pairedRegion;
}
}
if (!_userProvidedPrimaryRegion && _userProvidedSecondaryRegion)
{
var pairedRegion = _regionProvider.GetPairedRegion(_options.Value.SecondaryRegion);
if (pairedRegion != null && _options.Value.PrimaryRegion != pairedRegion)
{
// Primary region not specified on command line but isn't the paired region for the secondary region, replace it
_logger.LogInformation(InformationMessages.PrimaryRegionChangedToMatchPairedRegionOfSecondary, _options.Value.PrimaryRegion, _options.Value.SecondaryRegion, pairedRegion);
_options.Value.PrimaryRegion = pairedRegion;
}
}
if (_userProvidedPrimaryRegion && _userProvidedSecondaryRegion)
{
var pairedRegion = _regionProvider.GetPairedRegion(_options.Value.PrimaryRegion);
if (_options.Value.SecondaryRegion != pairedRegion)
{
// Secondary region is not the paired region, just output a warning in case this was not intended
_logger.LogWarning(WarningMessages.SecondaryRegionIsNotPairedWithPrimary, _options.Value.SecondaryRegion, _options.Value.PrimaryRegion, pairedRegion);
}
}
}
}
19
View Source File : GitHubNameResolver.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public async Task<IdenreplacedyDetail> GetMappingInformationFromAADName(string aadName)
{
var query = $"{kustoTable} | where aadName startswith '{aadName}' | project githubUserName, aadId, aadName, aadAlias, aadUpn | limit 1;";
// TODO: Figure out how to make this async
using (var reader = client.ExecuteQuery(query))
{
if (reader.Read())
{
return new IdenreplacedyDetail(){
GithubUserName = reader.GetString(0),
AadId = reader.GetString(1),
Name = reader.GetString(2),
Alias = reader.GetString(3),
AadUpn = reader.GetString(4)
};
}
logger.LogWarning("Could Not Resolve Idenreplacedy of Name = {0}", aadName);
return default;
}
}
19
View Source File : LoginWith2fa.cshtml.cs
License : Apache License 2.0
Project Creator : aspnet
License : Apache License 2.0
Project Creator : aspnet
public async Task<IActionResult> OnPostAsync(bool rememberMe, string returnUrl = null)
{
if (!ModelState.IsValid)
{
return Page();
}
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
if (user == null)
{
throw new ApplicationException($"Unable to load two-factor authentication user.");
}
var authenticatorCode = Input.TwoFactorCode.Replace(" ", string.Empty).Replace("-", string.Empty);
var result = await _signInManager.TwoFactorAuthenticatorSignInAsync(authenticatorCode, rememberMe, Input.RememberMachine);
if (result.Succeeded)
{
_logger.LogInformation("User with ID '{UserId}' logged in with 2fa.", user.Id);
return LocalRedirect(Url.GetLocalUrl(returnUrl));
}
else if (result.IsLockedOut)
{
_logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
return RedirectToPage("./Lockout");
}
else
{
_logger.LogWarning("Invalid authenticator code entered for user with ID '{UserId}'.", user.Id);
ModelState.AddModelError(string.Empty, "Invalid authenticator code.");
return Page();
}
}
19
View Source File : NotificationConfigurator.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
private async Task EnsureScheduledBuildFailSubscriptionExists(BuildDefinition pipeline, WebApiTeam team, bool persistChanges)
{
const string BuildFailureNotificationTag = "#AutomaticBuildFailureNotification";
var subscriptions = await service.GetSubscriptionsAsync(team.Id);
var subscription = subscriptions.FirstOrDefault(sub => sub.Description.Contains(BuildFailureNotificationTag));
logger.LogInformation("Team Is Subscribed TeamName = {0} PipelineId = {1}", team.Name, pipeline.Id);
string definitionName = $"\\{pipeline.Project.Name}\\{pipeline.Name}";
if (subscription == default)
{
var filterModel = new ExpressionFilterModel
{
Clauses = new ExpressionFilterClause[]
{
new ExpressionFilterClause { Index = 1, LogicalOperator = "", FieldName = "Status", Operator = "=", Value = "Failed" },
new ExpressionFilterClause { Index = 2, LogicalOperator = "And", FieldName = "Definition name", Operator = "=", Value = definitionName },
new ExpressionFilterClause { Index = 3, LogicalOperator = "And", FieldName = "Build reason", Operator = "=", Value = "Scheduled" }
}
};
var filter = new ExpressionFilter("ms.vss-build.build-completed-event", filterModel);
var idenreplacedy = new IdenreplacedyRef
{
Id = team.Id.ToString(),
Url = team.IdenreplacedyUrl
};
var newSubscription = new NotificationSubscriptionCreateParameters
{
Channel = new UserSubscriptionChannel { UseCustomAddress = false },
Description = $"A build fails {BuildFailureNotificationTag}",
Filter = filter,
Scope = new SubscriptionScope { Type = "none", Id = pipeline.Project.Id },
Subscriber = idenreplacedy,
};
logger.LogInformation("Creating Subscription PipelineId = {0}, TeamId = {1}", pipeline.Id, team.Id);
if (persistChanges)
{
subscription = await service.CreateSubscriptionAsync(newSubscription);
}
}
else
{
var filter = subscription.Filter as ExpressionFilter;
if (filter == null)
{
logger.LogWarning("Subscription expression is not correct for of team {0}", team.Name);
return;
}
var definitionClause = filter.FilterModel.Clauses.FirstOrDefault(c => c.FieldName == "Definition name");
if (definitionClause == null)
{
logger.LogWarning("Subscription doesn't have correct expression filters for of team {0}", team.Name);
return;
}
if (definitionClause.Value != definitionName)
{
definitionClause.Value = definitionName;
if (persistChanges)
{
var updateParameters = new NotificationSubscriptionUpdateParameters()
{
Channel = subscription.Channel,
Description = subscription.Description,
Filter = subscription.Filter,
Scope = subscription.Scope,
};
logger.LogInformation("Updating Subscription expression for team {0} with correct definition name {1}", team.Name, definitionName);
subscription = await service.UpdatedSubscriptionAsync(updateParameters, subscription.Id.ToString());
}
}
}
}
19
View Source File : PluginStageComponentProvider.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public IEnumerable<IStageRunner> FindComponents(IRunnerConfiguration config)
{
_logger.LogInformation(InformationMessages.FindingStageRunners);
if (_options.FindPath != null && _options.FindPath.Any())
{
var stageRunnerreplacedemblies = new List<FileInfo>();
foreach (var path in _options.FindPath)
{
// Find plugin replacedembly locations
var replacedemblies = _pluginFinder.FindPluginreplacedemblies(path.FullName, _sharedTypes);
// Remove duplicates (based on filename, without path), if any
var distinctreplacedemblies = replacedemblies.Select(a => new FileInfo(a)).GroupBy(f => f.Name).Select(f => f.First());
if (distinctreplacedemblies.Any())
{
_logger.LogInformation(InformationMessages.replacedemblyCountInPath, distinctreplacedemblies.Count(), path.FullName);
foreach (var replacedembly in distinctreplacedemblies)
{
stageRunnerreplacedemblies.Add(replacedembly);
}
}
else
{
_logger.LogDebug(TraceMessages.StageRunnerreplacedembliesNotFoundInPath, path.FullName);
}
}
if (stageRunnerreplacedemblies.Count > 0)
{
// Load stage runners into separate plugin host
var distinctStageRunnerreplacedemblies = stageRunnerreplacedemblies.GroupBy(f => f.Name).Select(f => f.First().FullName);
_pluginHost.LoadPlugins(distinctStageRunnerreplacedemblies, _sharedTypes);
return _pluginHost.GetPlugins().Where(p => p is IStageRunner).Select(p => (IStageRunner)p);
}
else
{
_logger.LogWarning(WarningMessages.StageRunnerreplacedembliesNotFound);
}
}
return Enumerable.Empty<IStageRunner>();
}
19
View Source File : TemplateRendererConverter.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
protected override async Task ConvertInternalAsync(CancellationToken token)
{
// Ensure conversion path exists
var conversionPath = new DirectoryInfo(Context.ConversionFolder);
if (!_fileRepository.DoesDirectoryExist(conversionPath.FullName))
{
_logger.LogDebug(TraceMessages.CreatingConversionPath, conversionPath.FullName);
_fileRepository.CreateDirectory(conversionPath.FullName);
}
// Get template paths
var templatePaths = Context.TemplateFolders.Select(p => new DirectoryInfo(p));
if (templatePaths.Any())
{
// Render templates
var generatedFiles = 0;
var messageBus = Model.MigrationTarget.MessageBus;
if (messageBus != null)
{
// Message Bus
generatedFiles += await GenerateFilesAsync(messageBus, templatePaths, conversionPath).ConfigureAwait(false);
// Applications
if (messageBus.Applications.Any())
{
foreach (var application in messageBus.Applications)
{
generatedFiles += await GenerateFilesAsync(application, templatePaths, conversionPath).ConfigureAwait(false);
// Messages
if (application.Messages.Any())
{
foreach (var message in application.Messages)
{
generatedFiles += await GenerateFilesAsync(message, templatePaths, conversionPath).ConfigureAwait(false);
}
}
// Channels
if (application.Channels.Any())
{
foreach (var channel in application.Channels)
{
generatedFiles += await GenerateFilesAsync(channel, templatePaths, conversionPath).ConfigureAwait(false);
}
}
// Intermediaries
if (application.Intermediaries.Any())
{
foreach (var intermediary in application.Intermediaries)
{
generatedFiles += await GenerateFilesAsync(intermediary, templatePaths, conversionPath).ConfigureAwait(false);
}
}
// Endpoints
if (application.Endpoints.Any())
{
foreach (var endpoint in application.Endpoints)
{
generatedFiles += await GenerateFilesAsync(endpoint, templatePaths, conversionPath).ConfigureAwait(false);
}
}
}
}
}
if (generatedFiles == 0)
{
_logger.LogInformation(InformationMessages.NoResourceTemplatesToConvert);
}
else
{
_logger.LogInformation(InformationMessages.GeneratedResourceTemplateFiles, generatedFiles);
}
}
else
{
_logger.LogWarning(WarningMessages.NoTemplatePathsFound);
}
}
19
View Source File : MinimumAgeAuthorizationHandler.cs
License : Apache License 2.0
Project Creator : aspnet
License : Apache License 2.0
Project Creator : aspnet
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, MinimumAgeRequirement requirement)
{
// Log as a warning so that it's very clear in sample output which authorization policies
// (and requirements/handlers) are in use
_logger.LogWarning("Evaluating authorization requirement for age >= {age}", requirement.Age);
// Check the user's age
var dateOfBirthClaim = context.User.FindFirst(c => c.Type == ClaimTypes.DateOfBirth);
if (dateOfBirthClaim != null)
{
// If the user has a date of birth claim, check their age
var dateOfBirth = Convert.ToDateTime(dateOfBirthClaim.Value);
var age = DateTime.Now.Year - dateOfBirth.Year;
if (dateOfBirth > DateTime.Now.AddYears(-age))
{
// Adjust age if the user hasn't had a birthday yet this year
age--;
}
// If the user meets the age criterion, mark the authorization requirement succeeded
if (age >= requirement.Age)
{
_logger.LogInformation("Minimum age authorization requirement {age} satisfied", requirement.Age);
context.Succeed(requirement);
}
else
{
_logger.LogInformation("Current user's DateOfBirth claim ({dateOfBirth}) does not satisfy the minimum age authorization requirement {age}",
dateOfBirthClaim.Value,
requirement.Age);
}
}
else
{
_logger.LogInformation("No DateOfBirth claim present");
}
return Task.CompletedTask;
}
19
View Source File : LoginWithRecoveryCode.cshtml.cs
License : Apache License 2.0
Project Creator : aspnet
License : Apache License 2.0
Project Creator : aspnet
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
if (!ModelState.IsValid)
{
return Page();
}
var user = await _signInManager.GetTwoFactorAuthenticationUserAsync();
if (user == null)
{
throw new ApplicationException($"Unable to load two-factor authentication user.");
}
var recoveryCode = Input.RecoveryCode.Replace(" ", string.Empty);
var result = await _signInManager.TwoFactorRecoveryCodeSignInAsync(recoveryCode);
if (result.Succeeded)
{
_logger.LogInformation("User with ID '{UserId}' logged in with a recovery code.", user.Id);
return LocalRedirect(Url.GetLocalUrl(returnUrl));
}
if (result.IsLockedOut)
{
_logger.LogWarning("User with ID '{UserId}' account locked out.", user.Id);
return RedirectToPage("./Lockout");
}
else
{
_logger.LogWarning("Invalid recovery code entered for user with ID '{UserId}' ", user.Id);
ModelState.AddModelError(string.Empty, "Invalid recovery code entered.");
return Page();
}
}
19
View Source File : RazorProjectEndpoint.cs
License : Apache License 2.0
Project Creator : aspnet
License : Apache License 2.0
Project Creator : aspnet
public async Task<Unit> Handle(RazorUpdateProjectParams request, CancellationToken cancellationToken)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}
var handle = request.ProjectSnapshotHandle;
if (handle == null)
{
_logger.LogWarning("Could not update project information. This often happens after Razor LanguageServer releases when project formats change. Once project information has been recalculated by OmniSharp this warning should go away.");
return Unit.Value;
}
await Task.Factory.StartNew(
() => _projectService.UpdateProject(
handle.FilePath,
handle.Configuration,
handle.RootNamespace,
handle.ProjectWorkspaceState ?? ProjectWorkspaceState.Default,
handle.Doreplacedents ?? Array.Empty<DoreplacedentSnapshotHandle>()),
CancellationToken.None,
TaskCreationOptions.None,
_foregroundDispatcher.ForegroundScheduler);
return Unit.Value;
}
19
View Source File : ReceivePortParser.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
protected override void ParseInternal(AzureIntegrationServicesModel model, MigrationContext context)
{
var group = model.GetSourceModel<ParsedBizTalkApplicationGroup>();
if (group?.Applications == null)
{
_logger.LogDebug(TraceMessages.SkippingParserAsTheSourceModelIsMissing, nameof(ReceivePortParser));
}
else
{
_logger.LogDebug(TraceMessages.RunningParser, nameof(ReceivePortParser));
foreach (var application in group.Applications)
{
// Defensive check
if (application.Application.Bindings == null)
{
_logger.LogWarning(WarningMessages.BindingInfoNotFound, application.Application.Name);
continue;
}
if (application.Application.Bindings.BindingInfo.ReceivePortCollection != null)
{
_logger.LogDebug(TraceMessages.ParsingBizTalkReceivePortCollectionInApplication, application.Application.Name);
var bindingFileDefinition = model.FindResourceDefinitionByKey(application.Application.Bindings.ResourceDefinitionKey, ModelConstants.ResourceDefinitionBindings);
var applicationResource = model.FindResourceByKey(application.Application?.ApplicationDefinition?.ResourceKey);
foreach (var receivePort in application.Application.Bindings.BindingInfo.ReceivePortCollection)
{
_logger.LogDebug(TraceMessages.ParsingBizTalkReceivePort, receivePort.Name);
receivePort.ResourceKey = string.Concat(application.Application.Bindings.ResourceDefinitionKey, ":", receivePort.Name);
// Create the resource under the binding file.
var receivePortResource = new ResourceItem
{
Key = receivePort.ResourceKey,
Name = receivePort.Name,
Description = receivePort.Description,
Type = ModelConstants.ResourceReceivePort,
ParentRefId = bindingFileDefinition.RefId,
Rating = ConversionRating.NotSupported
};
receivePort.Resource = receivePortResource; // Maintain pointer to the resource.
receivePortResource.SourceObject = receivePort; // Maintain backward pointer.
bindingFileDefinition.Resources.Add(receivePortResource);
receivePortResource.Properties.Add(ResourceItemProperties.PortDirectionProperty, receivePort.IsTwoWay ? ResourceItemProperties.PortDirectionTwoWay : ResourceItemProperties.PortDirectionOneWay);
if (applicationResource != null)
{
applicationResource.AddRelationship(new ResourceRelationship(receivePortResource.RefId, ResourceRelationshipType.Child));
receivePortResource.AddRelationship(new ResourceRelationship(applicationResource.RefId, ResourceRelationshipType.Parent));
}
else
{
var error = string.Format(CultureInfo.CurrentCulture, ErrorMessages.UnableToFindResourceDefinition, ModelConstants.ResourceApplication, application.Application?.ApplicationDefinition?.ResourceKey);
_logger.LogError(error);
context.Errors.Add(new ErrorMessage(error));
}
if (receivePort.ReceiveLocations != null)
{
foreach (var receiveLocation in receivePort.ReceiveLocations)
{
_logger.LogDebug(TraceMessages.ParsingBizTalkReceiveLocationPipelineData, receiveLocation.Name);
// Extract the send pipeline custom config.
receiveLocation.SendPipelineCustomConfiguration = ParsePipelineData(application, receiveLocation.Name, receiveLocation.SendPipelineData, PipelineDirection.Send, context.Errors);
// Extract the receive pipeline custom config.
receiveLocation.ReceivePipelineCustomConfiguration = ParsePipelineData(application, receiveLocation.Name, receiveLocation.ReceivePipelineData, PipelineDirection.Receive, context.Errors);
receiveLocation.ResourceKey = string.Concat(receivePort.Name, ":", receiveLocation.Name);
// Create the resource item for the receive location.
var receiveLocationResource = new ResourceItem
{
Key = receiveLocation.ResourceKey,
Name = receiveLocation.Name,
Description = receiveLocation.Description,
Type = ModelConstants.ResourceReceiveLocation,
ParentRefId = receivePortResource.RefId,
Rating = ConversionRating.NotSupported
};
receiveLocation.Resource = receiveLocationResource; // Maintain pointer to the resource.
receiveLocationResource.SourceObject = receiveLocation; // Maintain backward pointer.
receiveLocationResource.Properties.Add(ResourceItemProperties.PortTransportTypeProperty, receiveLocation.ReceiveLocationTransportType.Name);
receiveLocationResource.Properties.Add(ResourceItemProperties.ReceiveLocationAddressProperty, receiveLocation.Address);
receivePortResource.Resources.Add(receiveLocationResource);
}
}
}
}
}
_logger.LogDebug(TraceMessages.CompletedParser, nameof(ReceivePortParser));
}
}
19
View Source File : EndToEndTraceHelper.cs
License : MIT License
Project Creator : Azure
License : MIT License
Project Creator : Azure
public void ExtensionWarningEvent(string hubName, string functionName, string instanceId, string message)
{
EtwEventSource.Instance.ExtensionWarningEvent(
hubName,
LocalAppName,
LocalSlotName,
functionName,
instanceId,
message,
ExtensionVersion);
this.logger.LogWarning(
"{details}. InstanceId: {instanceId}. Function: {functionName}. HubName: {hubName}. AppName: {appName}. SlotName: {slotName}. ExtensionVersion: {extensionVersion}. SequenceNumber: {sequenceNumber}.",
message, instanceId, functionName, hubName, LocalAppName, LocalSlotName, ExtensionVersion, this.sequenceNumber++);
}
See More Examples