Skip to content

Commit

Permalink
Merge pull request #17559 from abpframework/RandomComputerId
Browse files Browse the repository at this point in the history
Add `RandomComputerId` to `CliAnalyticsCollectInputDto`.
  • Loading branch information
EngincanV authored Sep 5, 2023
2 parents dc20070 + df8a43a commit f4140ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public async Task LoginAsync(string userName, string password, string organizati
var accessToken = await AuthenticationService.GetAccessTokenAsync(configuration);

File.WriteAllText(CliPaths.AccessToken, accessToken, Encoding.UTF8);

await WriteRandomComputerIdAsync();
}

public async Task DeviceLoginAsync()
Expand All @@ -105,6 +107,8 @@ public async Task DeviceLoginAsync()
var accessToken = await AuthenticationService.GetAccessTokenAsync(configuration);

File.WriteAllText(CliPaths.AccessToken, accessToken, Encoding.UTF8);

await WriteRandomComputerIdAsync();
}

public async Task LogoutAsync()
Expand All @@ -125,6 +129,8 @@ public async Task LogoutAsync()

File.Delete(CliPaths.Lic);
}

await WriteRandomComputerIdAsync();
}

public async Task<bool> CheckMultipleOrganizationsAsync(string username)
Expand Down Expand Up @@ -177,4 +183,17 @@ public static bool IsLoggedIn()
{
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 change: 1 addition & 0 deletions framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/CliPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,6 +37,20 @@ public CliAnalyticsCollect(

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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public class CliAnalyticsCollectInputDto
public string Language { get; set; }

public string Ip { get; set; }

public string RandomComputerId { get; set; }
}

0 comments on commit f4140ae

Please sign in to comment.