Skip to content

Commit

Permalink
Dime.Scheduler Cloud SDK (#150)
Browse files Browse the repository at this point in the history
* Use API key authn

* Exception handling

* Use API endpoints and bump RestSharp

* Use API endpoints and bump RestSharp

* Map SDK to API service

* Add endpoints

* Import

* Routes, verbs and endpoints

* Add AppointmentNo to appointment graph

* Add flag to create job along with a task

* Optional source app/type parameters in appointment attributes

* Add Appointment No to notification #142

* Remove import params to appointment no

* Notification enum

* Undo notification type

* Bump package

* Simplify DimeSchedulerClient initialization

* Examples

* Readme

* Namespaces and refactoring

* Validate parameters

* Required parameters and connector endpoint

* Eliminate requirement for source app & type when removing appointments

* Bump package

* Namespacing

* Bump version to beta.1

* Example console app
  • Loading branch information
hbulens authored Nov 29, 2023
1 parent e2ded1d commit eb3d3c2
Show file tree
Hide file tree
Showing 232 changed files with 2,072 additions and 1,738 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Dime Software
Copyright (c) 2023 Dime Software

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
80 changes: 12 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div align="center">
<img src="https://cdn.dimescheduler.com/dime-scheduler/Dime.Scheduler-Black.svg" height="75px" />
<img src="https://cdn.dimescheduler.com/dime-scheduler/v2/logo.svg" height="75px" />
</div>

<p align="center">
<img src="assets/connect.svg?raw=true" width="350px">
</p>

<p align="center">
<img src="https://img.shields.io/azure-devops/build/dimesoftware/utilities/194?style=flat-square" /> <img src="https://img.shields.io/azure-devops/tests/dimesoftware/utilities/194?compact_message&style=flat-square" /> <img src='https://img.shields.io/nuget/vpre/dime.scheduler.sdk?style=flat-square' /> <img src="https://img.shields.io/azure-devops/coverage/dimesoftware/Utilities/194?style=flat-square" /> <img<img src="https://img.shields.io/nuget/v/Dime.Scheduler.Sdk?style=flat-square" /> <img src="https://github.com/dime-scheduler/sdk-dotnet/actions/workflows/codeql-analysis.yml/badge.svg" /> <img src='https://api.codeclimate.com/v1/badges/65852a78e1a9b7633574/maintainability' /> <img src="https://img.shields.io/badge/License-MIT-brightgreen.svg?style=flat-square"/> <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" />
<img src="https://img.shields.io/azure-devops/build/dimesoftware/utilities/194?style=flat-square" /> <img src="https://img.shields.io/azure-devops/tests/dimesoftware/utilities/194?compact_message&style=flat-square" /> <img src='https://img.shields.io/nuget/vpre/dime.scheduler?style=flat-square' /> <img src="https://img.shields.io/azure-devops/coverage/dimesoftware/Utilities/194?style=flat-square" /> <img<img src="https://img.shields.io/nuget/v/Dime.Scheduler.Sdk?style=flat-square" /> <img src="https://github.com/dime-scheduler/sdk-dotnet/actions/workflows/codeql-analysis.yml/badge.svg" /> <img src='https://api.codeclimate.com/v1/badges/65852a78e1a9b7633574/maintainability' /> <img src="https://img.shields.io/badge/License-MIT-brightgreen.svg?style=flat-square"/> <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" />
<a href="https://github.com/dime-scheduler/sdk-dotnet/discussions">
<img src="https://img.shields.io/badge/chat-discussions-brightgreen?style=flat-square">
</a>
Expand All @@ -27,88 +27,32 @@ This repository contains the .NET SDK for Dime.Scheduler's. The SDK is a gateway

Use the package manager NuGet to install the SDK:

`dotnet add package Dime.Scheduler.Sdk`
`dotnet add package Dime.Scheduler`

> Note: The SDK is still in preview. Do not use for production purposes just yet.
> [!IMPORTANT]
> Version 2 and onwards is only forwards compatible with Dime.Scheduler cloud.
> The `Dime.Scheduler.Sdk` package is maintained for the on-premises version.
## Prerequisites

To clone and run this application, you'll need Visual Studio 2022 or higher. The application is built with C# 10 and targets:

- .NET Standard 2.0
- .NET Standard 2.1
- .NET
- .NET 6

The SDK is currently only supported for the latest version of Dime.Scheduler. Once released, versioning of the SDK will take Dime.Schedulers versions into account.
To clone and run this application, you'll need Visual Studio 2022 or higher. It is built on the latest versions of .NET and C#.

## Usage

The example below fetches the resources available in Dime.Scheduler:

```csharp
string uri = "http://mydimescheduler.com";
IAuthenticator authenticator = new FormsAuthenticator(uri,"admin","admin");

DimeSchedulerClient client = new(uri, authenticator);

IResourceEndpoint resourceEndpoint = await client.Resources.Request();
IEnumerable<Resource> resources = await resourceEndpoint.GetAsync(new ResourceRequest());

foreach (Resource resource in resources)
Console.WriteLine(resource.Email);
```

The `DimeSchedulerClient` class is the entry point and it is where all endpoints are exposed:

```csharp
DimeSchedulerClient client = new(uri, authenticator);
```

Two arguments are required: the URI to Dime.Scheduler and credentials to connect to it. The `IAuthenticator` (with `FormsAuthenticator` as the default implementation) interface is called when an endpoint is requested:

```csharp
IResourceEndpoint resourceEndpoint = await client.Resources.Request();
```

When the credentials are invalid, an exception is thrown. Otherwise, the user is authenticated and can access the endpoint:

```csharp
IEnumerable<Resource> resources = await resourceEndpoint.GetAsync(new ResourceRequest());
DimeSchedulerClient client = new("key");
```

## Import

The import API is the entry point for external systems to feed data into Dime.Scheduler. The import endpoints expose a set of import pipelines to map and save data in the Dime.Scheduler database. Any class that implements the `IImportRequestable` interface is eligible to be processed by the import service in Dime.Scheduler.
> [!TIP]
> An optional argument is available to use the sandbox environment.
This example adds or updates a category:
Instantiate the object of choice and run it by its corresponding endpoint in the SDK.

```csharp
using Dime.Scheduler.Sdk.Import;

string uri = "http://mydimescheduler.com";
IAuthenticator authenticator = new FormsAuthenticator(uri, "admin", "admin");

DimeSchedulerClient client = new(uri, authenticator);

Category category = new("Category #1", "#6e62b5");
IImportEndpoint importEndpoint = await client.Import.Request();
await importEndpoint.RunAsync(category, TransactionType.Append);
```

This example adds or updates a filter group:

```csharp
using Dime.Scheduler.Sdk.Import;

string uri = "http://mydimescheduler.com";
IAuthenticator authenticator = new FormsAuthenticator(uri, "admin", "admin");

DimeSchedulerClient client = new(uri, authenticator);

FilterGroup filterGroup = new FilterGroup { Name = "Group 1" };
IImportEndpoint importEndpoint = await client.Import.Request();
await importEndpoint.RunAsync(filterGroup, TransactionType.Append);
await client.Categories.CreateAsync(category);
```

## Read more
Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div align="center">
<img src="https://cdn.dimescheduler.com/dime-scheduler/Dime.Scheduler-Black.svg" height="75px" />
<img src="https://cdn.dimescheduler.com/dime-scheduler/v2/logo.png" height="75px" />
</div>

<h1 align="center">Dime.Scheduler SDK for .NET examples</h1>

> Check out the **[📚 docs »](https://sdk.dimescheduler.com)** for more info.
> Check out the **[📚 docs »](https://docs.dimescheduler.com/develop)** for more info.
The notebooks in this directory can be run in Visual Studio with the [Notebook Editor](https://marketplace.visualstudio.com/items?itemName=MLNET.notebook).
The notebooks in this directory can be run in VS Code using .NETET Interactive and Polyglot Notebooks.

| File | Description |
| ---------------- | --------------- |
Expand Down
36 changes: 36 additions & 0 deletions examples/console/AppendResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Dime.Scheduler;
using Spectre.Console;

public class AppendResource
{
public AppendResource(Dime.Scheduler.Environment environment, string key)
{
Environment = environment;
Key = key;
}

private Dime.Scheduler.Environment Environment { get; }
private string Key { get; }

public async Task Run()
{
DimeSchedulerClient client = new(Key, Environment);

string name = AnsiConsole.Ask<string>("What is the name of the resource?");
string resourceNo = AnsiConsole.Ask<string>("What is their employee code?");

Dime.Scheduler.Entities.Resource resource = new()
{
SourceApp = "EXAMPLE",
SourceType = "EXAMPLE",
DisplayName = name,
ResourceNo = resourceNo
};

await AnsiConsole.Status().Start("Saving...", async ctx =>
{
await client.Resources.CreateAsync(resource);
Thread.Sleep(2000);
});
}
}
41 changes: 41 additions & 0 deletions examples/console/AppendTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Dime.Scheduler;
using Spectre.Console;

public class AppendTask
{
public AppendTask(Dime.Scheduler.Environment environment, string key)
{
Environment = environment;
Key = key;
}

private Dime.Scheduler.Environment Environment { get; }
private string Key { get; }

public async Task Run()
{
DimeSchedulerClient client = new(Key, Environment);

string name = AnsiConsole.Ask<string>("Name of this task:");
string descr = AnsiConsole.Ask<string>("Short description:");

// Required fields in a task include Source App, Source Type, Job No, Task No, Short Description
// By setting the CreateJob property to true, Dime.Scheduler will automatically create a job for this task
Dime.Scheduler.Entities.Task task = new()
{
SourceApp = "EXAMPLE",
SourceType = "EXAMPLE",
JobNo = name,
TaskNo = name,
Description = descr,
ShortDescription = descr.Length < 50 ? descr : descr.Substring(0, 50),
CreateJob = true
};

await AnsiConsole.Status().Start("Saving...", async ctx =>
{
await client.Tasks.CreateAsync(task);
Thread.Sleep(2000);
});
}
}
15 changes: 15 additions & 0 deletions examples/console/Dime.Scheduler.Examples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dime.Scheduler" Version="1.0.0-beta.1" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
</ItemGroup>

</Project>
42 changes: 42 additions & 0 deletions examples/console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Spectre.Console;

bool again = true;
do
{
// Step 1: action selection
string action = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What would you like to try out?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to show more examples)[/]")
.AddChoices(new[] { "Task", "Resource" }));

// Step 2: environment selection
string environment = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What environment should we be running the command on?")
.PageSize(10)
.AddChoices(new[] { "Production", "Sandbox" }));

Dime.Scheduler.Environment env = environment == "Production" ? Dime.Scheduler.Environment.Production : Dime.Scheduler.Environment.Sandbox;

// Step 3: API key
string key = AnsiConsole.Ask<string>("Please share the API key to use:");

switch (action)
{
case "Task":
AppendTask taskCmd = new(env, key);
await taskCmd.Run();
break;

case "Resource":
AppendResource resourceCmd = new(env, key);
await resourceCmd.Run();
break;
}

if (!AnsiConsole.Confirm("Want to do anything else?"))
again = false;
}
while (again);
Loading

0 comments on commit eb3d3c2

Please sign in to comment.