Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
Fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Sampson committed Jan 10, 2017
1 parent df6cc8e commit be21028
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 59 deletions.
4 changes: 4 additions & 0 deletions RemoteTaskServer/Api/Network/UlteriusAgentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ public void Start(bool keepAlive = true)

private void KeepAlive()
{
//let this sleep after launch so we dont get spammed
Thread.Sleep(10000);
while (true)
{


var alive = ChannelActive();
if (!alive)
{
Expand Down
16 changes: 8 additions & 8 deletions RemoteTaskServer/Api/Services/LocalSystem/SystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ public List<DriveInformation> GetDriveInformation()
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
// Console.WriteLine(ex.Message);
//Console.WriteLine(ex.StackTrace);
}

try
Expand Down Expand Up @@ -501,14 +501,14 @@ public List<DriveInformation> GetDriveInformation()
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
// Console.WriteLine(ex.Message);
//Console.WriteLine(ex.StackTrace);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
// Console.WriteLine(ex.Message);
// Console.WriteLine(ex.StackTrace);
}
}

Expand Down Expand Up @@ -559,8 +559,8 @@ public List<DriveInformation> GetDriveInformation()
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
// Console.WriteLine(ex.Message);
// Console.WriteLine(ex.StackTrace);
}
}
return driveList;
Expand Down
8 changes: 8 additions & 0 deletions RemoteTaskServer/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura>
<ExcludeAssemblies>
AgentInterface
OpenHardwareMonitorLib
InputManager
</ExcludeAssemblies>
</Costura>

</Weavers>
27 changes: 14 additions & 13 deletions RemoteTaskServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#region

using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime;
using Topshelf;
using UlteriusServer.Forms.Utilities;
Expand All @@ -22,32 +23,33 @@ internal class Program
private static void Main(string[] args)

{

try
{
if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1) return;
if (
Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location))
.Count() > 1) return;

ProfileOptimization.SetProfileRoot(AppEnvironment.DataPath);
ProfileOptimization.StartProfile("Startup.Profile");

if (args.Length > 0)
{

HostFactory.Run(x => //1
{
x.Service<UlteriusAgent>(s => //2
{
s.ConstructUsing(name => new UlteriusAgent()); //3
s.WhenStarted(tc => tc.Start()); //4
s.WhenStopped(tc => tc.Stop());
s.WhenStarted(tc => tc.Start()); //4
s.WhenStopped(tc => tc.Stop());
s.WhenSessionChanged((se, e, id) => { se.HandleEvent(e, id); }); //5
});
});
x.RunAsLocalSystem(); //6
x.EnableSessionChanged();
x.EnableSessionChanged();
x.EnableServiceRecovery(r => { r.RestartService(1); });
x.SetDescription("The server that powers Ulterius"); //7
x.SetDisplayName("Ulterius Server"); //8
x.SetServiceName("UlteriusServer"); //9
});
x.SetDisplayName("Ulterius Server"); //8
x.SetServiceName("UlteriusServer"); //9
});
}
else
{
Expand All @@ -65,9 +67,8 @@ private static void Main(string[] args)
}
}
}
catch
catch
{

Console.WriteLine("Something unexpected occured");
}
}
Expand Down
22 changes: 22 additions & 0 deletions RemoteTaskServer/UlteriusServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.2-beta1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -340,6 +356,10 @@
<HintPath>..\packages\vtortola.WebSocketListener.2.2.2.0\lib\net45\vtortola.WebSockets.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="vtortola.WebSockets.Deflate, Version=2.2.2.0, Culture=neutral, PublicKeyToken=7f78616efb4a208d, processorArchitecture=MSIL">
<HintPath>..\packages\vtortola.WebSocketListener.2.2.2.0\lib\net45\vtortola.WebSockets.Deflate.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="vtortola.WebSockets.Rfc6455, Version=2.2.2.0, Culture=neutral, PublicKeyToken=7f78616efb4a208d, processorArchitecture=MSIL">
<HintPath>..\packages\vtortola.WebSocketListener.2.2.2.0\lib\net45\vtortola.WebSockets.Rfc6455.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -374,6 +394,7 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.0-rc2\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.0.0-rc2\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\packages\Fody.1.28.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.1.28.3\build\Fody.targets'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>
Expand Down Expand Up @@ -428,6 +449,7 @@ foreach (var item in filesToCleanup)
<Target Name="CleanReferenceCopyLocalPaths" AfterTargets="AfterBuild;NonWinFodyTarget">
<CosturaCleanup Config="FodyWeavers.xml" Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
</Target>
<Import Project="..\packages\Fody.1.28.3\build\Fody.targets" Condition="Exists('..\packages\Fody.1.28.3\build\Fody.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
65 changes: 48 additions & 17 deletions RemoteTaskServer/Utilities/ExceptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,69 @@ private static void WriteLogs(string type, string information)
[HandleProcessCorruptedStateExceptions]
private static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var method = MethodBase.GetCurrentMethod();
var type = method.Name;
var information = JsonConvert.SerializeObject(e.Exception, Formatting.Indented);
WriteLogs(type, information);
try
{

var type = "DispatcherUnhandledException";
var information = JsonConvert.SerializeObject(e.Exception, Formatting.Indented);
WriteLogs(type, information);
}
catch (Exception)
{


}
}

[HandleProcessCorruptedStateExceptions]
private static void ThreadException(object sender, ThreadExceptionEventArgs e)
{
var method = MethodBase.GetCurrentMethod();
var type = method.Name;
var information = JsonConvert.SerializeObject(e.Exception, Formatting.Indented);
WriteLogs(type, information);
try
{

var type = "ThreadException";
var information = JsonConvert.SerializeObject(e.Exception, Formatting.Indented);
WriteLogs(type, information);
}
catch (Exception)
{


}
}

[HandleProcessCorruptedStateExceptions]
private static void UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
var method = MethodBase.GetCurrentMethod();
var type = method.Name;
var information = JsonConvert.SerializeObject(e.Exception, Formatting.Indented);
WriteLogs(type, information);
try
{
var type = "UnobservedTaskException";
var information = JsonConvert.SerializeObject(e.Exception, Formatting.Indented);
WriteLogs(type, information);
}
catch (Exception)
{


}
}

[HandleProcessCorruptedStateExceptions]
private static void UnhandledException(object sender, UnhandledExceptionEventArgs args)
{
var e = (Exception) args.ExceptionObject;
var method = MethodBase.GetCurrentMethod();
var type = method.Name;
var information = JsonConvert.SerializeObject(e, Formatting.Indented);
WriteLogs(type, information);
try
{
var e = (Exception)args.ExceptionObject;

var type = "UnhandledException";
var information = JsonConvert.SerializeObject(e, Formatting.Indented);
WriteLogs(type, information);
}
catch (Exception)
{


}
}

/// <summary>
Expand Down
6 changes: 1 addition & 5 deletions RemoteTaskServer/Utilities/Settings/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using UlteriusServer.WebServer;

Expand Down Expand Up @@ -52,11 +50,9 @@ public static Config Load()
}
}



private static void GenerateDefault()
{

var fileName = "Config.json";
var filePath = Path.Combine(AppEnvironment.DataPath, fileName);
File.WriteAllText(filePath, JsonConvert.SerializeObject(new Config(), Formatting.Indented));
Expand All @@ -72,7 +68,6 @@ public static object GetRaw()
}
}



internal class General
{
Expand Down Expand Up @@ -122,6 +117,7 @@ internal class Terminal
internal class Webcams
{
public bool UseWebcams { get; set; } = true;
public bool UseMotionDetection { get; set; } = false;
public int WebcamPort { get; set; } = 22010;
}

Expand Down
19 changes: 5 additions & 14 deletions RemoteTaskServer/Utilities/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,19 @@ public static void RestartAgent()
{
Console.WriteLine(ex.Message);
}
try
{
managerProcess?.Kill();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Thread.Sleep(3000);
ProcessStarter.PROCESS_INFORMATION agentInfo;
ProcessStarter.PROCESS_INFORMATION managerInfo;
var managerPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"DaemonManager.exe");


var agentPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"UlteriusAgent.exe");

ProcessStarter.StartProcessAndBypassUAC(managerPath,
out managerInfo);


ProcessStarter.StartProcessAndBypassUAC(agentPath,
out agentInfo);
managerProcess = Process.GetProcessById((int)managerInfo.dwProcessId);

agentProcess = Process.GetProcessById((int)agentInfo.dwProcessId);
if (agentProcess != null)
{
Expand Down
11 changes: 9 additions & 2 deletions RemoteTaskServer/WebCams/WebCamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Vision.Motion;
using UlteriusServer.Api;
using UlteriusServer.Utilities.Settings;

#endregion

Expand All @@ -18,14 +20,16 @@ namespace UlteriusServer.WebCams
public class WebCamManager
{
private static MotionDetector detector;


private static bool UseMotionDetection;

public static ConcurrentDictionary<string, byte[]> CameraFrames { get; set; }

public static ConcurrentDictionary<string, Camera> Cameras { get; set; }

public static void LoadCameras()
{
UseMotionDetection = Config.Load().Webcams.UseMotionDetection;
BlobCountingObjectsProcessing motionProcessor = new BlobCountingObjectsProcessing();

detector = new MotionDetector(
Expand Down Expand Up @@ -124,7 +128,10 @@ private static void HandleFrame(object sender, NewFrameEventArgs camera, string
}
else
{
detector.ProcessFrame(camera.Frame);
if (UseMotionDetection)
{
detector.ProcessFrame(camera.Frame);
}
CameraFrames[cameraId] = ImageToByte2(camera.Frame);

}
Expand Down
3 changes: 3 additions & 0 deletions RemoteTaskServer/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
<package id="AForge.Video.DirectShow" version="2.2.5" targetFramework="net461" />
<package id="AForge.Vision" version="2.2.5" targetFramework="net461" />
<package id="BouncyCastle" version="1.8.1" targetFramework="net461" />
<package id="Costura.Fody" version="1.3.3.0" targetFramework="net461" developmentDependency="true" />
<package id="DotNetZip" version="1.10.1" targetFramework="net461" />
<package id="Fody" version="1.28.3" targetFramework="net461" developmentDependency="true" />
<package id="JonSkeet.MiscUtil" version="0.1" targetFramework="net45" />
<package id="log4net" version="2.0.7" targetFramework="net461" />
<package id="Magnum" version="2.1.3" targetFramework="net461" />
<package id="MassTransit" version="2.9.0" targetFramework="net461" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.3" targetFramework="net461" />
<package id="Microsoft.Net.Compilers" version="2.0.0-rc2" targetFramework="net461" developmentDependency="true" />
<package id="Microsoft.Tpl.Dataflow" version="4.5.24" targetFramework="net461" />
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.2-beta1" targetFramework="net461" />
<package id="Open.NAT" version="2.1.0.0" targetFramework="net461" />
<package id="System.Threading.Tasks.Dataflow" version="4.7.0" targetFramework="net461" />
Expand Down

0 comments on commit be21028

Please sign in to comment.