Exemplo n.º 1
0
        public byte[] GetPackageFile(string packageGuid, string umbracoVersion)
        {
            var umbHelper      = new UmbracoHelper(UmbracoContext.Current);
            var pckRepoService = new PackageRepositoryService(umbHelper, umbHelper.MembershipHelper, ApplicationContext.Current.DatabaseContext);

            System.Version currUmbracoVersion;
            if (!System.Version.TryParse(umbracoVersion, out currUmbracoVersion))
            {
                throw new InvalidOperationException("Could not parse the version specified " + umbracoVersion);
            }

            var guid    = new Guid(packageGuid);
            var details = pckRepoService.GetDetails(guid, currUmbracoVersion, true);

            if (details == null)
            {
                throw new InvalidOperationException("No package found with id " + packageGuid);
            }

            if (details.ZipUrl.IsNullOrWhiteSpace())
            {
                throw new InvalidOperationException("This package is not compatible with the Umbraco version " + umbracoVersion);
            }

            var wf = new WikiFile(details.ZipFileId);

            if (wf == null)
            {
                throw new InvalidOperationException("Could not find wiki file by id " + details.ZipFileId);
            }
            wf.UpdateDownloadCounter(true, true);

            return(wf.ToByteArray());
        }
Exemplo n.º 2
0
        public byte[] fetchPackage(string packageGuid)
        {
            var umbHelper      = new UmbracoHelper(UmbracoContext.Current);
            var pckRepoService = new PackageRepositoryService(umbHelper, umbHelper.MembershipHelper, ApplicationContext.Current.DatabaseContext);

            //This doesn't matter what we set it to so long as it's below 7.5 since that is the version we introduce strict dependencies
            var currUmbracoVersion = new System.Version(4, 0, 0);
            var guid    = new Guid(packageGuid);
            var details = pckRepoService.GetDetails(guid, currUmbracoVersion, true);

            if (details == null)
            {
                throw new InvalidOperationException("No package found with id " + packageGuid);
            }

            if (details.ZipUrl.IsNullOrWhiteSpace())
            {
                throw new InvalidOperationException("This package is not compatible with your Umbraco version");
            }

            var wf = new WikiFile(details.ZipFileId);

            if (wf == null)
            {
                throw new InvalidOperationException("Could not find wiki file by id " + details.ZipFileId);
            }
            wf.UpdateDownloadCounter(true, true);

            return(wf.ToByteArray());
        }
 public PackageRepositoryController()
 {
     Service = new PackageRepositoryService(Umbraco, Members, DatabaseContext);
 }
Exemplo n.º 4
0
        public byte[] fetchPackageByVersion(string packageGuid, string repoVersion)
        {
            //first, translate repo version enum to our.umb version strings
            //version3 = v31
            //version4 = v4
            //version41 = v45
            //if v45, check if default package is v47 as well, as 4.7 install use v45 when calling the repo (thank god we are moving to nuget)
            //everything else = v4

            string version = "v4";

            switch (repoVersion.ToLower())
            {
            case "version3":
                version = "v31";
                break;

            case "version4":
                version = "v4";
                break;

            case "version41":
                version = "v45";
                break;

            case "version41legacy":
                version = "v45l";
                break;

            default:
                version = "v4";
                break;
            }

            var umbHelper      = new UmbracoHelper(UmbracoContext.Current);
            var pckRepoService = new PackageRepositoryService(umbHelper, umbHelper.MembershipHelper, ApplicationContext.Current.DatabaseContext);

            //This doesn't matter what we set it to so long as it's below 7.5 since that is the version we introduce strict dependencies
            //Side note: Umbraco 7.5.0 uses this endpoint but since 7.5.0 is already out there's nothing we can do about this, if we pass in 7.5.x then
            // the logic will use strict file versions which we cannot do because this endpoint is also used for < 7.5!
            // The worst that can happen in this case is that a strict package dependency has been made on 7.5 and then an umbraco 7.5 package
            // requests the file, well it won't get it because this will only return non strict packages.
            var currUmbracoVersion = new System.Version(4, 0, 0);
            var guid    = new Guid(packageGuid);
            var details = pckRepoService.GetDetails(guid, currUmbracoVersion, true);

            if (details == null)
            {
                return(new byte[0]);
            }

            if (details.ZipUrl.IsNullOrWhiteSpace())
            {
                throw new InvalidOperationException("This package is not compatible with the Umbraco version " + currUmbracoVersion);
            }

            var wf = new WikiFile(details.ZipFileId);

            //WikiFile wf = OurUmbraco.Repository.Packages.PackageFileByGuid(new Guid(packageGuid));

            //if the package doesn't care about the umbraco version needed...
            if (wf.Version.Version == "nan")
            {
                return(wf.ToByteArray());
            }

            //if v45
            if (version == "v45")
            {
                int v = 0;
                if (int.TryParse(wf.Version.Version.Replace("v", ""), out v))
                {
                    if (v >= 45)
                    {
                        return(wf.ToByteArray());
                    }
                }


                if (wf.Version.Version == "v47" || wf.Version.Version == "v45")
                {
                    return(wf.ToByteArray());
                }

                if (wf.Version.Version != version && wf.Version.Version != "nan")
                {
                    wf = WikiFile.FindPackageForUmbracoVersion(wf.NodeId, version);
                    return(wf.ToByteArray());
                }
            }

            return(new byte[0]);
        }