Skip to content

Commit 3c07251

Browse files
lxatstariongrouplxatrhea
authored andcommitted
Attachment finetuning (#203)
* Add Path property to Attachment * Implement Attachment functionality * Version bump * Code review changes * Fix according to review
1 parent 0221df5 commit 3c07251

File tree

9 files changed

+217
-65
lines changed

9 files changed

+217
-65
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AttachmentTestFixture.cs" company="RHEA System S.A.">
3+
// Copyright (c) 2015-2021 RHEA System S.A.
4+
//
5+
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft
6+
//
7+
// This file is part of CDP4-SDK Community Edition
8+
//
9+
// The CDP4-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The CDP4-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// </copyright>
23+
// --------------------------------------------------------------------------------------------------------------------
24+
25+
namespace CDP4Common.Tests.Poco
26+
{
27+
using System;
28+
29+
using CDP4Common.EngineeringModelData;
30+
using CDP4Common.SiteDirectoryData;
31+
32+
using NUnit.Framework;
33+
34+
[TestFixture]
35+
internal class AttachmentTestFixture
36+
{
37+
private Attachment attachment;
38+
39+
[SetUp]
40+
public void Setup()
41+
{
42+
this.attachment = new Attachment(Guid.NewGuid(), null, null);
43+
this.attachment.FileName = "filerev";
44+
45+
this.attachment.FileType.Add(new FileType(Guid.NewGuid(), null, null) { Extension = "ext1" });
46+
this.attachment.FileType.Add(new FileType(Guid.NewGuid(), null, null) { Extension = "ext2" });
47+
}
48+
49+
[Test]
50+
public void VerifyPathForFileRevisionLocatedInFileStore()
51+
{
52+
Assert.AreEqual("filerev.ext1.ext2", this.attachment.Path);
53+
}
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="AttachmentTestFixture.cs" company="RHEA System S.A.">
3+
// Copyright (c) 2015-2021 RHEA System S.A.
4+
//
5+
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft
6+
//
7+
// This file is part of CDP4-SDK Community Edition
8+
//
9+
// The CDP4-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The CDP4-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// </copyright>
23+
// --------------------------------------------------------------------------------------------------------------------
24+
25+
namespace CDP4Common.Tests.Poco
26+
{
27+
using System;
28+
29+
using CDP4Common.EngineeringModelData;
30+
using CDP4Common.SiteDirectoryData;
31+
32+
using NUnit.Framework;
33+
34+
[TestFixture]
35+
internal class AttachmentTestFixture
36+
{
37+
private Attachment attachment;
38+
39+
[SetUp]
40+
public void Setup()
41+
{
42+
this.attachment = new Attachment(Guid.NewGuid(), null, null);
43+
this.attachment.FileName = "filerev";
44+
45+
this.attachment.FileType.Add(new FileType(Guid.NewGuid(), null, null) { Extension = "ext1" });
46+
this.attachment.FileType.Add(new FileType(Guid.NewGuid(), null, null) { Extension = "ext2" });
47+
}
48+
49+
[Test]
50+
public void VerifyPathForFileRevisionLocatedInFileStore()
51+
{
52+
Assert.AreEqual("filerev.ext1.ext2", this.attachment.Path);
53+
}
54+
}
55+
}

CDP4Common/Dto/Attachment.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// --------------------------------------------------------------------------------------------------------------------
22
// <copyright file="Attachment.cs" company="RHEA System S.A.">
33
// Copyright (c) 2015-2021 RHEA System S.A.
4-
//
4+
//
55
// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Patxi Ozkoidi, Alexander van Delft, Nathanael Smiechowski, Ahmed Ahmed, Simon Wood
6-
//
6+
//
77
// This file is part of COMET-IME Community Edition.
88
// The COMET-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration
99
// compliant with ECSS-E-TM-10-25 Annex A and Annex C.
10-
//
10+
//
1111
// The COMET-IME Community Edition is free software; you can redistribute it and/or
1212
// modify it under the terms of the GNU Affero General Public
1313
// License as published by the Free Software Foundation; either
1414
// version 3 of the License, or any later version.
15-
//
15+
//
1616
// The COMET-IME Community Edition is distributed in the hope that it will be useful,
1717
// but WITHOUT ANY WARRANTY; without even the implied warranty of
1818
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1919
// Lesser General Public License for more details.
20-
//
20+
//
2121
// You should have received a copy of the GNU Affero General Public License
2222
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
// </copyright>
@@ -30,5 +30,9 @@ namespace CDP4Common.DTO
3030
/// </summary>
3131
public partial class Attachment : ILocalFile
3232
{
33+
/// <summary>
34+
/// Contains the path of the file in the context of the User's PC
35+
/// </summary>
36+
public string LocalPath { get; set; }
3337
}
3438
}

CDP4Common/Dto/FileRevision.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// --------------------------------------------------------------------------------------------------------------------
22
// <copyright file="FileRevision.cs" company="RHEA System S.A.">
33
// Copyright (c) 2015-2021 RHEA System S.A.
4-
//
4+
//
55
// Author: Sam Gerené, Alex Vorobiev, Naron Phou, Patxi Ozkoidi, Alexander van Delft, Nathanael Smiechowski, Ahmed Ahmed, Simon Wood
6-
//
6+
//
77
// This file is part of COMET-IME Community Edition.
88
// The COMET-IME Community Edition is the RHEA Concurrent Design Desktop Application and Excel Integration
99
// compliant with ECSS-E-TM-10-25 Annex A and Annex C.
10-
//
10+
//
1111
// The COMET-IME Community Edition is free software; you can redistribute it and/or
1212
// modify it under the terms of the GNU Affero General Public
1313
// License as published by the Free Software Foundation; either
1414
// version 3 of the License, or any later version.
15-
//
15+
//
1616
// The COMET-IME Community Edition is distributed in the hope that it will be useful,
1717
// but WITHOUT ANY WARRANTY; without even the implied warranty of
1818
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1919
// Lesser General Public License for more details.
20-
//
20+
//
2121
// You should have received a copy of the GNU Affero General Public License
2222
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2323
// </copyright>
@@ -30,5 +30,9 @@ namespace CDP4Common.DTO
3030
/// </summary>
3131
public partial class FileRevision : ILocalFile
3232
{
33+
/// <summary>
34+
/// Contains the path of the file in the context of the User's PC
35+
/// </summary>
36+
public string LocalPath { get; set; }
3337
}
3438
}
Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
// --------------------------------------------------------------------------------------------------------------------
2-
// <copyright file="ILocalFile.cs" company="RHEA System S.A.">
3-
// Copyright (c) 2015-2020 RHEA System S.A.
4-
//
5-
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft
6-
//
7-
// This file is part of CDP4-SDK Community Edition
8-
//
9-
// The CDP4-SDK Community Edition is free software; you can redistribute it and/or
10-
// modify it under the terms of the GNU Lesser General Public
11-
// License as published by the Free Software Foundation; either
12-
// version 3 of the License, or (at your option) any later version.
13-
//
14-
// The CDP4-SDK Community Edition is distributed in the hope that it will be useful,
15-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17-
// Lesser General Public License for more details.
18-
//
19-
// You should have received a copy of the GNU Lesser General Public License
20-
// along with this program; if not, write to the Free Software Foundation,
21-
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22-
// </copyright>
23-
// --------------------------------------------------------------------------------------------------------------------
24-
25-
namespace CDP4Common
26-
{
27-
using CDP4Common.EngineeringModelData;
28-
29-
/// <summary>
30-
/// An interface for classes containing data that's needed in a file upload scenario.
31-
/// Typically used for <see cref="FileRevision"/> objects.
32-
/// </summary>
33-
public interface ILocalFile
34-
{
35-
/// <summary>
36-
/// Contains the path of the file in the context of the User's PC
37-
/// </summary>
38-
string LocalPath { get; }
39-
40-
/// <summary>
41-
/// Gets or sets the ContentHash.
42-
/// </summary>
43-
/// <remarks>
44-
/// SHA-1 hash code of the content (byte stream) of this object
45-
/// Note: The SHA-1 cryptographic hash is described in <a href="http://en.wikipedia.org/wiki/SHA-1">http://en.wikipedia.org/wiki/SHA-1</a>. It provides a unique hash to the file content of the file and was selected for future compatibility with a GIT (<a href="http://git-scm.com/">http://git-scm.com/</a>) version controlled file store. Implementations of E-TM-10-25 need to provide a way to associate a SHA-1 hash to the content of a file. Whether or not the content of two FileRevisions differs can then be determined by just comparing the SHA-1 hashes without the need for having access to the actual file content itself.
46-
/// </remarks>
47-
string ContentHash { get; }
48-
}
49-
}
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="ILocalFile.cs" company="RHEA System S.A.">
3+
// Copyright (c) 2015-2020 RHEA System S.A.
4+
//
5+
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft
6+
//
7+
// This file is part of CDP4-SDK Community Edition
8+
//
9+
// The CDP4-SDK Community Edition is free software; you can redistribute it and/or
10+
// modify it under the terms of the GNU Lesser General Public
11+
// License as published by the Free Software Foundation; either
12+
// version 3 of the License, or (at your option) any later version.
13+
//
14+
// The CDP4-SDK Community Edition is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
// Lesser General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU Lesser General Public License
20+
// along with this program; if not, write to the Free Software Foundation,
21+
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22+
// </copyright>
23+
// --------------------------------------------------------------------------------------------------------------------
24+
25+
namespace CDP4Common
26+
{
27+
using CDP4Common.EngineeringModelData;
28+
29+
/// <summary>
30+
/// An interface for classes containing data that's needed in a file upload scenario.
31+
/// Typically used for <see cref="FileRevision"/> objects.
32+
/// </summary>
33+
public interface ILocalFile
34+
{
35+
/// <summary>
36+
/// Contains the path of the file in the context of the User's PC
37+
/// </summary>
38+
string LocalPath { get; }
39+
40+
/// <summary>
41+
/// Gets or sets the ContentHash.
42+
/// </summary>
43+
/// <remarks>
44+
/// SHA-1 hash code of the content (byte stream) of this object
45+
/// Note: The SHA-1 cryptographic hash is described in <a href="http://en.wikipedia.org/wiki/SHA-1">http://en.wikipedia.org/wiki/SHA-1</a>. It provides a unique hash to the file content of the file and was selected for future compatibility with a GIT (<a href="http://git-scm.com/">http://git-scm.com/</a>) version controlled file store. Implementations of E-TM-10-25 need to provide a way to associate a SHA-1 hash to the content of a file. Whether or not the content of two FileRevisions differs can then be determined by just comparing the SHA-1 hashes without the need for having access to the actual file content itself.
46+
/// </remarks>
47+
string ContentHash { get; }
48+
}
49+
}

CDP4Common/Poco/Attachment.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// --------------------------------------------------------------------------------------------------------------------
22
// <copyright file="Attachment.cs" company="RHEA System S.A.">
3-
// Copyright (c) 2015-2020 RHEA System S.A.
3+
// Copyright (c) 2015-2021 RHEA System S.A.
44
//
55
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft
66
//
@@ -24,11 +24,46 @@
2424

2525
namespace CDP4Common.EngineeringModelData
2626
{
27+
using System;
28+
using System.Linq;
29+
using System.Text;
30+
2731
/// <summary>
2832
/// Extended part for the auto-generated <see cref="Attachment"/>
2933
/// </summary>
3034
public partial class Attachment : ILocalFile
3135
{
36+
/// <summary>
37+
/// Gets or sets the Path.
38+
/// </summary>
39+
/// <remarks>
40+
/// full path name including folder path and type extension(s)
41+
/// Note: The path is derived to be the concatenation of the path of the containingFolder (if any) followed by a forward slash and the name of this FileRevision and then a dot separated concatenation of the extensions of the associated FileTypes. This yields a path that is similar to that of a "file://" URL starting from the containing FileStore.
42+
/// </remarks>
43+
/// <exception cref="InvalidOperationException">
44+
/// The Path property is a derived property; when the getter and setter are invoked an InvalidOperationException will be thrown.
45+
/// </exception>
46+
public string Path => this.GetDerivedPath();
47+
48+
/// <summary>
49+
/// Returns the derived <see cref="Path"/> value
50+
/// </summary>
51+
/// <returns>The <see cref="Path"/> value</returns>
52+
private string GetDerivedPath()
53+
{
54+
var path = new StringBuilder();
55+
56+
path.Append(this.FileName);
57+
58+
foreach (var fileType in this.FileType.Where(x => !string.IsNullOrWhiteSpace(x.Extension)))
59+
{
60+
path.Append(".");
61+
path.Append(fileType.Extension);
62+
}
63+
64+
return path.ToString();
65+
}
66+
3267
/// <summary>
3368
/// Gets or sets the (temporary) LocalPath of the file
3469
/// </summary>

CDP4Dal/DAL/Dal.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace CDP4Dal.DAL
3333
using System.Threading;
3434
using System.Threading.Tasks;
3535

36+
using CDP4Common;
3637
using CDP4Common.CommonData;
3738
using CDP4Common.Helpers;
3839
using CDP4Common.MetaInfo;

CDP4Dal/Operations/ThingTransaction.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,14 @@ public OperationContainer FinalizeTransaction()
617617
}
618618

619619
/// <summary>
620-
/// Get all the files that need to be added to the DataStore accoring to the added/changed/deleted <see cref="Thing"/>s
620+
/// Get all the files that need to be added to the DataStore according to the added <see cref="Thing"/>s that implement <see cref="ILocalFile"/>.
621621
/// </summary>
622622
/// <returns>An Array of strings that contain the local paths in the context of the users' computer</returns>
623623
public string[] GetFiles()
624624
{
625625
var files = new List<string>();
626-
627-
foreach (var thing in this.AddedThing.OfType<ILocalFile>().Union(this.UpdatedThing.OfType<ILocalFile>()).Where(x => x.LocalPath != null))
626+
627+
foreach (var thing in this.AddedThing.OfType<ILocalFile>().Where(x => x.LocalPath != null))
628628
{
629629
if (string.IsNullOrWhiteSpace(thing.ContentHash))
630630
{

CDP4Dal/Session.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,6 @@ public bool CanCancel()
794794
continue;
795795
}
796796

797-
cancellationTokenSource?.Cancel();
798-
799797
return true;
800798
}
801799

0 commit comments

Comments
 (0)