Skip to content

Commit

Permalink
Scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiusgreat committed Mar 26, 2024
1 parent 8d7d030 commit 4358331
Show file tree
Hide file tree
Showing 40 changed files with 211 additions and 1,862 deletions.
7 changes: 4 additions & 3 deletions Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Canvas.Views.Web" Version="1.8.1" />
<PackageReference Include="Estimator" Version="1.0.1" />
<PackageReference Include="MudBlazor" Version="6.12.0" />
<PackageReference Include="Canvas.Views.Web" Version="3.0.8" />
<PackageReference Include="Estimator" Version="1.0.2" />
<PackageReference Include="MudBlazor" Version="6.19.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Gateways\Alpaca\Libs\Alpaca.csproj" />
<ProjectReference Include="..\Gateways\Simulation\Libs\Simulation.csproj" />
</ItemGroup>

Expand Down
22 changes: 8 additions & 14 deletions Client/Components/BaseComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Distribution.Services;
using Microsoft.AspNetCore.Components;
using Schedule.Runners;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Client.Components
Expand All @@ -10,23 +11,16 @@ public class BaseComponent : ComponentBase
/// <summary>
/// Updater
/// </summary>
protected virtual TimeRunner Updater { get; set; } = new()
{
Count = 1,
Span = TimeSpan.FromMilliseconds(100)
};
protected virtual ScheduleService Updater { get; set; } = new ScheduleService();

/// <summary>
/// Render
/// </summary>
protected virtual Task Render(Action action)
protected virtual Task Render(Action action) => Updater.Send(() =>
{
return Updater.Send(() =>
{
action();
InvokeAsync(StateHasChanged);

}).Task;
}
action();
InvokeAsync(StateHasChanged);
Thread.Sleep(1);
}).Task;
}
}
20 changes: 3 additions & 17 deletions Client/Components/ChartsComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Client.Components
{
public partial class ChartsComponent : IDisposable, IAsyncDisposable
public partial class ChartsComponent : IDisposable
{
/// <summary>
/// Reference to view control
Expand Down Expand Up @@ -89,7 +89,7 @@ public virtual Task UpdateItems(IList<KeyValuePair<string, PointModel>> inputs,

var domain = new DomainModel
{
IndexDomain = new[] { Shapes.Count - (count ?? Shapes.Count), Shapes.Count }
IndexDomain = new int[] { Shapes.Count - (count ?? Shapes.Count), Shapes.Count }
};

return Render(() => View.Update(domain, Shapes));
Expand All @@ -108,20 +108,6 @@ public virtual void Clear()
/// <summary>
/// Dispose
/// </summary>
/// <returns></returns>
public virtual ValueTask DisposeAsync()
{
Dispose();

return new ValueTask(Task.CompletedTask);
}

/// <summary>
/// Dispose
/// </summary>
public virtual void Dispose()
{
View?.DisposeAsync();
}
public virtual void Dispose() => View?.Dispose();
}
}
65 changes: 45 additions & 20 deletions Client/Components/PageComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Configuration;
using Schedule.Runners;
using System;
using System.Linq;
using System.Threading.Tasks;
using Terminal.Core.Domains;
using Terminal.Core.Services;

namespace Client.Components
{
Expand All @@ -23,43 +22,69 @@ public partial class PageComponent
public virtual OrdersComponent OrdersView { get; set; }
public virtual PositionsComponent PositionsView { get; set; }
public virtual StatementsComponent StatementsView { get; set; }
public virtual IConnector Adapter { get; set; }
public virtual IGateway Adapter { get; set; }
public virtual Action Setup { get; set; }

public virtual async Task OnConnect()
{
OnDisconnect();
Setup();
try
{
OnDisconnect();
Setup();

IsConnection = true;
IsSubscription = true;
IsConnection = true;
IsSubscription = true;

await Adapter.Connect();
await Adapter.Connect();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

public virtual void OnDisconnect()
{
IsConnection = false;
IsSubscription = false;
try
{
Adapter?.Disconnect();

Adapter?.Disconnect();
ChartsView.Clear();
ReportsView.Clear();

ChartsView.Clear();
ReportsView.Clear();
IsConnection = false;
IsSubscription = false;
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

public virtual async Task OnSubscribe()
public virtual void OnSubscribe()
{
IsSubscription = true;

await Adapter.Subscribe();
try
{
IsSubscription = true;
Adapter.Account.Instruments.ForEach(o => Adapter.Subscribe(o.Key));
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

public virtual void OnUnsubscribe()
{
IsSubscription = false;

Adapter.Unsubscribe();
try
{
IsSubscription = false;
Adapter.Account.Instruments.ForEach(o => Adapter.Unsubscribe(o.Key));
}
catch (Exception e)
{
Console.WriteLine(e);
}
}

public virtual void OnOpenStatements()
Expand Down
Loading

0 comments on commit 4358331

Please sign in to comment.