Skip to content

Commit

Permalink
add support for CDM TimeSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
ozangoktan committed Sep 3, 2024
1 parent 77b8971 commit 8042a11
Show file tree
Hide file tree
Showing 26 changed files with 1,052 additions and 120 deletions.
211 changes: 211 additions & 0 deletions CogniteSdk.Types/Alpha/Common/Identity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// Copyright 2020 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using System;
using CogniteSdk.Beta.DataModels;

namespace CogniteSdk.Alpha
{
/// <summary>
/// Identity class. Set either Id, ExternalId or InstanceId.
/// </summary>
public class IdentityWithInstanceId : IIdentity
{
private InstanceIdentifier _instanceId;
private long? _id;
private string _externalId;

/// <summary>
/// Creates an identity with externalId set.
/// </summary>
/// <param name="externalId">The externalId to set</param>
public IdentityWithInstanceId(string externalId)
{
ExternalId = externalId;
}

/// <summary>
/// Creates an identity with internalId set.
/// </summary>
/// <param name="id">The internalId to set</param>
public IdentityWithInstanceId(long id)
{
Id = id;
}

/// <summary>
/// Creates an identity with externalId and space set.
/// </summary>
/// <param name="instanceId">Instance Identifier containing space and externalId</param>
public IdentityWithInstanceId(InstanceIdentifier instanceId)
{
InstanceId = instanceId;
}

/// <summary>
/// Identity with internal id.
/// </summary>
public long? Id
{
get => _id;
set
{
if (_externalId != null)
{
throw new ArgumentException($"Cannot set Id ({value}) when ExternalId ({_externalId}) is already set.");
}
if (_instanceId != null)
{
throw new ArgumentException($"Cannot set Id ({value}) when InstanceId ({_instanceId}) is already set.");
}

_id = value;
}
}

/// <summary>
/// Identity with externalId
/// </summary>
public string ExternalId
{
get => _externalId;
set
{
if (_id.HasValue)
{
throw new ArgumentException($"Cannot set externalId ({value}) when Id ({_id}) is already set.");
}
if (_instanceId != null)
{
throw new ArgumentException($"Cannot set externalId ({value}) when InstanceId ({_instanceId}) is already set.");
}

_externalId = value;
}
}
/// <summary>
/// Identity with instanceId
/// </summary>
public InstanceIdentifier InstanceId
{
get => _instanceId;
set
{
if (_id.HasValue)
{
throw new ArgumentException($"Cannot set instanceId ({value}) when Id ({_id}) is already set.");
}
if (_externalId != null)
{
throw new ArgumentException($"Cannot set instanceId ({value}) when ExternalId ({_externalId}) is already set.");
}

_instanceId = value ?? new InstanceIdentifier();
}
}

/// <summary>
/// Create new external Id.
/// </summary>
/// <param name="externalId">External id value</param>
/// <returns>New external Id.</returns>
public static IdentityWithInstanceId Create(string externalId)
{
return new IdentityWithInstanceId(externalId);
}

/// <summary>
/// Create new internal Id.
/// </summary>
/// <param name="internalId">Internal id value</param>
/// <returns>New internal Id.</returns>
public static IdentityWithInstanceId Create(long internalId)
{
return new IdentityWithInstanceId(internalId);
}

/// <summary>
/// Create new instance Id.
/// </summary>
/// <param name="instanceId">Instance id value</param>
/// <returns>New instance Id.</returns>
public static IdentityWithInstanceId Create(InstanceIdentifier instanceId)
{
return new IdentityWithInstanceId(instanceId);
}

/// <summary>Returns a string that represents the current object.</summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString()
{
if (Id.HasValue)
{
return $"{{ Id = {Id} }}";
}
else if (ExternalId != null)
{
return $"{{ ExternalId = \"{ExternalId}\" }}";
}
else
{
return $"{{{InstanceId}}}";
}

}

/// <summary>
/// Return true if <paramref name="obj"/> is another, identitical Identity.
/// </summary>
/// <param name="obj">Object to compare</param>
/// <returns>True if equal, false otherwise</returns>
public override bool Equals(object obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

if (!(obj is IdentityWithInstanceId other))
{
return false;
}

if (Id.HasValue)
{
return Id == other.Id;
}

if (ExternalId != null)
{
return ExternalId == other.ExternalId;
}

if (InstanceId != null)
{
return InstanceId.Equals(other.InstanceId);
}

return !other.Id.HasValue && other.ExternalId == null && other.InstanceId == null;
}

/// <summary>
/// Returns a hashcode representing this Identity.
/// </summary>
/// <returns>Hashcode representing this</returns>
public override int GetHashCode()
{
if (Id.HasValue)
{
return Id.GetHashCode();
}
else if (InstanceId != null)
{
return InstanceId.GetHashCode();
}
else
{
return ExternalId?.GetHashCode() ?? 0;
}
}
}
}
38 changes: 38 additions & 0 deletions CogniteSdk.Types/Alpha/DataPoints/DataPointsCreate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using CogniteSdk.Alpha;
using CogniteSdk.Types.Common;
using System.Collections.Generic;

namespace CogniteSdk.Alpha
{
/// <summary>
/// Data Points write class.
/// </summary>
public class DataPointsCreate
{
/// <summary>
/// The list of data points. The limit per request is 100000 data points.
/// </summary>
public IEnumerable<DataPoint> DataPoints { get; set; }

/// <summary>
/// A server-generated ID for the object.
/// </summary>
public IdentityWithInstanceId Id { get; set; }

/// <summary>
/// The external ID provided by the client. Must be unique for the resource type.
/// </summary>
public IdentityWithInstanceId ExternalId { get; set; }

/// <summary>
/// The instance ID provided by the client. Must be unique for the resource type.
/// </summary>
public IdentityWithInstanceId InstanceId { get; set; }

/// <inheritdoc />
public override string ToString() => Stringable.ToString<DataPointsCreate>(this);
}
}
49 changes: 49 additions & 0 deletions CogniteSdk.Types/Alpha/DataPoints/DataPointsDelete.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2020 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using CogniteSdk.Beta.DataModels;
using CogniteSdk.Types.Common;

namespace CogniteSdk.Alpha
{
/// <summary>
/// Identity class with time range.
/// </summary>
public class IdentityWithRange
{
/// <summary>
/// The number of milliseconds since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC), minus
/// leap seconds.
/// </summary>
public long InclusiveBegin { get; set; }

/// <summary>
/// The number of milliseconds since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC), minus
/// leap seconds.
/// </summary>
public long? ExclusiveEnd { get; set; }

/// <summary>
/// A server-generated ID for the object.
/// </summary>
public long? Id { get; set; }

/// <summary>
/// The external ID provided by the client. Must be unique for the resource type.
/// </summary>
public string ExternalId { get; set; }

/// <summary>
/// The instance ID provided by the client. Must be unique for the resource type.
/// </summary>
public InstanceIdentifier InstanceId { get; set; }

/// <inheritdoc />
public override string ToString() => Stringable.ToString<IdentityWithRange>(this);
}

/// <summary>
/// Data Points delete type.
/// </summary>
public class DataPointsDelete : ItemsWithoutCursor<IdentityWithRange> { }
}
18 changes: 18 additions & 0 deletions CogniteSdk.Types/Alpha/DataPoints/DataPointsItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 Cognite AS
// SPDX-License-Identifier: Apache-2.0

using CogniteSdk.Beta.DataModels;

namespace CogniteSdk.Alpha
{
/// <summary>
/// Data Points item class.
/// </summary>
public class DataPointsItem<T> : CogniteSdk.DataPointsItem<T>
{
/// <summary>
/// The instance ID of the time series the data points belong to.
/// </summary>
public InstanceIdentifier InstanceId { get; set; }
}
}
Loading

0 comments on commit 8042a11

Please sign in to comment.