Skip to content

Draft: Cleanup/code guidelines #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: future
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<PropertyGroup>
<dotnetVersion>8.0.0</dotnetVersion>
<efCoreVersion>8.0.4</efCoreVersion>

<LangVersion>latest</LangVersion>
</PropertyGroup>

<!-- Package refereces for all projects if IsPackable=true -->
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/Core/BinaryConnection.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ The following table illustrates differences between Little-Endian and Big-Endian

### .NET Conversion-Methods

The .Net-Framework offers serveral Helper Methods and Classes and should be used for the conversion of data before sending it via network. To make sure, that multibyte values have the right byte order before being converted in to a byte-stream use [IpAdress.HostToNetworkOrder](https://msdn.microsoft.com/de-de/library/653kcke1%28v=vs.110%29.aspx) For incoming data [IpAddress.NetworkToHostOrder](https://msdn.microsoft.com/de-de/library/system.net.ipaddress.networktohostorder%28v=vs.100%29.aspx) maybe used.
The .Net-Framework offers serveral Helper Methods and Classes and should be used for the conversion of data before sending it via network. To make sure, that multibyte values have the right byte order before being converted in to a byte-stream use [.HostToNetworkOrder](https://msdn.microsoft.com/de-de/library/653kcke1%28v=vs.110%29.aspx) For incoming data [IpAddress.NetworkToHostOrder](https://msdn.microsoft.com/de-de/library/system.net.ipaddress.networktohostorder%28v=vs.100%29.aspx) maybe used.

To create Byte-Arrays the .Net-class [BitConverter](https://msdn.microsoft.com/en-us/library/vstudio/system.bitconverter%28v=vs.100%29.aspx) may be used after the multibyte values have been converted into the right order.
7 changes: 7 additions & 0 deletions docs/migrations/v8_to_v10.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
## Removal of ProductFileEntity

The `ProductFileEntity` was not used in the product-model. There was no api to access it in a simple way. With the implementation of the [`FileSystem`](https://github.com/PHOENIXCONTACT/MORYX-Framework/pull/517) it is also not required anymore.

## Renamings and Typo-Fixes

- TcpClientConfig.IpAdress -> TcpClientConfig.IpAddress
- TcpListenerConfig.IpAdress -> TcpListenerConfig.IpAddress
- ResourceRelationType.CurrentExchangablePart -> ResourceRelationType.CurrentExchangeablePart
- ResourceRelationType.PossibleExchangablePart -> ResourceRelationType.PossibleExchangeablePart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Runtime.Serialization;
using Moryx.AbstractionLayer.Recipes;
using Moryx.Serialization;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Moryx.Configuration;
using Moryx.Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
using Moryx.Serialization;
using Moryx.Tools;
using Moryx.Workplans;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Moryx.AbstractionLayer.Products.Endpoints
Expand Down Expand Up @@ -131,7 +128,7 @@ private void ConvertParts(IProductType productType, IEnumerable<PropertyInfo> pr
Name = property.Name,
DisplayName = displayName,
Type = FetchProductType(property.PropertyType),
Parts = partModel is null ? new PartModel[0] : new[] { partModel },
Parts = partModel is null ? [] : [partModel],
PropertyTemplates = EntryConvert.EncodeClass(property.PropertyType, _productSerialization)
};
connectors.Add(connector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
using Microsoft.AspNetCore.Mvc;
using Moryx.AbstractionLayer.Recipes;
using Moryx.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using Moryx.Serialization;
using System.Net;
using Microsoft.AspNetCore.Authorization;
using Moryx.Configuration;
using Moryx.Asp.Extensions;
using Moryx.AbstractionLayer.Properties;
using Microsoft.Extensions.DependencyInjection;
using Moryx.AbstractionLayer.Resources;
using Moryx.Runtime.Modules;
using System.ComponentModel;

namespace Moryx.AbstractionLayer.Products.Endpoints
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Moryx.AbstractionLayer.Properties;
using Moryx.Asp.Extensions;
using Moryx.Workplans;
using System.Collections.Generic;

namespace Moryx.AbstractionLayer.Products.Endpoints
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;
using System.Linq;
using Moryx.Serialization;

namespace Moryx.AbstractionLayer.Resources.Endpoints
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;
using System.Reflection;
using Moryx.Serialization;

Expand All @@ -26,7 +25,7 @@ public ResourceModel[] QueryConversion(Resource[] matches)
{
var model = ToModel(matches[i], true);
model.References = Query.IncludedReferences?.Length > 0
? FilteredReferences(matches[i]) : new ResourceReferenceModel[0];
? FilteredReferences(matches[i]) : [];
models[i] = model;
}

Expand All @@ -40,7 +39,7 @@ public ResourceModel QueryConversion(Resource match)
{
var model = ToModel(match, true);
model.References = Query.IncludedReferences?.Length > 0
? FilteredReferences(match) : new ResourceReferenceModel[0];
? FilteredReferences(match) : [];
return model;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Moryx.Serialization;
Expand Down Expand Up @@ -137,7 +133,7 @@ protected ResourceReferenceModel ConvertReference(Resource current, PropertyInfo
return referenceModel;

// Convert referenced resource objects and possible instance types
var referenceTargets = (value as IEnumerable<IResource>) ?? new[] { (IResource)value };
var referenceTargets = (value as IEnumerable<IResource>) ?? [(IResource)value];
foreach (Resource resource in referenceTargets)
{
// Load references partially UNLESS they are new, unsaved objects
Expand All @@ -164,12 +160,12 @@ private static ICollection<Type> MergeTypeConstraints(PropertyInfo property, Typ
{
// If there are no overrides the only limitation is the target type
if (!referenceOverrides.ContainsKey(property.Name))
return new[] { targetType };
return [targetType];

// Otherwise find all types that limit the reference type without redundancies. This means eliminating all types
// represented by another type
var myOverrides = referenceOverrides[property.Name];
return myOverrides.Concat(new[] { targetType })
return myOverrides.Concat([targetType])
.Where(type => !myOverrides.Any(over => over != type && type.IsAssignableFrom(over))).ToList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Moryx.AbstractionLayer.Resources.Endpoints
Expand All @@ -22,6 +21,6 @@ public class ResourceReferenceModel
/// Targets of this reference
/// </summary>
[DataMember]
public List<ResourceModel> Targets { get; set; } = new List<ResourceModel>();
public List<ResourceModel> Targets { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -166,7 +163,7 @@ private ActionResult<ResourceModel> Construct(string type)
.AddDefaultValueProvider());

var model = new ResourceToModelConverter(_resourceTypeTree, _serialization).GetDetails(resource);
model.Methods = Array.Empty<MethodEntry>(); // Reset methods because they can not be invoked on new objects
model.Methods = []; // Reset methods because they can not be invoked on new objects
return model;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Moryx.Configuration;
using Moryx.Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0

using Moryx.AbstractionLayer.Products;
using System.Linq;

namespace Moryx.AbstractionLayer.TestTools
{
Expand Down
2 changes: 0 additions & 2 deletions src/Moryx.AbstractionLayer.TestTools/DummyProductRecipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using Moryx.AbstractionLayer.Recipes;
using Moryx.Workplans;
using System.Collections.Generic;
using System.Linq;

namespace Moryx.AbstractionLayer.TestTools
{
Expand Down
2 changes: 0 additions & 2 deletions src/Moryx.AbstractionLayer.TestTools/DummyProductType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the Apache License, Version 2.0

using Moryx.AbstractionLayer.Products;
using System.Collections.Generic;
using System.Linq;

namespace Moryx.AbstractionLayer.TestTools
{
Expand Down
1 change: 0 additions & 1 deletion src/Moryx.AbstractionLayer.TestTools/DummyWorkplan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0

using Moryx.Workplans;
using System.Linq;

namespace Moryx.AbstractionLayer.TestTools
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using Moryx.AbstractionLayer.Resources;

namespace Moryx.AbstractionLayer.TestTools
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging.Abstractions;
using Moryx.AbstractionLayer.Resources;
using Moryx.Logging;
Expand Down
1 change: 0 additions & 1 deletion src/Moryx.AbstractionLayer/Activities/Activity.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using Moryx.AbstractionLayer.Capabilities;
using Moryx.Tools;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;

namespace Moryx.AbstractionLayer
{
/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Moryx.AbstractionLayer/Activities/IActivity.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using Moryx.AbstractionLayer.Capabilities;

namespace Moryx.AbstractionLayer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using Moryx.Workplans;

namespace Moryx.AbstractionLayer
Expand Down
1 change: 0 additions & 1 deletion src/Moryx.AbstractionLayer/Activities/Parameters.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using Moryx.Tools;

namespace Moryx.AbstractionLayer
Expand Down
2 changes: 0 additions & 2 deletions src/Moryx.AbstractionLayer/Activities/Tracing.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Linq;
using System.Runtime.Serialization;

namespace Moryx.AbstractionLayer
Expand Down
4 changes: 1 addition & 3 deletions src/Moryx.AbstractionLayer/Activities/TracingExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace Moryx.AbstractionLayer
namespace Moryx.AbstractionLayer
{
/// <summary>
/// Extension to override tracing information
Expand Down
4 changes: 1 addition & 3 deletions src/Moryx.AbstractionLayer/Capabilities/CapabilitiesBase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;

namespace Moryx.AbstractionLayer.Capabilities
{
/// <summary>
Expand All @@ -20,7 +18,7 @@ bool ICapabilities.Provides(ICapabilities required) =>

/// <inheritdoc />
public IEnumerable<ICapabilities> GetAll() =>
new ICapabilities[] { this };
[this];

/// <summary>
/// Check if our required capabilities are provided by the given object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;
using System.Linq;

namespace Moryx.AbstractionLayer.Capabilities
{
/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Moryx.AbstractionLayer/Capabilities/ICapabilities.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;

namespace Moryx.AbstractionLayer.Capabilities
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Moryx.AbstractionLayer.Capabilities
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace Moryx.AbstractionLayer
namespace Moryx.AbstractionLayer
{
/// <summary>
/// Constraint that evalutes an expression and compares it to an expected value
Expand Down
2 changes: 0 additions & 2 deletions src/Moryx.AbstractionLayer/Drivers/Camera/ICameraDriver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Moryx.AbstractionLayer.Drivers;
using System;
using System.Threading.Tasks;

namespace Moryx.Drivers.Camera.Interfaces
{
Expand Down
1 change: 0 additions & 1 deletion src/Moryx.AbstractionLayer/Drivers/Driver.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using Moryx.AbstractionLayer.Resources;
using Moryx.StateMachines;

Expand Down
Loading