Skip to content

Commit

Permalink
Update Readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
gregyjames committed Jan 23, 2024
1 parent d63c9ca commit a55b959
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,45 @@ dotnet add package OctaneEngineCore
# Usage
```csharp
private const string Url = "https://plugins.jetbrains.com/files/7973/281233/sonarlint-intellij-7.4.0.60471.zip?updateId=281233&pluginId=7973&family=INTELLIJ";
private static void Main()
{
//Logging Setup
var seriLog = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Verbose()
.WriteTo.File("./OctaneLog.txt")
.WriteTo.Console(theme: AnsiConsoleTheme.Sixteen)
.CreateLogger();
var factory = LoggerFactory.Create(logging => {
logging.AddSerilog(seriLog);
});

//JSON Config Loading
var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true);
var configRoot = builder.Build();
var config = new OctaneConfiguration(configRoot, factory);

//Find Optimal number of parts
var optimalNumberOfParts = Engine.GetOptimalNumberOfParts(Url).Result;
seriLog.Information("Optimal number of parts to download file: {OptimalNumberOfParts}", optimalNumberOfParts);

seriLog.Information("Speed: {Result}", NetworkAnalyzer.GetCurrentNetworkSpeed().Result);
seriLog.Information("Latency: {Result}", NetworkAnalyzer.GetCurrentNetworkLatency().Result);

private static void Main(){
#region Logging Configuration
var seriLog = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Error()
.WriteTo.Async(a => a.File("./OctaneLog.txt"))
.WriteTo.Async(a => a.Console(theme: AnsiConsoleTheme.Sixteen))
.CreateLogger();
var factory = LoggerFactory.Create(logging =>
{
logging.AddSerilog(seriLog);
});
#endregion

#region Configuration Loading
var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true);
var configRoot = builder.Build();
#endregion

#region Find and Set optimal number of parts
//var optimalNumberOfParts = Engine.GetOptimalNumberOfParts(Url).Result;
//seriLog.Information("Optimal number of parts to download file: {OptimalNumberOfParts}", optimalNumberOfParts);
//seriLog.Information("Speed: {Result}", NetworkAnalyzer.GetCurrentNetworkSpeed().Result);
//seriLog.Information("Latency: {Result}", NetworkAnalyzer.GetCurrentNetworkLatency().Result);
#endregion

var pauseTokenSource = new PauseTokenSource();
var cancelTokenSource = new CancellationTokenSource();

var octaneEngine = new Engine(factory, config);
octaneEngine.DownloadFile(Url, null, pauseTokenSource, cancelTokenSource).Wait(cancelTokenSource.Token);
using var cancelTokenSource = new CancellationTokenSource();
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterInstance(factory).As<ILoggerFactory>();
containerBuilder.RegisterInstance(configRoot).As<IConfiguration>();
containerBuilder.AddOctane();
var engineContainer = containerBuilder.Build();
var engine = engineContainer.Resolve<IEngine>();
engine.DownloadFile(Url, null, pauseTokenSource, cancelTokenSource).Wait();
}

```

Expand Down

0 comments on commit a55b959

Please sign in to comment.