Skip to content

Commit

Permalink
Merge pull request #23 from betalgo/dev
Browse files Browse the repository at this point in the history
8.0.1 Update, introducing support for Azure Function.
  • Loading branch information
kayhantolga committed Apr 4, 2024
2 parents 8bd1973 + 367d2a1 commit 55ceddc
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageProjectUrl>https://portal.lasercateyes.com</PackageProjectUrl>
<PackageIcon>LaserCatEyes_Logo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>8.0.0</Version>
<Version>8.0.1</Version>
<Authors>Betalgo Up Ltd.</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>Laser Cat Eyes</Product>
Expand Down
3 changes: 2 additions & 1 deletion LaserCatEyes.DataServiceSdk/LaserCatEyesDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public LaserCatEyesDataService(IOptions<LaserCatEyesOptions> laserCatEyesOptions
return;
}

var deviceName = $"{Environment.MachineName}:{Environment.UserName}";
var websiteInstanceId = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
var deviceName = string.IsNullOrEmpty(websiteInstanceId) ? $"{Environment.MachineName}:{Environment.UserName}" : $"stateless:{Environment.UserName}";
_laserCatEyesOptions.DeviceUuid ??= Utilities.ToGuid(deviceName);

SubAppUpdate subApp = new()
Expand Down
2 changes: 1 addition & 1 deletion LaserCatEyes.Domain/LaserCatEyes.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageProjectUrl>https://portal.lasercateyes.com</PackageProjectUrl>
<PackageIcon>LaserCatEyes_Logo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>8.0.0</Version>
<Version>8.0.1</Version>
<Authors>Betalgo Up Ltd.</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>Laser Cat Eyes</Product>
Expand Down
14 changes: 9 additions & 5 deletions LaserCatEyes.DotNetSdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaserCatEyes.DataServiceSdk
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaserCatEyes.Domain", "LaserCatEyes.Domain\LaserCatEyes.Domain.csproj", "{97F1C3A7-028E-4A5A-8F4C-6357FF55444D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNetStandard", "DotNetStandard", "{35E9EDC4-69A4-4BC8-976A-7A3C817BAB41}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNetCore", "DotNetCore", "{ACE7AFE5-4429-49C6-A091-38BBE9C74411}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{ACE7AFE5-4429-49C6-A091-38BBE9C74411}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaserCatEyes.HttpClientListener", "LaserCatEyes.HttpClientListener\LaserCatEyes.HttpClientListener.csproj", "{5977C50D-83B2-4654-9EAF-385B0AC18E32}"
EndProject
Expand All @@ -37,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleNetServerApp", "Sampl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaserCatEyes.WCFListener", "LaserCatEyes.WCFListener\LaserCatEyes.WCFListener.csproj", "{35DB7BC6-2F9D-41D3-9F09-1CB3F34D1735}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaserCatEyes.FunctionEndpointListener", "LaserCatEyes.FunctionEndpointListener\LaserCatEyes.FunctionEndpointListener.csproj", "{F300FE2D-621D-4654-9592-42E115BC2B8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -71,6 +71,10 @@ Global
{35DB7BC6-2F9D-41D3-9F09-1CB3F34D1735}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35DB7BC6-2F9D-41D3-9F09-1CB3F34D1735}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35DB7BC6-2F9D-41D3-9F09-1CB3F34D1735}.Release|Any CPU.Build.0 = Release|Any CPU
{F300FE2D-621D-4654-9592-42E115BC2B8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F300FE2D-621D-4654-9592-42E115BC2B8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F300FE2D-621D-4654-9592-42E115BC2B8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F300FE2D-621D-4654-9592-42E115BC2B8F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -79,14 +83,14 @@ Global
{6953B012-1F16-4C86-AB74-23C4F5FC3ED1} = {ACE7AFE5-4429-49C6-A091-38BBE9C74411}
{F9A2B11A-1DA8-4C22-9F79-5E3D90ED6333} = {ACE7AFE5-4429-49C6-A091-38BBE9C74411}
{97F1C3A7-028E-4A5A-8F4C-6357FF55444D} = {E2B713C8-7C45-4632-8DB0-DC133E5CB6F0}
{35E9EDC4-69A4-4BC8-976A-7A3C817BAB41} = {E2B713C8-7C45-4632-8DB0-DC133E5CB6F0}
{ACE7AFE5-4429-49C6-A091-38BBE9C74411} = {E2B713C8-7C45-4632-8DB0-DC133E5CB6F0}
{5977C50D-83B2-4654-9EAF-385B0AC18E32} = {ACE7AFE5-4429-49C6-A091-38BBE9C74411}
{FCEE9B6D-C73A-41EB-9293-1B32E919E45A} = {2AB160A4-6D9A-43DE-B2D5-E4096B0443D2}
{68BACA33-4244-4F4E-B03B-55084CED5461} = {2AB160A4-6D9A-43DE-B2D5-E4096B0443D2}
{7E774EBE-B681-430A-AC2A-2F28474E08F3} = {5E92817F-20C0-4D02-8698-D9F7FBA95FAC}
{6678D16F-3AA0-4F56-92AB-01D86F6E24D6} = {5E92817F-20C0-4D02-8698-D9F7FBA95FAC}
{35DB7BC6-2F9D-41D3-9F09-1CB3F34D1735} = {35E9EDC4-69A4-4BC8-976A-7A3C817BAB41}
{35DB7BC6-2F9D-41D3-9F09-1CB3F34D1735} = {ACE7AFE5-4429-49C6-A091-38BBE9C74411}
{F300FE2D-621D-4654-9592-42E115BC2B8F} = {ACE7AFE5-4429-49C6-A091-38BBE9C74411}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A80951DD-7E4D-4D23-BB6F-89B70EA6172C}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;</TargetFrameworks>
<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.0</Version>
<Version>8.0.1</Version>
<Authors>Betalgo Up Ltd.</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>Laser Cat Eyes</Product>
Expand Down Expand Up @@ -36,6 +36,11 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Features" Version="8.0.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Features" Version="7.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
Expand Down
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));
}
}
}
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>
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.
58 changes: 58 additions & 0 deletions LaserCatEyes.FunctionEndpointListener/README.md
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]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageProjectUrl>https://portal.lasercateyes.com</PackageProjectUrl>
<PackageIcon>LaserCatEyes_Logo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>8.0.0</Version>
<Version>8.0.1</Version>
<Authors>Betalgo Up Ltd.</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>Laser Cat Eyes</Product>
Expand Down
2 changes: 1 addition & 1 deletion LaserCatEyes.WCFListener/LaserCatEyes.WCFListener.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageProjectUrl>https://portal.lasercateyes.com</PackageProjectUrl>
<PackageIcon>LaserCatEyes_Logo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>8.0.0</Version>
<Version>8.0.1</Version>
<Authors>Betalgo Up Ltd.</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>Laser Cat Eyes</Product>
Expand Down

0 comments on commit 55ceddc

Please sign in to comment.