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

GH96: read and cache revisions #97

Merged
merged 9 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove ReadByRoute options
  • Loading branch information
Alexander van Delft committed Feb 24, 2020
commit 538ec64cdfb97a15edce54bd89696cd8713f1032
10 changes: 0 additions & 10 deletions CDP4Dal.NetCore.Tests/DAL/DalTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,6 @@ public override Task<IEnumerable<Thing>> Write(OperationContainer operationConta
throw new System.NotImplementedException();
}

public override Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
}

public override Task<IEnumerable<Thing>> Read<T>(T thing, CancellationToken token, IQueryAttributes attributes = null)
{
throw new System.NotImplementedException();
Expand Down Expand Up @@ -310,11 +305,6 @@ public override Task<IEnumerable<Thing>> Write(OperationContainer operationConta
throw new NotImplementedException();
}

public override Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
}

public override Task<IEnumerable<Thing>> Read<T>(T thing, CancellationToken token, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
Expand Down
5 changes: 0 additions & 5 deletions CDP4Dal.NetCore.Tests/SessionTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,6 @@ public Task<IEnumerable<Thing>> Write(OperationContainer operationContainer, IEn
throw new NotImplementedException();
}

public Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
}

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
Expand Down
10 changes: 0 additions & 10 deletions CDP4Dal.Tests/DAL/DalTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,6 @@ public override Task<IEnumerable<Thing>> Write(OperationContainer operationConta
throw new System.NotImplementedException();
}

public override Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
}

public override Task<IEnumerable<Thing>> Read<T>(T thing, CancellationToken token, IQueryAttributes attributes = null)
{
throw new System.NotImplementedException();
Expand Down Expand Up @@ -311,11 +306,6 @@ public override Task<IEnumerable<Thing>> Write(OperationContainer operationConta
throw new NotImplementedException();
}

public override Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
}

public override Task<IEnumerable<Thing>> Read<T>(T thing, CancellationToken token, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
Expand Down
5 changes: 0 additions & 5 deletions CDP4Dal.Tests/SessionTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,6 @@ public Task<IEnumerable<Thing>> Write(OperationContainer operationContainer, IEn
throw new NotImplementedException();
}

public Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotImplementedException();
}

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
Expand Down
19 changes: 0 additions & 19 deletions CDP4Dal/DAL/Dal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,6 @@ protected Dal()
/// </returns>
public abstract Task<IEnumerable<Thing>> Write(OperationContainer operationContainer, IEnumerable<string> files = null);

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
/// <param name="route">
/// The Uri/route of the Thing that needs to be read from the data-source
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/>
/// </param>
/// <param name="attributes">
/// An instance of <see cref="IQueryAttributes"/> to be used with the request
/// </param>
/// <returns>
/// A list of <see cref="Thing"/>s that are contained by the provided <see cref="Thing"/> including the <see cref="Thing"/>.
/// In case the <see cref="Thing"/> is a top container then all the <see cref="Thing"/>s that have been updated since the
/// last read will be returned.
/// </returns>
public abstract Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null);

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
Expand Down
22 changes: 0 additions & 22 deletions CDP4Dal/DAL/IDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,6 @@ public interface IDal
/// </returns>
Task<IEnumerable<Thing>> Write(OperationContainer operationContainer, IEnumerable<string> files = null);

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
/// <param name="route">
/// The Uri/route of the Thing that needs to be read from the data-source
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/>
/// </param>
/// <param name="attributes">
/// An instance of <see cref="IQueryAttributes"/> to be used with the request
/// </param>
/// <returns>
/// A list of <see cref="Thing"/> that are contained by the provided <see cref="Thing"/> including the <see cref="Thing"/>.
/// In case the
/// <param name="thing">
/// </param>
/// is a top container then all the <see cref="Thing"/>s that have been updated since the
/// last read will be returned.
/// </returns>
Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null);

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions CDP4Dal/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ public interface ISession
/// <summary>
/// Read a list of <see cref="Thing"/>s in the associated <see cref="IDal"/>
/// </summary>
/// <param name="routes">The <see cref="IEnumerable{String}"/> that contains the Routes of the things to read</param>
/// <param name="things">The <see cref="IEnumerable{Thing}"/> that contains the <see cref="Thing"/>s to read</param>
/// <param name="queryAttributes">The <see cref="IQueryAttributes"/> to be used to read data</param>
/// <returns>
/// an await-able <see cref="Task"/>
/// </returns>
Task Read(IEnumerable<string> routes, IQueryAttributes queryAttributes);
Task Read(IEnumerable<Thing> things, IQueryAttributes queryAttributes);

/// <summary>
/// Write all the <see cref="Operation"/>s from an <see cref="OperationContainer"/> asynchronously.
Expand Down
18 changes: 9 additions & 9 deletions CDP4Dal/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,26 +482,26 @@ public async Task Read(Thing thing, IQueryAttributes queryAttributes)
/// <summary>
/// Read a list of <see cref="Thing"/>s in the associated <see cref="IDal"/>
/// </summary>
/// <param name="routes">The <see cref="IEnumerable{String}"/> that contains the Routes of the things to read</param>
/// <param name="things">The <see cref="IEnumerable{Thing}"/> that contains the <see cref="Thing"/> to read</param>
/// <param name="queryAttributes">The <see cref="IQueryAttributes"/> to be used to read data</param>
/// <returns>
/// an await-able <see cref="Task"/>
/// </returns>
public async Task Read(IEnumerable<string> routes, IQueryAttributes queryAttributes)
public async Task Read(IEnumerable<Thing> things, IQueryAttributes queryAttributes)
{
if (this.ActivePerson == null)
{
throw new InvalidOperationException($"The data cannot be read when the ActivePerson is null; The Open method must be called prior to any of the Read methods");
}

var routeList = routes.ToList();
var thingList = things.ToList();

if (!routeList.Any())
if (!thingList.Any())
{
throw new ArgumentException($"The requested list of things is null or empty.");
}

logger.Info("Session.Read {0} things", routeList.Count());
logger.Info("Session.Read {0} things", thingList.Count());

var foundThings = new List<CDP4Common.DTO.Thing>();

Expand All @@ -510,23 +510,23 @@ public async Task Read(IEnumerable<string> routes, IQueryAttributes queryAttribu
// Max 10 async calls at a time, otherwise we could create a sort of a DDOS attack to the DAL/webservice
var loopCount = 10;

while (routeList.Any())
while (thingList.Any())
{
var tasks = new List<Task<IEnumerable<CDP4Common.DTO.Thing>>>();

// Create the token source
this.cancellationTokenSource = new CancellationTokenSource();

foreach (var route in routeList.Take(loopCount))
foreach (var thing in thingList.Take(loopCount))
{
tasks.Add(this.Dal.ReadByRoute(route, this.cancellationTokenSource.Token, queryAttributes));
tasks.Add(this.Dal.Read(thing.ToDto(), this.cancellationTokenSource.Token, queryAttributes));
}

var newThings = (await Task.WhenAll(tasks.ToArray())).SelectMany(x => x).ToList();

foundThings.AddRange(newThings);

routeList = routeList.Skip(loopCount).ToList();
thingList = thingList.Skip(loopCount).ToList();
}
}
catch (OperationCanceledException)
Expand Down
22 changes: 0 additions & 22 deletions CDP4JsonFileDal/JsonFileDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,28 +221,6 @@ public override Task<IEnumerable<Thing>> Write(OperationContainer operationConta
throw new NotSupportedException("Writing OperationContainer to the data-source is not supported");
}

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
/// <param name="route">
/// The Uri/route of the Thing that needs to be read from the data-source
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/>
/// </param>
/// <param name="attributes">
/// An instance of <see cref="IQueryAttributes"/> to be used with the request
/// </param>
/// <returns>
/// A list of <see cref="Thing"/>s that are contained by the provided <see cref="Thing"/> including the <see cref="Thing"/>.
/// In case the <see cref="Thing"/> is a top container then all the <see cref="Thing"/>s that have been updated since the
/// last read will be returned.
/// </returns>
public override Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotSupportedException("Reading Things by route/URI is not supported");
}

/// <summary>
/// Reads the data related to the provided <see cref="CDP4Common.DTO.Thing"/> from the data-source
/// </summary>
Expand Down
29 changes: 0 additions & 29 deletions CDP4ServicesDal/CdpServicesDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,35 +247,6 @@ public override async Task<IEnumerable<Thing>> Read(CDP4Common.DTO.Iteration ite
return result;
}

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
/// <param name="route">
/// The Uri/route of the Thing that needs to be read from the data-source
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/>
/// </param>
/// <param name="attributes">
/// An instance of <see cref="IQueryAttributes"/> to be used with the request
/// </param>
/// <returns>
/// A list of <see cref="Thing"/> that are contained by the provided <see cref="Thing"/> including the <see cref="Thing"/>.
/// In case the <see cref="Thing"/> is a top container then all the <see cref="Thing"/>s that have been updated since the
/// last read will be returned.
/// </returns>
public override async Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
if (this.Credentials == null || this.Credentials.Uri == null)
{
throw new InvalidOperationException("The CDP4 DAL is not open.");
}

var watch = Stopwatch.StartNew();

return await this.ReadByRoute(watch, route, cancellationToken, attributes);
}

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
Expand Down
22 changes: 0 additions & 22 deletions CDP4WspDal/WSPDal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,28 +209,6 @@ public override async Task<IEnumerable<Thing>> Write(OperationContainer operatio
return result;
}

/// <summary>
/// Reads the data related to the provided <see cref="Thing"/> from the data-source
/// </summary>
/// <param name="route">
/// The Uri/route of the Thing that needs to be read from the data-source
/// </param>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/>
/// </param>
/// <param name="attributes">
/// An instance of <see cref="IQueryAttributes"/> to be used with the request
/// </param>
/// <returns>
/// A list of <see cref="Thing"/>s that are contained by the provided <see cref="Thing"/> including the <see cref="Thing"/>.
/// In case the <see cref="Thing"/> is a top container then all the <see cref="Thing"/>s that have been updated since the
/// last read will be returned.
/// </returns>
public override Task<IEnumerable<Thing>> ReadByRoute(string route, CancellationToken cancellationToken, IQueryAttributes attributes = null)
{
throw new NotSupportedException("Reading Things by route/URI is not supported");
}

/// <summary>
/// Write all the <see cref="Operation"/>s from all the <see cref="OperationContainer"/>s.
/// </summary>
Expand Down