Skip to content

Commit 0fa8e5c

Browse files
authored
Merge pull request #417 from Qtoss-Alpha/master
SeleniumWebDriver
2 parents 8aa16ea + 1cfa6a8 commit 0fa8e5c

27 files changed

+644
-43
lines changed

src/Infrastructure/BotSharp.Abstraction/Browsing/IWebBrowser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ public interface IWebBrowser
2525
Task CloseBrowser(string contextId);
2626
Task CloseCurrentPage(string contextId);
2727
Task<BrowserActionResult> SendHttpRequest(string contextId, HttpRequestParams actionParams);
28-
Task<string> GetAttributeValue(MessageInfo message, ElementLocatingArgs location, BrowserActionResult result);
28+
Task<BrowserActionResult> GetAttributeValue(MessageInfo message, ElementLocatingArgs location);
2929
}

src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementActionArgs.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,29 @@ namespace BotSharp.Abstraction.Browsing.Models;
44

55
public class ElementActionArgs
66
{
7-
private BroswerActionEnum _action;
8-
public BroswerActionEnum Action => _action;
7+
public BroswerActionEnum Action { get; set; }
98

10-
private string _content;
11-
public string Content => _content;
9+
public string? Content { get; set; }
1210

13-
public ElementActionArgs(BroswerActionEnum action)
11+
public ElementPosition? Position { get; set; }
12+
13+
/// <summary>
14+
/// Required for deserialization
15+
/// </summary>
16+
public ElementActionArgs()
17+
{
18+
19+
}
20+
21+
public ElementActionArgs(BroswerActionEnum action, ElementPosition? position = null)
1422
{
15-
_action = action;
23+
Action = action;
24+
Position = position;
1625
}
1726

1827
public ElementActionArgs(BroswerActionEnum action, string content)
1928
{
20-
_action = action;
21-
_content = content;
29+
Action = action;
30+
Content = content;
2231
}
2332
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace BotSharp.Abstraction.Browsing.Models;
2+
3+
public class ElementPosition
4+
{
5+
public float X { get; set; } = default!;
6+
7+
public float Y { get; set; } = default!;
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Browsing.Settings;
2+
3+
public class WebBrowsingSettings
4+
{
5+
public string Driver { get; set; } = "Playwright";
6+
}

src/Infrastructure/BotSharp.Abstraction/Repositories/BotSharpDatabaseSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class BotSharpDatabaseSettings : DatabaseBasicSettings
77
public string BotSharpMongoDb { get; set; }
88
public string TablePrefix { get; set; }
99
public DbConnectionSetting BotSharp { get; set; }
10+
public string Redis { get; set; }
1011
}
1112

1213
public class DatabaseBasicSettings

src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@
149149
<ItemGroup>
150150
<PackageReference Include="Aspects.Cache" Version="2.0.4" />
151151
<PackageReference Include="Colorful.Console" Version="1.2.15" />
152-
<PackageReference Include="EntityFrameworkCore.BootKit" Version="6.3.1" />
153-
<PackageReference Include="Fluid.Core" Version="2.7.0" />
152+
<PackageReference Include="EntityFrameworkCore.BootKit" Version="8.2.1" />
153+
<PackageReference Include="Fluid.Core" Version="2.8.0" />
154154
<PackageReference Include="Nanoid" Version="3.0.0" />
155+
<PackageReference Include="RedLock.net" Version="2.3.2" />
155156
</ItemGroup>
156157

157158
<ItemGroup>

src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public static IServiceCollection AddBotSharpCore(this IServiceCollection service
1414
{
1515
services.AddScoped<ISettingService, SettingService>();
1616
services.AddScoped<IUserService, UserService>();
17+
services.AddSingleton<DistributedLocker>();
1718

1819
RegisterPlugins(services, config);
1920
ConfigureBotSharpOptions(services, configOptions);
21+
2022
return services;
2123
}
2224

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using RedLockNet;
2+
using RedLockNet.SERedis;
3+
using RedLockNet.SERedis.Configuration;
4+
using StackExchange.Redis;
5+
6+
namespace BotSharp.Core.Infrastructures;
7+
8+
public class DistributedLocker
9+
{
10+
private readonly BotSharpDatabaseSettings _settings;
11+
private readonly RedLockFactory _lockFactory;
12+
13+
public DistributedLocker(/*BotSharpDatabaseSettings settings*/)
14+
{
15+
// _settings = settings;
16+
17+
var multiplexers = new List<RedLockMultiplexer>();
18+
foreach (var x in "".Split(';'))
19+
{
20+
var option = new ConfigurationOptions
21+
{
22+
AbortOnConnectFail = false,
23+
EndPoints = { x }
24+
};
25+
var _connMuliplexer = ConnectionMultiplexer.Connect(option);
26+
multiplexers.Add(_connMuliplexer);
27+
}
28+
29+
_lockFactory = RedLockFactory.Create(multiplexers);
30+
}
31+
32+
public async Task Lock(string resource, Func<Task> action)
33+
{
34+
var expiry = TimeSpan.FromSeconds(60);
35+
var wait = TimeSpan.FromSeconds(30);
36+
var retry = TimeSpan.FromSeconds(3);
37+
38+
await using (var redLock = await _lockFactory.CreateLockAsync(resource, expiry, wait, retry))
39+
{
40+
if (redLock.IsAcquired)
41+
{
42+
await action();
43+
}
44+
else
45+
{
46+
Console.WriteLine($"Acquire locak failed due to {resource} after {wait}s timeout.");
47+
}
48+
}
49+
}
50+
}

src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BotSharp.Abstraction.Repositories;
21
using Microsoft.Data.SqlClient;
32
using MySqlConnector;
43
using System.Data.Common;

src/Plugins/BotSharp.Plugin.SqlDriver/BotSharp.Plugin.SqlDriver.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
@@ -33,7 +33,6 @@
3333
</ItemGroup>
3434

3535
<ItemGroup>
36-
<PackageReference Include="Dapper" Version="2.1.28" />
3736
<PackageReference Include="MySqlConnector" Version="2.3.5" />
3837
</ItemGroup>
3938

0 commit comments

Comments
 (0)