Comments (5)
@definitelyNotACatfish Issue is related with the indexer provided by Measurement
.
You can remove the indexer as a workaround. Its main purpose is to ease the use of custom fragments. I'll provide a fix.
from cumulocity-clients-dotnet.
Hi @joerghartmann I'll wait for the fix. In the meantime I "implemented" the method in an own class for my specific needs
from cumulocity-clients-dotnet.
Could you please share the implementation with me?
from cumulocity-clients-dotnet.
Thats the method I created, basically just cp from your repo:
private async Task<bool> createMeasurementAsync(measurementsCollectionModel body)
{
Uri url = new Uri($"{httpClient.BaseAddress}measurement/measurements");
var request = new HttpRequestMessage
{
Content = new StringContent(body.ToString(), Encoding.UTF8, "application/vnd.com.nsn.cumulocity.measurementcollection+json"),
Method = HttpMethod.Post,
RequestUri = url
};
request.Headers.TryAddWithoutValidation("Content-Type", "application/vnd.com.nsn.cumulocity.measurementcollection+json");
request.Headers.TryAddWithoutValidation("Accept", "application/vnd.com.nsn.cumulocity.error+json, application/vnd.com.nsn.cumulocity.measurement+json, application/vnd.com.nsn.cumulocity.measurementcollection+json");
var response = await httpClient.SendAsync(request);
// Try to ensure successful measurement creation, else return false
try
{
response.EnsureSuccessStatusCode();
}
catch
{
return false;
}
return true;
}
The collection model is a bit ugly, but I'm in a hurry and it works:
public class measurementsCollectionModel
{
/// <summary>
/// An array containing the measurements of the request.
/// </summary>
public List<object>? measurements { get; set; } = new List<object>();
/// <summary>
/// Constructor providing measurements list
/// </summary>
public measurementsCollectionModel(List<object> measurements)
{
this.measurements = measurements;
}
/// <summary>
/// Print class as JSON, using custom JSON generation
/// </summary>
public override string ToString()
{
string json = "";
if(this.measurements == null) return "{\n\"measurements\" : []\n}";
// Create start tag
json = "{\n\"measurements\" : [\n";
// Call each measurement toString() in measurements
foreach (var measurement in this.measurements)
{
json += measurement.ToString();
json += ",";
}
// Cut away the uneccessary "," at the end
json = json.Substring(0,json.Length-1);
// Close JSON
json += "]\n}";
return json;
}
}
The custom toString() here can be ignored, I have to do some magic in the measurement classes, which I can't show and so I had to print them seperatly here.
from cumulocity-clients-dotnet.
@definitelyNotACatfish We'll ignore the indexer in our converter implementation. Extensible objects (such as Measurement, Alarm, ....) are not convertible to JSON.
from cumulocity-clients-dotnet.
Related Issues (9)
- NotificationSubscription.Context.MO does not work as intended HOT 6
- Main branch not buildable HOT 1
- No method for generating an access token HOT 3
- [JsonPropertyName("api")] in NotificationSubscription.cs not correct HOT 2
- Fix resourcePath concatenating absolute paths
- base address has slash appendix HOT 1
- remove warning count
- Add support for setting processing modes (e.g. transient, quiescent) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cumulocity-clients-dotnet.