-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.tt
139 lines (123 loc) · 3.69 KB
/
test.tt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<#@ template debug="false" hostspecific="true" language="C#" #>
//#@ import namespace="Newtonsoft.Json" #
<#@ assembly name="vuecore.dll" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="Microsoft.AspNetCore.Mvc.ViewFeatures" #>
// @ import namespace="Microsoft.AspNetCore.Mvc.ApiExplorer"
<#@ @ import namespace="System.Reflection" #>
//nuget package dll hell resolverhow to import @ import namespace="Microsoft.NETCore.Targets" #
// #@ import namespace="Microsoft.AspNetCore.Mvc" #
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System.Threading.Tasks" #>
// #@ import namespace="System.Runtime" #
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="bVue" #>
<#@ Assembly name="EnvDTE" #>
<#@ output extension=".ts" #>
<# /* Environment.CurrentDirectory */ #><#
string assemblyName = "vuecore.dll";
string assemblyPath = Environment.CurrentDirectory + "\\bin\\Debug\\net5.0\\"+assemblyName;
//string[] namespaces = new string[]{ "bVue.code.controllers","bVue.code"};
#><# /*= assemblyPath*/ #><#
ProxyDomain pd = new ProxyDomain();
//Assembly assembly = pd.GetAssembly(assemblyPath);
Assembly assembly = Assembly.LoadFrom(assemblyPath);
//Assembly assembly = Assembly.GetExecutingAssembly();
var asms = AppDomain.CurrentDomain.GetAssemblies();
List<Type> types = new List<Type>();
//foreach(var s in namespaces){
foreach(var a in asms)
{
types = types.Concat(GetTypesInNamespace(assembly, "")).ToList();
}
//}
#>
//AUTOGENERATED DO NOT EDIT THIS FILE <#= DateTime.Now.ToString() #>
////////////////////
// available hubs //
////////////////////
//#region available hubs
//JS header:
declare var $:any;
import fetchival from 'fetchival';
export class Api {
constructor(baseurl: string) {
this.url = baseurl;
<# foreach (var hub in types)
{
string hName = GetController(hub.Name);
#>
this.<#= hub.Name!=null?hName:hName #> = new <#= hub.Name #>(this.url);
<#
}
#>
}
url:string;
<#
foreach (var hub in types)
{
string hName = GetController(hub.Name);
#>
/** * The hub implemented by <#=hub.FullName#> */
public <#= hub.Name!=null?hName:hName #> : <#= hub.Name #> ;
<#
}
#>
}
//#endregion available hubs
<#
foreach (var hub in types)
{
string hName = GetController(hub.Name);
#>
/** * The hub implemented by <#=hub.FullName#> */
export class <#= hub.Name #>
{
constructor(baseurl: string) {
this.url = baseurl;
}
url:string;
public hello(search:string):Promise<string>
{ //todo parametrize and make more dynamic
return fetchival(this.url+'/test/hello', {
headers: { 'Content-Type': 'application/json', token:'yourcookie' }
}).get({
search:search
});
}
}
<#
}
#>
export default Api;
//#endregion data contracts
<#+
public Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
{
return assembly.GetTypes().Where(t => t.BaseType!=null && t.BaseType.Name.ToLower().EndsWith("controller")
//&& String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)
).ToArray();
}
private string GetController(string s)
{
return s.Replace("Controller","", StringComparison.InvariantCultureIgnoreCase);
}
class ProxyDomain : MarshalByRefObject
{
public Assembly GetAssembly(string assemblyPath)
{
try
{
return Assembly.LoadFrom(assemblyPath);
}
catch (Exception ex)
{
throw new InvalidOperationException(ex.Message);
}
}
}
#>