Beispiel #1
0
        //////////////////////////////////////////////////
        // Tests backend
        //////////////////////////////////////////////////

        private void AnyTest(string v1, string v2, int res)
        {
            Assert.AreEqual(
                UVersion.CompareVersions(v1, v2), res
                );

            if (res == 0)
            {
                return;
            }

            int opposite = res == 1 ? -1 : 1;

            Assert.AreEqual(
                UVersion.CompareVersions(v2, v1), opposite
                );
        }
        public List <UWikiFileVersion> GetAllVersions()
        {
            var versions         = new UVersion();
            var allVersions      = versions.GetAllVersions();
            var wikiFileVersions = new List <UWikiFileVersion>();

            foreach (var version in allVersions)
            {
                wikiFileVersions.Add(new UWikiFileVersion
                {
                    Name            = version.Name,
                    Key             = version.Key,
                    VoteDescription = version.FullVersion.VersionDescription()
                });
            }

            return(wikiFileVersions);
        }
Beispiel #3
0
        public ActionResult CompatibilityReport(int projectId, int fileId)
        {
            var compatReport = new VersionCompatibilityService(DatabaseContext);

            var currentMember = Members.IsLoggedIn() ? Members.GetCurrentMember() : null;

            var project = Umbraco.TypedContent(projectId);

            return(PartialView("~/Views/Partials/Projects/CompatibilityReport.cshtml",
                               new VersionCompatibilityReportModel
            {
                VersionCompatibilities = compatReport.GetCompatibilityReport(projectId),
                CurrentMemberIsLoggedIn = currentMember != null,
                FileId = fileId,
                ProjectId = projectId,
                AllVersions = UVersion.GetAllVersions(),
                WorksOnUaaS = project.GetPropertyValue <bool>("worksOnUaaS")
            }));
        }
Beispiel #4
0
        public IEnumerable <VersionCompatibility> GetCompatibilityReport(int projectId)
        {
            var versions        = new UVersion();
            var uVersions       = versions.GetAllVersions();
            var projectProvider = new OurUmbraco.MarketPlace.NodeListing.NodeListingProvider();
            var project         = projectProvider.GetListing(projectId, true);

            var compatList = new List <VersionCompatibility>();

            var projectCompatibilities = _databaseContext.Database.Fetch <dynamic>(
                "SELECT * FROM DeliVersionCompatibility WHERE projectId = @projectId", new { projectId = projectId });

            foreach (var ver in uVersions)
            {
                var ver1    = ver;
                var reports = projectCompatibilities.Where(x => x.version == ver1.Name.Replace("Version ", string.Empty) && x.projectId == project.Id).ToArray();

                if (reports.Any())
                {
                    float compats = reports.Count(x => x.isCompatible);
                    float numReps = reports.Count();
                    var   perc    = Convert.ToInt32(((compats / numReps) * 100));

                    var smiley = "unhappy";

                    if (perc >= 95)
                    {
                        smiley = "joyous";
                    }
                    else if (perc < 95 && perc >= 80)
                    {
                        smiley = "happy";
                    }
                    else if (perc < 80 && perc >= 65)
                    {
                        smiley = "neutral";
                    }
                    else if (perc < 65 && perc >= 50)
                    {
                        smiley = "unhappy";
                    }
                    else
                    {
                        smiley = "superUnhappy";
                    }



                    compatList.Add(new VersionCompatibility()
                    {
                        Percentage = perc, Smiley = smiley, Version = ver.Name
                    });
                }
                else
                {
                    compatList.Add(new VersionCompatibility()
                    {
                        Percentage = 0, Smiley = "untested", Version = ver.Name
                    });
                }
            }

            return(compatList);
        }
Beispiel #5
0
        /// <summary>
        /// This tries to clean the string to convert to a Version instance based on the various ways we store version string values for projects
        /// </summary>
        /// <param name="version"></param>
        /// <param name="reduceToConfigured"></param>
        /// <returns>
        /// This compares the version passed in, then checks what the latest configured minor version is in uVersion.config with comparison
        /// to this minor version and uses that.
        /// </returns>
        public static System.Version GetFromUmbracoString(this string version, bool reduceToConfigured = true)
        {
            if (string.IsNullOrWhiteSpace(version))
            {
                return(null);
            }

            //need to clean up this string, it could be all sorts of things
            version = version.ToLower()
                      .Split('-')[0]
                      .Replace("saved", "")
                      .Replace("nan", "")
                      .Replace("v", "")
                      .Replace(".x", "")
                      .Trim(',');
            var versions = new UVersion();

            if (!version.Contains(".") && version.Length > 0)
            {
                //if there's no . then it stored the strange way like in uVersion.config
                var uVersion = versions.GetAllVersions().FirstOrDefault(x => x.Key == $"v{version}");

                if (uVersion != null)
                {
                    version = uVersion.FullVersion.ToString();
                }
                else
                {
                    //pad it out to 3 digits
                    int o;
                    version = version.PadRight(3, '0');
                    if (int.TryParse(version, out o))
                    {
                        //if it ends with '0', that means it's a X.X.X version
                        // if it does not end with '0', that means that the last 2 digits are the
                        // Minor part of the version
                        version = version.EndsWith("0")
                            ? string.Format("{0}.{1}.{2}", version[0], version[1], 0)
                            : string.Format("{0}.{1}.{2}", version[0], version.Substring(1), 0);
                    }
                }
            }

            if (!System.Version.TryParse(version, out var result))
            {
                return(null);
            }

            if (!reduceToConfigured)
            {
                return(result);
            }

            //Now we need to check what the latest configured major/minor version that corresponds to this one is and use that version.
            // This is so that search results are actually returned. Example, if running 7.4.3 but the latest configured minor is 7.4.0, then
            // no search results are returned because nothing would be tagged as compatible with 7.4.3, only 7.4.0

            // get all Version's configured order by latest
            var allAsVersion = versions.GetAllAsVersions().ToArray();

            //search for the latest compatible version to search on
            foreach (var v in allAsVersion)
            {
                if (result > v)
                {
                    return(v);
                }
            }

            //we couldn't find anything,
            //this will occur if the passed in version is not greater than any configured versions, in this case we have no choice
            // but to return a very small version, we'll stick with 4.5 since this is the infamous hard coded value
            return(new System.Version(4, 5, 0));
        }