Skip to content

Commit 26090a9

Browse files
A few initial examples
0 parents  commit 26090a9

15 files changed

+1116
-0
lines changed

.gitignore

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Release Notes.txt
2+
*.binlog
3+
*.trx
4+
*.properties
5+
*.dll
6+
*-*.dll
7+
*.sdf
8+
.vs/
9+
Packages
10+
Build
11+
TestResults
12+
x86/Debug
13+
x86/Release
14+
x64/Debug
15+
x64/Release
16+
_g_*
17+
*.o
18+
*.so*
19+
obj
20+
bin
21+
*.Generated.cs
22+
*.suo
23+
*.vspscc
24+
*.user
25+
*.bak
26+
*.user
27+
*.aps
28+
*.pch
29+
*_i.c
30+
*_p.c
31+
*.ncb
32+
*.suo
33+
*.bak
34+
*.cache
35+
*.ilk
36+
*.log
37+
[Bb]in
38+
[Dd]ebug*/
39+
*.sbr
40+
obj/
41+
[Rr]elease*/
42+
_ReSharper*/
43+
desktop.ini
44+
Thumbs.db
45+
$tf/
46+
Temp-*/
47+
*.3rdparty/
48+
*.1*
49+
*.2*
50+
*.3*
51+
*.4*
52+
*.5*
53+
*.6*
54+
*.7*
55+
*.8*
56+
*.9*
57+
*.vsp*
58+
*.psess
59+
*.orig
60+
*.sq3
61+
*.db
62+
tmp.*
63+
*.tmp_proj
64+
*wpftmp.csproj
65+
.idea/
66+
.tmp*
67+
buildProto/
68+
global.json
69+
.fake
70+
.ionide
71+
/.docker

Api-Examples-Dotnet.sln

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32825.248
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TickBars", "TickBars\TickBars.csproj", "{66F7A2E1-C82D-4764-99C9-54D9F20158AE}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{EC9E460C-8CE7-4712-9C0F-F5FD29A76E31}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StaticData", "StaticData\StaticData.csproj", "{74395987-8564-4B96-B867-9392CCA24088}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "$", "$", "{AA059617-9D86-4D50-9AB3-A1DE54AE854E}"
13+
ProjectSection(SolutionItems) = preProject
14+
config.json = config.json
15+
EndProjectSection
16+
EndProject
17+
Global
18+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
19+
Debug|Any CPU = Debug|Any CPU
20+
Release|Any CPU = Release|Any CPU
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{66F7A2E1-C82D-4764-99C9-54D9F20158AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{66F7A2E1-C82D-4764-99C9-54D9F20158AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{66F7A2E1-C82D-4764-99C9-54D9F20158AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{66F7A2E1-C82D-4764-99C9-54D9F20158AE}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{EC9E460C-8CE7-4712-9C0F-F5FD29A76E31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{EC9E460C-8CE7-4712-9C0F-F5FD29A76E31}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{EC9E460C-8CE7-4712-9C0F-F5FD29A76E31}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{EC9E460C-8CE7-4712-9C0F-F5FD29A76E31}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{74395987-8564-4B96-B867-9392CCA24088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{74395987-8564-4B96-B867-9392CCA24088}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{74395987-8564-4B96-B867-9392CCA24088}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{74395987-8564-4B96-B867-9392CCA24088}.Release|Any CPU.Build.0 = Release|Any CPU
35+
EndGlobalSection
36+
GlobalSection(SolutionProperties) = preSolution
37+
HideSolutionNode = FALSE
38+
EndGlobalSection
39+
GlobalSection(NestedProjects) = preSolution
40+
{66F7A2E1-C82D-4764-99C9-54D9F20158AE} = {AA059617-9D86-4D50-9AB3-A1DE54AE854E}
41+
{EC9E460C-8CE7-4712-9C0F-F5FD29A76E31} = {AA059617-9D86-4D50-9AB3-A1DE54AE854E}
42+
{74395987-8564-4B96-B867-9392CCA24088} = {AA059617-9D86-4D50-9AB3-A1DE54AE854E}
43+
EndGlobalSection
44+
GlobalSection(ExtensibilityGlobals) = postSolution
45+
SolutionGuid = {C35944C2-9418-4A3A-879C-90C5AC45F285}
46+
EndGlobalSection
47+
EndGlobal

Api-Examples-Dotnet.sln.DotSettings

Lines changed: 439 additions & 0 deletions
Large diffs are not rendered by default.

Settings.StyleCop

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<StyleCopSettings Version="105">
2+
<GlobalSettings>
3+
<StringProperty Name="MergeSettingsFiles">NoMerge</StringProperty>
4+
</GlobalSettings>
5+
<Parsers>
6+
<Parser ParserId="StyleCop.CSharp.CsParser">
7+
<ParserSettings>
8+
<BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty>
9+
<BooleanProperty Name="Enabled">False</BooleanProperty>
10+
</ParserSettings>
11+
</Parser>
12+
</Parsers>
13+
<Analyzers>
14+
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
15+
<Rules>
16+
<Rule Name="ElementDocumentationMustBeSpelledCorrectly">
17+
<RuleSettings>
18+
<BooleanProperty Name="Enabled">False</BooleanProperty>
19+
</RuleSettings>
20+
</Rule>
21+
</Rules>
22+
<AnalyzerSettings>
23+
<StringProperty Name="CompanyName">Systemathics SAS</StringProperty>
24+
<StringProperty Name="Copyright">Copyright (c) Systemathics ([email protected])</StringProperty>
25+
</AnalyzerSettings>
26+
</Analyzer>
27+
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
28+
<Rules>
29+
<Rule Name="FieldNamesMustNotUseHungarianNotation">
30+
<RuleSettings>
31+
<BooleanProperty Name="Enabled">False</BooleanProperty>
32+
</RuleSettings>
33+
</Rule>
34+
</Rules>
35+
<AnalyzerSettings>
36+
<CollectionProperty Name="Hungarian">
37+
</CollectionProperty>
38+
</AnalyzerSettings>
39+
</Analyzer>
40+
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
41+
<Rules>
42+
<Rule Name="DoNotPlaceRegionsWithinElements">
43+
<RuleSettings>
44+
<BooleanProperty Name="Enabled">False</BooleanProperty>
45+
</RuleSettings>
46+
</Rule>
47+
</Rules>
48+
<AnalyzerSettings />
49+
</Analyzer>
50+
</Analyzers>
51+
</StyleCopSettings>

Shared/Auth0Utils.cs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="Auth0Utils.cs" company="Systemathics SAS">
3+
// Copyright (c) Systemathics ([email protected])
4+
// </copyright>
5+
// --------------------------------------------------------------------------------------------------------------------
6+
7+
namespace Shared
8+
{
9+
#region Usings
10+
11+
using System.IdentityModel.Tokens.Jwt;
12+
13+
using Auth0.AuthenticationApi;
14+
using Auth0.AuthenticationApi.Models;
15+
16+
#endregion
17+
18+
/// <summary>
19+
/// The Auth0 utils.
20+
/// </summary>
21+
/// <remarks>
22+
/// Given apis.systemathics.cloud API (== Audience) we also want to route permissions in the received tokens
23+
/// Auth0Dashboard: RBAC Settings > Enable RBAC
24+
/// Auth0Dashboard: RBAC Settings > Add Permissions in the Access Token
25+
/// </remarks>
26+
public static class Auth0Utils
27+
{
28+
#region Public Methods
29+
30+
/// <summary>
31+
/// Get access token for a "client" (deemed to be a machine, program, batch, etc...) authenticated using id and secret.
32+
/// </summary>
33+
/// <param name="domain">
34+
/// The domain.
35+
/// </param>
36+
/// <param name="audience">
37+
/// The audience.
38+
/// </param>
39+
/// <param name="clientId">
40+
/// The client id.
41+
/// </param>
42+
/// <param name="clientSecret">
43+
/// The client secret.
44+
/// </param>
45+
/// <param name="accessToken">
46+
/// The access token.
47+
/// </param>
48+
/// <remarks>
49+
/// The below call gets back an "access token" (what we have access to) no "id token" is received as we already proven our identity (we have the secret)
50+
/// Auth0Dashboard: "Machine-to-Machine Application"
51+
/// </remarks>
52+
public static void GetAccessToken(string domain, string audience, string clientId, string clientSecret, out JwtSecurityToken accessToken)
53+
{
54+
var auth0Client = new AuthenticationApiClient(domain);
55+
var tokenRequest = new ClientCredentialsTokenRequest { ClientId = clientId, ClientSecret = clientSecret, Audience = audience };
56+
57+
var getTokenTask = auth0Client.GetTokenAsync(tokenRequest);
58+
getTokenTask.Wait();
59+
accessToken = new JwtSecurityToken(getTokenTask.Result.AccessToken);
60+
}
61+
62+
/// <summary>
63+
/// Get access token (and id token) for a user, authenticated using username and password
64+
/// </summary>
65+
/// <param name="domain">
66+
/// The domain.
67+
/// </param>
68+
/// <param name="audience">
69+
/// The audience.
70+
/// </param>
71+
/// <param name="clientId">
72+
/// The client Id.
73+
/// </param>
74+
/// <param name="userName">
75+
/// The user Name.
76+
/// </param>
77+
/// <param name="password">
78+
/// The password.
79+
/// </param>
80+
/// <param name="accessToken">
81+
/// The access token.
82+
/// </param>
83+
/// <param name="idToken">
84+
/// The id token.
85+
/// </param>
86+
/// <remarks>
87+
/// The below call gets back an "id token" (who we are) _and_ an "access token" (what we have access to)
88+
/// Auth0Dashboard: "Regular Web Application" with "Token Endpoint Authentication Method" set to "None"
89+
/// Auth0Dashboard: "Settings" &gt; API Authorization Settings &gt; "Default Directory" set to "db" (points to internal users db)
90+
/// </remarks>
91+
public static void GetAccessToken(
92+
string domain,
93+
string audience,
94+
string clientId,
95+
string userName,
96+
string password,
97+
out JwtSecurityToken accessToken,
98+
out JwtSecurityToken idToken)
99+
{
100+
var auth0Client = new AuthenticationApiClient(domain);
101+
var tokenRequest = new ResourceOwnerTokenRequest
102+
{
103+
Audience = audience,
104+
ClientId = clientId,
105+
Username = userName,
106+
Password = password,
107+
Scope = "openid"
108+
};
109+
110+
var getTokenTask = auth0Client.GetTokenAsync(tokenRequest);
111+
getTokenTask.Wait();
112+
113+
idToken = new JwtSecurityToken(getTokenTask.Result.IdToken);
114+
accessToken = new JwtSecurityToken(getTokenTask.Result.AccessToken);
115+
}
116+
117+
#endregion
118+
}
119+
}

Shared/ConstraintsHelpers.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="ConstraintsHelpers.cs" company="Systemathics SAS">
3+
// Copyright (c) Systemathics ([email protected])
4+
// </copyright>
5+
// --------------------------------------------------------------------------------------------------------------------
6+
7+
namespace Shared
8+
{
9+
#region Usings
10+
11+
using Systemathics.Apis.Type.Shared.V1;
12+
13+
using Google.Type;
14+
15+
#endregion
16+
17+
/// <summary>
18+
/// The constraints helpers.
19+
/// </summary>
20+
public static class ConstraintsHelpers
21+
{
22+
#region Public Methods
23+
24+
/// <summary>
25+
/// The last n days.
26+
/// </summary>
27+
/// <param name="days">
28+
/// The days.
29+
/// </param>
30+
/// <returns>
31+
/// The <see cref="Constraints"/>.
32+
/// </returns>
33+
public static Constraints LastNDays(int days)
34+
{
35+
// Create time intervals
36+
var yesterday = DateTime.Today.AddDays(-1);
37+
var start = yesterday.AddDays(-days);
38+
39+
// Build the bars request date interval (we are using Google date time format : we have to cast the dates)
40+
var dateIntervals = new DateInterval
41+
{
42+
StartDate = new Date { Year = start.Year, Month = start.Month, Day = start.Day },
43+
EndDate = new Date { Year = yesterday.Year, Month = yesterday.Month, Day = yesterday.Day }
44+
};
45+
46+
// Build the bars request time interval (we are using Google date time format : we have to cast the dates)
47+
// var timeInterval = new TimeInterval
48+
// {
49+
// StartTime = new TimeOfDay { Hours = 14, Minutes = 00, Seconds = 00 },
50+
// EndTime = new TimeOfDay { Hours = 20, Minutes = 00, Seconds = 00 }
51+
// };
52+
53+
// Generate constraints based on the previous space selection:
54+
var constraints = new Constraints();
55+
constraints.DateIntervals.Add(dateIntervals);
56+
57+
// constraints.TimeIntervals.Add(timeInterval);
58+
return constraints;
59+
}
60+
61+
#endregion
62+
}
63+
}

0 commit comments

Comments
 (0)