Skip to content

Commit 91ed418

Browse files
committed
mv src to ServiceStackInterface
1 parent 4b6e6ef commit 91ed418

File tree

915 files changed

+183
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

915 files changed

+183
-184
lines changed

ServiceInterface/AppHost.cs

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
using System;
2+
using System.IO;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Collections;
6+
using ServiceStack;
7+
using ServiceStack.IO;
8+
using ServiceStack.Script;
9+
using ServiceStack.Text;
10+
using ServiceStack.Data;
11+
using ServiceStack.OrmLite;
12+
using ServiceStack.Configuration;
13+
using Funq;
14+
15+
namespace SharpScript;
16+
17+
public class AppHost : AppHostBase
18+
{
19+
public AppHost()
20+
: base("#Script Pages", typeof(ScriptServices).Assembly) { }
21+
22+
public ScriptContext LinqContext;
23+
24+
public override void Configure(Container container)
25+
{
26+
SetConfig(new HostConfig {
27+
DebugMode = AppSettings.Get("DebugMode", Env.IsWindows),
28+
});
29+
30+
Plugins.Add(new ServiceStack.Api.OpenApi.OpenApiFeature());
31+
32+
var path = MapProjectPath("~/wwwroot/assets/js/customers.json");
33+
var json = File.ReadAllText(path);
34+
TemplateQueryData.Customers = json.FromJson<List<Customer>>();
35+
36+
container.Register<ICustomers>(c => new Customers(TemplateQueryData.Customers));
37+
container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
38+
39+
using (var db = container.Resolve<IDbConnectionFactory>().Open())
40+
{
41+
db.CreateTable<Order>();
42+
db.CreateTable<Customer>();
43+
db.CreateTable<Product>();
44+
TemplateQueryData.Customers.Each(x => db.Save(x, references:true));
45+
db.InsertAll(TemplateQueryData.Products);
46+
47+
db.CreateTable<Quote>();
48+
db.Insert(new Quote { Id = 1, Url = "https://gist.githubusercontent.com/gistlyn/0ab7494dfbff78466ef622d501662027/raw/b3dd1e9f8e82c169a32829071aa7f761c6494843/quote.md" });
49+
}
50+
51+
Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
52+
53+
Plugins.Add(new AutoQueryDataFeature { MaxLimit = 100 }
54+
.AddDataSource(ctx => ctx.ServiceSource<GithubRepo>(ctx.Dto.ConvertTo<GetGithubRepos>(),
55+
HostContext.Cache, TimeSpan.FromMinutes(10)))
56+
);
57+
58+
var customFilters = new CustomScriptMethods();
59+
Plugins.Add(new SharpPagesFeature {
60+
ScriptLanguages = { ScriptLisp.Language },
61+
ScriptMethods = {
62+
customFilters,
63+
new DbScriptsAsync()
64+
},
65+
FilterTransformers = {
66+
["convertScriptToCodeBlocks"] = GitHubMarkdownScripts.convertScriptToCodeBlocks,
67+
["convertScriptToLispBlocks"] = GitHubMarkdownScripts.convertScriptToLispBlocks,
68+
},
69+
Args = {
70+
["products"] = TemplateQueryData.Products
71+
},
72+
ScriptTypes = {
73+
typeof(Ints),
74+
typeof(Adder),
75+
typeof(StaticLog),
76+
typeof(InstanceLog),
77+
typeof(GenericStaticLog<>),
78+
},
79+
RenderExpressionExceptions = true,
80+
MetadataDebugAdminRole = RoleNames.AllowAnon,
81+
ExcludeFiltersNamed = { "dbExec" }
82+
});
83+
84+
AfterInitCallbacks.Add(host => {
85+
var feature = GetPlugin<SharpPagesFeature>();
86+
87+
var files = GetVirtualFileSources().First(x => x is FileSystemVirtualFiles);
88+
foreach (var file in files.GetDirectory("docs").GetAllMatchingFiles("*.html"))
89+
{
90+
var page = feature.GetPage(file.VirtualPath).Init().Result;
91+
if (page.Args.TryGetValue("order", out object order) && page.Args.TryGetValue("title", out object title))
92+
{
93+
customFilters.DocsIndex[int.Parse((string)order)] = new KeyValuePair<string,string>(GetPath(file.VirtualPath), (string)title);
94+
}
95+
}
96+
97+
foreach (var file in files.GetDirectory("sharp-apps").GetAllMatchingFiles("*.html"))
98+
{
99+
var page = feature.GetPage(file.VirtualPath).Init().Result;
100+
if (page.Args.TryGetValue("order", out object order) && page.Args.TryGetValue("title", out object title))
101+
{
102+
customFilters.AppsIndex[int.Parse((string)order)] = new KeyValuePair<string,string>(GetPath(file.VirtualPath), (string)title);
103+
}
104+
}
105+
106+
foreach (var file in files.GetDirectory("scode").GetAllMatchingFiles("*.html"))
107+
{
108+
var page = feature.GetPage(file.VirtualPath).Init().Result;
109+
if (page.Args.TryGetValue("order", out object order) && page.Args.TryGetValue("title", out object title))
110+
{
111+
customFilters.CodeIndex[int.Parse((string)order)] = new KeyValuePair<string,string>(GetPath(file.VirtualPath), (string)title);
112+
}
113+
}
114+
115+
foreach (var file in files.GetDirectory("lisp").GetAllMatchingFiles("*.html"))
116+
{
117+
var page = feature.GetPage(file.VirtualPath).Init().Result;
118+
if (page.Args.TryGetValue("order", out object order) && page.Args.TryGetValue("title", out object title))
119+
{
120+
customFilters.LispIndex[int.Parse((string)order)] = new KeyValuePair<string,string>(GetPath(file.VirtualPath), (string)title);
121+
}
122+
}
123+
124+
foreach (var file in files.GetDirectory("usecases").GetAllMatchingFiles("*.html"))
125+
{
126+
var page = feature.GetPage(file.VirtualPath).Init().Result;
127+
if (page.Args.TryGetValue("order", out object order) && page.Args.TryGetValue("title", out object title))
128+
{
129+
customFilters.UseCasesIndex[int.Parse((string)order)] = new KeyValuePair<string,string>(GetPath(file.VirtualPath), (string)title);
130+
}
131+
}
132+
133+
foreach (var file in files.GetDirectory("linq").GetAllMatchingFiles("*.html"))
134+
{
135+
var page = feature.GetPage(file.VirtualPath).Init().Result;
136+
if (page.Args.TryGetValue("order", out object order) && page.Args.TryGetValue("title", out object title))
137+
{
138+
customFilters.LinqIndex[int.Parse((string)order)] = new KeyValuePair<string,string>(GetPath(file.VirtualPath), (string)title);
139+
}
140+
}
141+
142+
var protectedScriptNames = new HashSet<string>(ScriptMethodInfo.GetMethodsAvailable(typeof(ProtectedScripts)).Map(x => x.Name));
143+
144+
LinqContext = new ScriptContext {
145+
ScriptLanguages = { ScriptLisp.Language },
146+
Args = {
147+
[ScriptConstants.DefaultDateFormat] = "yyyy/MM/dd",
148+
["products"] = TemplateQueryData.Products,
149+
["products-list"] = Lisp.ToCons(TemplateQueryData.Products),
150+
["customers"] = TemplateQueryData.Customers,
151+
["customers-list"] = Lisp.ToCons(TemplateQueryData.Customers),
152+
["comparer"] = new CaseInsensitiveComparer(),
153+
["anagramComparer"] = new AnagramEqualityComparer(),
154+
},
155+
ScriptTypes = {
156+
typeof(DateTime),
157+
typeof(CaseInsensitiveComparer),
158+
typeof(AnagramEqualityComparer),
159+
},
160+
ScriptMethods = {
161+
new ProtectedScripts()
162+
},
163+
};
164+
protectedScriptNames.Each(x => LinqContext.ExcludeFiltersNamed.Add(x));
165+
LinqContext.Init();
166+
});
167+
}
168+
169+
public string GetPath(string virtualPath)
170+
{
171+
var path = "/" + virtualPath.LastLeftPart('.');
172+
if (path.EndsWith("/index"))
173+
path = path.Substring(0, path.Length - "index".Length);
174+
175+
return path;
176+
}
177+
}
178+
179+
public class Quote
180+
{
181+
public int Id { get; set; }
182+
public string Url { get; set; }
183+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)