Skip to content

Commit

Permalink
feat: introduce CommunityToolkit.Diagnostics for guards (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
berezovskyi authored Jan 30, 2025
1 parent f47cebd commit aea7341
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 106 deletions.
4 changes: 2 additions & 2 deletions OSLC4Net_SDK/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<PackageVersion Include="NuGet.Build.Tasks.Pack" Version="6.12.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="System.Json" Version="4.8.0" />

<!-- depedencyManagement / convergence -->
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<!-- Main deps -->
<PackageVersion Include="dotNetRdf.Core" Version="3.3.2" />
<PackageVersion Include="Antlr3.Runtime" Version="3.5.1" />
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.4.0" />
<!-- conneg support &c for System.Net.Http -->
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<!-- Test deps -->
Expand All @@ -41,4 +41,4 @@
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="dotNetRdf" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ProjectReference Include="..\OSLC4Net.Core\OSLC4Net.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="log4net" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions OSLC4Net_SDK/OSLC4Net.Client/OSLC4Net.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<ProjectReference Include="..\OSLC4Net.Core.DotNetRdfProvider\OSLC4Net.Core.DotNetRdfProvider.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="dotNetRdf.Core"/>
<PackageReference Include="Microsoft.AspNet.WebApi.Client"/>
<PackageReference Include="log4net"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ProjectReference Include="..\OSLC4Net.Core\OSLC4Net.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="log4net" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" />
<PackageReference Include="Newtonsoft.Json" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ProjectReference Include="..\OSLC4Net.Core\OSLC4Net.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="System.Json" />
<PackageReference Include="log4net" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ProjectReference Include="..\OSLC4Net.Core\OSLC4Net.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="log4net" />
<PackageReference Include="Antlr3.Runtime" />
</ItemGroup>
Expand Down
219 changes: 115 additions & 104 deletions OSLC4Net_SDK/OSLC4Net.Core/Model/ServiceProvider.cs
Original file line number Diff line number Diff line change
@@ -1,205 +1,216 @@
/*******************************************************************************
* Copyright (c) 2012 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Steve Pitschke - initial API and implementation
*******************************************************************************/

using OSLC4Net.Core.Attribute;

namespace OSLC4Net.Core.Model;

/// <summary>
/// OSLC ServiceProvider resource
/// </summary>
[OslcNamespace(OslcConstants.OSLC_CORE_NAMESPACE)]
[OslcResourceShape(title = "OSLC Service Provider Resource Shape", describes = new string[] { OslcConstants.TYPE_SERVICE_PROVIDER })]
public class ServiceProvider : AbstractResource
{
private readonly SortedSet<Uri> details = new SortedUriSet();
private readonly IList<PrefixDefinition> prefixDefinitions = new List<PrefixDefinition>();
private readonly IList<Service> services = new List<Service>();

private DateTime? created; // TODO - ServiceProvider.created nice to have, but not required.
private string description;
private string identifier; // TODO - ServiceProvider.identifier nice to have, but not required.
private OAuthConfiguration oauthConfiguration;
private Publisher publisher;
private string title;

public ServiceProvider() : base()
{
}

public void AddService(Service srvc)
{
this.services.Add(srvc);
}

[OslcDescription("The date and time that this resource was created")]
[OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "created")]
[OslcReadOnly]
[OslcTitle("Created")]
/*******************************************************************************
* Copyright (c) 2012 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Steve Pitschke - initial API and implementation
*******************************************************************************/

using CommunityToolkit.Diagnostics;
using OSLC4Net.Core.Attribute;

namespace OSLC4Net.Core.Model;

/// <summary>
/// OSLC ServiceProvider resource
/// </summary>
[OslcNamespace(OslcConstants.OSLC_CORE_NAMESPACE)]
[OslcResourceShape(title = "OSLC Service Provider Resource Shape", describes =
[
OslcConstants.TYPE_SERVICE_PROVIDER
])]
public class ServiceProvider : AbstractResource
{
private readonly SortedSet<Uri> _details = new SortedUriSet();
private readonly IList<PrefixDefinition> _prefixDefinitions = new List<PrefixDefinition>();
private readonly IList<Service> _services = new List<Service>();

private DateTime? _created; // TODO - ServiceProvider.created nice to have, but not required.
private string _description;
private string _identifier; // TODO - ServiceProvider.identifier nice to have, but not required.
private OAuthConfiguration _oauthConfiguration;
private Publisher _publisher;
private string _title;

public ServiceProvider() : base()
{
}

public void AddService(Service service)
{
Guard.IsNotNull(service, nameof(service));
this._services.Add(service);
}

[OslcDescription("The date and time that this resource was created")]
[OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "created")]
[OslcReadOnly]
[OslcTitle("Created")]
public DateTime? GetCreated()
{
return created;
{
return _created;
}

[OslcDescription("Description of the service provider")]
[OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "description")]
[OslcReadOnly]
[OslcReadOnly]
[OslcTitle("Description")]
[OslcValueType(ValueType.XMLLiteral)]
[OslcValueType(ValueType.XMLLiteral)]
public string GetDescription()
{
return description;
return _description;
}

[OslcDescription("URLs that may be used to retrieve web pages to determine additional details about the service provider")]
[OslcPropertyDefinition(OslcConstants.OSLC_CORE_NAMESPACE + "details")]
[OslcReadOnly]
[OslcTitle("Details")]
[OslcReadOnly]
[OslcTitle("Details")]
public Uri[] GetDetails()
{
return details.ToArray();
return _details.ToArray();
}

[OslcDescription("A unique identifier for this resource")]
[OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "identifier")]
[OslcReadOnly]
[OslcTitle("Identifier")]
[OslcDescription("A unique identifier for this resource")]
[OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "identifier")]
[OslcReadOnly]
[OslcTitle("Identifier")]
public string GetIdentifier()
{
return identifier;
{
return _identifier;
}

[OslcDescription("Defines the three OAuth URIs required for a client to act as an OAuth consumer")]
[OslcPropertyDefinition(OslcConstants.OSLC_CORE_NAMESPACE + "oauthConfiguration")]
[OslcRange(OslcConstants.TYPE_O_AUTH_CONFIGURATION)]
[OslcReadOnly]
[OslcReadOnly]
[OslcRepresentation(Representation.Inline)]
[OslcTitle("OAuth Configuration")]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_OAUTH_CONFIGURATION)]
[OslcValueType(ValueType.LocalResource)]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_OAUTH_CONFIGURATION)]
[OslcValueType(ValueType.LocalResource)]
public OAuthConfiguration GetOauthConfiguration()
{
return oauthConfiguration;
return _oauthConfiguration;
}

[OslcDescription("Defines namespace prefixes for use in JSON representations and in forming OSLC Query Syntax strings")]
[OslcName("prefixDefinition")]
[OslcPropertyDefinition(OslcConstants.OSLC_CORE_NAMESPACE + "prefixDefinition")]
[OslcRange(OslcConstants.TYPE_PREFIX_DEFINITION)]
[OslcReadOnly]
[OslcReadOnly]
[OslcRepresentation(Representation.Inline)]
[OslcTitle("Prefix Definitions")]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_PREFIX_DEFINITION)]
[OslcValueType(ValueType.LocalResource)]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_PREFIX_DEFINITION)]
[OslcValueType(ValueType.LocalResource)]
public PrefixDefinition[] GetPrefixDefinitions()
{
return prefixDefinitions.ToArray();
return _prefixDefinitions.ToArray();
}

[OslcDescription("Describes the software product that provides the implementation")]
[OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "publisher")]
[OslcRange(OslcConstants.TYPE_PUBLISHER)]
[OslcReadOnly]
[OslcReadOnly]
[OslcRepresentation(Representation.Inline)]
[OslcTitle("Publisher")]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_PUBLISHER)]
[OslcValueType(ValueType.LocalResource)]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_PUBLISHER)]
[OslcValueType(ValueType.LocalResource)]
public Publisher GetPublisher()
{
return publisher;
return _publisher;
}

[OslcDescription("Describes services offered by the service provider")]
[OslcName("service")]
[OslcOccurs(Occurs.OneOrMany)]
[OslcPropertyDefinition(OslcConstants.OSLC_CORE_NAMESPACE + "service")]
[OslcRange(OslcConstants.TYPE_SERVICE)]
[OslcReadOnly]
[OslcReadOnly]
[OslcRepresentation(Representation.Inline)]
[OslcTitle("Services")]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_SERVICE)]
[OslcValueShape(OslcConstants.PATH_RESOURCE_SHAPES + "/" + OslcConstants.PATH_SERVICE)]
[OslcValueType(ValueType.LocalResource)]
public Service[] GetServices()
{
return services.ToArray();
return _services.ToArray();
}

[OslcDescription("Title of the service provider")]
[OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "title")]
[OslcReadOnly]
[OslcReadOnly]
[OslcTitle("Title")]
[OslcValueType(ValueType.XMLLiteral)]
[OslcValueType(ValueType.XMLLiteral)]
public string GetTitle()
{
return title;
return _title;
}

public void SetCreated(DateTime? created)
{
this.created = created;
}

{
this._created = created;
}

public void SetDescription(string description)
{
this.description = description;
this._description = description;
}

public void SetDetails(Uri[] details)
{
this.details.Clear();
this._details.Clear();
if (details != null)
{
this.details.AddAll(details);
{
this._details.AddAll(details);
}
}

public void SetIdentifier(string identifier)
{
this.identifier = identifier;
{
this._identifier = identifier;
}

public void SetOauthConfiguration(OAuthConfiguration oauthConfiguration)
{
this.oauthConfiguration = oauthConfiguration;
this._oauthConfiguration = oauthConfiguration;
}

public void SetPrefixDefinitions(PrefixDefinition[] prefixDefinitions)
{
this.prefixDefinitions.Clear();
this._prefixDefinitions.Clear();
if (prefixDefinitions != null)
{
this.prefixDefinitions.AddAll(prefixDefinitions);
{
this._prefixDefinitions.AddAll(prefixDefinitions);
}
}

public void SetPublisher(Publisher publisher)
{
this.publisher = publisher;
this._publisher = publisher;
}

public void SetServices(Service[] services)
public void SetServices(Service[]? services)
{
this.services.Clear();
this._services.Clear();
if (services != null)
{
this.services.AddAll(services);
{
this._services.AddAll(services);
}
}

public void SetServices(IEnumerable<Service> services)
{
this._services.Clear();
this._services.AddAll(services);
}

public void SetTitle(string title)
{
this.title = title;
}
}
this._title = title;
}
}
1 change: 1 addition & 0 deletions OSLC4Net_SDK/OSLC4Net.Core/OSLC4Net.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" />
<PackageReference Include="log4net" />
</ItemGroup>
</Project>
Loading

0 comments on commit aea7341

Please sign in to comment.