/src/AddIns/Misc/PackageManagement/Project/Src/PackageFromRepository.cs

https://github.com/ajadex/SharpDevelop · C# · 215 lines · 156 code · 42 blank · 17 comment · 6 complexity · def48702b3d68fdd235f0a95dbb14db1 MD5 · raw file

  1. // Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. using System.Collections.Generic;
  20. using System.IO;
  21. using System.Runtime.Versioning;
  22. using NuGet;
  23. namespace ICSharpCode.PackageManagement
  24. {
  25. public class PackageFromRepository : IPackageFromRepository
  26. {
  27. IPackage package;
  28. bool? hasDependencies;
  29. public PackageFromRepository(IPackage package, IPackageRepository repository)
  30. {
  31. this.package = package;
  32. this.Repository = repository;
  33. }
  34. public IPackageRepository Repository { get; private set; }
  35. public IEnumerable<IPackageAssemblyReference> AssemblyReferences {
  36. get { return package.AssemblyReferences; }
  37. }
  38. public string Id {
  39. get { return package.Id; }
  40. }
  41. public SemanticVersion Version {
  42. get { return package.Version; }
  43. }
  44. public string Title {
  45. get { return package.Title; }
  46. }
  47. public IEnumerable<string> Authors {
  48. get { return package.Authors; }
  49. }
  50. public IEnumerable<string> Owners {
  51. get { return package.Owners; }
  52. }
  53. public Uri IconUrl {
  54. get { return package.IconUrl; }
  55. }
  56. public Uri LicenseUrl {
  57. get { return package.LicenseUrl; }
  58. }
  59. public Uri ProjectUrl {
  60. get { return package.ProjectUrl;}
  61. }
  62. public bool RequireLicenseAcceptance {
  63. get { return package.RequireLicenseAcceptance; }
  64. }
  65. public string Description {
  66. get { return package.Description; }
  67. }
  68. public string Summary {
  69. get { return package.Summary; }
  70. }
  71. public string Language {
  72. get { return package.Language; }
  73. }
  74. public string Tags {
  75. get { return package.Tags; }
  76. }
  77. public IEnumerable<FrameworkAssemblyReference> FrameworkAssemblies {
  78. get { return package.FrameworkAssemblies; }
  79. }
  80. public IEnumerable<PackageDependency> Dependencies {
  81. get { return package.GetCompatiblePackageDependencies(null); }
  82. }
  83. public Uri ReportAbuseUrl {
  84. get { return package.ReportAbuseUrl; }
  85. }
  86. public int DownloadCount {
  87. get { return package.DownloadCount; }
  88. }
  89. public DateTime? LastUpdated {
  90. get { return GetLastUpdated(); }
  91. }
  92. DateTime? GetLastUpdated()
  93. {
  94. DateTimeOffset? lastUpdated = GetDataServicePackageLastUpdated();
  95. if (lastUpdated.HasValue) {
  96. return lastUpdated.Value.DateTime;
  97. }
  98. return null;
  99. }
  100. protected virtual DateTimeOffset? GetDataServicePackageLastUpdated()
  101. {
  102. var dataServicePackage = package as DataServicePackage;
  103. if (dataServicePackage != null) {
  104. return dataServicePackage.LastUpdated;
  105. }
  106. return null;
  107. }
  108. public IEnumerable<IPackageFile> GetFiles()
  109. {
  110. return package.GetFiles();
  111. }
  112. public Stream GetStream()
  113. {
  114. return package.GetStream();
  115. }
  116. public bool HasDependencies {
  117. get {
  118. if (!hasDependencies.HasValue) {
  119. IEnumerator<PackageDependency> enumerator = Dependencies.GetEnumerator();
  120. hasDependencies = enumerator.MoveNext();
  121. }
  122. return hasDependencies.Value;
  123. }
  124. }
  125. public bool IsLatestVersion {
  126. get { return package.IsLatestVersion; }
  127. }
  128. public Nullable<DateTimeOffset> Published {
  129. get { return package.Published; }
  130. }
  131. public string ReleaseNotes {
  132. get { return package.ReleaseNotes; }
  133. }
  134. public string Copyright {
  135. get { return package.Copyright; }
  136. }
  137. public bool IsAbsoluteLatestVersion {
  138. get { return package.IsAbsoluteLatestVersion; }
  139. }
  140. public bool Listed {
  141. get { return package.Listed; }
  142. }
  143. public IEnumerable<PackageDependencySet> DependencySets {
  144. get { return package.DependencySets; }
  145. }
  146. public IEnumerable<FrameworkName> GetSupportedFrameworks()
  147. {
  148. return package.GetSupportedFrameworks();
  149. }
  150. public override string ToString()
  151. {
  152. return package.ToString();
  153. }
  154. public ICollection<PackageReferenceSet> PackageAssemblyReferences {
  155. get { return package.PackageAssemblyReferences; }
  156. }
  157. public Version MinClientVersion {
  158. get { return package.MinClientVersion; }
  159. }
  160. public Uri GalleryUrl {
  161. get {
  162. var dataServicePackage = package as DataServicePackage;
  163. if (dataServicePackage != null) {
  164. return dataServicePackage.GalleryDetailsUrl;
  165. }
  166. return null;
  167. }
  168. }
  169. public bool DevelopmentDependency {
  170. get { return package.DevelopmentDependency; }
  171. }
  172. }
  173. }