/// <summary>
        /// Used by the package CLI tool, gets a list of project files to check if one already exists with the same name
        /// </summary>
        public IEnumerable <WikiFile> GetProjectFiles()
        {
            // The project/member id are exposed as base properties and are resolved from the identity created on the request
            var files = WikiFile.CurrentFiles(ProjectNodeId);

            return(files.Where(x => x.FileType == "package" || x.FileType == "hotfix").OrderByDescending(x => x.Version.Version).ToList());
        }
Пример #2
0
        private void UpdateProjectExamineIndex(IPublishedContent content, int downloads)
        {
            var simpleDataSet = new SimpleDataSet
            {
                NodeDefinition = new IndexedNode(),
                RowData        = new Dictionary <string, string>()
            };

            var projectVotes   = Utils.GetProjectTotalVotes(content.Id);
            var files          = WikiFile.CurrentFiles(content.Id).ToArray();
            var compatVersions = Utils.GetProjectCompatibleVersions(content.Id) ?? new List <string>();

            var simpleDataIndexer = (SimpleDataIndexer)ExamineManager.Instance.IndexProviderCollection["projectIndexer"];

            simpleDataSet = ((ProjectNodeIndexDataService)simpleDataIndexer.DataService)
                            .MapProjectToSimpleDataIndexItem(content, simpleDataSet, "project", projectVotes, files, downloads, compatVersions);

            if (simpleDataSet.NodeDefinition.Type == null)
            {
                simpleDataSet.NodeDefinition.Type = "project";
            }

            var xml = simpleDataSet.RowData.ToExamineXml(simpleDataSet.NodeDefinition.NodeId, simpleDataSet.NodeDefinition.Type);

            simpleDataIndexer.ReIndexNode(xml, "project");
        }
Пример #3
0
        public IEnumerable <SimpleDataSet> GetAllData(string indexType)
        {
            EnsureUmbracoContext();

            var projects = UmbracoContext.Current.ContentCache.GetByXPath("//Community/Projects//Project [projectLive='1']").ToArray();

            var allProjectIds       = projects.Select(x => x.Id).ToArray();
            var allProjectKarma     = Utils.GetProjectTotalVotes();
            var allProjectWikiFiles = WikiFile.CurrentFiles(allProjectIds);
            var allProjectDownloads = Utils.GetProjectTotalDownload();
            var allCompatVersions   = Utils.GetProjectCompatibleVersions();

            foreach (var project in projects)
            {
                LogHelper.Debug(this.GetType(), "Indexing " + project.Name);

                var simpleDataSet = new SimpleDataSet {
                    NodeDefinition = new IndexedNode(), RowData = new Dictionary <string, string>()
                };

                var projectDownloads = allProjectDownloads.ContainsKey(project.Id) ? allProjectDownloads[project.Id] : 0;
                var projectKarma     = allProjectKarma.ContainsKey(project.Id) ? allProjectKarma[project.Id] : 0;
                var projectFiles     = allProjectWikiFiles.ContainsKey(project.Id) ? allProjectWikiFiles[project.Id] : Enumerable.Empty <WikiFile>();
                var projectVersions  = allCompatVersions.ContainsKey(project.Id) ? allCompatVersions[project.Id] : Enumerable.Empty <string>();

                yield return(MapProjectToSimpleDataIndexItem(project, simpleDataSet, indexType, projectKarma, projectFiles, projectDownloads, projectVersions));
            }
        }
Пример #4
0
        public IEnumerable <SimpleDataSet> GetAllData(string indexType)
        {
            var umbContxt = EnsureUmbracoContext();

            var projects = umbContxt.ContentCache.GetByXPath("//Community/Projects//Project [projectLive='1']").ToArray();

            var allProjectIds          = projects.Select(x => x.Id).ToArray();
            var allProjectKarma        = Utils.GetProjectTotalVotes();
            var allProjectWikiFiles    = WikiFile.CurrentFiles(allProjectIds);
            var allProjectDownloads    = Utils.GetProjectTotalPackageDownload();
            var allCompatVersions      = Utils.GetProjectCompatibleVersions();
            var mostRecentDownloadDate = WikiFile.GetMostRecentDownloadDate();
            var downloadStats          = WikiFile.GetMonthlyDownloadStatsByProject(mostRecentDownloadDate.Subtract(TimeSpan.FromDays(365)));

            foreach (var project in projects)
            {
                LogHelper.Debug(this.GetType(), "Indexing " + project.Name);

                var simpleDataSet = new SimpleDataSet {
                    NodeDefinition = new IndexedNode(), RowData = new Dictionary <string, string>()
                };

                var projectDownloads = allProjectDownloads.ContainsKey(project.Id) ? allProjectDownloads[project.Id] : 0;
                var projectKarma     = allProjectKarma.ContainsKey(project.Id) ? allProjectKarma[project.Id] : 0;
                var projectFiles     = allProjectWikiFiles.ContainsKey(project.Id) ? allProjectWikiFiles[project.Id].ToArray() : new WikiFile[] { };
                var projectVersions  = allCompatVersions.ContainsKey(project.Id) ? allCompatVersions[project.Id] : Enumerable.Empty <string>();

                yield return(MapProjectToSimpleDataIndexItem(
                                 downloadStats,
                                 mostRecentDownloadDate,
                                 project, simpleDataSet, indexType, projectKarma, projectFiles, projectDownloads, projectVersions));
            }
        }
Пример #5
0
        private Models.Package MapContentToPackage(IPublishedContent content)
        {
            if (content == null)
            {
                return(null);
            }

            var wikiFiles = WikiFile.CurrentFiles(content.Id);

            return(new Models.Package
            {
                Category = content.Parent.Name,
                Created = content.CreateDate,
                Excerpt = GetPackageExcerpt(content, 12),
                Downloads = Utils.GetProjectTotalDownloadCount(content.Id),
                Id = content.GetPropertyValue <Guid>("packageGuid"),
                Likes = Utils.GetProjectTotalVotes(content.Id),
                Name = content.Name,
                Icon = GetThumbnailUrl(BASE_URL + content.GetPropertyValue <string>("defaultScreenshotPath", "/css/img/package2.png"), 154, 281),
                LatestVersion = content.GetPropertyValue <string>("version"),
                MinimumVersion = GetMinimumVersion(content.GetPropertyValue <int>("file"), wikiFiles.Where(x => x.FileType.InvariantEquals("package"))),
                OwnerInfo = GetPackageOwnerInfo(content.GetPropertyValue <int>("owner"), content.GetPropertyValue <bool>("openForCollab", false), content.Id),
                Url = string.Concat(BASE_URL, content.Url)
            });
        }
Пример #6
0
        public IEnumerable <IMediaFile> GetMediaForProjectByType(int projectId, FileType type)
        {
            var wikiFiles = WikiFile.CurrentFiles(projectId);

            var mediaFiles = new List <MediaFile>();

            foreach (var wikiFile in wikiFiles)
            {
                var mediaFile = new MediaFile
                {
                    Current             = wikiFile.Current,
                    Archived            = wikiFile.Archived,
                    CreateDate          = wikiFile.CreateDate,
                    Name                = wikiFile.Name,
                    Id                  = wikiFile.Id,
                    CreatedBy           = wikiFile.CreatedBy,
                    DotNetVersion       = wikiFile.DotNetVersion,
                    Downloads           = wikiFile.Downloads,
                    FileType            = (FileType)Enum.Parse(typeof(FileType), wikiFile.FileType),
                    FileVersion         = wikiFile.NodeVersion,
                    Path                = wikiFile.Path,
                    RemovedBy           = wikiFile.RemovedBy,
                    SupportsMediumTrust = false,
                    UmbVersion          = wikiFile.Versions,
                    Verified            = wikiFile.Verified
                };

                if (mediaFiles.Contains(mediaFile) == false)
                {
                    mediaFiles.Add(mediaFile);
                }
            }

            return(mediaFiles);
        }
Пример #7
0
        private void RebindFiles()
        {
            List <WikiFile> files = WikiFile.CurrentFiles(pageId);

            rp_files.DataSource = files;
            rp_files.Visible    = (files.Count > 0);
            rp_files.DataBind();
        }
Пример #8
0
        public IEnumerable <SimpleDataSet> GetAllData(string indexType)
        {
            var umbContxt = EnsureUmbracoContext();

            var projects = umbContxt.ContentCache.GetByXPath("//Community/Projects//Project [projectLive='1']").ToArray();

            var nugetService = new NugetPackageDownloadService();

            var nugetDownloads = nugetService.GetNugetPackageDownloads();

            var allProjectIds          = projects.Select(x => x.Id).ToArray();
            var allProjectKarma        = Utils.GetProjectTotalVotes();
            var allProjectWikiFiles    = WikiFile.CurrentFiles(allProjectIds);
            var allProjectDownloads    = Utils.GetProjectTotalPackageDownload();
            var allCompatVersions      = Utils.GetProjectCompatibleVersions();
            var mostRecentDownloadDate = WikiFile.GetMostRecentDownloadDate();

            // if most recent download date is MinValue then there is no download data to query
            var downloadStats = mostRecentDownloadDate == DateTime.MinValue
                ? new Dictionary <int, MonthlyProjectDownloads>()
                : WikiFile.GetMonthlyDownloadStatsByProject(mostRecentDownloadDate.Subtract(TimeSpan.FromDays(365)));

            foreach (var project in projects)
            {
                LogHelper.Debug(this.GetType(), "Indexing " + project.Name);

                var simpleDataSet = new SimpleDataSet {
                    NodeDefinition = new IndexedNode(), RowData = new Dictionary <string, string>()
                };

                var projectDownloads = allProjectDownloads.ContainsKey(project.Id) ? allProjectDownloads[project.Id] : 0;
                var projectKarma     = allProjectKarma.ContainsKey(project.Id) ? allProjectKarma[project.Id] : 0;
                var projectFiles     = allProjectWikiFiles.ContainsKey(project.Id) ? allProjectWikiFiles[project.Id].ToArray() : new WikiFile[] { };
                var projectVersions  = allCompatVersions.ContainsKey(project.Id) ? allCompatVersions[project.Id] : Enumerable.Empty <string>();

                var nugetPackageId = nugetService.GetNuGetPackageId(project);

                int?dailyNugetDownLoads = null;

                if (!string.IsNullOrWhiteSpace(nugetPackageId))
                {
                    var packageInfo = nugetDownloads.FirstOrDefault(x => x.PackageId == nugetPackageId);

                    if (packageInfo != null)
                    {
                        projectDownloads   += packageInfo.TotalDownLoads;
                        dailyNugetDownLoads = packageInfo.AverageDownloadPerDay;
                    }
                }

                yield return(MapProjectToSimpleDataIndexItem(
                                 downloadStats,
                                 mostRecentDownloadDate,
                                 project, simpleDataSet, indexType, projectKarma, projectFiles, projectDownloads, projectVersions, dailyNugetDownLoads));
            }
        }
Пример #9
0
        private void UpdateProjectExamineIndex(IPublishedContent content, int downloads)
        {
            if (content == null)
            {
                return;
            }

            var simpleDataSet = new SimpleDataSet
            {
                NodeDefinition = new IndexedNode(),
                RowData        = new Dictionary <string, string>()
            };

            var projectVotes   = Utils.GetProjectTotalVotes(content.Id);
            var files          = WikiFile.CurrentFiles(content.Id).ToArray();
            var compatVersions = Utils.GetProjectCompatibleVersions(content.Id) ?? new List <string>();
            var downloadStats  = WikiFile.GetMonthlyDownloadStatsByProject(
                content.Id,
                DateTime.Now.Subtract(TimeSpan.FromDays(365)));

            var nugetService        = new OurUmbraco.Community.Nuget.NugetPackageDownloadService();
            var nugetPackageId      = nugetService.GetNuGetPackageId(content);
            int?dailyNugetDownLoads = null;


            if (!nugetPackageId.IsNullOrWhiteSpace())
            {
                var nugetDownloads = nugetService.GetNugetPackageDownloads();

                var packageInfo = nugetDownloads.FirstOrDefault(x => x.PackageId == nugetPackageId);

                if (packageInfo != null)
                {
                    downloads          += packageInfo.TotalDownLoads;
                    dailyNugetDownLoads = packageInfo.AverageDownloadPerDay;
                }
            }


            var simpleDataIndexer = (SimpleDataIndexer)ExamineManager.Instance.IndexProviderCollection["projectIndexer"];

            simpleDataSet = ((ProjectNodeIndexDataService)simpleDataIndexer.DataService)
                            .MapProjectToSimpleDataIndexItem(downloadStats, DateTime.Now, content, simpleDataSet, "project", projectVotes, files, downloads, compatVersions, dailyNugetDownLoads);

            if (simpleDataSet.NodeDefinition.Type == null)
            {
                simpleDataSet.NodeDefinition.Type = "project";
            }

            var xml = simpleDataSet.RowData.ToExamineXml(simpleDataSet.NodeDefinition.NodeId, simpleDataSet.NodeDefinition.Type);

            simpleDataIndexer.ReIndexNode(xml, "project");
        }
Пример #10
0
        public List <Package> GetPackageStatisticsData()
        {
            var packages = new List <Package>();

            var umbracoContext      = UmbracoContext.Current;
            var prs                 = new PackageRepositoryService(new UmbracoHelper(umbracoContext), new MembershipHelper(umbracoContext), UmbracoContext.Current.Application.DatabaseContext);
            var allPackages         = prs.GetPackages(0, 2000);
            var allPackagesPackages = allPackages.Packages;

            var umbracoHelper      = new UmbracoHelper(UmbracoContext.Current);
            var allPackagesContent = umbracoHelper.TypedContentAtXPath("//Project").ToList();

            foreach (var package in allPackagesPackages)
            {
                var packageContent = allPackagesContent.FirstOrDefault(x =>
                                                                       string.Equals(x.GetPropertyValue <string>("packageGuid"), package.Id.ToString(), StringComparison.InvariantCultureIgnoreCase));

                var pkgFiles = new List <WikiFile>();
                if (packageContent != null)
                {
                    pkgFiles = WikiFile.CurrentFiles(packageContent.Id).OrderByDescending(x => x.CreateDate).ToList();
                }

                var statisticsPackage = new Package
                {
                    Name             = package.Name,
                    Owner            = package.OwnerInfo.Owner,
                    Created          = package.Created.ToString("yyyy-MM-dd"),
                    Updated          = (pkgFiles.Any() ? pkgFiles.First().CreateDate : DateTime.MinValue).ToString("yyyy-MM-dd"),
                    Version          = package.LatestVersion.TrimStart('v', 'V'),
                    Compatibility    = pkgFiles.Any() ? pkgFiles.First().Version.Version : string.Empty,
                    Compatibility2   = pkgFiles.Any() ? pkgFiles.First().Versions.ToVersionString().Replace(" ", string.Empty) : string.Empty,
                    License          = packageContent?.GetPropertyValue <string>("licenseName") ?? string.Empty,
                    HasDocumentation = pkgFiles.Any(x => x.FileType == "docs"),
                    Votes            = package.Likes,
                    Downloads        = package.Downloads
                };

                packages.Add(statisticsPackage);
            }


            return(packages);
        }
        void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
        {
            if (sender.ContentType.Alias == "Project")
            {
                //ensure that packages have a guid
                if (sender.getProperty("packageGuid") != null && String.IsNullOrEmpty(sender.getProperty("packageGuid").Value.ToString()))
                {
                    sender.getProperty("packageGuid").Value = Guid.NewGuid().ToString();
                    sender.Save();
                }

                //if the score is above the minimum, set the approved variable
                int score = Xslt.Score(sender.Id, "powersProject");
                if (score >= 15)
                {
                    sender.getProperty("approved").Value = true;
                    sender.Save();
                }

                //this ensures the package stores it's compatible versions on the node itself, so we save a ton of sql calls
                if (sender.getProperty("compatibleVersions") != null)
                {
                    List <string> compatibleVersions = new List <string>();
                    foreach (WikiFile wf in WikiFile.CurrentFiles(sender.Id))
                    {
                        if (wf.FileType == "package")
                        {
                            foreach (var ver in wf.Versions)
                            {
                                if (!compatibleVersions.Contains(ver.Version))
                                {
                                    compatibleVersions.Add(ver.Version);
                                }
                            }
                        }
                    }

                    string _compatibleVersions = string.Join(",", compatibleVersions.ToArray());
                    sender.getProperty("compatibleVersions").Value = "saved," + _compatibleVersions;
                }
            }
        }
Пример #12
0
        private PackageDetails MapContentToPackageDetails(IPublishedContent content)
        {
            if (content == null)
            {
                return(null);
            }

            var package        = MapContentToPackage(content);
            var packageDetails = new PackageDetails(package);
            var wikiFiles      = WikiFile.CurrentFiles(content.Id);

            packageDetails.Compatibility   = GetPackageCompatibility(content);
            packageDetails.NetVersion      = content.GetPropertyValue <string>("dotNetVersion");
            packageDetails.LicenseName     = content.GetPropertyValue <string>("licenseName");
            packageDetails.LicenseUrl      = content.GetPropertyValue <string>("licenseUrl");
            packageDetails.Description     = content.GetPropertyValue <string>("description").CleanHtmlAttributes();
            packageDetails.Images          = GetPackageImages(wikiFiles.Where(x => x.FileType.InvariantEquals("screenshot")), 154, 281);
            packageDetails.ExternalSources = GetExternalSources(content);
            packageDetails.ZipUrl          = string.Concat(BASE_URL, "/FileDownload?id=", content.GetPropertyValue <string>("file"));
            packageDetails.Created         = content.CreateDate;

            return(packageDetails);
        }
Пример #13
0
        /// <summary>
        /// Returns a PackageDetails instance
        /// </summary>
        /// <param name="content"></param>
        /// <param name="currentUmbracoVersion"></param>
        /// <returns>
        /// If the current umbraco version is not compatible with any package files, the ZipUrl and ZipFileId will be empty
        /// </returns>
        private PackageDetails MapContentToPackageDetails(IPublishedContent content, System.Version currentUmbracoVersion)
        {
            if (currentUmbracoVersion == null)
            {
                throw new ArgumentNullException("currentUmbracoVersion");
            }
            if (content == null)
            {
                return(null);
            }

            var package = MapContentToPackage(content, null);

            if (package == null)
            {
                return(null);
            }

            var wikiFiles = WikiFile.CurrentFiles(content.Id);

            //TODO: SD: I dunno where these come from or if we care about it?
            //var deliCompatVersions = Utils.GetProjectCompatibleVersions(content.Id) ?? new List<string>();

            var allPackageFiles = wikiFiles.Where(x => x.FileType.InvariantEquals("package") && x.Archived == false).ToArray();

            //get the strict packages in the correct desc order
            var strictPackageFileVersions = GetAllStrictSupportedPackageVersions(allPackageFiles).ToArray();
            //these are ordered by package version desc
            var nonStrictPackageFiles = GetNonStrictSupportedPackageVersions(allPackageFiles).ToArray();
            var nugetService          = new NugetPackageDownloadService();
            var nuGetPackageId        = nugetService.GetNuGetPackageId(content);

            var packageDetails = new PackageDetails(package)
            {
                TargetedUmbracoVersions = GetAllFilePackageVersions(allPackageFiles).Select(x => {
                    //ensure the version has consistent parts (major.minor.build)
                    var version = x.Build >= 0 ? x : new System.Version(x.Major, x.Minor, 0);
                    return(version.ToString(3));
                }).ToArray(),
                Compatibility      = GetPackageCompatibility(content),
                StrictFileVersions = strictPackageFileVersions.Select(x => new PackageFileVersion
                {
                    PackageVersion = x.PackageVersion.Build >= 0
                        ? x.PackageVersion.ToString(3)
                        : new System.Version(x.PackageVersion.Major, x.PackageVersion.Minor, 0).ToString(3),
                    MinUmbracoVersion = x.MinUmbracoVersion.Build >= 0
                        ? x.MinUmbracoVersion.ToString(3)
                        : new System.Version(x.MinUmbracoVersion.Major, x.MinUmbracoVersion.Minor, 0).ToString(3),
                    FileId = x.FileId
                }).ToList(),
                NetVersion      = content.GetPropertyValue <string>("dotNetVersion"),
                LicenseName     = content.GetPropertyValue <string>("licenseName"),
                LicenseUrl      = content.GetPropertyValue <string>("licenseUrl"),
                Description     = content.GetPropertyValue <string>("description").CleanHtmlAttributes(),
                Images          = GetPackageImages(wikiFiles.Where(x => x.FileType.InvariantEquals("screenshot")), 154, 281),
                ExternalSources = GetExternalSources(content),
                NuGetPackageId  = nuGetPackageId,
                IsNuGetFormat   = content.GetPropertyValue <bool>("isNuGetFormat")
            };

            var version75 = new System.Version(7, 5, 0);

            //this is the file marked as the current/latest release
            var currentReleaseFile = content.GetPropertyValue <int>("file");

            if (strictPackageFileVersions.Length == 0)
            {
                //if there are no strict package files then return the latest package file

                packageDetails.ZipUrl    = string.Concat(BASE_URL, "/FileDownload?id=", currentReleaseFile);
                packageDetails.ZipFileId = currentReleaseFile;
            }
            else if (currentUmbracoVersion < version75)
            {
                //if the umbraco version is < 7.5 it means that strict package formats are not supported
                AssignLatestNonStrictPackageFile(nonStrictPackageFiles, currentReleaseFile, packageDetails);
            }
            else
            {
                //this package has some strict version dependency files, so we need to figure out which one is
                // compatible with the current umbraco version passed in and also use the latest available
                // package version that is compatible.

                int found = -1;
                foreach (var pckVersion in strictPackageFileVersions)
                {
                    //if this version will work with the umbraco version, then use it
                    if (currentUmbracoVersion >= pckVersion.MinUmbracoVersion)
                    {
                        found = pckVersion.FileId;
                        break;
                    }
                }

                if (found != -1)
                {
                    //got one! so use it's id for the file download
                    packageDetails.ZipUrl    = string.Concat(BASE_URL, "/FileDownload?id=", found);
                    packageDetails.ZipFileId = found;
                }
                else if (nonStrictPackageFiles.Length > 0)
                {
                    //Here's the other case, if this package has both strict and non-strict package file versions and we didn't find one above,
                    //than we need to determine if the latest non-strict package file format should be used for the current version being passed in

                    AssignLatestNonStrictPackageFile(nonStrictPackageFiles, currentReleaseFile, packageDetails);
                }
            }

            packageDetails.Created = content.CreateDate;

            return(packageDetails);
        }
Пример #14
0
 /// <summary>
 /// Get all the files that are associated with this project
 /// </summary>
 /// <param name="projectId"></param>
 /// <returns></returns>
 public List <WikiFile> GetMediaFilesByProjectId(int projectId)
 {
     return(WikiFile.CurrentFiles(projectId));
 }
Пример #15
0
        public PackageStats GetPackageStats(string startDate, string endDate)
        {
            if (DateTime.TryParse(startDate, out var start) == false)
            {
                return(null);
            }

            if (DateTime.TryParse(endDate, out var end) == false)
            {
                return(null);
            }

            var packageStats = new PackageStats
            {
                Created          = new HashSet <string>(),
                Updated          = new HashSet <string>(),
                All              = new HashSet <string>(),
                CreatorNames     = new HashSet <string>(),
                ContributorNames = new HashSet <string>()
            };

            var contributorNames = new HashSet <string>();

            var allPackages = GetAllPackages();

            var createdPackages = allPackages
                                  .Where(x => x.CreateDate >= start && x.CreateDate <= end)
                                  .ToList();

            foreach (var package in createdPackages)
            {
                packageStats.CreatorNames.Add(GetOwnerName(package));

                foreach (var contributorName in GetContributorNames(package))
                {
                    contributorNames.Add(contributorName);
                }
            }

            var updatedPackages = new List <IPublishedContent>();

            foreach (var package in allPackages)
            {
                var wikiFiles = WikiFile.CurrentFiles(package.Id);

                if (wikiFiles.Any(x => x.CreateDate >= start && x.CreateDate < end) == false)
                {
                    continue;
                }
                if (createdPackages.Any(x => x.Id == package.Id))
                {
                    continue;
                }

                updatedPackages.Add(package);

                packageStats.CreatorNames.Add(GetOwnerName(package));

                foreach (var contributorName in GetContributorNames(package))
                {
                    contributorNames.Add(contributorName);
                }
            }

            foreach (var package in createdPackages)
            {
                packageStats.Created.Add(package.Name);
            }

            foreach (var package in updatedPackages)
            {
                packageStats.Updated.Add(package.Name);
            }

            foreach (var package in allPackages)
            {
                packageStats.All.Add(package.Name);
            }


            foreach (var name in contributorNames)
            {
                if (packageStats.CreatorNames.Contains(name) == false)
                {
                    packageStats.ContributorNames.Add(name);
                }
            }

            return(packageStats);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            library.RegisterJavaScriptFile("tinyMce", "/scripts/tiny_mce/tiny_mce_src.js");

            if (!Page.IsPostBack)
            {
                int pId = 0;

                Member m = Member.GetCurrentMember();
                var    memberHasEnoughReputation = MemberHasEnoughReputation(m);
                if (memberHasEnoughReputation == false)
                {
                    holder.Visible     = false;
                    notallowed.Visible = true;
                }
                else
                {
                    if (m.Groups.ContainsKey(MemberGroup.GetByName("Vendor").Id))
                    {
                        p_purchaseUrl.Visible = true;
                        d_notice.Visible      = false;
                    }


                    string            taglist = string.Empty;
                    XPathNodeIterator tags    =
                        umbraco.editorControls.tags.library.getAllTagsInGroup("project").Current.Select("./tags/tag");

                    while (tags.MoveNext())
                    {
                        taglist += "\"" + tags.Current.Value + "\",";
                    }

                    bool hideHq = true;
                    if (m.Groups.ContainsKey(MemberGroup.GetByName("HQ").Id))
                    {
                        hideHq = false;
                    }

                    List <Category> categories = Packages.Categories(false, hideHq);
                    dd_category.Items.Add(new ListItem("Please select...", ""));

                    foreach (Category c in categories)
                    {
                        dd_category.Items.Add(new ListItem(c.Text, c.Id.ToString()));
                    }

                    ScriptManager.RegisterStartupScript(
                        this,
                        this.GetType(),
                        "inittagsuggest",
                        " $(document).ready(function() { $('#projecttagger').autocomplete([" + taglist +
                        "],{max: 8,scroll: true,scrollHeight: 300}); enableTagger();});",
                        true);


                    if (!string.IsNullOrEmpty(Request.QueryString["id"]) && int.TryParse(Request.QueryString["id"], out pId) &&
                        library.IsLoggedOn())
                    {
                        Document d = new Document(pId);

                        if ((int)d.getProperty("owner").Value == m.Id || Utils.IsProjectContributor(m.Id, d.Id))
                        {
                            lt_title.Text = "Edit project";

                            bt_submit.CommandName     = "save";
                            bt_submit.CommandArgument = d.Id.ToString();

                            tb_name.Text    = d.Text;
                            tb_version.Text = d.getProperty("version").Value.ToString();
                            tb_desc.Text    = d.getProperty("description").Value.ToString();

                            cb_stable.Checked = (d.getProperty("stable").Value.ToString() == "1");
                            tb_status.Text    = d.getProperty("status").Value.ToString();

                            tb_demoUrl.Text    = d.getProperty("demoUrl").Value.ToString();
                            tb_sourceUrl.Text  = d.getProperty("sourceUrl").Value.ToString();
                            tb_websiteUrl.Text = d.getProperty("websiteUrl").Value.ToString();

                            tb_licenseUrl.Text = d.getProperty("licenseUrl").Value.ToString();
                            tb_license.Text    = d.getProperty("licenseName").Value.ToString();

                            tb_purchaseUrl.Text = d.getProperty("vendorUrl").Value.ToString();

                            dd_category.SelectedValue = d.Parent.Id.ToString();

                            List <WikiFile> Files = WikiFile.CurrentFiles(d.Id);


                            bool hasScreenshots = false;
                            if (Files.Count > 0)
                            {
                                foreach (WikiFile f in Files)
                                {
                                    if (f.FileType != "screenshot")
                                    {
                                        dd_package.Items.Add(new ListItem(f.Name, f.Id.ToString()));
                                    }
                                    else
                                    {
                                        dd_screenshot.Items.Add(new ListItem(f.Name, f.Id.ToString()));
                                        hasScreenshots = true;
                                    }
                                }

                                dd_package.SelectedValue = d.getProperty("file").Value.ToString();

                                p_file.Visible = true;
                            }
                            else
                            {
                                p_file.Visible = false;
                            }

                            p_screenshot.Visible = false;

                            if (hasScreenshots)
                            {
                                p_screenshot.Visible        = true;
                                dd_screenshot.SelectedValue = d.getProperty("defaultScreenshot").Value.ToString();
                            }
                            else
                            {
                                p_screenshot.Visible = false;
                            }



                            List <ITag> projecttags = umbraco.editorControls.tags.library.GetTagsFromNodeAsITags(pId);

                            if (projecttags.Count > 0)
                            {
                                string stags = string.Empty;
                                foreach (ITag tag in projecttags)
                                {
                                    stags += tag.TagCaption + ",";
                                }

                                stags = stags.Substring(0, stags.Length - 1);

                                ScriptManager.RegisterStartupScript(
                                    this,
                                    this.GetType(),
                                    "inittags",
                                    " $(document).ready(function() {$('#projecttagger').addTag('" + stags + "');});",
                                    true);
                            }
                        }
                    }
                    else
                    {
                        p_screenshot.Visible = false;
                        p_file.Visible       = false;
                        lt_title.Text        = "Create new project";
                    }
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Returns a PackageDetails instance
        /// </summary>
        /// <param name="content"></param>
        /// <param name="currentUmbracoVersion"></param>
        /// <returns>
        /// If the current umbraco version is not compatible with any package files, the ZipUrl and ZipFileId will be empty
        /// </returns>
        private PackageDetails MapContentToPackageDetails(IPublishedContent content, System.Version currentUmbracoVersion)
        {
            if (currentUmbracoVersion == null)
            {
                throw new ArgumentNullException("currentUmbracoVersion");
            }
            if (content == null)
            {
                return(null);
            }

            var package = MapContentToPackage(content);

            if (package == null)
            {
                return(null);
            }

            var wikiFiles = WikiFile.CurrentFiles(content.Id);

            //TODO: SD: I dunno where these come from or if we care about it?
            //var deliCompatVersions = Utils.GetProjectCompatibleVersions(content.Id) ?? new List<string>();

            var allPackageFiles = wikiFiles.Where(x => x.FileType.InvariantEquals("package")).ToArray();

            //get the strict packages in the correct desc order
            var strictPackageFileVersions = GetAllStrictSupportedPackageVersions(allPackageFiles).ToArray();

            var packageDetails = new PackageDetails(package)
            {
                TargetedUmbracoVersions = GetAllFilePackageVersions(allPackageFiles).Select(x => x.ToString(3)).ToArray(),
                Compatibility           = GetPackageCompatibility(content),
                StrictFileVersions      = strictPackageFileVersions.Select(x => new PackageFileVersion {
                    PackageVersion = x.PackageVersion.ToString(3), MinUmbracoVersion = x.MinUmbracoVersion.ToString(3), FileId = x.FileId
                }).ToList(),
                NetVersion      = content.GetPropertyValue <string>("dotNetVersion"),
                LicenseName     = content.GetPropertyValue <string>("licenseName"),
                LicenseUrl      = content.GetPropertyValue <string>("licenseUrl"),
                Description     = content.GetPropertyValue <string>("description").CleanHtmlAttributes(),
                Images          = GetPackageImages(wikiFiles.Where(x => x.FileType.InvariantEquals("screenshot")), 154, 281),
                ExternalSources = GetExternalSources(content)
            };

            var version75 = new System.Version(7, 5, 0);

            //this is the file marked as the current/latest release
            var currentReleaseFile = content.GetPropertyValue <int>("file");

            if (strictPackageFileVersions.Length == 0)
            {
                //if there are no strict package files then return the latest package file

                packageDetails.ZipUrl    = string.Concat(BASE_URL, "/FileDownload?id=", currentReleaseFile);
                packageDetails.ZipFileId = currentReleaseFile;
            }
            else if (currentUmbracoVersion < version75)
            {
                //if the umbraco version is < 7.5 it means that strict package formats are not supported

                //TODO: Now we have to do the opposite of below and filter out any package file versions that have strict
                // umbraco dependencies applied. Anything that has 7.5 (which would be the very minimum strict dependency) we can check for

                //these are ordered by package version desc
                var nonStrictPackageFiles = GetNonStrictSupportedPackageVersions(allPackageFiles).ToArray();

                if (nonStrictPackageFiles.Length != 0)
                {
                    //there might be a case where the 'current release file' is not the latest version found, so let's check if
                    //the latest release file is included in the non-strict packages and if so we'll use that, otherwise we'll use the latest
                    var found = nonStrictPackageFiles.FirstOrDefault(x => x.FileId == currentReleaseFile);
                    if (found != null)
                    {
                        //it's included in the non strict packages so use it
                        packageDetails.ZipUrl    = string.Concat(BASE_URL, "/FileDownload?id=", currentReleaseFile);
                        packageDetails.ZipFileId = currentReleaseFile;
                    }
                    else
                    {
                        //use the latest available package version
                        packageDetails.ZipUrl    = string.Concat(BASE_URL, "/FileDownload?id=", nonStrictPackageFiles[0].FileId);
                        packageDetails.ZipFileId = nonStrictPackageFiles[0].FileId;
                    }
                }
            }
            else
            {
                //this package has some strict version dependency files, so we need to figure out which one is
                // compatible with the current umbraco version passed in and also use the latest available
                // package version that is compatible.

                int found = -1;
                foreach (var pckVersion in strictPackageFileVersions)
                {
                    //if this version will work with the umbraco version, then use it
                    if (currentUmbracoVersion >= pckVersion.MinUmbracoVersion)
                    {
                        found = pckVersion.FileId;
                        break;
                    }
                }

                if (found != -1)
                {
                    //got one! so use it's id for the file download
                    packageDetails.ZipUrl    = string.Concat(BASE_URL, "/FileDownload?id=", found);
                    packageDetails.ZipFileId = found;
                }
            }

            packageDetails.Created = content.CreateDate;

            return(packageDetails);
        }
        public ActionResult GetPackageInfos()
        {
            var packages = GetAllPackages();

            var packageInfos = new List <PackageInfo>();

            var nugetService          = new NugetPackageDownloadService();
            var nugetPackageDownloads = nugetService.GetNugetPackageDownloads();

            var licenses = new HashSet <string>();

            foreach (var package in packages)
            {
                var compatibleVersions = package.GetPropertyValue <string>("compatibleVersions");
                var categoryName       = string.Empty;
                var categoryNodeId     = package.GetPropertyValue <int>("category");
                if (categoryNodeId != 0)
                {
                    categoryName = Umbraco.TypedContent(categoryNodeId).Name;
                }

                var ownerName     = string.Empty;
                var ownerMemberId = package.GetPropertyValue <int>("owner");
                if (ownerMemberId != 0)
                {
                    ownerName = Umbraco.TypedMember(ownerMemberId).Name;
                }

                var ourDownloads     = Utils.GetProjectTotalDownloadCount(package.Id);
                var nugetPackageId   = nugetService.GetNuGetPackageId(package);
                var nugetDownloads   = 0;
                var nugetPackageInfo = nugetPackageDownloads.FirstOrDefault(x => x.PackageId == nugetPackageId);
                if (nugetPackageInfo != null)
                {
                    nugetDownloads = nugetPackageInfo.TotalDownLoads;
                }
                var lastUpdate = package.UpdateDate;
                // If files have been updated later than this then use that date
                var wikiFiles  = WikiFile.CurrentFiles(package.Id);
                var latestFile = wikiFiles.Where(x => x.FileType == "package").OrderByDescending(x => x.CreateDate).FirstOrDefault();
                if (latestFile != null && latestFile.CreateDate > lastUpdate)
                {
                    lastUpdate = latestFile.CreateDate;
                }

                var licenseName = package.GetPropertyValue <string>("licenseName");
                licenses.Add(licenseName);

                var openSource       = false;
                var openSourceChecks = new List <string>
                {
                    "MIT",
                    "CC",
                    "BSD",
                    "Apache",
                    "GPL",
                    "GNU",
                    "Free",
                    "Unlicense",
                    "MS-PL",
                    "OSL",
                    "MPL",
                    "Open Government",
                    "WTFPL",
                    // Questionable but.. ok
                    "TBD",
                    "Undefined",
                    "No license"
                };

                // These two match the above, but are not open source
                if (licenseName != "Resizer Freedom license" && licenseName != "MIT + Commercial")
                {
                    foreach (var item in openSourceChecks)
                    {
                        if (!licenseName.InvariantContains(item))
                        {
                            continue;
                        }

                        openSource = true;
                        // Immediately break out of foreach, no more checks needed
                        break;
                    }
                }

                var packageInfo = new PackageInfo
                {
                    Name     = package.Name,
                    Category = categoryName,
                    // We don't know.. look at the license maybe?
                    OpenSource         = openSource,
                    License            = licenseName,
                    LicenseUrl         = package.GetPropertyValue <string>("licenseUrl"),
                    Owner              = ownerName,
                    CloudCompatible    = package.GetPropertyValue <bool>("worksOnUaaS"),
                    DownloadsTotal     = ourDownloads + nugetDownloads,
                    LastUpdate         = lastUpdate.ToString("yyyy-MM-dd"),
                    Version7Compatible = compatibleVersions.InvariantContains("v7"),
                    Version8Compatible = compatibleVersions.InvariantContains("v8"),
                    Url = package.UrlWithDomain()
                };

                packageInfos.Add(packageInfo);
            }

            var json = JsonConvert.SerializeObject(packageInfos);
            var dt   = (DataTable)JsonConvert.DeserializeObject(json, typeof(DataTable));
            var csv  = DataTableToCsv(dt);

            var fileBytes = Encoding.UTF8.GetBytes(string.Join(Environment.NewLine, csv));
            var file      = File(fileBytes, "text/csv", "packaginfos.csv");

            return(file);
        }