diff --git a/source/Tefin.Grpc/ProtocProcess.fs b/source/Tefin.Grpc/ProtocProcess.fs index 0e97711..7c67ca8 100644 --- a/source/Tefin.Grpc/ProtocProcess.fs +++ b/source/Tefin.Grpc/ProtocProcess.fs @@ -168,5 +168,14 @@ module ProtocProcess = let csFiles = ResizeArray() 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 } diff --git a/source/Tefin.Grpc/ServiceClient.fs b/source/Tefin.Grpc/ServiceClient.fs index 09d812f..21f1a12 100644 --- a/source/Tefin.Grpc/ServiceClient.fs +++ b/source/Tefin.Grpc/ServiceClient.fs @@ -52,8 +52,12 @@ module ServiceClient = let lastParam = m.GetParameters() |> Array.last not (lastParam.ParameterType = typeof)) + let generateSourceFiles (io: IOs) (compileParams: CompileParameters) = task { + + let check () = () + let grpcParams = { compileParams with Config = GrpcPackage.grpcConfigValues } diff --git a/source/Tefin/Features/CompileFeature.cs b/source/Tefin/Features/CompileFeature.cs index 6d3f105..ac149f3 100644 --- a/source/Tefin/Features/CompileFeature.cs +++ b/source/Tefin/Features/CompileFeature.cs @@ -19,9 +19,9 @@ public class CompileFeature( IOs io) { private static readonly Dictionary 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); } @@ -29,7 +29,7 @@ public class CompileFeature( GlobalHub.publish(new ClientCompileMessage(true)); CompileParameters? cParams = new(clientName, description, serviceName, protoFiles, Array.Empty(), 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); @@ -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); } diff --git a/source/Tefin/ViewModels/Overlay/AddGrpcServiceOverlayViewModel.cs b/source/Tefin/ViewModels/Overlay/AddGrpcServiceOverlayViewModel.cs index ac89841..5aa4439 100644 --- a/source/Tefin/ViewModels/Overlay/AddGrpcServiceOverlayViewModel.cs +++ b/source/Tefin/ViewModels/Overlay/AddGrpcServiceOverlayViewModel.cs @@ -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) { @@ -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] @@ -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; } @@ -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; diff --git a/source/Tefin/ViewModels/Tabs/Grpc/DuplexStreamingReqViewModel.cs b/source/Tefin/ViewModels/Tabs/Grpc/DuplexStreamingReqViewModel.cs index 342af3a..85da490 100644 --- a/source/Tefin/ViewModels/Tabs/Grpc/DuplexStreamingReqViewModel.cs +++ b/source/Tefin/ViewModels/Tabs/Grpc/DuplexStreamingReqViewModel.cs @@ -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;