diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-19 01:50:58 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-19 01:50:58 +0200 |
| commit | 9736b8c8ede6a0d121dea8381f0abb561fad5631 (patch) | |
| tree | 1c38f3f5be82b923ffae40fae00a25487179ab54 /Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs | |
| parent | be3343cc0268179c7a6f628fa5e68f323a3335e5 (diff) | |
| download | Tango-9736b8c8ede6a0d121dea8381f0abb561fad5631.tar.gz Tango-9736b8c8ede6a0d121dea8381f0abb561fad5631.zip | |
Implemented auto generated web clients for PPC and machine studio.
Improved interactions with web clients across solutions.
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs')
| -rw-r--r-- | Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs new file mode 100644 index 000000000..e95f57344 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.CodeGeneration; +using Tango.Core.Helpers; +using Tango.Transport.Web; +using Tango.Web.Authentication; +using Tango.Web.Controllers; + +namespace Tango.WebClientGenerator +{ + class Program + { + static void Main(string[] args) + { + //Generate PPC client. + GenerateWebClient<PPC.Common.Web.LoginRequest, PPC.Common.Web.LoginResponse, MachineService.Controllers.PPCController>("Tango.PPC.Common.Web", "PPCWebClientBase", PathHelper.GetSolutionFolder() + @"\PPC\Tango.PPC.Common\Web"); + + //Generate Machine Studio client. + GenerateWebClient<MachineStudio.Common.Web.LoginRequest, MachineStudio.Common.Web.LoginResponse, MachineService.Controllers.MachineStudioController>("Tango.MachineStudio.Common.Web", "MachineStudioWebClientBase", PathHelper.GetSolutionFolder() + @"\MachineStudio\Tango.MachineStudio.Common\Web"); + } + + private static void GenerateWebClient<TLoginRequest, TLoginResponse, TController>(String nameSpace, String name, String path) where TLoginRequest : WebRequestMessage where TLoginResponse : WebTokenResponse where TController : JsonController + { + TangoWebClientCodeFile model = new TangoWebClientCodeFile(); + model.Namespace = nameSpace; + model.ControllerName = typeof(TController).Name.Replace("Controller", ""); + model.Name = name; + model.LoginRequest = typeof(TLoginRequest).FullName; + model.LoginResponse = typeof(TLoginResponse).FullName; + + foreach (var action in typeof(TController).GetMethods().Where(x => typeof(WebResponseMessage).IsAssignableFrom(x.ReturnType) && x.Name != "Login")) + { + model.Actions.Add(new TangoWebClientCodeFile.ControllerAction() + { + Name = action.Name, + Request = action.GetParameters()[0].ParameterType.FullName, + Response = action.ReturnType.FullName, + }); + } + + String code = model.GenerateCode(); + File.WriteAllText(Path.Combine(path, name + ".cs"), code); + } + } +} |
