Skip to content

Commit 356f962

Browse files
authored
Init Commit
Init Commit
0 parents  commit 356f962

File tree

80 files changed

+3885
-0
lines changed

Some content is hidden

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

80 files changed

+3885
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="CommandLineParser" Version="2.3.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\FsBaseExecSvc\FsBaseExecSvc.csproj"></ProjectReference>
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<None Update="profile.ini">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using CommandLine;
2+
using DIFacility;
3+
using FsBaseExecSvc.Client;
4+
using FsBaseExecSvc.Interface;
5+
using Lamar;
6+
using Microsoft.Win32;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Diagnostics;
10+
using System.IO;
11+
using System.Reflection;
12+
using System.Security;
13+
using System.Threading;
14+
using System.Threading.Tasks;
15+
16+
namespace ClientExample
17+
{
18+
class EntraceOption
19+
{
20+
[Option("config", Required = true, HelpText = "Config file name")]
21+
public string ConfigFile { get; set; } = "";
22+
[Option("update", Required = false, HelpText = "Update the tool")]
23+
public bool Update { get; set; }
24+
25+
[Option("node", Required = false, HelpText = "Node to run, note the config file is still current node local")]
26+
public string Node { get; set; } = System.Net.Dns.GetHostName();
27+
28+
private readonly static string ServiceName = "FileWatcherProcessService";
29+
public bool VerifyInput()
30+
{
31+
if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ServiceName)))
32+
{
33+
Console.WriteLine($@"Incomplete version of file. Please copy again");
34+
return false;
35+
}
36+
if (!this.Update && !File.Exists(this.ConfigFile))
37+
{
38+
Console.WriteLine($@"Config file {this.ConfigFile} not exist");
39+
return false;
40+
}
41+
return true;
42+
}
43+
44+
public string Run()
45+
{
46+
var factory = ClientEntraceFactory.GetClientEntrance(new RPCClientTokenProvider());
47+
LogLevelService.SetVerboseOn();
48+
49+
IFsRPCBase fsDemoRPC = factory.GetRPCClient("itest");
50+
var result = fsDemoRPC.RunOnNode("rwsam16", "time=11111", 3);
51+
52+
if (this.Update)
53+
{
54+
fsDemoRPC.UpdateServiceCred(this.Node);
55+
fsDemoRPC.UpdateServiceBinary(this.Node);
56+
return "Update Completes";
57+
}
58+
else
59+
{
60+
//example for reboot continue, just an example, you should build your own criteria for reboot-continue
61+
if (this.ConfigFile.Contains("12345"))
62+
{
63+
result = fsDemoRPC.RunAfterRebootOnNode(this.Node, File.ReadAllText(this.ConfigFile));
64+
return result.output;
65+
}
66+
else
67+
{
68+
result = fsDemoRPC.RunOnNode(this.Node, File.ReadAllText(this.ConfigFile));
69+
return result.output;
70+
}
71+
}
72+
}
73+
}
74+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using CommandLine;
2+
using DIFacility;
3+
using FsBaseExecSvc.Client;
4+
using FsBaseExecSvc.Interface;
5+
using System;
6+
using System.ComponentModel;
7+
8+
namespace ClientExample
9+
{
10+
//this is a demo of client, you should make your own change to keep credential safe.
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
16+
//ParserResult<EntraceOption> item = Parser.Default.ParseArguments<EntraceOption>(args);
17+
//item.WithParsed<EntraceOption>(opts => ProcessOption(opts, args));
18+
var factory = ClientEntraceFactory.GetClientEntrance(new RPCClientTokenProvider());
19+
LogLevelService.SetVerboseOn();
20+
21+
IFsRPCBase fsDemoRPC = factory.GetRPCClient("itest");
22+
var result = fsDemoRPC.RunOnNode("rwsam16", "time=11111",3);
23+
24+
Console.WriteLine(result);
25+
Console.ReadLine();
26+
}
27+
private static void ProcessOption(EntraceOption opts, string[] args)
28+
{
29+
if (opts.VerifyInput())
30+
{
31+
string result = opts.Run();
32+
Console.WriteLine(result);
33+
}
34+
else
35+
{
36+
Console.WriteLine("Exit due to input not valid");
37+
}
38+
}
39+
}
40+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<PublishProtocol>FileSystem</PublishProtocol>
8+
<Configuration>Release</Configuration>
9+
<Platform>Any CPU</Platform>
10+
<TargetFramework>netcoreapp2.2</TargetFramework>
11+
<PublishDir>bin\Release\netcoreapp2.2\publish\</PublishDir>
12+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
13+
<SelfContained>false</SelfContained>
14+
<_IsPortable>true</_IsPortable>
15+
</PropertyGroup>
16+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using DIFacility.SharedRegistry;
2+
using FsBaseExecSvc.Abstract;
3+
using FsBaseExecSvc.Client;
4+
using FsBaseExecSvc.Executor;
5+
using FsBaseExecSvc.Interface;
6+
using FsBaseExecSvc.Registry;
7+
using Lamar;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.IO;
11+
using System.Linq;
12+
using System.Reflection;
13+
using System.Text;
14+
15+
namespace ClientExample
16+
{
17+
/// <summary>
18+
/// it provides the record with typical file format to write onto the server's SMB path
19+
/// </summary>
20+
public class RPCClientTokenProvider : ITokenProvider
21+
{
22+
public IEnumerable<string> GetClientTokenNames()
23+
{
24+
return new string[] { "itest" };
25+
}
26+
}
27+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DOMAIN=mydomain
2+
USERNAME=myname
3+
PASSWD=mypwdplain_you_should_find_other_way_to_hide_this
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.168
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileWatcherProcessService", "FileWatcherProcessService\FileWatcherProcessService.csproj", "{168D5A09-3681-4683-B382-09B9C4217E53}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FsBaseExecSvc", "FsBaseExecSvc\FsBaseExecSvc.csproj", "{47177D51-17BC-470E-9B5F-99FFFC6BC30F}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientExample", "ClientExample\ClientExample.csproj", "{EE99FD67-369D-48A5-B3DA-77B3F698D475}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{168D5A09-3681-4683-B382-09B9C4217E53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{168D5A09-3681-4683-B382-09B9C4217E53}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{168D5A09-3681-4683-B382-09B9C4217E53}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{168D5A09-3681-4683-B382-09B9C4217E53}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{47177D51-17BC-470E-9B5F-99FFFC6BC30F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{47177D51-17BC-470E-9B5F-99FFFC6BC30F}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{47177D51-17BC-470E-9B5F-99FFFC6BC30F}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{47177D51-17BC-470E-9B5F-99FFFC6BC30F}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{EE99FD67-369D-48A5-B3DA-77B3F698D475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{EE99FD67-369D-48A5-B3DA-77B3F698D475}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{EE99FD67-369D-48A5-B3DA-77B3F698D475}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{EE99FD67-369D-48A5-B3DA-77B3F698D475}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {E00B62CC-1234-4FC4-B203-78A8F24DF5F6}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
<LangVersion>7.3</LangVersion>
7+
<Version>1.0.2</Version>
8+
<Description>An easy to use Filesystem Base request processing service, using FileWatcher, Generic Hosting, with RPC like support</Description>
9+
<ApplicationIcon />
10+
<StartupObject />
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
15+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.2.0" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\FsBaseExecSvc\FsBaseExecSvc.csproj"></ProjectReference>
20+
</ItemGroup>
21+
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using FsBaseExecCli.ServerRegistry;
2+
using FsBaseExecSvc.Abstract;
3+
using FsBaseExecSvc.Executor;
4+
using FsBaseExecSvc.Interface;
5+
using Microsoft.Extensions.Logging;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Threading;
11+
12+
namespace FsBaseExecCli.UserProcessor
13+
{
14+
[Processor("itest")]
15+
class InternalRecordProcessor : IExecuteLogic
16+
{
17+
18+
public string ProcessingLogic(IEnumerable<string> requestContent)
19+
{
20+
var firstLine = requestContent.FirstOrDefault();
21+
if (firstLine != null)
22+
{
23+
if(firstLine.IndexOf("ECHO=", StringComparison.OrdinalIgnoreCase) >= 0)
24+
{
25+
return $@"{Environment.MachineName}-{firstLine.ToLower().Replace("echo=", "")}";
26+
}
27+
if (firstLine.IndexOf("TIME=", StringComparison.OrdinalIgnoreCase) >= 0)
28+
{
29+
Thread.Sleep(5000);
30+
return $@"{Environment.MachineName}-{firstLine.ToLower().Replace("time=", "after sleep 5 seconds")}";
31+
}
32+
else
33+
{
34+
return $@"Default test";
35+
}
36+
}
37+
else
38+
{
39+
return $@"[FAIL]The content contains nothing";
40+
}
41+
}
42+
}
43+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using DIFacility;
2+
using DIFacility.SharedLib.Utils;
3+
using FsBaseExecCli.ServerRegistry;
4+
using FsBaseExecSvc;
5+
using FsBaseExecSvc.Hosting;
6+
using Lamar;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Hosting;
10+
using System;
11+
using System.IO;
12+
using System.Reflection;
13+
using System.Threading;
14+
using System.Threading.Tasks;
15+
16+
namespace FileWatcherProcessService
17+
{
18+
class Program
19+
{
20+
static async Task Main(string[] args)
21+
{
22+
IFileProcessingHost host = FileProcessingHostEntrance.GetFileProcessingHost(new RPCServerTokenToProcessorMapper());
23+
if(args.Length>0 && args[0].Equals("debug"))
24+
{
25+
host.RunConsole();
26+
Console.WriteLine("Press Enter to exit");
27+
Console.ReadLine();
28+
await host.StopConsoleAsync();
29+
}
30+
else
31+
{
32+
host.RunAsService();
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)