-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPS.snippet
More file actions
138 lines (128 loc) · 4.62 KB
/
PS.snippet
File metadata and controls
138 lines (128 loc) · 4.62 KB
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
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Model Configuration Template</Title>
<Author>Unskilled</Author>
<Description>Creates a base context configuration</Description>
<Shortcut>PSConfig</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>model</ID>
<ToolTip>the model class name</ToolTip>
<Default>ModelClassName</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
public class $model$Configuration : IEntityTypeConfiguration<$model$>
{
public void Configure(EntityTypeBuilder<$model$> builder)
{
builder.HasKey(b => b.Id);
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>Client Template</Title>
<Author>Unskilled</Author>
<Description>Creates a client for the PS API for a given model</Description>
<Shortcut>PSClient</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>model</ID>
<ToolTip>the model class name</ToolTip>
<Default>ModelClassName</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
public class $model$Client : PolysenseClient
{
public $model$Client(HttpClient httpClient) : base(httpClient)
{
client.BaseAddress = new Uri($$"{client.BaseAddress}$model$s/");
}
public async Task<PagedResponse<IEnumerable<$model$>>> Get$model$s(int pageNumber = 1, int pageSize = PaginationFilter.DefaultPageSize, CancellationToken token = default)
{
var endpoint = $$"?pageNumber={pageNumber}&pageSize={pageSize}";
return (await GetAsync<PagedResponse<IEnumerable<$model$>>>(endpoint, token)).Build(client);
}
public async Task<$model$> Get$model$(int id, CancellationToken token = default)
{
return await GetAsync<$model$>($$"{id}", token);
}
public async Task<$model$> Set$model$($model$ $model$, CancellationToken token = default)
{
return await PostAsync($model$, string.Empty, token);
}
public async Task<$model$> Update$model$($model$ $model$, CancellationToken token = default)
{
return await PutAsync($model$, string.Empty, token);
}
public async Task<$model$> Delete$model$(int id, CancellationToken token = default)
{
return await DeleteAsync<$model$>($$"{id}", token);
}
public async Task<$model$> Delete$model$($model$ $model$, CancellationToken token = default)
{
return await DeleteAsync($model$, token: token);
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<!--WEB SCAPER SNIPPETS-->
<CodeSnippet Format="1.0.0">
<Header>
<Title>WebScraper Template</Title>
<Author>Unskilled</Author>
<Description>Creates a base scraper configuration</Description>
<Shortcut>PSScraper</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>Name</ID>
<ToolTip>The name of your scraper</ToolTip>
<Default>ScraperName</Default>
</Literal>
<Literal>
<ID>Time</ID>
<ToolTip>The amount of time your scraper takes</ToolTip>
<Default>5</Default>
</Literal>
<Literal>
<ID>UnitofTime</ID>
<ToolTip>The unit of time of your scraper</ToolTip>
<Default>Second</Default>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[
public class $Name$$Time$$UnitofTime$Scraper : BaseScraper, ITestWebScraper
{
protected async override Task Scrape(HtmlWeb website, ILogger logger, CancellationToken token)
{
var watch = Stopwatch.StartNew();
logger.LogInformation("Default $Time$ $UnitofTime$ scraper on UB Unlimited");
var doc = await website.LoadFromWebAsync("https://www.ubunlimited.com");
watch.Stop();
var elapsedTime = watch.ElapsedMilliseconds;
logger.LogInformation($$"Scrapped UB Unlimited in {elapsedTime} ms");
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>