public override int GetHashCode() { int hash = 1; if (LibraryId.Length != 0) { hash ^= LibraryId.GetHashCode(); } if (PageIndex != 0) { hash ^= PageIndex.GetHashCode(); } if (PageSize != 0) { hash ^= PageSize.GetHashCode(); } if (SearchText.Length != 0) { hash ^= SearchText.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { unchecked { return((LibraryId.GetHashCode() * 397) ^ LibraryNumber.GetHashCode()); } }
public override void ReadData(CitpBinaryReader data) { base.ReadData(data); ThmbnailFormat = data.ReadCookie(); ThumbnailWidth = data.ReadUInt16(); ThumbnailHeight = data.ReadUInt16(); ThumbnailFlags = (ThumbnailOptions)data.ReadByte(); LibraryType = (MsexElementType)data.ReadByte(); if (MsexVersion < 1.1) { LibraryId.ParseNumber(data.ReadByte()); } else { LibraryId = data.ReadMsexLibraryId(); } int elementCount = (MsexVersion < 1.2) ? data.ReadByte() : data.ReadUInt16(); for (int n = 0; n < elementCount; n++) { ElementNumbers.Add(data.ReadByte()); } }
public void DistinctCombineTargetFrameworks() { var id = new LibraryId("source", "name", "version"); var references = new[] { new LibraryReference( id, new[] { "f1" }, new[] { new LibraryId("source", "d", "1") }, false), new LibraryReference( id, new[] { "f2" }, new[] { new LibraryId("source", "d", "2") }, false) }; var actual = _sut.Distinct(references).ToList(); actual.Count.ShouldBe(1); actual[0].Id.ShouldBe(id); actual[0].TargetFrameworks.ShouldBe(new[] { "f1", "f2" }, true); actual[0].Dependencies.Count.ShouldBe(2); actual[0].Dependencies[0].Name.ShouldBe("d"); actual[0].Dependencies[0].Version.ShouldBe("1"); actual[0].Dependencies[1].Name.ShouldBe("d"); actual[0].Dependencies[1].Version.ShouldBe("2"); }
public LibraryReference(LibraryId id, string[] targetFrameworks, IList <LibraryId> dependencies, bool isInternal) { Id = id; Dependencies = dependencies; TargetFrameworks = targetFrameworks; IsInternal = isInternal; }
public async Task UpdateAllPackagesReadMe() { var libraryId = new LibraryId("source", "name", "version"); var metadata = new Package(); _storage .Setup(r => r.GetAllLibrariesAsync(CancellationToken.None)) .ReturnsAsync(new[] { libraryId }); var adapter = new Mock <IPackageRepositoryAdapter>(MockBehavior.Strict); _container.RegisterInstance("source", adapter.Object); adapter .Setup(a => a.LoadPackageAsync(libraryId, CancellationToken.None)) .ReturnsAsync(metadata); adapter .Setup(a => a.UpdatePackageReadMeAsync(metadata, CancellationToken.None)) .Returns(Task.CompletedTask); var actual = await _sut.UpdateAllPackagesReadMeAsync(CancellationToken.None); actual.Count.ShouldBe(1); actual[0].ShouldBe(metadata); _storage.VerifyAll(); adapter.VerifyAll(); }
public async Task <Package> LoadPackageAsync(LibraryId id, CancellationToken token) { var index = await Storage.ReadLibraryIndexJsonAsync <LibraryIndexJson>(id, token); var package = new Package { SourceCode = id.SourceCode, LicenseCode = index.License.Code, UsedBy = index.UsedBy.Select(i => new PackageApplication(i.Name, i.InternalOnly)).ToArray() }; if (!index.License.Status.IsNullOrEmpty()) { package.ApprovalStatus = Enum.Parse <PackageApprovalStatus>(index.License.Status); } package.Remarks = await Storage.ReadRemarksFileName(id, token); package.ThirdPartyNotices = await Storage.ReadThirdPartyNoticesFile(id, token); foreach (var license in index.Licenses) { package.Licenses.Add(new PackageLicense { Code = license.Code, HRef = license.HRef, Subject = license.Subject, CodeDescription = license.Description }); } await AppendSpecAttributesAsync(id, package, token); return(package); }
private async Task <NuGetSpec> ReadSpecAsync(LibraryId id, CancellationToken token) { using (var specContent = await Storage.OpenLibraryFileReadAsync(id, NuGetConstants.RepositorySpecFileName, token)) { return(Api.ParseSpec(specContent)); } }
public override void WriteData(CitpBinaryWriter data) { base.WriteData(data); data.WriteCookie(ThumbnailFormat); data.Write(ThumbnailWidth); data.Write(ThumbnailHeight); data.Write((byte)ThumbnailFlags); data.Write((byte)LibraryType); if (MsexVersion < CitpMsexVersions.Msex11Version) { data.Write(LibraryId.ToNumber()); } else { data.WriteMsexLibraryId(LibraryId); } if (MsexVersion < CitpMsexVersions.Msex12Version) { data.Write((byte)ElementNumbers.Count); } else { data.Write((UInt16)ElementNumbers.Count); } foreach (byte element in ElementNumbers) { data.Write(element); } }
protected async Task <byte[]> GetPackageContentAsync(LibraryId id, CancellationToken token) { using (var stream = await Storage.OpenLibraryFileReadAsync(id, RepositoryPackageFileName, token)) { if (stream != null) { return(await stream.ToArrayAsync(token)); } } if (!_packageContentById.TryGetValue(id, out var content)) { content = await DownloadPackageContentAsync(id, token); if (content == null) { throw new InvalidOperationException("Package {0} {1} not found on {2}.".FormatWith(id.Name, id.Version, id.SourceCode)); } _packageContentById.TryAdd(id, content); if (DownloadPackageIntoRepository) { await Storage.WriteLibraryFileAsync(id, RepositoryPackageFileName, content, token); } } return(content); }
private async Task <PackageJson> ReadPackageJsonAsync(LibraryId id, CancellationToken token) { using (var jsonContent = await Storage.OpenLibraryFileReadAsync(id, NpmConstants.RepositoryPackageJsonFileName, token)) { return(Api.ParsePackageJson(jsonContent)); } }
public Task UpdatePackageReadMeAsync(Package package, CancellationToken token) { package.AssertNotNull(nameof(package)); var id = new LibraryId(package.SourceCode, package.Name, package.Version); return(Storage.CreateDefaultThirdPartyNoticesFile(id, token)); }
private static async Task CreateEmptyFileAsync(IStorage storage, LibraryId id, string fileName, CancellationToken token) { using (var stream = await storage.OpenLibraryFileReadAsync(id, fileName, CancellationToken.None)) { if (stream == null) { await storage.WriteLibraryFileAsync(id, fileName, Array.Empty <byte>(), token); } } }
/// <summary> /// Initializes a new instance of the <see cref="VbaLibrary"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="guid">The unique identifier.</param> /// <param name="majorVersion">The major version.</param> /// <param name="minorVersion">The minor version.</param> /// <param name="type">The type.</param> /// <param name="fullPath">The full path.</param> /// <param name="displayName">The display name.</param> public VbaLibrary(string name, Guid guid, uint majorVersion, uint minorVersion, uint type, string fullPath, string displayName) { Name = name; Libid = new LibraryId(guid, majorVersion, minorVersion, type, fullPath, displayName); }
public async ValueTask <PackageRemoveResult> RemoveFromApplicationAsync(LibraryId id, string appName, CancellationToken token) { var result = await ResolveAdapter(id.SourceCode).RemoveFromApplicationAsync(id, appName, token); if (result == PackageRemoveResult.RemovedNoRefs) { await Storage.RemoveLibraryAsync(id, token); } return(result); }
protected override async Task AppendSpecAttributesAsync(LibraryId id, Package package, CancellationToken token) { var spec = await ReadSpecAsync(id, token); package.Name = spec.Id; package.Version = spec.Version; package.Description = spec.Description; package.HRef = spec.PackageHRef; package.Author = spec.Authors; package.Copyright = spec.Copyright; }
protected override async Task AppendSpecAttributesAsync(LibraryId id, Package package, CancellationToken token) { var json = await ReadPackageJsonAsync(id, token); // no Copyright package.Name = json.Name; package.Version = json.Version; package.Description = json.Description; package.HRef = json.PackageHRef; package.Author = json.Authors; }
public override int GetHashCode() { unchecked { int hashCode = (int)LibraryType; hashCode = (hashCode * 397) ^ LibraryNumber.GetHashCode(); hashCode = (hashCode * 397) ^ LibraryId.GetHashCode(); hashCode = (hashCode * 397) ^ (int)UpdateFlags; hashCode = (hashCode * 397) ^ (AffectedElements?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (AffectedLibraries?.GetHashCode() ?? 0); return(hashCode); } }
public override int GetHashCode() { int result = base.GetHashCode(); result = (result * 397) ^ LibraryId.GetHashCode(); result = (result * 397) ^ LibraryName.GetHashCode(); result = (result * 397) ^ LibraryPicture.GetHashCode(); result = (result * 397) ^ Title.GetHashCode(); result = (result * 397) ^ Author.GetHashCode(); result = (result * 397) ^ Isbn.GetHashCode(); result = (result * 397) ^ PublishYear.GetHashCode(); return(result); }
public async ValueTask <bool> DownloadAsync(LibraryId id, CancellationToken token) { var index = await Storage.ReadLibraryIndexJsonAsync <LibraryIndexJson>(id, token); var isNew = false; if (index == null) { isNew = true; index = new LibraryIndexJson(); await CreateNewAsync(id, index, token); } else { var exists = await Storage.LibraryFileExistsAsync(id, RepositoryPackageFileName, token); if (!exists && DownloadPackageIntoRepository) { await GetPackageContentAsync(id, token); } } _packageContentById.TryRemove(id, out _); var indexSnapshot = isNew ? default : new LibraryIndexJsonSnapshot(index); if (index.License.Code.IsNullOrEmpty()) { foreach (var license in index.Licenses) { await RefreshLicenseAsync(id, license, token); if (license.Subject.EqualsIgnoreCase(PackageLicense.SubjectPackage)) { await CheckPackageLicenseCodeMatchUrlAsync(id, license, token); if (license.Description.IsNullOrEmpty()) { index.License.Code = license.Code; } } } } if (isNew || indexSnapshot.HasChanges(index)) { await Storage.WriteLibraryIndexJsonAsync(id, index, token); } return(isNew); }
protected void Page_PreRender(object sender, EventArgs e) { if (IsPostBack) { if (LibraryDistrictId.SelectedValue != SelectedDistrictId.Value) { SelectedDistrictId.Value = LibraryDistrictId.SelectedValue; LibraryBranchData.DataBind(); LibraryId.Items.Clear(); LibraryId.Items.Add(new ListItem("[Select a Library Branch]", string.Empty)); LibraryId.DataBind(); } } }
public async Task RemoveFromApplicationKeepPackage() { var libraryId = new LibraryId("source", "name", "version"); var adapter = new Mock <IPackageRepositoryAdapter>(MockBehavior.Strict); adapter .Setup(a => a.RemoveFromApplicationAsync(libraryId, "app1", CancellationToken.None)) .ReturnsAsync(PackageRemoveResult.Removed); _container.RegisterInstance(libraryId.SourceCode, adapter.Object); var actual = await _sut.RemoveFromApplicationAsync(libraryId, "app1", CancellationToken.None); actual.ShouldBe(PackageRemoveResult.Removed); }
private static async Task <string> ReadFileAsync(IStorage storage, LibraryId id, string fileName, CancellationToken token) { string result = null; using (var stream = await storage.OpenLibraryFileReadAsync(id, fileName, token)) { if (stream != null) { using (var reader = new StreamReader(stream)) { result = await reader.ReadToEndAsync(); } } } return(result.IsNullOrEmpty() ? null : result); }
public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } var other = (BookSearchResult)obj; return(LibraryId.Equals(other.LibraryId) && LibraryName.Equals(other.LibraryName) && LibraryPicture.Equals(other.LibraryPicture) && Title.Equals(other.Title) && Author.Equals(other.Author) && PublishYear.Equals(other.PublishYear) && Isbn.Equals(other.Isbn)); }
public bool Equals([CanBeNull] CitpElementLibraryUpdatedInformation other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(LibraryType == other.LibraryType && LibraryNumber == other.LibraryNumber && LibraryId.Equals(other.LibraryId) && UpdateFlags == other.UpdateFlags && SequenceComparison.SequenceEqual(AffectedElements, other.AffectedElements) && SequenceComparison.SequenceEqual(AffectedLibraries, other.AffectedLibraries)); }
protected async Task <LibraryLicense> ResolveUrlLicenseAsync(LibraryId id, string url, string subject, CancellationToken token) { var license = new LibraryLicense { Subject = subject, HRef = url }; var info = await LicenseResolver.ResolveByUrlAsync(url, token); license.Code = info?.Code; if (info?.FileContent != null) { await Storage.WriteLibraryFileAsync(id, subject + "-" + info.FileName, info.FileContent, token); } return(license); }
private async Task RefreshLicenseAsync(LibraryId id, LibraryLicense license, CancellationToken token) { if (!license.Code.IsNullOrEmpty() || license.HRef.IsNullOrEmpty()) { return; } var test = await ResolveUrlLicenseAsync(id, license.HRef, license.Subject, token); if (test.Code.IsNullOrEmpty()) { license.Description = "License should be verified on {0}".FormatWith(license.HRef); } else { license.Description = null; license.Code = test.Code; } }
public override void ReadData(CitpBinaryReader data) { base.ReadData(data); if (MsexVersion < CitpMsexVersions.Msex11Version) { LibraryId.ParseNumber(data.ReadByte()); } else { LibraryId = data.ReadMsexLibraryId(); } int elementCount = MsexVersion < CitpMsexVersions.Msex12Version ? data.ReadByte() : data.ReadUInt16(); for (int n = 0; n < elementCount; n++) { Elements.Add(new EffectInfomation(data, MsexVersion)); } }
public override void ReadData(CitpBinaryReader data) { base.ReadData(data); if (MsexVersion < 1.1) { LibraryId.ParseNumber(data.ReadByte()); } else { LibraryId = data.ReadMsexLibraryId(); } int elementCount = MsexVersion < 1.2 ? data.ReadByte() : data.ReadUInt16(); for (int n = 0; n < elementCount; n++) { Elements.Add(new MediaInformation(data)); } }
public async ValueTask <PackageRemoveResult> RemoveFromApplicationAsync(LibraryId id, string appName, CancellationToken token) { appName.AssertNotNull(nameof(appName)); var model = await Storage.ReadLibraryIndexJsonAsync <LibraryIndexJson>(id, token); var result = PackageRemoveResult.None; var index = model.UsedBy.IndexOf(i => i.Name.EqualsIgnoreCase(appName)); if (index >= 0) { model.UsedBy.RemoveAt(index); await Storage.WriteLibraryIndexJsonAsync(id, model, token); result = model.UsedBy.Count == 0 ? PackageRemoveResult.RemovedNoRefs : PackageRemoveResult.Removed; } return(result); }