Skip to content

Commit 5a6f16b

Browse files
committed
Add v2 core code
1 parent 406cae8 commit 5a6f16b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5101
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{74CA3917-E2F3-4C75-96AF-156BC52C4C5E}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<RootNamespace>InEngine.Commands</RootNamespace>
9+
<AssemblyName>InEngine.Commands</AssemblyName>
10+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
11+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13+
<DebugSymbols>true</DebugSymbols>
14+
<DebugType>full</DebugType>
15+
<Optimize>false</Optimize>
16+
<OutputPath>bin\Debug</OutputPath>
17+
<DefineConstants>DEBUG;</DefineConstants>
18+
<ErrorReport>prompt</ErrorReport>
19+
<WarningLevel>4</WarningLevel>
20+
<ConsolePause>false</ConsolePause>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
<Optimize>true</Optimize>
24+
<OutputPath>bin\Release</OutputPath>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
<ConsolePause>false</ConsolePause>
28+
</PropertyGroup>
29+
<ItemGroup>
30+
<Reference Include="System" />
31+
<Reference Include="System.ComponentModel.DataAnnotations" />
32+
</ItemGroup>
33+
<ItemGroup>
34+
<Compile Include="Properties\AssemblyInfo.cs" />
35+
<Compile Include="Sample\Minimal.cs" />
36+
<Compile Include="Sample\ShowProgress.cs" />
37+
<Compile Include="Sample\SayHello.cs" />
38+
</ItemGroup>
39+
<ItemGroup>
40+
<Folder Include="Sample\" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<ProjectReference Include="..\InEngine.Core\InEngine.Core.csproj">
44+
<Project>{1C604C4F-3F98-483C-89E3-C951BE03366A}</Project>
45+
<Name>InEngine.Core</Name>
46+
</ProjectReference>
47+
</ItemGroup>
48+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
49+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle("InEngine.Commands")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("")]
12+
[assembly: AssemblyCopyright("${AuthorCopyright}")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion("1.0.*")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using InEngine.Core;
2+
3+
namespace InEngine.Commands.Sample
4+
{
5+
/*
6+
* At a minimum, a command must implement the ICommand interface.
7+
*
8+
* A command result must be returned from the Run method.
9+
* The command result has an optional message. This is especially helpful
10+
* when the command does not finish successfully.
11+
*/
12+
public class Minimal : ICommand
13+
{
14+
public CommandResult Run()
15+
{
16+
return new CommandResult(true);
17+
}
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using InEngine.Core;
2+
using System;
3+
4+
namespace InEngine.Commands.Sample
5+
{
6+
public class SayHello : AbstractCommand
7+
{
8+
public override CommandResult Run()
9+
{
10+
Console.WriteLine("hello...");
11+
return new CommandResult(true);
12+
}
13+
}
14+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using InEngine.Core;
2+
3+
namespace InEngine.Commands.Sample
4+
{
5+
/*
6+
* The AbstractCommand class adds functionality, including a logger and a
7+
* progress bar.
8+
*/
9+
public class ShowProgress : AbstractCommand
10+
{
11+
/*
12+
* Note that the override keyword is necessary in the Run method
13+
* signature as the base class method is virtual.
14+
*/
15+
public override CommandResult Run()
16+
{
17+
// Define the ticks (aka steps) for the command...
18+
var maxTicks = 100000;
19+
SetProgressBarMaxTicks(maxTicks);
20+
21+
// Do some work...
22+
for (var i = 0; i <= maxTicks;i++)
23+
{
24+
// Update the command's progress
25+
UpdateProgress(i);
26+
}
27+
28+
return new CommandResult(true);
29+
}
30+
}
31+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Konsole;
2+
using NLog;
3+
using Quartz;
4+
5+
namespace InEngine.Core
6+
{
7+
abstract public class AbstractCommand : ICommand, IJob
8+
{
9+
public IJobExecutionContext JobExecutionContext { get; set; }
10+
public Logger Logger { get; internal set; }
11+
public ProgressBar ProgressBar { get; internal set; }
12+
string _name;
13+
public string Name
14+
{
15+
get { return _name; }
16+
set
17+
{
18+
_name = value;
19+
Logger = LogManager.GetLogger(_name);
20+
}
21+
}
22+
23+
protected AbstractCommand()
24+
{
25+
Name = GetType().FullName;
26+
}
27+
28+
public virtual CommandResult Run()
29+
{
30+
throw new System.NotImplementedException();
31+
}
32+
33+
public void SetProgressBarMaxTicks(int maxTicks) => ProgressBar = new ProgressBar(maxTicks);
34+
public void UpdateProgress(int tick) => ProgressBar.Refresh(tick, Name);
35+
36+
public void Execute(IJobExecutionContext context)
37+
{
38+
JobExecutionContext = context;
39+
Run();
40+
}
41+
}
42+
}

src/InEngine.Core/CommandResult.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace InEngine.Core
2+
{
3+
public class CommandResult
4+
{
5+
public bool IsSuccessful { get; set; }
6+
public string Message { get; set; }
7+
8+
public CommandResult(bool isSuccssful, string message = "")
9+
{
10+
IsSuccessful = isSuccssful;
11+
Message = message;
12+
}
13+
}
14+
}

src/InEngine.Core/Config.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Configuration;
3+
using InEngine.Core.Queue;
4+
5+
namespace InEngine.Core
6+
{
7+
public class Config
8+
{
9+
public static string QueueName { get { return GetString("QueueName", "InEngine:Queue"); } set => throw new NotImplementedException(); }
10+
public static string RedisHost { get { return GetString("RedisHost", "localhost"); } set => throw new NotImplementedException(); }
11+
public static int RedisPort { get { return GetInt("RedisDb", 6379); } set => throw new NotImplementedException(); }
12+
public static int RedisDb { get { return GetInt("RedisDb", 0); } set => throw new NotImplementedException(); }
13+
public static string RedisPassword { get { return GetString("RedisHist"); } set => throw new NotImplementedException(); }
14+
15+
public static int GetInt(string key, int defaultValue = 0)
16+
{
17+
var val = ConfigurationManager.AppSettings[key];
18+
return val == null ? defaultValue : Convert.ToInt32(val);
19+
}
20+
21+
public static string GetString(string key, string defaultValue = "")
22+
{
23+
return ConfigurationManager.AppSettings[key] ?? defaultValue;
24+
}
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace InEngine.Core.Exceptions
4+
{
5+
public class CommandFailedException : Exception
6+
{
7+
public CommandFailedException(string message) : base(message)
8+
{
9+
}
10+
11+
public CommandFailedException(string message, Exception innerException) : base(message, innerException)
12+
{
13+
}
14+
}
15+
}

src/InEngine.Core/ICommand.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace InEngine.Core
2+
{
3+
public interface ICommand
4+
{
5+
CommandResult Run();
6+
}
7+
}

0 commit comments

Comments
 (0)