Skip to content

Commit

Permalink
fix #25
Browse files Browse the repository at this point in the history
  • Loading branch information
erik.araojo committed Apr 6, 2024
1 parent 5bf212a commit 008aefb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
11 changes: 10 additions & 1 deletion source/Tefin.Grpc/ProtocProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,14 @@ module ProtocProcess =

let csFiles = ResizeArray<string>()
do! generateFor protosFiles[0] csFiles
return csFiles |> Seq.distinct |> Seq.toArray

let generatedCsFiles = csFiles |> Seq.distinct |> Seq.toArray

if (generatedCsFiles.Length > 0) then
//If we have generated new *.cs files, delete any dll lying around
let dlls = io.Dir.GetFiles(System.IO.Path.GetDirectoryName(generatedCsFiles[0]), "*.dll", System.IO.SearchOption.TopDirectoryOnly)
for dll in dlls do
io.File.Delete dll

return generatedCsFiles
}
4 changes: 4 additions & 0 deletions source/Tefin.Grpc/ServiceClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ module ServiceClient =
let lastParam = m.GetParameters() |> Array.last
not (lastParam.ParameterType = typeof<CallOptions>))


let generateSourceFiles (io: IOs) (compileParams: CompileParameters) =
task {

let check () = ()

let grpcParams =
{ compileParams with
Config = GrpcPackage.grpcConfigValues }
Expand Down
8 changes: 4 additions & 4 deletions source/Tefin/Features/CompileFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public class CompileFeature(
IOs io) {
private static readonly Dictionary<string, CompileOutput> CompilationCache = new();

public async Task<(bool, CompileOutput)> CompileExisting(string[] csFiles) {
public async Task<(bool, CompileOutput)> CompileExisting(string[] codeFiles) {
try {
var key = string.Join("-", csFiles);
var key = string.Join("-", codeFiles);
if (CompilationCache.TryGetValue(key, out var cOutput)) {
return (true, cOutput);
}

GlobalHub.publish(new ClientCompileMessage(true));
CompileParameters? cParams = new(clientName, description, serviceName, protoFiles, Array.Empty<string>(),
reflectionUrl, null);
var com = await ServiceClient.compile(io, csFiles, cParams);
var com = await ServiceClient.compile(io, codeFiles, cParams);
if (com.IsOk) {
CompilationCache.Add(key, com.ResultValue);
return (true, com.ResultValue);
Expand Down Expand Up @@ -59,7 +59,7 @@ public class CompileFeature(
var com = await ServiceClient.compile(Resolver.value, csFilesRet.ResultValue, cParams);
if (com.IsOk) {
var key = string.Join("-", csFilesRet.ResultValue);
CompilationCache.Add(key, com.ResultValue);
CompilationCache[key] = com.ResultValue;
return (true, com.ResultValue);
}

Expand Down
27 changes: 19 additions & 8 deletions source/Tefin/ViewModels/Overlay/AddGrpcServiceOverlayViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ namespace Tefin.ViewModels.Overlay;

public class AddGrpcServiceOverlayViewModel : ViewModelBase, IOverlayViewModel {
private readonly ProjectTypes.Project _project;
private string _address = "";
private string _clientName = "";
private string _address = string.Empty;
private string _clientName = string.Empty;
private bool _isDiscoveringUsingProto;
private string _protoFile = "";
private string _protoFilesOrUrl = "";
private string _protoFile = string.Empty;
private string _protoFilesOrUrl = string.Empty;
private string? _selectedDiscoveredService;

public AddGrpcServiceOverlayViewModel(ProjectTypes.Project project) {
Expand All @@ -36,7 +36,7 @@ public AddGrpcServiceOverlayViewModel(ProjectTypes.Project project) {
this.OkayCommand = this.CreateCommand(this.OnOkay);
this.ReflectionUrl = "http://localhost:5000";
this.Title = "Add a client";
this.Description = "";
this.Description = string.Empty;
}

[IsHttp]
Expand Down Expand Up @@ -80,7 +80,19 @@ public string ReflectionUrl {
[Required(ErrorMessage = "Service is required")]
public string? SelectedDiscoveredService {
get => this._selectedDiscoveredService;
set => this.RaiseAndSetIfChanged(ref this._selectedDiscoveredService, value);
set {
this.RaiseAndSetIfChanged(ref this._selectedDiscoveredService, value);
if (!string.IsNullOrWhiteSpace(this._selectedDiscoveredService)) {
if (string.IsNullOrWhiteSpace(this.ClientName)) {
var name = this._selectedDiscoveredService.Split(".").Last();
this.ClientName = $"{name}Client";
}

if (string.IsNullOrWhiteSpace(this.Address)) {
this.Address = "http://";
}
}
}
}

public string Title { get; }
Expand Down Expand Up @@ -149,8 +161,7 @@ private async Task OnOkay() {
var disco = new DiscoverFeature(protoFiles, this.ReflectionUrl);
var (ok2, _) = await disco.Discover(this.Io);
if (ok2) {
var cmd = new CompileFeature(this._selectedDiscoveredService!, this._clientName, "desc", protoFiles,
this.ReflectionUrl, this.Io);
var cmd = new CompileFeature(this._selectedDiscoveredService!, this._clientName, "desc", protoFiles, this.ReflectionUrl, this.Io);
var (ok, output) = await cmd.Run();
if (ok) {
var csFiles = output.Input.Value.SourceFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ public override string GetRequestContent() {
}
}

return "";
return string.Empty;
}

public override async Task ImportRequest() => await GrpcUiUtils.ImportRequest(this.RequestEditor,
this.ClientStreamEditor, this._listType, this.MethodInfo, this.Io);
public override void ImportRequestFile(string file) => GrpcUiUtils.ImportRequest(this.RequestEditor,
this.ClientStreamEditor, this._listType, this.MethodInfo, file, this.Io);

public void SetupDuplexStream(DuplexStreamingCallResponse response) {
this._callResponse = response;
Expand Down

0 comments on commit 008aefb

Please sign in to comment.