diff --git a/Func/.gitignore b/Func/.gitignore deleted file mode 100644 index ff5b00c50..000000000 --- a/Func/.gitignore +++ /dev/null @@ -1,264 +0,0 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# Azure Functions localsettings file -local.settings.json - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -project.fragment.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -#*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc \ No newline at end of file diff --git a/Func/Convert.cs b/Func/Convert.cs index 8073671b4..a25f270fb 100644 --- a/Func/Convert.cs +++ b/Func/Convert.cs @@ -1,11 +1,7 @@ -using System.IO; -using System.Threading; -using System.Threading.Tasks; using ICSharpCode.CodeConverter.Web; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; using Newtonsoft.Json; @@ -16,36 +12,38 @@ public class Convert public const string DefaultRequest = @"{""code"":""Public Class VisualBasicClass\r\n\r\nEnd Class"",""requestedConversion"":""vbnet2cs""}"; public const string DefaultConversion = "\r\npublic partial class VisualBasicClass\r\n{\r\n\r\n}"; - private readonly ILoggerFactory _loggerFactory; + private readonly ILogger _logger; - public Convert(ILoggerFactory loggerFactory) + public Convert(ILogger logger) { - _loggerFactory = loggerFactory; + _logger = logger; } // // Sample data: {"code":"Public Class VisualBasicClass\r\n\r\nEnd Class","requestedConversion":"vbnet2cs"} // - [FunctionName("Convert")] -#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods - Name must be "Run" for this to work AFAIK - public async Task Run( - [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, - CancellationToken hostCancellationToken) + [Function("Convert")] +#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods + public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, #pragma warning restore VSTHRD200 // Use "Async" suffix for async methods + CancellationToken hostCancellationToken) { - var logger = _loggerFactory.CreateLogger(); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); if (0 == string.CompareOrdinal(requestBody, DefaultRequest)) { - logger.LogInformation("Short-circuiting for default conversion request"); + _logger.LogInformation("Short-circuiting for default conversion request"); return new OkObjectResult(new ConvertResponse(true, DefaultConversion, "")); } var data = JsonConvert.DeserializeObject(requestBody); + if (null == data) { + return new BadRequestResult(); + } + using var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(hostCancellationToken, req.HttpContext.RequestAborted); var response = await WebConverter.ConvertAsync(data, cancellationSource.Token); return new OkObjectResult(response); } -} \ No newline at end of file +} diff --git a/Func/Func.csproj b/Func/Func.csproj index e269fe062..1dbc5fbcf 100644 --- a/Func/Func.csproj +++ b/Func/Func.csproj @@ -1,20 +1,34 @@  - net6.0 + net8.0 v4 + Exe + enable + disable ICSharpCode.CodeConverter.Func ICSharpCode.CodeConverter.Func - <_FunctionsSkipCleanOutput>true - 1d2f0b91-7e29-4920-8a93-e52863d06c2e + <_FunctionsSkipCleanOutput>true + - + - - + + + + + + + + + + + + + @@ -23,9 +37,6 @@ - - - PreserveNewest @@ -35,4 +46,7 @@ Never - + + + + \ No newline at end of file diff --git a/Func/GlobalSuppressions.cs b/Func/GlobalSuppressions.cs deleted file mode 100644 index 6c38c3b03..000000000 --- a/Func/GlobalSuppressions.cs +++ /dev/null @@ -1,8 +0,0 @@ -// This file is used by Code Analysis to maintain SuppressMessage -// attributes that are applied to this project. -// Project-level suppressions either have no target or are given -// a specific target and scoped to a namespace, type, member, etc. - -using System.Diagnostics.CodeAnalysis; - -[assembly: SuppressMessage("Style", "IDE0161:Convert to file-scoped namespace", Justification = "", Scope = "namespace", Target = "~N:ICSharpCode.CodeConverter.Func")] diff --git a/Func/Program.cs b/Func/Program.cs new file mode 100644 index 000000000..c2df7fbe4 --- /dev/null +++ b/Func/Program.cs @@ -0,0 +1,14 @@ +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +var host = new HostBuilder() + .ConfigureFunctionsWebApplication() + .ConfigureServices(services => + { + services.AddApplicationInsightsTelemetryWorkerService(); + services.ConfigureFunctionsApplicationInsights(); + }) + .Build(); + +host.Run(); diff --git a/Func/Properties/launchSettings.json b/Func/Properties/launchSettings.json new file mode 100644 index 000000000..081f51ca8 --- /dev/null +++ b/Func/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "profiles": { + "Func": { + "commandName": "Project", + "commandLineArgs": "--port 7144", + "launchBrowser": false + } + } +} \ No newline at end of file diff --git a/Func/Properties/serviceDependencies.json b/Func/Properties/serviceDependencies.json index fcc92d112..df4dcc9d8 100644 --- a/Func/Properties/serviceDependencies.json +++ b/Func/Properties/serviceDependencies.json @@ -1,5 +1,8 @@ { "dependencies": { + "appInsights1": { + "type": "appInsights" + }, "storage1": { "type": "storage", "connectionId": "AzureWebJobsStorage" diff --git a/Func/Properties/serviceDependencies.local.json b/Func/Properties/serviceDependencies.local.json index 155d87e0d..b804a2893 100644 --- a/Func/Properties/serviceDependencies.local.json +++ b/Func/Properties/serviceDependencies.local.json @@ -1,5 +1,8 @@ { "dependencies": { + "appInsights1": { + "type": "appInsights.sdk" + }, "storage1": { "type": "storage.emulator", "connectionId": "AzureWebJobsStorage" diff --git a/Func/Startup.cs b/Func/Startup.cs deleted file mode 100644 index 6597a8fc2..000000000 --- a/Func/Startup.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.Azure.Functions.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -[assembly: FunctionsStartup(typeof(ICSharpCode.CodeConverter.Func.Startup))] - -namespace ICSharpCode.CodeConverter.Func -{ - public class Startup : FunctionsStartup - { - public override void Configure(IFunctionsHostBuilder builder) - { - //builder.Services.AddHttpClient(); - - //builder.Services.AddSingleton((s) => { - // return new MyService(); - //}); - - //builder.Services.AddSingleton(); - } - } -} \ No newline at end of file diff --git a/Func/Version.cs b/Func/Version.cs index fa7cda7da..5ec17bcc6 100644 --- a/Func/Version.cs +++ b/Func/Version.cs @@ -1,18 +1,23 @@ -using System.Threading.Tasks; using ICSharpCode.CodeConverter.Util; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Azure.WebJobs; -using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; namespace ICSharpCode.CodeConverter.Func; -public static class Version +public class Version { - [FunctionName("Version")] -#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods - Name must be "Run" for this to work AFAIK - public static async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req, ILogger log) => -#pragma warning restore VSTHRD200 // Use "Async" suffix for async methods - new OkObjectResult(CodeConverterVersion.GetVersion()); -} \ No newline at end of file + private readonly ILogger _logger; + + public Version(ILogger logger) + { + _logger = logger; + } + + [Function("Version")] + public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req) + { + return new OkObjectResult(CodeConverterVersion.GetVersion()); + } +} diff --git a/Func/host.json b/Func/host.json index beb2e4020..ee5cf5f83 100644 --- a/Func/host.json +++ b/Func/host.json @@ -5,7 +5,8 @@ "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" - } + }, + "enableLiveMetricsFilters": true } } } \ No newline at end of file diff --git a/Func/local.settings.json b/Func/local.settings.json index 852f6ce57..64a872fcd 100644 --- a/Func/local.settings.json +++ b/Func/local.settings.json @@ -1,10 +1,7 @@ -{ +{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", - "FUNCTIONS_WORKER_RUNTIME": "dotnet" - }, - "Host": { - "CORS": "*" + "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated" } } \ No newline at end of file diff --git a/Tests/CSharp/TriviaTests.cs b/Tests/CSharp/TriviaTests.cs index 4e91a3c62..6aa15dfa9 100644 --- a/Tests/CSharp/TriviaTests.cs +++ b/Tests/CSharp/TriviaTests.cs @@ -424,7 +424,7 @@ End Sub var conversionResult = await ProjectConversion.ConvertTextAsync(vbCode, options); var regex = new Regex(@"#error Cannot convert \w+ - see comment for details\s+ \/\* Cannot convert.*?\*\/", RegexOptions.Singleline); - Assert.Equal(1, conversionResult.Exceptions.Count); + Assert.Single(conversionResult.Exceptions); Assert.Matches(regex, conversionResult.ConvertedCode); } } \ No newline at end of file diff --git a/Tests/TestRunners/ConverterTestBase.cs b/Tests/TestRunners/ConverterTestBase.cs index cb67c6960..fbd3ce668 100644 --- a/Tests/TestRunners/ConverterTestBase.cs +++ b/Tests/TestRunners/ConverterTestBase.cs @@ -74,7 +74,7 @@ private static bool LineCanHaveCSharpComment(string l) .Skip(1).Select(afterPrefix => afterPrefix.Split('\n')[0].TrimEnd()).ToList(); var missingSourceLineNumbers = lineNumbersAdded.Except(convertedCommentLineNumbers); if (missingSourceLineNumbers.Any()) { - Assert.False(true, "Comments not converted from source lines: " + string.Join(", ", missingSourceLineNumbers) + GetSourceAndConverted(sourceWithComments, convertedCode)); + Assert.Fail("Comments not converted from source lines: " + string.Join(", ", missingSourceLineNumbers) + GetSourceAndConverted(sourceWithComments, convertedCode)); } OurAssert.Equal(string.Join(", ", lineNumbersAdded), string.Join(", ", convertedCommentLineNumbers), () => GetSourceAndConverted(sourceWithComments, convertedCode)); } @@ -107,8 +107,7 @@ public async Task TestConversionVisualBasicToCSharpAsync(string visualBasicCode, bool incompatibleWithAutomatedCommentTesting = false) { if (expectSurroundingBlock) expectedCsharpCode = SurroundWithBlock(expectedCsharpCode); - var conversionOptions = new TextConversionOptions(DefaultReferences.NetStandard2) - { + var conversionOptions = new TextConversionOptions(DefaultReferences.NetStandard2) { RootNamespaceOverride = _rootNamespace, ShowCompilationErrors = !expectSurroundingBlock }; @@ -163,8 +162,7 @@ private static void AssertConvertedCodeResultEquals(string convertedCodeFollowed private static void AssertCodeEqual(string originalSource, string expectedConversion, string actualConversion) { - OurAssert.EqualIgnoringNewlines(expectedConversion, actualConversion, () => - { + OurAssert.EqualIgnoringNewlines(expectedConversion, actualConversion, () => { StringBuilder sb = OurAssert.DescribeStringDiff(expectedConversion, actualConversion); sb.AppendLine(OurAssert.LineSplitter); sb.AppendLine("source:"); @@ -182,8 +180,7 @@ private static (IReadOnlyCollection Lines, IReadOnlyCollection L { var lines = Utils.HomogenizeEol(code).Split(new[] { Environment.NewLine }, StringSplitOptions.None); var lineNumbersAdded = new List(); - var newLines = lines.Select((line, i) => - { + var newLines = lines.Select((line, i) => { var lineNumber = i.ToString(); var potentialExistingComments = line.Split(new[] { singleLineCommentStart }, StringSplitOptions.None).Skip(1); if (potentialExistingComments.Count() == 1 || !lineCanHaveComment(line)) return line; @@ -207,8 +204,7 @@ public CSToVBWithoutSimplifierConversion() string ILanguageConversion.TargetLanguage => _baseConversion.TargetLanguage; - ConversionOptions ILanguageConversion.ConversionOptions - { + ConversionOptions ILanguageConversion.ConversionOptions { get => _baseConversion.ConversionOptions; set => _baseConversion.ConversionOptions = value; } diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 0ea2bd3a5..647e04d44 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -11,11 +11,16 @@ - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + runtime; build; native; contentfiles; analyzers; buildtransitive + all +