-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathExtensions.cs
207 lines (196 loc) · 8.68 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using AVPRIndex;
using YamlDotNet.Core.Tokens;
using static AVPRIndex.Domain;
namespace AVPRClient
{
public static class Extensions
{
public static bool IdentityEquals(
this AVPRClient.ValidationPackage package,
AVPRClient.ValidationPackage other
)
{
return package.Name == other.Name
&& package.MajorVersion == other.MajorVersion
&& package.MinorVersion == other.MinorVersion
&& package.PatchVersion == other.PatchVersion
&& package.PreReleaseVersionSuffix == other.PreReleaseVersionSuffix
&& package.BuildMetadataVersionSuffix == other.BuildMetadataVersionSuffix;
}
public static bool IdentityEquals(
this AVPRClient.ValidationPackage package,
AVPRIndex.Domain.ValidationPackageIndex indexedPackage
)
{
return package.Name == indexedPackage.Metadata.Name
&& package.MajorVersion == indexedPackage.Metadata.MajorVersion
&& package.MinorVersion == indexedPackage.Metadata.MinorVersion
&& package.PatchVersion == indexedPackage.Metadata.PatchVersion
&& package.PreReleaseVersionSuffix == indexedPackage.Metadata.PreReleaseVersionSuffix
&& package.BuildMetadataVersionSuffix == indexedPackage.Metadata.BuildMetadataVersionSuffix;
}
public static bool IdentityEquals(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage,
AVPRClient.ValidationPackage package
)
{
return package.Name == indexedPackage.Metadata.Name
&& package.MajorVersion == indexedPackage.Metadata.MajorVersion
&& package.MinorVersion == indexedPackage.Metadata.MinorVersion
&& package.PatchVersion == indexedPackage.Metadata.PatchVersion
&& package.PreReleaseVersionSuffix == indexedPackage.Metadata.PreReleaseVersionSuffix
&& package.BuildMetadataVersionSuffix == indexedPackage.Metadata.BuildMetadataVersionSuffix;
}
public static AVPRClient.ValidationPackage toValidationPackage(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage,
DateTimeOffset releaseDate
)
{
return new AVPRClient.ValidationPackage
{
Name = indexedPackage.Metadata.Name,
Summary = indexedPackage.Metadata.Summary,
Description = indexedPackage.Metadata.Description,
MajorVersion = indexedPackage.Metadata.MajorVersion,
MinorVersion = indexedPackage.Metadata.MinorVersion,
PatchVersion = indexedPackage.Metadata.PatchVersion,
PreReleaseVersionSuffix = indexedPackage.Metadata.PreReleaseVersionSuffix,
BuildMetadataVersionSuffix = indexedPackage.Metadata.BuildMetadataVersionSuffix,
PackageContent = BinaryContent.fromFile(indexedPackage.RepoPath),
ReleaseDate = releaseDate,
Tags =
indexedPackage.Metadata.Tags
.Select(tag =>
{
return new AVPRClient.OntologyAnnotation
{
Name = tag.Name,
TermAccessionNumber = tag.TermAccessionNumber,
TermSourceREF = tag.TermSourceREF
};
})
.ToList(),
ReleaseNotes = indexedPackage.Metadata.ReleaseNotes,
Authors =
indexedPackage.Metadata.Authors
.Select(author =>
{
return new AVPRClient.Author
{
FullName = author.FullName,
Email = author.Email,
Affiliation = author.Affiliation,
AffiliationLink = author.AffiliationLink
};
})
.ToList(),
CQCHookEndpoint = indexedPackage.Metadata.CQCHookEndpoint
};
}
public static AVPRClient.ValidationPackage toValidationPackage(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage
)
{
return indexedPackage.toValidationPackage(DateTimeOffset.Now);
}
public static AVPRClient.PackageContentHash toPackageContentHash(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage,
bool HashFileDirectly = false
)
{
if ( HashFileDirectly)
{
return new AVPRClient.PackageContentHash
{
PackageName = indexedPackage.Metadata.Name,
Hash = Hash.hashFile(indexedPackage.RepoPath),
PackageMajorVersion = indexedPackage.Metadata.MajorVersion,
PackageMinorVersion = indexedPackage.Metadata.MinorVersion,
PackagePatchVersion = indexedPackage.Metadata.PatchVersion,
PackagePreReleaseVersionSuffix = indexedPackage.Metadata.PreReleaseVersionSuffix,
PackageBuildMetadataVersionSuffix = indexedPackage.Metadata.BuildMetadataVersionSuffix
};
}
else
{
return new AVPRClient.PackageContentHash
{
PackageName = indexedPackage.Metadata.Name,
Hash = indexedPackage.ContentHash,
PackageMajorVersion = indexedPackage.Metadata.MajorVersion,
PackageMinorVersion = indexedPackage.Metadata.MinorVersion,
PackagePatchVersion = indexedPackage.Metadata.PatchVersion,
PackagePreReleaseVersionSuffix = indexedPackage.Metadata.PreReleaseVersionSuffix,
PackageBuildMetadataVersionSuffix = indexedPackage.Metadata.BuildMetadataVersionSuffix
};
}
}
public static AVPRIndex.Domain.Author AsIndexType(
this Author authors
)
{
return
new AVPRIndex.Domain.Author
{
FullName = authors.FullName,
Email = authors.Email,
Affiliation = authors.Affiliation,
AffiliationLink = authors.AffiliationLink
};
}
public static AVPRIndex.Domain.Author [] AsIndexType (
this ICollection<Author> authors
)
{
return authors
.Select(author => author.AsIndexType())
.ToArray();
}
public static AVPRIndex.Domain.OntologyAnnotation AsIndexType(
this OntologyAnnotation tag
)
{
return new AVPRIndex.Domain.OntologyAnnotation
{
Name = tag.Name,
TermSourceREF = tag.TermSourceREF,
TermAccessionNumber = tag.TermAccessionNumber
};
}
public static AVPRIndex.Domain.OntologyAnnotation[] AsIndexType(
this ICollection<OntologyAnnotation> ontologyAnnotations
)
{
return ontologyAnnotations
.Select(tag => tag.AsIndexType())
.ToArray();
}
public static AVPRIndex.Domain.ValidationPackageMetadata toValidationPackageMetadata(
this AVPRClient.ValidationPackage validationPackage
)
{
return Domain.ValidationPackageMetadata.create(
name: validationPackage.Name,
summary: validationPackage.Summary,
description: validationPackage.Description,
majorVersion: validationPackage.MajorVersion,
minorVersion: validationPackage.MinorVersion,
patchVersion: validationPackage.PatchVersion,
PreReleaseVersionSuffix: validationPackage.PreReleaseVersionSuffix,
BuildMetadataVersionSuffix: validationPackage.BuildMetadataVersionSuffix,
Publish: Microsoft.FSharp.Core.FSharpOption<bool>.None,
Authors: validationPackage.Authors.AsIndexType(),
Tags: validationPackage.Tags.AsIndexType(),
ReleaseNotes: validationPackage.ReleaseNotes,
CQCHookEndpoint: validationPackage.CQCHookEndpoint
);
}
}
}