Skip to content
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

Consistency refactor #23

Merged
merged 6 commits into from
Dec 9, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ configurations/*
*/buildoutput/*
Service/configurations/*
Service/files/*
.idea/*
1 change: 1 addition & 0 deletions Connector/ConnectorRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using Cognite.Simulator.Utils;
using CogniteSdk.Alpha;
using Connector.Dwsim;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

Expand Down
4 changes: 2 additions & 2 deletions Connector/Dwsim/AutomationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Cognite.Simulator.Utils.Automation;

namespace Connector;
namespace Connector.Dwsim;

public class DwsimAutomationConfig : AutomationConfig
{
public string DwsimInstallationPath { get; set; }

public DwsimAutomationConfig()

Check warning on line 25 in Connector/Dwsim/AutomationConfig.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'DwsimInstallationPath' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 25 in Connector/Dwsim/AutomationConfig.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Non-nullable property 'DwsimInstallationPath' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 25 in Connector/Dwsim/AutomationConfig.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Non-nullable property 'DwsimInstallationPath' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
ProgramId = "DWSIM.Automation.Automation3";
}
Expand Down
20 changes: 10 additions & 10 deletions Connector/Dwsim/DwsimClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Cognite.Simulator.Utils;
using Cognite.Simulator.Utils.Automation;
using CogniteSdk.Alpha;
using Microsoft.Extensions.Logging;

using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
using Cognite.Simulator.Utils;
using Cognite.Simulator.Utils.Automation;
using CogniteSdk.Alpha;
using Microsoft.Extensions.Logging;

namespace Connector
namespace Connector.Dwsim
{
/// <summary>
/// Wrapper class that
Expand All @@ -40,7 +40,7 @@
private readonly UnitConverter _unitConverter;

// Lock to prevent concurrent access to simulator resources
private readonly object simulatorLock = new object();
private readonly object _simulatorLock = new object();

public DwsimClient(
ILogger<DwsimClient> logger, DefaultConfig<DwsimAutomationConfig> config)
Expand All @@ -54,8 +54,8 @@
string propsDll = Path.Combine(config.Automation.DwsimInstallationPath, "DWSIM.FlowsheetBase.dll");
Assembly assembly = Assembly.LoadFrom(propsDll);
ResourceManager rm = new ResourceManager("DWSIM.FlowsheetBase.Properties", assembly);
_propMap = rm.GetResourceSet(CultureInfo.InvariantCulture, true, false)

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'IEnumerable<DictionaryEntry> Enumerable.Cast<DictionaryEntry>(IEnumerable source)'.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / build

The type 'string?' cannot be used as type parameter 'TKey' in the generic type or method 'Enumerable.ToDictionary<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>)'. Nullability of type argument 'string?' doesn't match 'notnull' constraint.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in value of type 'Dictionary<string?, string?>' doesn't match target type 'Dictionary<string, string>'.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Possible null reference argument for parameter 'source' in 'IEnumerable<DictionaryEntry> Enumerable.Cast<DictionaryEntry>(IEnumerable source)'.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

The type 'string?' cannot be used as type parameter 'TKey' in the generic type or method 'Enumerable.ToDictionary<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>)'. Nullability of type argument 'string?' doesn't match 'notnull' constraint.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Nullability of reference types in value of type 'Dictionary<string?, string?>' doesn't match target type 'Dictionary<string, string>'.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Possible null reference argument for parameter 'source' in 'IEnumerable<DictionaryEntry> Enumerable.Cast<DictionaryEntry>(IEnumerable source)'.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

The type 'string?' cannot be used as type parameter 'TKey' in the generic type or method 'Enumerable.ToDictionary<TSource, TKey, TElement>(IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>)'. Nullability of type argument 'string?' doesn't match 'notnull' constraint.

Check warning on line 57 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Nullability of reference types in value of type 'Dictionary<string?, string?>' doesn't match target type 'Dictionary<string, string>'.
.Cast<DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());

Check warning on line 58 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in return type of 'lambda expression' doesn't match the target delegate 'Func<DictionaryEntry, string?>' (possibly because of nullability attributes).

Check warning on line 58 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 58 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Nullability of reference types in return type of 'lambda expression' doesn't match the target delegate 'Func<DictionaryEntry, string?>' (possibly because of nullability attributes).

Check warning on line 58 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Dereference of a possibly null reference.

Check warning on line 58 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Nullability of reference types in return type of 'lambda expression' doesn't match the target delegate 'Func<DictionaryEntry, string?>' (possibly because of nullability attributes).

Check warning on line 58 in Connector/Dwsim/DwsimClient.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Dereference of a possibly null reference.
_unitConverter = new UnitConverter(config.Automation.DwsimInstallationPath);
}

Expand All @@ -72,7 +72,7 @@
{
_logger.LogInformation("Testing DWSIM connection...");

lock (simulatorLock)
lock (_simulatorLock)
{
try
{
Expand All @@ -91,7 +91,7 @@
public bool CanOpenModel(string path)
{
_logger.LogDebug("Attempting to open file {Path}", path);
lock (simulatorLock)
lock (_simulatorLock)
{
try
{
Expand All @@ -118,7 +118,7 @@
public Task<Dictionary<string, SimulatorValueItem>> RunSimulation(DefaultModelFilestate modelState, SimulatorRoutineRevision routineRev, Dictionary<string, SimulatorValueItem> inputData)
{
_logger.LogDebug($"- Started running {routineRev.ExternalId} in DWSIM");
lock (simulatorLock)
lock (_simulatorLock)
{
try
{
Expand Down
Loading
Loading