Browse Source

Create a `RandomComputerId` to `CliAnalyticsCollectInputDto`.

pull/17559/head
maliming 3 years ago
parent
commit
ec4c682ad8
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 19
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs
  2. 1
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs
  3. 21
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollect.cs
  4. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollectInputDto.cs

19
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs

@ -90,6 +90,8 @@ public class AuthService : IAuthService, ITransientDependency
var accessToken = await AuthenticationService.GetAccessTokenAsync(configuration);
File.WriteAllText(CliPaths.AccessToken, accessToken, Encoding.UTF8);
await WriteRandomComputerIdAsync();
}
public async Task DeviceLoginAsync()
@ -105,6 +107,8 @@ public class AuthService : IAuthService, ITransientDependency
var accessToken = await AuthenticationService.GetAccessTokenAsync(configuration);
File.WriteAllText(CliPaths.AccessToken, accessToken, Encoding.UTF8);
await WriteRandomComputerIdAsync();
}
public async Task LogoutAsync()
@ -125,6 +129,8 @@ public class AuthService : IAuthService, ITransientDependency
File.Delete(CliPaths.Lic);
}
await WriteRandomComputerIdAsync();
}
public async Task<bool> CheckMultipleOrganizationsAsync(string username)
@ -177,4 +183,17 @@ public class AuthService : IAuthService, ITransientDependency
{
return File.Exists(CliPaths.AccessToken);
}
private async Task WriteRandomComputerIdAsync()
{
var loginInfo = await GetLoginInfoAsync();
if (loginInfo != null && loginInfo.Id.HasValue)
{
File.WriteAllText(CliPaths.RandomComputerId, loginInfo.Id.Value.ToString("D"), Encoding.UTF8);
}
else
{
File.WriteAllText(CliPaths.RandomComputerId, Guid.NewGuid().ToString("D"), Encoding.UTF8);
}
}
}

1
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs

@ -10,6 +10,7 @@ public static class CliPaths
public static string Log => Path.Combine(AbpRootPath, "cli", "logs");
public static string Root => Path.Combine(AbpRootPath, "cli");
public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin");
public static string RandomComputerId => Path.Combine(AbpRootPath, "cli", "random-computer-id.bin");
public static string Memory => Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!, "memory.bin");
public static string Build => Path.Combine(AbpRootPath, "build");
public static string Lic => Path.Combine(Path.GetTempPath(), Encoding.ASCII.GetString(new byte[] { 65, 98, 112, 76, 105, 99, 101, 110, 115, 101, 46, 98, 105, 110 }));

21
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollect.cs

@ -1,9 +1,11 @@
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Auth;
using Volo.Abp.Cli.Http;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http;
@ -19,22 +21,39 @@ public class CliAnalyticsCollect : ICliAnalyticsCollect, ITransientDependency
private readonly ILogger<CliAnalyticsCollect> _logger;
private readonly IRemoteServiceExceptionHandler _remoteServiceExceptionHandler;
private readonly CliHttpClientFactory _cliHttpClientFactory;
private readonly IAuthService _authService;
public CliAnalyticsCollect(
ICancellationTokenProvider cancellationTokenProvider,
IJsonSerializer jsonSerializer,
IRemoteServiceExceptionHandler remoteServiceExceptionHandler,
CliHttpClientFactory cliHttpClientFactory)
CliHttpClientFactory cliHttpClientFactory,
IAuthService authService)
{
_cancellationTokenProvider = cancellationTokenProvider;
_jsonSerializer = jsonSerializer;
_remoteServiceExceptionHandler = remoteServiceExceptionHandler;
_cliHttpClientFactory = cliHttpClientFactory;
_authService = authService;
_logger = NullLogger<CliAnalyticsCollect>.Instance;
}
public async Task CollectAsync(CliAnalyticsCollectInputDto input)
{
if (input.RandomComputerId.IsNullOrWhiteSpace())
{
if (!File.Exists(CliPaths.RandomComputerId))
{
var randomComputerId = Guid.NewGuid().ToString("D");
input.RandomComputerId = randomComputerId;
File.WriteAllText(CliPaths.RandomComputerId, randomComputerId, Encoding.UTF8);
}
else
{
input.RandomComputerId = File.ReadAllText(CliPaths.RandomComputerId, Encoding.UTF8);
}
}
var postData = _jsonSerializer.Serialize(input);
var url = $"{CliUrls.WwwAbpIo}api/clianalytics/collect";

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Analyticses/CliAnalyticsCollectInputDto.cs

@ -23,4 +23,6 @@ public class CliAnalyticsCollectInputDto
public string Language { get; set; }
public string Ip { get; set; }
public string RandomComputerId { get; set; }
}

Loading…
Cancel
Save