-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from betalgo/dev
8.0.1 Update, introducing support for Azure Function.
- Loading branch information
Showing
12 changed files
with
255 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
LaserCatEyes.FunctionEndpointListener/FunctionEndpointListenerMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using LaserCatEyes.Domain; | ||
using LaserCatEyes.Domain.Models; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Middleware; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace LaserCatEyes.FunctionEndpointListener; | ||
|
||
public class FunctionEndpointListenerMiddleware : IFunctionsWorkerMiddleware | ||
{ | ||
private readonly bool _isServiceReady; | ||
private readonly ILaserCatEyesDataService? _laserCatEyesDataService; | ||
|
||
public FunctionEndpointListenerMiddleware(ILaserCatEyesDataService? laserCatEyesDataService, ILogger<FunctionEndpointListenerMiddleware> logger) | ||
{ | ||
if (laserCatEyesDataService == null) | ||
{ | ||
logger.LogWarning($"Couldn't bind {nameof(FunctionEndpointListenerMiddleware)} because {nameof(ILaserCatEyesDataService)} is null"); | ||
return; | ||
} | ||
|
||
if (!laserCatEyesDataService.IsServiceReady()) | ||
{ | ||
logger.LogWarning($"Couldn't bind {nameof(FunctionEndpointListenerMiddleware)} because {nameof(ILaserCatEyesDataService)} was not ready"); | ||
return; | ||
} | ||
|
||
_laserCatEyesDataService = laserCatEyesDataService; | ||
_isServiceReady = true; | ||
} | ||
|
||
|
||
public async Task Invoke(FunctionContext functionContext, FunctionExecutionDelegate next) | ||
{ | ||
var operationId = Guid.NewGuid(); | ||
|
||
try | ||
{ | ||
var context = await functionContext.GetHttpRequestDataAsync(); | ||
if (context == null || !_isServiceReady) | ||
{ | ||
await next(functionContext); | ||
return; | ||
} | ||
|
||
_laserCatEyesDataService!.Report(PackageData.CreateRequestPackage( | ||
operationId, context.Url.OriginalString, | ||
Utilities.HttpMethodStringToEnumConverter(context.Method), | ||
context.Headers?.SelectMany(r => r.Value.Select(value => new HeaderCouple(r.Key, value))).ToList(), | ||
await Utilities.ReadBodyStream(context.Body), | ||
DateTime.UtcNow, | ||
null, | ||
null | ||
)); | ||
|
||
await next(functionContext); | ||
} | ||
finally | ||
{ | ||
var response = functionContext.GetHttpResponseData(); | ||
await using var replacementResponseBody = new MemoryStream(); | ||
if (response != null) | ||
{ | ||
var originalPosition = response.Body.Position; | ||
response.Body.Position = 0; | ||
await response.Body.CopyToAsync(replacementResponseBody); | ||
response.Body.Position = originalPosition; | ||
} | ||
|
||
_laserCatEyesDataService!.Report(PackageData.CreateResponsePackage( | ||
operationId, | ||
(int?)response?.StatusCode, | ||
response?.Headers.SelectMany(r => r.Value.Select(value => new HeaderCouple(r.Key, value))).ToList(), | ||
await Utilities.ReadBodyStream(replacementResponseBody), | ||
DateTime.UtcNow)); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
LaserCatEyes.FunctionEndpointListener/LaserCatEyes.FunctionEndpointListener.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net8.0;net7.0;net6.0;</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<Copyright>Betalgo Up Ltd.</Copyright> | ||
<LangVersion>Latest</LangVersion> | ||
<PackageProjectUrl>https://portal.lasercateyes.com</PackageProjectUrl> | ||
<PackageIcon>LaserCatEyes_Logo.png</PackageIcon> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>8.0.1</Version> | ||
<Authors>Betalgo Up Ltd.</Authors> | ||
<Company>Betalgo Up Ltd.</Company> | ||
<Product>Laser Cat Eyes</Product> | ||
<Description> | ||
lasercateyes.com | ||
Laser Cat Eyes is an online debugging tool that can capture, inspect, monitor all HTTP/HTTPS traffic from your application. It contains a network function like diagnose network issues, etc. | ||
|
||
With Laser Cat Eyes all team members can remotely display in realtime all traffic smoothly that other members capture in their device. It allows team members to test and debug scripts right along with each other in realtime remotely. Laser Cat Eyes is a comprehensive helper to save time, to improve productivity with its easy to use layout, also it helps to play a lot with request and response. | ||
|
||
All internal traffics that we are sending and receiving between the web browser/client and the server is invisible, and this brings difficulty, stress. Determining where is the fault exactly is a time-consuming process, a small error can sometimes take hours to debug with different browsers, operating systems, and devices, bugs are inevitable. Laser Cat Eyes offers extensive features that make it easy to see what is happening, so you debug your application effectively, quickly diagnose, and fix problems. | ||
</Description> | ||
<RepositoryUrl>https://github.com/betalgo/LCE-DotNet-SDK</RepositoryUrl> | ||
<PackageTags>network, debugging</PackageTags> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Core" Version="1.17.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\LaserCatEyes.DataServiceSdk\LaserCatEyes.DataServiceSdk.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="LaserCatEyes_Logo.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="README.md"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
53 changes: 53 additions & 0 deletions
53
LaserCatEyes.FunctionEndpointListener/LaserCatEyesServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
| ||
using LaserCatEyes.DataServiceSdk; | ||
using LaserCatEyes.Domain; | ||
using LaserCatEyes.Domain.Models; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace LaserCatEyes.FunctionEndpointListener | ||
{ | ||
public static class LaserCatEyesServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddLaserCatEyesFunctionEndpointListener(this IServiceCollection services, Action<LaserCatEyesOptions> setupAction) | ||
{ | ||
services.TryAddSingleton<IConfigureOptions<LaserCatEyesOptions>>(new ConfigureNamedOptions<LaserCatEyesOptions>(setupAction.Method.Name, setupAction)); | ||
return AddLaserCatEyesFunctionEndpointListenerBase(services); | ||
} | ||
|
||
public static IServiceCollection AddLaserCatEyesFunctionEndpointListener(this IServiceCollection services) | ||
{ | ||
var configuration = services.BuildServiceProvider().GetRequiredService<IConfiguration>(); | ||
services.Configure<LaserCatEyesOptions>(configuration.GetSection(LaserCatEyesOptions.SettingKey)); | ||
|
||
if (configuration.GetSection(LaserCatEyesSystemOptions.SettingKey) != null) | ||
{ | ||
services.Configure<LaserCatEyesSystemOptions>(configuration.GetSection(LaserCatEyesSystemOptions.SettingKey)); | ||
} | ||
|
||
return AddLaserCatEyesFunctionEndpointListenerBase(services); | ||
} | ||
|
||
public static IServiceCollection AddLaserCatEyesFunctionEndpointListener(this IServiceCollection services, string appKey) | ||
{ | ||
services.TryAddSingleton(Options.Create(new LaserCatEyesOptions(appKey))); | ||
return AddLaserCatEyesFunctionEndpointListenerBase(services); | ||
} | ||
|
||
private static IServiceCollection AddLaserCatEyesFunctionEndpointListenerBase(IServiceCollection services) | ||
{ | ||
services.TryAddSingleton<ILaserCatEyesDataService, LaserCatEyesDataService>(); | ||
services.AddTransient<FunctionEndpointListenerMiddleware>(); | ||
return services; | ||
} | ||
|
||
public static IApplicationBuilder UseLaserCatEyesFunctionEndpointListenerMiddleware(this IApplicationBuilder services) | ||
{ | ||
services.UseMiddleware<FunctionEndpointListenerMiddleware>(); | ||
return services; | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# LaserCatEyes DotNet SDK - currently in BETA program | ||
![.NET](https://github.com/betalgo/LCE-DotNet-SDK/workflows/.NET/badge.svg?branch=master) | ||
|
||
[![LaserCatEyes.EndpointListener](https://img.shields.io/nuget/v/LaserCatEyes.EndpointListener?label=nuget.LaserCatEyes.EndpointListener)](https://www.nuget.org/packages/LaserCatEyes.EndpointListener/) | ||
|
||
[Laser Cat Eyes] is a network monitoring tool that helps mobile app developers diagnose issues between their apps and backend services. | ||
|
||
### Installation & Implementation of EnpointListener | ||
1. LaserCatEyes is available through [Nuget](https://www.nuget.org/packages/LaserCatEyes.FunctionEndpointListener/). | ||
First, [install NuGet](http:https://docs.nuget.org/docs/start-here/installing-nuget). Then, install [LaserCatEyes.EndpointListener](https://www.nuget.org/packages/LaserCatEyes.EndpointListener/) from the package manager console: | ||
``` | ||
PM> Install-Package LaserCatEyes.FunctionEndpointListener | ||
``` | ||
|
||
2. In ``Startup`` class ``Configure`` method inject middleware | ||
```csharp | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
... | ||
if (env.IsDevelopment())//This is a debugging tool, you don't want to run it in production, right!? | ||
{ | ||
... | ||
//Seriously don't run it in production environment | ||
app.UseLaserCatEyesFunctionEndpointListenerMiddleware(); | ||
} | ||
... | ||
} | ||
``` | ||
3. In ``Startup`` class ``ConfigureServices`` method inject add Endpoint Listener | ||
|
||
```csharp | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
... | ||
if (env.IsDevelopment())//This is a debugging tool, you don't want to run it in production, right!? | ||
{ | ||
... | ||
//Seriously don't run it in production environment | ||
services.AddLaserCatEyesFunctionEndpointListener(MY_APP_KEY_FROM_LASER_CAT_EYES_PORTAL); | ||
//OR (more option will be available soon) | ||
services.AddLaserCatEyesFunctionEndpointListener(option => | ||
{ | ||
option.AppKey = MY_APP_KEY_FROM_LASER_CAT_EYES_PORTAL; | ||
option.AspCoreEnvironment = "STAGE"; | ||
option.Version = "1.2.3.4"; | ||
option.BuildNumber = "1"; | ||
}); | ||
} | ||
... | ||
} | ||
``` | ||
|
||
[Laser-Cat-Eyes web portal]: <https://portal.lasercateyes.com> | ||
[Laser Cat Eyes]: <https://lasercateyes.com> | ||
|
||
## Author | ||
|
||
<img src="http:https://www.betalgo.com/img/logo-dark.png" width="10px"> Betalgo, [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters