Code Monkey home page Code Monkey logo

cumulocity-clients-dotnet's Introduction

CumulocityCoreLibrary

Usage

Use the public factory to access API classes. The factory is available as a singleton and groups API classes by category.

using Com.Cumulocity.Client.Supplementary;

var factory = new CumulocityCoreLibrary(...);
var api = factory.Applications.ApplicationsApi;

In addition, each API class provides a public initializer.

var api = ApplicationsApi()

The HttpClient needs to be an argument for creating each API class and for creating the creating.

Configure request information

Additional request information need to be configured for each API class, such as HTTP scheme, host name or additional headers (i.e. Authorization header). The client is using the System.Net library and thus a HttpClient needs to be configured. Before creating the API classes, make sure that the BaseAdress configured as followed:

var uri = new Uri(...);
var httpClient = new HttpClient();
httpClient.BaseAddress = uri;
var factory = new CumulocityCoreLibrary(httpClient);

Use your own domain model

The CumulocityCoreLibrary allows custom data models. The following classes are designed to be extensible:

  • Alarm, AuditRecord, CategoryOptions, CustomProperties, Event, ManagedObject, Measurement, Operation

Those classes allow to add an arbitrary number of additional properties as a list of key-value pairs. These properties are known as custom fragments and can be of any type. Each custom fragment is identified by a unique name. Thus, developers can propagate their custom fragments using:

Alarm.Serialization.RegisterAdditionalProperty(String, Type);

Each of the extensible objects contains a dictionary object holding instances of custom fragments. Use the custom fragment's key to access its value.

Tests

Example usage is explained within the Test project. To configure the tests, it's required to specify host and credentials. Locate the appsettings.test.json file and configure the settings:

{
	"Configuration": {
		"Hostname": "http://... or https://...",
		"Username": "...",
		"Password": "***"
	}
}

Basic Authentication

The client sends HTTP requests with the Authorization header. Use the NetworkCredential class to pass user name and password.

using System;
using System.Net;
using System.Net.Http;

var httpClientHandler = new HttpClientHandler()
{
	Credentials = new NetworkCredential("userName", ",***")
};
var httpClient = new HttpClient(httpClientHandler);

Contribution

If you've spotted something that doesn't work as you'd expect, or if you have a new feature you'd like to add, we're happy to accept contributions and bug reports.

For bug reports, please raise an issue directly in this repository by selecting the issues tab and then clicking the new issue button. Please ensure that your bug report is as detailed as possible and allows us to reproduce your issue easily.

In the case of new contributions, please create a new branch from the latest version of main. When your feature is complete and ready to evaluate, raise a new pull request.


These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project.

cumulocity-clients-dotnet's People

Contributors

joerghartmann avatar markjmreynolds-sag avatar openapi-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cumulocity-clients-dotnet's Issues

No method for generating an access token

When I want to generate an access token, to access the inventory, I can't use the LoginTokenAPI. The class does not contain any method got generate the token. Is the class obsolete?

NotificationSubscription.Context.MO does not work as intended

Hi,

when I try to subscribe using CreateSubscription from "NotificationSubscription.cs", the generated "NotificationSubscription" body as input parameter looks like this:

{
  "context": "MO",
  "source": {
    "id": "wonderfulID"
  },
  "subscription": "Subscription",
  "subscriptionFilter": {
    "api": [
      "events"
    ],
    "typeFilter": "c8y_LoriotUplinkRequest"
  }
}

It does not correctly convert the context, it seems that it does not use the "[EnumMember(Value = "mo")]" of enum "Context".
Anyway, when I change the enum "MO" to "mo" in "NotificationSubscription.cs"

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Context 
{
	[EnumMember(Value = "mo")]
	mo,
	[EnumMember(Value = "tenant")]
	tenant
}

it works:

{
  "context": "mo",
  "source": {
    "id": "wonderfulID"
  },
  "subscription": "Subscription",
  "subscriptionFilter": {
    "api": [
      "events"
    ],
    "typeFilter": "c8y_LoriotUplinkRequest"
  }
}

Add support for setting processing modes (e.g. transient, quiescent)

Add support for setting the Cumulocity processing mode on all PUT, POST and DELETE requests.

This is documented in the general section of the docs under "Processing mode".

Use-case

In order to save costs, some measurements are pushed to the platform using the TRANSIENT processing mode so that the measurements are visible in the UI however they are not persisted in the platform.

Feature details

  • Ability to set it on a per-request basis (using default headers would add this mode for all requests, which is often not desired)

Can't generate a measurement using MeasurementsAPI

I'm trying to create measurements via MeasurementsApi.CreateMeasurement, but I get an exception every time. I'm using this code to generate a measurement:

var measurement = new Measurement(
      new Measurement.Source("12345678"),
      DateTime.Now,
      "mytestType"
  );
  measurement.CustomFragments = new Dictionary<string, object>{
      {
          "myValue",
          new Dictionary<string, MeasurementValue>{
              {"nested", new MeasurementValue{value=1.234, unit="V"}}
          }
      }
  };

  var response = measurementsApi.CreateMeasurement(new MeasurementCollection<Measurement>(new List<Measurement> { measurement }));

I dug down the rabbit hole and found out, that it fails, because the Measurement class does not have the property "Item".
By using "CreateMeasurement" in the first lines it tries to convert the body to a "JsonNode". The "JsonNode" contains "Item" as default member.

Do I miss something or is it a bug? What's the best work arround currently?

Main branch not buildable

Currently (29.11.2022), the main branch is not build able by default. I had to comment out 2 Files:

  • IInventoryApi.cs
  • InventoryApi.cs

I didn't check what the problem excaclty is, because I don't need these files, but can you please check?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.