Skip to content
Snippets Groups Projects
Commit 7cee55c6 authored by Tim Übelhör's avatar Tim Übelhör
Browse files

Implementing suggestions of the VS code analysis.

parent 33f9be60
Branches
Tags
No related merge requests found
Showing
with 112 additions and 49 deletions
......@@ -67,6 +67,7 @@
<Compile Include="Classes\FileSamplesTable.cs" />
<Compile Include="Classes\CyclicSamplesTable.cs" />
<Compile Include="Classes\DataRepository.cs" />
<Compile Include="Classes\NewValuesEventArgs.cs" />
<Compile Include="Classes\SimulationDataStorer.cs" />
<Compile Include="Interfaces\IChannel.cs" />
<Compile Include="Interfaces\IEnumerationChannel.cs" />
......
......
......@@ -10,7 +10,7 @@ namespace ModeliChart.Basics
/// A default implementation of <see cref="IDataRepository"/>
/// using a Dictionary of DataSource names and ISamplesStorages.
/// </summary>
public class DataRepository : IDataRepository
public sealed class DataRepository : IDataRepository
{
// Factory function for storage
private readonly Func<IEnumerable<uint>, ISamplesStorage> createStorage;
......
......
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Threading.Tasks;
using System.Threading;
using System.Linq;
using System.Data;
using System.Threading.Tasks;
namespace ModeliChart.Basics
{
/// <summary>
/// Writes samples to a file on the disk so it can take much more memory than the
/// </summary>
public class FileSamplesTable : IDisposable
public sealed class FileSamplesTable : IDisposable
{
// Uses a custom dense binary serialization: [double[] values, double time]
// Appens newest value to the end.
......@@ -204,6 +203,8 @@ namespace ModeliChart.Basics
{
// Dispose the managed resources
StopWriteTaskAsync().Wait();
writeTask.Dispose();
writeCache.Dispose();
// File will be deleted because of the DeleteOnClose flag.
stream.Dispose();
}
......
......
using System;
using System.Collections.Generic;
namespace ModeliChart.Basics
{
public class NewValuesEventArgs : EventArgs
{
public string ModelInstanceName { get; set; }
public double Time { get; set; }
public IEnumerable<uint> ValueRefs { get; set; }
public IEnumerable<double> Values { get; set; }
}
}
......@@ -16,7 +16,7 @@ namespace ModeliChart.Basics
simulation.NewValuesAvailable += Simulation_NewValuesAvailable;
}
private void Simulation_NewValuesAvailable(object sender, (string ModelInstanceName, double Time, IEnumerable<uint> ValueRefs, IEnumerable<double> Values) e)
private void Simulation_NewValuesAvailable(object sender, NewValuesEventArgs e)
{
dataRepository.AddValues(e.ModelInstanceName, e.Time, e.ValueRefs, e.Values);
}
......
......
......@@ -95,8 +95,7 @@ namespace ModeliChart.Basics
/// Gets called as soon as new values are available.
/// Usually after DoStep or when a remote simulation sent new data.
/// </summary>
event EventHandler<(string ModelInstanceName, double Time,
IEnumerable<uint> ValueRefs, IEnumerable<double> Values)> NewValuesAvailable;
event EventHandler<NewValuesEventArgs> NewValuesAvailable;
/// <summary>
/// Set the value for a channel in this simulation.
......
......
Subproject commit 5ec7e4e302f797d0d3b7815c336a621574c1c8df
Subproject commit 41ca02885852c4fac79f053169a0fb242fd3c57e
......@@ -35,7 +35,7 @@ namespace ModeliChart.LocalMode
private double currentTime = 0;
private double stepSize = 0.01;
public event EventHandler<(string ModelInstanceName, double Time, IEnumerable<uint> ValueRefs, IEnumerable<double> Values)> NewValuesAvailable;
public event EventHandler<NewValuesEventArgs> NewValuesAvailable;
/// <summary>
/// Creates a new SimulationController by injecting the dataSources and channelLinks
......@@ -93,7 +93,14 @@ namespace ModeliChart.LocalMode
{
instance.DoStep(currentTime, stepSize);
var (ValueRefs, Values) = instance.GetCurrentValues();
NewValuesAvailable?.Invoke(this, (instance.Name, currentTime, ValueRefs, Values));
NewValuesAvailable?.Invoke(this,
new NewValuesEventArgs
{
ModelInstanceName = instance.Name,
Time = currentTime,
ValueRefs = ValueRefs,
Values = Values
});
}
Interlocked.Exchange(ref currentTime, currentTime + stepSize);
// Execute pending tasks
......
......
......@@ -7,7 +7,7 @@ namespace ModeliChart.FmuTools
/// Small IDisposable wrapper for a temporary file.
/// The file will be deletet on disposal.
/// </summary>
public class TempFile : IDisposable
public sealed class TempFile : IDisposable
{
public string PathToFile { get; private set; }
......@@ -20,7 +20,7 @@ namespace ModeliChart.FmuTools
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
protected virtual void Dispose(bool disposing)
public void Dispose(bool disposing)
{
if (!disposedValue)
{
......@@ -39,7 +39,7 @@ namespace ModeliChart.FmuTools
}
// This code added to correctly implement the disposable pattern.
void IDisposable.Dispose()
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
Dispose(true);
......
......
......@@ -15,6 +15,7 @@
{
if (disposing && (components != null))
{
logBuffer.Dispose();
components.Dispose();
}
base.Dispose(disposing);
......
......
......@@ -9,7 +9,7 @@ namespace ModeliChart.Log
{
const int MAX_LOG_LINES = 100;
// Producer consumer principle so only one thread can access the console.
private BlockingCollection<string> _logBuffer = new BlockingCollection<string>();
private readonly BlockingCollection<string> logBuffer = new BlockingCollection<string>();
public ConsoleOutput()
{
......@@ -26,9 +26,9 @@ namespace ModeliChart.Log
/// </summary>
private void ConsumeMessages()
{
while (!_logBuffer.IsCompleted)
while (!logBuffer.IsCompleted)
{
writeToConsole(_logBuffer.Take());
WriteToConsole(logBuffer.Take());
}
}
......@@ -36,15 +36,15 @@ namespace ModeliChart.Log
/// Actually adds the message to the console
/// </summary>
/// <param name="message"></param>
private void writeToConsole(string message)
private void WriteToConsole(string message)
{
if (logListBox.InvokeRequired)
{
logListBox.BeginInvoke(new Action(() => writeToConsole(message)));
logListBox.BeginInvoke(new Action(() => WriteToConsole(message)));
}
else
{
logListBox.Items.Add(getPrefix() + message);
logListBox.Items.Add(GetPrefix() + message);
// Prevent too many messages
if (logListBox.Items.Count > MAX_LOG_LINES)
{
......@@ -56,7 +56,7 @@ namespace ModeliChart.Log
}
}
private string getPrefix()
private string GetPrefix()
{
return "[" + DateTime.Now.ToLongTimeString() + "]: ";
}
......@@ -68,7 +68,7 @@ namespace ModeliChart.Log
public void WriteLine(string message)
{
// Only enqueue the message
_logBuffer.Add(message);
logBuffer.Add(message);
}
}
......
......
......@@ -69,6 +69,7 @@
<Compile Include="MessageBox\MsgBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StatusLogger.cs" />
</ItemGroup>
<ItemGroup>
......
......
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ModeliChart.Log.Properties")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModeliChart.Log.Properties")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a7f15804-95e6-4555-af21-f69bc5fe6997")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
......@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace ModeliChart.RemoteMode
{
public class ModeliGrpcClient : IModeliRpcClient
public sealed class ModeliGrpcClient : IModeliRpcClient
{
// rpc interfaces
private ModeliBackend.ModeliBackendClient _client;
......@@ -41,11 +41,11 @@ namespace ModeliChart.RemoteMode
{
await _channel.ConnectAsync().ConfigureAwait(false);
// Start stream receiving
logTask = Task.Run(readLogs);
newValuesTask = Task.Run(readValues);
logTask = Task.Run(ReadLogs);
newValuesTask = Task.Run(ReadValues);
}
private async Task readLogs()
private async Task ReadLogs()
{
using (var call = _client.Log(new LogRequest()))
{
......@@ -63,7 +63,7 @@ namespace ModeliChart.RemoteMode
}
}
private async Task readValues()
private async Task ReadValues()
{
using (var call = _client.NewValues(new NewValuesRequest()))
{
......
......
......@@ -6,11 +6,11 @@ using System.Threading.Tasks;
namespace ModeliChart.RemoteMode
{
public class RemoteInstance : IModelInstance
public sealed class RemoteInstance : IModelInstance
{
// Rpc connection to the backend
private IModeliRpcClient rpcClient;
private ILookup<uint, IChannel> channelsByValueRef;
private readonly IModeliRpcClient rpcClient;
private readonly ILookup<uint, IChannel> channelsByValueRef;
public string Name { get; private set; }
......@@ -63,7 +63,6 @@ namespace ModeliChart.RemoteMode
public void Dispose()
{
throw new NotImplementedException();
}
}
}
......@@ -9,7 +9,7 @@ using System.Threading;
namespace ModeliChart.RemoteMode
{
public class RemoteSimulation : ISimulation, IRpcSimulation
public sealed class RemoteSimulation : ISimulation, IRpcSimulation
{
// Execute RPC calls
private ModeliGrpcClient rpcClient;
......@@ -19,7 +19,7 @@ namespace ModeliChart.RemoteMode
private double stepSize = 0.01;
private double currentTime = 0;
public event EventHandler<(string ModelInstanceName, double Time, IEnumerable<uint> ValueRefs, IEnumerable<double> Values)> NewValuesAvailable;
public event EventHandler<NewValuesEventArgs> NewValuesAvailable;
/// <summary>
......@@ -47,8 +47,14 @@ namespace ModeliChart.RemoteMode
values.AddRange(e.RealValues);
values.AddRange(e.BoolValues.Select(value => Convert.ToDouble(value)));
Interlocked.Exchange(ref currentTime, e.Timestamp);
NewValuesAvailable?.Invoke(this, (e.InstanceName, e.Timestamp, valueRefs, values));
NewValuesAvailable?.Invoke(this,
new NewValuesEventArgs
{
ModelInstanceName = e.InstanceName,
Time = e.Timestamp,
ValueRefs = valueRefs,
Values = values
});
}
private void Rpc_LogArrived(object sender, RemoteLogEventArgs e)
......
......
......@@ -15,6 +15,8 @@
{
if (disposing && (components != null))
{
openHand.Dispose();
grabbingHand.Dispose();
components.Dispose();
}
base.Dispose(disposing);
......
......
......@@ -6,17 +6,17 @@ namespace ModeliChart.UserControls
{
public partial class AvailableChannelEntry : UserControl, IDraggable
{
private IChannel _channel;
private Cursor _grabbingHand;
private Cursor _openHand;
private IChannel channel;
private readonly Cursor grabbingHand;
private readonly Cursor openHand;
private ChannelType _channelType = ChannelType.None;
public AvailableChannelEntry()
{
InitializeComponent();
_grabbingHand = new Cursor(GetType(), "Resources.Grabbed15-19.cur");
_openHand = new Cursor(GetType(), "Resources.openhand.cur");
grabbingHand = new Cursor(GetType(), "Resources.Grabbed15-19.cur");
openHand = new Cursor(GetType(), "Resources.openhand.cur");
}
public AvailableChannelEntry(IChannel channel)
......@@ -32,7 +32,7 @@ namespace ModeliChart.UserControls
{
get
{
return _channel;
return channel;
}
set
{
......@@ -40,7 +40,7 @@ namespace ModeliChart.UserControls
{
ChannelName = value.Name;
ChannelDescription = value.Description;
_channel = value;
channel = value;
DisplayChannelType = value.ChannelType;
Settable = value.Settable;
Unit = value.DisplayedUnit;
......@@ -77,9 +77,9 @@ namespace ModeliChart.UserControls
public bool Settable
{
get {
if (_channel != null)
if (channel != null)
{
return _channel.Settable;
return channel.Settable;
}
else
{
......@@ -153,9 +153,9 @@ namespace ModeliChart.UserControls
}
public void DragSource_MouseDown(object sender, MouseEventArgs e)
{
if (_channel != null)
if (channel != null)
{
this.DoDragDrop(_channel, DragDropEffects.Copy);
this.DoDragDrop(channel, DragDropEffects.Copy);
}
}
public void DragSource_MouseUp(object sender, MouseEventArgs e)
......
......
......@@ -224,7 +224,7 @@ namespace ModeliChart.UserControls
}
// LinearChannelLink is immutable so the receiver needs to know the old one to remove it.
public class ChannelLinkChangedArgs
public class ChannelLinkChangedArgs: EventArgs
{
public LinearChannelLink NewLink { get; set; }
public LinearChannelLink OldLink { get; set; }
......
......
......@@ -18,7 +18,7 @@ namespace ModeliChart.UserControls
public virtual double DisplayedInterval { get; set; }
public virtual IEnumerable<IChannel> Channels => throw new NotImplementedException();
public virtual IEnumerable<IChannel> Channels => new IChannel[] { channel };
// Konstruktor
public InstrumentControlBase(ISimulation simulation, IDataRepository dataRepository)
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment