Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8 #368

Merged
merged 4 commits into from
Jun 14, 2024
Merged

V8 #368

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Ghosts.Client/Ghosts.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@
<Compile Include="Comms\ClientSocket\BackgroundTaskQueue.cs" />
<Compile Include="Comms\ClientSocket\ClientSocketConnection.cs" />
<Compile Include="Comms\ClientSocket\QueueEntry.cs" />
<Compile Include="Handlers\AwsCli.cs" />
<Compile Include="Handlers\Aws.cs" />
<Compile Include="Handlers\Azure.cs" />
<Compile Include="Handlers\BaseBrowserHandler.cs" />
<Compile Include="Handlers\BlogHelper.cs" />
<Compile Include="Handlers\BlogHelperDrupal.cs" />
Expand Down Expand Up @@ -272,6 +273,9 @@
<None Include="kill-ghosts.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Sample Timelines\Aws.json" />
<None Include="Sample Timelines\Browser Crawl.json" />
<None Include="Sample Timelines\Browser upload.json" />
<None Include="Sample Timelines\BrowserFirefoxSocial.json" />
<None Include="Sample Timelines\Cron.json" />
<None Include="Sample Timelines\Administrative Commands.json" />
Expand All @@ -293,6 +297,7 @@
<Compile Include="TimelineManager\Orchestrator.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Sample Timelines\NpcSystem.json" />
<None Include="Sample Timelines\outlook.json" />
<None Include="Sample Timelines\Outlookv2.json" />
<None Include="Sample Timelines\Pidgin.json" />
Expand Down
116 changes: 116 additions & 0 deletions src/Ghosts.Client/Handlers/Aws.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.

using System;
using System.Diagnostics;
using System.Threading;
using Ghosts.Domain;
using Ghosts.Domain.Code;
using Ghosts.Domain.Code.Helpers;

namespace Ghosts.Client.Handlers
{
public class Aws : BaseHandler
{
private string Result { get; set; }
private readonly TimelineHandler _handler;

public Aws(TimelineHandler handler)
{
_handler = handler;

try
{
if (_handler.Loop)
{
while (true)
{
Ex();
}
}

Ex();
}
catch (Exception e)
{
Log.Error(e);
}
}

private void Ex()
{
var handlerArgs = BuildHandlerArgVariables.BuildHandlerArgs(_handler);
foreach (var timelineEvent in _handler.TimeLineEvents)
{
WorkingHours.Is(_handler);

if (timelineEvent.DelayBeforeActual > 0)
Thread.Sleep(timelineEvent.DelayBeforeActual);

switch (timelineEvent.Command)
{
default:
foreach (var cmdObj in timelineEvent.CommandArgs)
{
var cmd = cmdObj?.ToString();
if (!string.IsNullOrEmpty(cmd))
{
cmd = BuildHandlerArgVariables.ReplaceCommandVariables(cmd, handlerArgs);
this.Command(cmd);
}
}

break;
}
if (timelineEvent.DelayAfterActual <= 0) continue;
Thread.Sleep(timelineEvent.DelayAfterActual);
}
}

private void Command(string command)
{
this.Result = string.Empty;

command = $"{command} --no-verify";

try
{
var p = new Process
{
EnableRaisingEvents = false,
StartInfo =
{
FileName = "aws",
Arguments = command,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
p.Start();

while (!p.StandardOutput.EndOfStream)
{
this.Result += p.StandardOutput.ReadToEnd();
}

var err = string.Empty;
while (!p.StandardError.EndOfStream)
{
err += p.StandardError.ReadToEnd();
}
err = err.RemoveTextBetweenMarkers("urllib3/connectionpool", "#ssl-warnings");
if (err.Length > 0)
{
Log.Error($"{err} on {command}");
}

Report(new ReportItem {Handler = HandlerType.Aws.ToString(), Command = command, Result = this.Result});
}
catch (Exception exc)
{
Log.Debug(exc);
}
}
}
}
111 changes: 0 additions & 111 deletions src/Ghosts.Client/Handlers/AwsCli.cs

This file was deleted.

112 changes: 112 additions & 0 deletions src/Ghosts.Client/Handlers/Azure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.

using System;
using System.Diagnostics;
using System.Threading;
using Ghosts.Domain;
using Ghosts.Domain.Code;

namespace Ghosts.Client.Handlers
{
public class Azure : BaseHandler
{
private string Result { get; set; }
private readonly TimelineHandler _handler;

public Azure(TimelineHandler handler)
{
_handler = handler;

try
{
if (_handler.Loop)
{
while (true)
{
Ex();
}
}

Ex();
}
catch (Exception e)
{
Log.Error(e);
}
}

private void Ex()
{
var handlerArgs = BuildHandlerArgVariables.BuildHandlerArgs(_handler);
foreach (var timelineEvent in _handler.TimeLineEvents)
{
WorkingHours.Is(_handler);

if (timelineEvent.DelayBeforeActual > 0)
Thread.Sleep(timelineEvent.DelayBeforeActual);

switch (timelineEvent.Command)
{
default:
foreach (var cmdObj in timelineEvent.CommandArgs)
{
var cmd = cmdObj?.ToString();
if (!string.IsNullOrEmpty(cmd))
{
cmd = BuildHandlerArgVariables.ReplaceCommandVariables(cmd, handlerArgs);
this.Command(cmd);
}
}

break;
}
if (timelineEvent.DelayAfterActual <= 0) continue;
Thread.Sleep(timelineEvent.DelayAfterActual);
}
}

private void Command(string command)
{
this.Result = string.Empty;

try
{
var p = new Process
{
EnableRaisingEvents = false,
StartInfo =
{
FileName = "az",
Arguments = command,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
p.Start();

while (!p.StandardOutput.EndOfStream)
{
this.Result += p.StandardOutput.ReadToEnd();
}

var err = string.Empty;
while (!p.StandardError.EndOfStream)
{
err += p.StandardError.ReadToEnd();
}
if (err.Length > 0)
{
Log.Error($"{err} on {command}");
}

Report(new ReportItem {Handler = HandlerType.Azure.ToString(), Command = command, Result = this.Result});
}
catch (Exception exc)
{
Log.Debug(exc);
}
}
}
}
3 changes: 1 addition & 2 deletions src/Ghosts.Client/Health/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Ghosts.Client.Infrastructure;
using Ghosts.Domain;
using Ghosts.Domain.Code;
using Newtonsoft.Json;
Expand All @@ -29,7 +28,7 @@ public Check()
public void Run()
{
// now watch that file for changes
_watcher = new FileSystemWatcher(ApplicationDetails.ConfigurationFiles.Path);
_watcher = new FileSystemWatcher(ApplicationDetails.ConfigurationFiles.InstallPath);
_watcher.Filter = Path.GetFileName(ApplicationDetails.ConfigurationFiles.Health);
_log.Trace($"watching {_watcher.Path}");
_watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.FileName | NotifyFilters.Size;
Expand Down
2 changes: 1 addition & 1 deletion src/Ghosts.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("8.0.0.0")]
[assembly: AssemblyInformationalVersion("8.0.0.0")]
[assembly: AssemblyFileVersion("8.0.51.50")]
[assembly: AssemblyFileVersion("8.1.0.0")]
Loading
Loading