Skip to content

Commit 47b4705

Browse files
authored
Merge pull request #424 from danuw/docs/docusaurus-setup
DRAFT - Docs/docusaurus setup
2 parents 80fb686 + e58c157 commit 47b4705

File tree

70 files changed

+18880
-0
lines changed

Some content is hidden

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

70 files changed

+18880
-0
lines changed

casdk-docs/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

casdk-docs/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Website
2+
3+
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
4+
5+
### Installation
6+
7+
```
8+
$ yarn
9+
```
10+
11+
### Local Development
12+
13+
```
14+
$ yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
### Build
20+
21+
```
22+
$ yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26+
27+
### Deployment
28+
29+
Using SSH:
30+
31+
```
32+
$ USE_SSH=true yarn deploy
33+
```
34+
35+
Not using SSH:
36+
37+
```
38+
$ GIT_USER=<Your GitHub username> yarn deploy
39+
```
40+
41+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.

casdk-docs/babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
slug: welcome
3+
title: Welcome
4+
tags: [facebook, hello, docusaurus]
5+
---
6+
7+
Welcome to our documentation site!
8+
9+
A blog post folder can be convenient to co-locate blog post images:
10+
11+
![Docusaurus Plushie](./docusaurus-plushie-banner.jpeg)
12+
13+
The blog supports tags as well!
14+
15+
**And if you don't want a blog**: just delete this directory, and use `blog: false` in your Docusaurus config.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
slug: release-v1.1
3+
title: Release v1.1
4+
tags: [v1.1, release]
5+
---
6+
7+
Release 1.1
8+
9+
:::tip
10+
11+
Use the power of React to create interactive blog posts.
12+
13+
```js
14+
<button onClick={() => alert('button clicked!')}>Click me!</button>
15+
```
16+
17+
<button onClick={() => alert('button clicked!')}>Click me!</button>
18+
19+
:::
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"label": "Architecture",
3+
"position": 9,
4+
"link": {
5+
"type": "generated-index"
6+
}
7+
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
---
2+
sidebar_position: 4
3+
---
4+
5+
# C# Client Library
6+
7+
This document outlines the designs behind the GSF Carbon Aware C# Client
8+
Library.
9+
10+
## Namespace
11+
12+
Given the fact this is going to be a library exposing functionality to
13+
consumers, will use the
14+
[standard](https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-namespaces)
15+
namespace naming schema:
16+
`<Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]`. For GSF
17+
CarbonAware SDK this the following schema:
18+
19+
- **Company**: **_GSF_**
20+
- **Product**: **_CarbonAware_**
21+
- **Feature**: **_Models_**, **_Handlers_**, ...
22+
23+
An example of a namespace would be: `namespace GSF.CarbonAware.Models` and a
24+
class (record, interface, ...) that belongs to that namespace would be:
25+
26+
```c#
27+
namespace GSF.CarbonAware.Models;
28+
29+
public record EmissionsData
30+
{
31+
....
32+
}
33+
```
34+
35+
The following namespaces are included:
36+
37+
| namespace |
38+
| ----------------------------- |
39+
| GSF.CarbonAware.Exceptions |
40+
| GSF.CarbonAware.Configuration |
41+
| GSF.CarbonAware.Handlers |
42+
| GSF.CarbonAware.Models |
43+
| GSF.CarbonAware.Parameters |
44+
45+
## Features
46+
47+
### Models
48+
49+
There are two main classes that represents the data fetched from the data
50+
sources (i.e `Static Json`, [WattTime](https://www.watttime.org),
51+
[ElectricityMaps](https://www.electricitymaps.com), and
52+
[ElectricityMapsFree](https://www.co2signal.com/)):
53+
54+
- `EmissionsData`
55+
- `EmissionsForecast`
56+
57+
A record is defined for each of these data types owned by the library.
58+
59+
```c#
60+
namespace GSF.CarbonAware.Models;
61+
public record EmissionsData
62+
{
63+
string Location
64+
DateTimeOffset Time
65+
double Rating
66+
TimeSpan Duration
67+
}
68+
```
69+
70+
```c#
71+
namespace GSF.CarbonAware.Models;
72+
public record EmissionsForecast
73+
{
74+
DateTimeOffset RequestedAt
75+
DateTimeOffset GeneratedAt
76+
IEnumerable<EmissionsData> EmissionsDataPoints
77+
IEnumerable<EmissionsData> OptimalDataPoints
78+
}
79+
```
80+
81+
The user can expect to either have a primitive type (such as an int) or one of
82+
these specific models as a return type of the **Handlers**.
83+
84+
### Handlers
85+
86+
There will be two handlers for each of the data types returned:
87+
88+
- `EmissionsHandler`
89+
- `ForecastHandler`
90+
91+
Each is responsible for interacting on its own domain. For instance,
92+
EmissionsHandler can have a method `GetAverageCarbonIntensityAsync()` to pull
93+
EmissionsData data from a configured data source and calculate the average
94+
carbon intensity. ForecastHandler can have a method `GetCurrentAsync()`, that
95+
will return a EmissionsForecast instance. (**Note**: The current core
96+
implementation is using async/await paradigm, which would be the default for
97+
library too).
98+
99+
In addition, there is a `LocationHandler` that is responsible for retrieving all
100+
the locations supported by the underlying datasource.
101+
102+
### Parameters
103+
104+
Both handlers require that exact fields be passed in as input. Within the docs
105+
of each library function, we specifically call out which fields the function
106+
expects to be defined versus which are optional. Internally, we handle creating
107+
the CarbonAwareParameters object and validating the fields through that.
108+
109+
## Carbon Aware Parameters
110+
111+
The `CarbonAwareParameters` class allows the user to pass in a unique parameter
112+
instance to the public methods in the Handlers with the specific parameters
113+
needed by that call. The list of allowed parameters is defined in the class and
114+
includes
115+
116+
- SingleLocation
117+
- MultipleLocations
118+
- Start
119+
- End
120+
- RequestedAt
121+
- Duration
122+
123+
### Parameter Display Names
124+
125+
The display name of each parameter can be overriden using the public setter. By
126+
default, each parameter display name is set to the variable name (ex:
127+
`Start = "start"`). The parameter display names are used when creating the
128+
validation error messages. Overriding them is useful in situations where the
129+
variables the user is using for input don't exactly match the default display
130+
name of the parameter (e.g. the user variable in the controller is
131+
`periodStartTime` instead of `startTime`). That way, when the error is thrown to
132+
the user, the parameter names will match the users' expectation
133+
134+
To do the override, define a class that inherits from
135+
CarbonAwareParametersBaseDTO and uses the [FromQuery(Name =
136+
"myAwesomeDisplayName")] or [JsonPropertyName("myAwesomeDisplayName")]
137+
attribute. A second (less recommended) option is to pass the optional arg
138+
Dictionary<string, string>? displayNameMap when you are directly creating the
139+
object. With either option, the SDK handles updating references internally.
140+
141+
### Required Properties
142+
143+
The first core check the parameters class does is validating that required
144+
parameters are defined. By default, all parameters are considered optional.
145+
Calling the `SetRequiredProperties(...)` function with the desired arguments
146+
sets the required parameters for the instance.
147+
148+
```csharp
149+
/// <summary>
150+
/// Accepts any PropertyNames as arguments and sets the associated property as required for validation.
151+
/// </summary>
152+
public void SetRequiredProperties(params PropertyName[] requiredProperties)
153+
```
154+
155+
### Validations
156+
157+
The second core check the parameters class does is enforcing validations on the
158+
parameters themselves. Some common examples include
159+
160+
- Relationship validations: _`start < end` must be true_
161+
- Content validations: _`list.Any()` must be true for list fields_
162+
163+
Calling the `SetValidations(...)` function with the desired arguments sets the
164+
validations for the instance.
165+
166+
```csharp
167+
/// <summary>
168+
/// Accepts any ValidationName as arguments and sets the associated validation to check.
169+
/// </summary>
170+
public void SetValidations(params ValidationName[] validationNames)
171+
```
172+
173+
### Validate
174+
175+
Calling the `Validate(...)` function validates (1) required parameters and (2)
176+
specified validations. Currently, the only validation we check is whether
177+
`start` is before `end`.
178+
179+
If no errors are thrown, the function simply returns. If any validation errors
180+
are found, they are packaged into a single `ArgumentException` error with each
181+
being part of the `data` dictionary.
182+
183+
```
184+
/// <summary>
185+
/// Validates the properties and relationships between properties. Any validation errors found are packaged into an
186+
/// ArgumentException and thrown. If there are no errors, simply returns void.
187+
/// </summary>
188+
public void Validate()
189+
```
190+
191+
### Getters With Default Fallbacks
192+
193+
Certain parameters have special getters that allow you to define a fallback
194+
default value if the parameter is null. This can be useful in cases where a
195+
parameter is optional, so you want to get it if it was defined by the user, or
196+
otherwise fallback to a specific default. These include `Start`, `End`,
197+
`Requested`,and `Duration`
198+
199+
```
200+
DateTimeOffset StartOrDefault(DateTimeOffset defaultStart)
201+
DateTimeOffset EndOrDefault(DateTimeOffset defaultEnd)
202+
DateTimeOffset RequestedOrDefault(DateTimeOffset defaultRequested)
203+
TimeSpan DurationOrDefault
204+
205+
```
206+
207+
### Error Handling
208+
209+
The `CarbonAwareException` class is used to report errors to the consumer. It
210+
follows the `Exception` class approach, where messages and details are provided
211+
as part of error reporting.
212+
213+
## References
214+
215+
<https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/>

0 commit comments

Comments
 (0)