Skip to content

Commit fe6383b

Browse files
Merge pull request #37 from Digital-Production-Aachen/fixOVFMergingBug
Declared async interface of FileReader and FileWriter depricated sinc…
2 parents 71f6d6e + 718c2c4 commit fe6383b

File tree

14 files changed

+274
-151
lines changed

14 files changed

+274
-151
lines changed

ReaderWriter/3rdPartyFormatAdapters/ASP/ASPFileReaderWriter/ASPFileReader.cs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ You should have received a copy of the GNU Lesser General Public
3131
using System.Threading.Tasks;
3232
using OpenVectorFormat.AbstractReaderWriter;
3333
using OpenVectorFormat.Utils;
34+
using OpenVectorFormat;
3435

3536
namespace OpenVectorFormat.ASPFileReaderWriter
3637
{
@@ -68,7 +69,7 @@ public override Job JobShell
6869
}
6970

7071
/// <inheritdoc/>
71-
public override async Task OpenJobAsync(string filename, IFileReaderWriterProgress progress)
72+
public override void OpenJob(string filename, IFileReaderWriterProgress progress)
7273
{
7374
if (!SupportedFileFormats.Contains(Path.GetExtension(filename)))
7475
{
@@ -84,19 +85,19 @@ public override async Task OpenJobAsync(string filename, IFileReaderWriterProgre
8485

8586
_filename = filename;
8687

87-
await Task.Run(() => { ParseASPFile(); });
88+
ParseASPFile();
8889
}
8990

9091
/// <inheritdoc/>
91-
public async override Task<Job> CacheJobToMemoryAsync()
92+
public override Job CacheJobToMemory()
9293
{
9394
if (_cacheState == CacheState.CompleteJobCached)
9495
{
9596
return CompleteJob;
9697
}
9798
else if (File.Exists(_filename))
9899
{
99-
await Task.Run(() => { ParseASPFile(); });
100+
ParseASPFile();
100101
return CompleteJob;
101102
}
102103
else
@@ -121,9 +122,7 @@ public override WorkPlane GetWorkPlaneShell(int i_workPlane)
121122

122123
if (CacheState == CacheState.CompleteJobCached)
123124
{
124-
WorkPlane wpShell = new WorkPlane();
125-
ProtoUtils.CopyWithExclude(CompleteJob.WorkPlanes[i_workPlane], wpShell, new List<int> { WorkPlane.VectorBlocksFieldNumber });
126-
return wpShell;
125+
return CompleteJob.WorkPlanes[i_workPlane].CloneWithoutVectorData();
127126
}
128127
else
129128
{
@@ -132,35 +131,29 @@ public override WorkPlane GetWorkPlaneShell(int i_workPlane)
132131
}
133132

134133
/// <inheritdoc/>
135-
public async override Task<WorkPlane> GetWorkPlaneAsync(int i_workPlane)
134+
public override WorkPlane GetWorkPlane(int i_workPlane)
136135
{
137-
return await Task.Run(() =>
136+
if (_cacheState == CacheState.CompleteJobCached)
138137
{
139-
if (_cacheState == CacheState.CompleteJobCached)
140-
{
141-
return CompleteJob.WorkPlanes[i_workPlane];
142-
}
143-
else
144-
{
145-
throw new InvalidDataException("No data loaded yet! Call OpenJobAsync first!");
146-
}
147-
});
138+
return CompleteJob.WorkPlanes[i_workPlane];
139+
}
140+
else
141+
{
142+
throw new InvalidDataException("No data loaded yet! Call OpenJobAsync first!");
143+
}
148144
}
149145

150146
/// <inheritdoc/>
151-
public async override Task<VectorBlock> GetVectorBlockAsync(int i_workPlane, int i_vectorblock)
147+
public override VectorBlock GetVectorBlock(int i_workPlane, int i_vectorblock)
152148
{
153-
return await Task.Run(() =>
149+
if (_cacheState == CacheState.CompleteJobCached)
154150
{
155-
if (_cacheState == CacheState.CompleteJobCached)
156-
{
157-
return CompleteJob.WorkPlanes[i_workPlane].VectorBlocks[i_vectorblock];
158-
}
159-
else
160-
{
161-
throw new InvalidDataException("No data loaded yet! Call OpenJobAsync first!");
162-
}
163-
});
151+
return CompleteJob.WorkPlanes[i_workPlane].VectorBlocks[i_vectorblock];
152+
}
153+
else
154+
{
155+
throw new InvalidDataException("No data loaded yet! Call OpenJobAsync first!");
156+
}
164157
}
165158

166159
/// <inheritdoc/>

ReaderWriter/3rdPartyFormatAdapters/ASP/ASPFileReaderWriter/ASPFileWriter.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,21 @@ public ASPFileWriter()
6262
public new static List<string> SupportedFileFormats { get; } = new List<string>() { ".asp" };
6363

6464
/// <inheritdoc/>
65-
public async override Task AppendWorkPlaneAsync(WorkPlane workPlane)
65+
public override void AppendWorkPlane(WorkPlane workPlane)
6666
{
67-
68-
await Task.Run(() =>
67+
for (uint i = 0; i < workPlane.Repeats + 1; i++)
6968
{
70-
for (uint i = 0; i < workPlane.Repeats + 1; i++)
69+
for (int i_vectorblock = 0; i_vectorblock < workPlane.VectorBlocks.Count; i_vectorblock++)
7170
{
72-
for (int i_vectorblock = 0; i_vectorblock < workPlane.VectorBlocks.Count; i_vectorblock++)
73-
{
74-
_addVectorBlock(workPlane.VectorBlocks[i_vectorblock]);
75-
}
71+
_addVectorBlock(workPlane.VectorBlocks[i_vectorblock]);
7672
}
77-
});
78-
73+
}
7974
}
8075

8176
/// <inheritdoc/>
82-
public async override Task AppendVectorBlockAsync(VectorBlock block)
77+
public override void AppendVectorBlock(VectorBlock block)
8378
{
84-
await Task.Run(() => _addVectorBlock(block));
79+
_addVectorBlock(block);
8580
}
8681

8782
/// <inheritdoc/>
@@ -317,7 +312,7 @@ private void _writeGo(float[] pt)
317312
}
318313

319314
/// <inheritdoc/>
320-
public override async Task SimpleJobWriteAsync(Job job, string filename, IFileReaderWriterProgress progress)
315+
public override void SimpleJobWrite(Job job, string filename, IFileReaderWriterProgress progress)
321316
{
322317
CheckConsistence(job.NumWorkPlanes, job.WorkPlanes.Count);
323318
for (int i = 0; i < job.NumWorkPlanes; i++)
@@ -331,7 +326,7 @@ public override async Task SimpleJobWriteAsync(Job job, string filename, IFileRe
331326
this.progress = progress;
332327
foreach (WorkPlane wp in job.WorkPlanes)
333328
{
334-
await AppendWorkPlaneAsync(wp);
329+
AppendWorkPlane(wp);
335330
}
336331
_fs.Close();
337332
_fileOperationInProgress = FileWriteOperation.None;

ReaderWriter/3rdPartyFormatAdapters/CLI_ILT/ILTFileReaderAdapter/ILTFileReaderAdapter.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public override Job JobShell
9494

9595
public override CacheState CacheState => _cacheState;
9696

97-
public override async Task OpenJobAsync(string filename, IFileReaderWriterProgress progress)
97+
public override void OpenJob(string filename, IFileReaderWriterProgress progress)
9898
{
9999
this.progress = progress;
100100
this.filename = filename;
@@ -103,14 +103,11 @@ public override async Task OpenJobAsync(string filename, IFileReaderWriterProgre
103103
ModelsectionMap = new Dictionary<IModelSection, int>();
104104
ModelsectionIdMap = new Dictionary<string, int>();
105105
job = new Job();
106-
await Task.Run(() =>
107-
{
108-
OpenFile();
109-
});
106+
OpenFile();
110107
return;
111108
}
112109

113-
public async override Task<Job> CacheJobToMemoryAsync()
110+
public override Job CacheJobToMemory()
114111
{
115112
CheckFile();
116113
if (!vectorDataLoaded)
@@ -128,7 +125,7 @@ public async override Task<Job> CacheJobToMemoryAsync()
128125
return job;
129126
}
130127

131-
public async override Task<WorkPlane> GetWorkPlaneAsync(int i_workPlane)
128+
public override WorkPlane GetWorkPlane(int i_workPlane)
132129
{
133130
if (vectorDataLoaded)
134131
{
@@ -139,7 +136,7 @@ public async override Task<WorkPlane> GetWorkPlaneAsync(int i_workPlane)
139136
WorkPlane fullWorkPlane = job.WorkPlanes[i_workPlane].Clone();//copy the shell
140137
for (int j = 0; j < fullWorkPlane.VectorBlocks.Count; j++)
141138
{
142-
fullWorkPlane.VectorBlocks[j] = await GetVectorBlockAsync(i_workPlane, j);
139+
fullWorkPlane.VectorBlocks[j] = GetVectorBlock(i_workPlane, j);
143140
}
144141
return fullWorkPlane;//ownership passed
145142
}
@@ -153,17 +150,15 @@ public override WorkPlane GetWorkPlaneShell(int i_workPlane)
153150
}
154151
if (CacheState == CacheState.CompleteJobCached)
155152
{
156-
WorkPlane wpShell = new WorkPlane();
157-
ProtoUtils.CopyWithExclude(job.WorkPlanes[i_workPlane], wpShell, new List<int> { WorkPlane.VectorBlocksFieldNumber });
158-
return wpShell;
153+
return job.WorkPlanes[i_workPlane].CloneWithoutVectorData();
159154
}
160155
else
161156
{
162157
throw new InvalidDataException("No data loaded yet! Call OpenJobAsync first!");
163158
}
164159
}
165160

166-
public async override Task<VectorBlock> GetVectorBlockAsync(int i_workPlane, int i_vectorblock)
161+
public override VectorBlock GetVectorBlock(int i_workPlane, int i_vectorblock)
167162
{
168163
if (vectorDataLoaded)
169164
{

ReaderWriter/AbstractReaderWriter/FileReader.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,34 @@ public abstract class FileReader : IReader, IDisposable
5959
/// </summary>
6060
/// <param name="filename">name of the file to open</param>
6161
/// <param name="progress">status update interface to be called</param>
62-
public abstract Task OpenJobAsync(string filename, IFileReaderWriterProgress progress);
62+
[Obsolete("Please use OpenJob")]
63+
public Task OpenJobAsync(string filename, IFileReaderWriterProgress progress)
64+
{
65+
OpenJob(filename, progress);
66+
return Task.CompletedTask;
67+
}
68+
69+
/// <summary>
70+
/// Open the given file, calling the given interface for status updates.
71+
/// Depending on file header and file extension, the file is either completely loaded into memory, or only the JobShell is loaded.
72+
/// The Job / JobShell is placed at <see cref="JobShell"/>
73+
/// </summary>
74+
/// <param name="filename">name of the file to open</param>
75+
/// <param name="progress">status update interface to be called</param>
76+
public abstract void OpenJob(string filename, IFileReaderWriterProgress progress);
77+
78+
/// <summary>
79+
/// Retrieves the complete job with all workplane data.
80+
/// CAUTION: Job will be cached to memory completely regardless of its size, not advised for large jobs.
81+
/// Cached job will stay in memory, future calls to <see cref="GetWorkPlaneShell(int)"/>, <see cref="GetWorkPlane(int)"/> and <see cref="GetVectorBlock(int, int)"/> will be accelareted.
82+
/// <see cref="CacheState"/> will be set to CompleteJobCached.
83+
/// </summary>
84+
/// <returns>Complete job with all <see cref="WorkPlane"/>s and <see cref="VectorBlock"/>s.</returns>
85+
[Obsolete("Please use CacheJobToMemory")]
86+
public Task<Job> CacheJobToMemoryAsync()
87+
{
88+
return Task.FromResult(CacheJobToMemory());
89+
}
6390

6491
/// <summary>
6592
/// Retrieves the complete job with all workplane data.
@@ -68,7 +95,7 @@ public abstract class FileReader : IReader, IDisposable
6895
/// <see cref="CacheState"/> will be set to CompleteJobCached.
6996
/// </summary>
7097
/// <returns>Complete job with all <see cref="WorkPlane"/>s and <see cref="VectorBlock"/>s.</returns>
71-
public abstract Task<OpenVectorFormat.Job> CacheJobToMemoryAsync();
98+
public abstract Job CacheJobToMemory();
7299

73100
/// <summary>
74101
/// Unloads stored vector data from memory. If the data is queried again, it needs to be read from the disk again.
@@ -103,13 +130,26 @@ public virtual void CloseFile()
103130
public abstract void Dispose();
104131

105132
/// <inheritdoc/>
106-
public abstract Task<WorkPlane> GetWorkPlaneAsync(int i_workPlane);
133+
[Obsolete("Please use GetWorkPlane")]
134+
public Task<WorkPlane> GetWorkPlaneAsync(int i_workPlane)
135+
{
136+
return Task.FromResult(GetWorkPlane(i_workPlane));
137+
}
138+
139+
/// <inheritdoc/>
140+
public abstract WorkPlane GetWorkPlane(int i_workPlane);
107141

108142
/// <inheritdoc/>
109143
public abstract WorkPlane GetWorkPlaneShell(int i_workPlane);
110144

111145
/// <inheritdoc/>
112-
public abstract Task<VectorBlock> GetVectorBlockAsync(int i_workPlane, int i_vectorblock);
146+
[Obsolete("Please use GetVectorBlock")]
147+
public Task<VectorBlock> GetVectorBlockAsync(int i_workPlane, int i_vectorblock)
148+
{
149+
return Task.FromResult(GetVectorBlock(i_workPlane, i_vectorblock));
150+
}
151+
152+
public abstract VectorBlock GetVectorBlock(int i_workPlane, int i_vectorblock);
113153
}//end FileReader
114154

115155
}//end namespace VectorFileHandler

ReaderWriter/AbstractReaderWriter/FileWriter.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,42 @@ public abstract class FileWriter : IWriter, IDisposable
6060
/// <param name="job">job to write</param>
6161
/// <param name="filename">Path and name for savefile</param>
6262
/// <param name="progress">status update interface to be called</param>
63-
public abstract Task SimpleJobWriteAsync(Job job, string filename, IFileReaderWriterProgress progress);
63+
[Obsolete("Please use SimpleJobWrite")]
64+
public virtual Task SimpleJobWriteAsync(Job job, string filename, IFileReaderWriterProgress progress)
65+
{
66+
SimpleJobWrite(job, filename, progress);
67+
return Task.CompletedTask;
68+
}
69+
70+
public abstract void SimpleJobWrite(Job job, string filename, IFileReaderWriterProgress progress);
6471

6572
/// <summary>Disposes the FileWriter, finishing the partial write (if initiated).</summary>
6673
public abstract void Dispose();
6774

6875
/// <inheritdoc/>
69-
public abstract Task AppendWorkPlaneAsync(WorkPlane workPlane);
76+
[Obsolete("Please use AppendWorkPlane")]
77+
public Task AppendWorkPlaneAsync(WorkPlane workPlane)
78+
{
79+
AppendWorkPlane(workPlane);
80+
return Task.CompletedTask;
81+
}
82+
83+
/// <inheritdoc/>
84+
public abstract void AppendWorkPlane(WorkPlane workPlane);
7085

7186
/// <inheritdoc/>
72-
public abstract Task AppendVectorBlockAsync(VectorBlock block);
87+
[Obsolete("Please use AppendVectorBlock")]
88+
public Task AppendVectorBlockAsync(VectorBlock block)
89+
{
90+
AppendVectorBlock(block);
91+
return Task.CompletedTask;
92+
}
93+
94+
/// <summary>
95+
/// Writes the VectorBlock to the workPlane last appended in the job.
96+
/// </summary>
97+
/// <param name="block">VectorBlock to write to file</param>
98+
public abstract void AppendVectorBlock(VectorBlock block);
7399

74100
/// <summary>Indicates if a fileOperation is running, i.e. if a filestream is open.</summary>
75101
public abstract FileWriteOperation FileOperationInProgress { get; }

ReaderWriter/AbstractReaderWriter/IReader.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ You should have received a copy of the GNU Lesser General Public
2222
---- Copyright End ----
2323
*/
2424

25-
using System.Threading.Tasks;
25+
using System;
26+
using System.Threading.Tasks;
2627
using OpenVectorFormat;
2728

2829
namespace OpenVectorFormat.AbstractReaderWriter
@@ -41,8 +42,14 @@ Job JobShell
4142
/// <summary>Retrieves workPlane point data on demand, delegating ownership of the data to the caller. The complete WorkPlane needs to be cached into memory for this operation.</summary>
4243
/// <param name="i_workPlane">index of workPlane</param>
4344
/// <returns>Requested WorkPlane with all associated VectorBlocks.</returns>
45+
[Obsolete("Please use GetWorkPlane")]
4446
Task<WorkPlane> GetWorkPlaneAsync(int i_workPlane);
4547

48+
/// <summary>Retrieves workPlane point data on demand, delegating ownership of the data to the caller. The complete WorkPlane needs to be cached into memory for this operation.</summary>
49+
/// <param name="i_workPlane">index of workPlane</param>
50+
/// <returns>Requested WorkPlane with all associated VectorBlocks.</returns>
51+
WorkPlane GetWorkPlane(int i_workPlane);
52+
4653
/// <summary>Retrieves WorkPlaneShell with all the meta-data, without the actual vectorblocks, delegating ownership of the data to the caller.</summary>
4754
/// <param name="i_workPlane">index of workPlane</param>
4855
/// <returns>Requested WorkPlane with all associated VectorBlocks</returns>
@@ -52,6 +59,13 @@ Job JobShell
5259
/// <param name="i_workPlane">index of workPlane</param>
5360
/// <param name="i_vectorblock">index of vectorblock</param>
5461
/// <returns>Requested VectorBlock</returns>
62+
[Obsolete("Please use GetVectorBlock")]
5563
Task<VectorBlock> GetVectorBlockAsync(int i_workPlane, int i_vectorblock);
64+
65+
/// <summary>Retrieves vector block point data on demand, delegating ownership of the data to the caller.</summary>
66+
/// <param name="i_workPlane">index of workPlane</param>
67+
/// <param name="i_vectorblock">index of vectorblock</param>
68+
/// <returns>Requested VectorBlock</returns>
69+
VectorBlock GetVectorBlock(int i_workPlane, int i_vectorblock);
5670
}
5771
}

0 commit comments

Comments
 (0)