Skip to content
Open
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
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
goplugin/
bin/
.log
**/node_modules/
**/node_modules/
NaveegoGrpcPlugin/NaveegoGrpcPlugin/obj/Debug/netcoreapp3.0/

NaveegoGrpcPlugin/.vs/NaveegoGrpcPlugin/v16/

NaveegoGrpcPlugin/NaveegoGrpcPlugin/obj/

*.txt

NaveegoGrpcPlugin/.vs/NaveegoGrpcPlugin/DesignTimeBuild/.dtbcache
28 changes: 23 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# I had to build my implementation first
FROM mcr.microsoft.com/dotnet/core/runtime:3.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY NaveegoGrpcPlugin/NaveegoGrpcPlugin/NaveegoGrpcPlugin.csproj NaveegoGrpcPlugin/
RUN dotnet restore NaveegoGrpcPlugin/NaveegoGrpcPlugin.csproj
COPY . .
WORKDIR /src/NaveegoGrpcPlugin/NaveegoGrpcPlugin
RUN dotnet build NaveegoGrpcPlugin.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish NaveegoGrpcPlugin.csproj -c Release -o /app -r linux-x64 --self-contained true

FROM base AS final
WORKDIR /app
COPY --from=publish /app .

FROM golang:1.11-stretch

WORKDIR /code-challenge-plugin
#Then copy it into the go environment
COPY --from=final /app .

ADD go.mod .
ADD go.sum .
Expand All @@ -14,9 +35,6 @@ ADD host.go .

ENTRYPOINT ["go", "run", "host.go"]

# Build your implementation here


CMD ["./NaveegoGrpcPlugin"]

# Put your implementation here
CMD ["plugin"]
#ENTRYPOINT ["/bin/sh"]
25 changes: 25 additions & 0 deletions NaveegoGrpcPlugin/NaveegoGrpcPlugin.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29318.209
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NaveegoGrpcPlugin", "NaveegoGrpcPlugin\NaveegoGrpcPlugin.csproj", "{65952571-BC78-418F-A4B6-1A46A1225AAB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{65952571-BC78-418F-A4B6-1A46A1225AAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65952571-BC78-418F-A4B6-1A46A1225AAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65952571-BC78-418F-A4B6-1A46A1225AAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65952571-BC78-418F-A4B6-1A46A1225AAB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4F447E73-BAC3-49DF-AFD2-4EF27FF8529D}
EndGlobalSection
EndGlobal
117 changes: 117 additions & 0 deletions NaveegoGrpcPlugin/NaveegoGrpcPlugin/Classes/Types.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NaveegoGrpcPlugin
{
public class Types
{
public string ColumnName { get; set; }
public Dictionary<Type, int> TypeVotes { get; private set; }
private bool typeFound;

public Types(string columnName, string value)
{
ColumnName = columnName;
SetUpTypes();
DetectTypes(value);
}

private void SetUpTypes()
{
TypeVotes = new Dictionary<Type, int>();
TypeVotes.Add(typeof(int), 0);
TypeVotes.Add(typeof(decimal), 0);
TypeVotes.Add(typeof(DateTime), 0);
TypeVotes.Add(typeof(bool), 0);
TypeVotes.Add(typeof(string), 0);
}



public void DetectTypes(string value)
{
typeFound = false;
VoteForNumber(value);
VoteForInt(value);
VoteForDatetime(value);
VoteForBoolean(value);
if (!typeFound)
{
VoteForString();
}
}


private void VoteForNumber(string value)
{
decimal decimalCheck;
decimal.TryParse(value, out decimalCheck);
if (decimalCheck != 0)
{
TypeVotes[typeof(decimal)] = TypeVotes[typeof(decimal)] + 1;
typeFound = true;
}
}

private void VoteForInt(string value)
{
int integerCheck;
int.TryParse(value, out integerCheck);
if (integerCheck != 0)
{
TypeVotes[typeof(int)] = TypeVotes[typeof(int)] + 1;
typeFound = true;
}
}


private void VoteForDatetime(string value)
{
DateTime datetimeCheck;
DateTime.TryParse(value, out datetimeCheck);
if (datetimeCheck != DateTime.MinValue)
{
TypeVotes[typeof(DateTime)] = TypeVotes[typeof(DateTime)] + 1;
typeFound = true;
}
}

private void VoteForBoolean(string value)
{
bool booleanCheck;
if (bool.TryParse(value, out booleanCheck))
{
TypeVotes[typeof(bool)] = TypeVotes[typeof(bool)] + 1;
typeFound = true;
}
}

private void VoteForString()
{
TypeVotes[typeof(string)] = TypeVotes[typeof(string)] + 1;
}

public string TypeNameConvert(Type type)
{
if (type == typeof(string))
return "string";
else if (type == typeof(int))
return "integer";
else if (type == typeof(decimal))
return "number";
else if (type == typeof(DateTime))
return "datetime";
else if (type == typeof(bool))
return "boolean";
else
return string.Empty;
}



}


}
18 changes: 18 additions & 0 deletions NaveegoGrpcPlugin/NaveegoGrpcPlugin/NaveegoGrpcPlugin.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvHelper" Version="12.1.2" />
<PackageReference Include="Glob.cs" Version="4.0.37" />
<PackageReference Include="Grpc.AspNetCore" Version="2.23.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
<Protobuf Include="Protos\plugin.proto" GrpcServices="Server" />
</ItemGroup>

</Project>
71 changes: 71 additions & 0 deletions NaveegoGrpcPlugin/NaveegoGrpcPlugin/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;

namespace NaveegoGrpcPlugin
{
public class Program
{

public static int Main(string[] args)
{

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.File("PluginLog.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();

try
{
AppDomain.CurrentDomain.ProcessExit += ProcessExitHandler;
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
CreateHostBuilder(args, configuration).Build().Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}

}

private static void ProcessExitHandler(object sender, EventArgs e)
{
Console.WriteLine("Shutting down");

}

public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(options =>
{
var port = configuration.GetValue<int>("GrpcPort");
// Setup a HTTP/2 endpoint without TLS.
options.ListenLocalhost(port, o => o.Protocols =
HttpProtocols.Http2);
});
webBuilder.UseStartup<Startup>();
webBuilder.UseSerilog();
});
}
}
12 changes: 12 additions & 0 deletions NaveegoGrpcPlugin/NaveegoGrpcPlugin/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"NaveegoGrpcPlugin": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading