コード例 #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());
        }
コード例 #2
0
        internal static WikiFile PackageFileByGuid(Guid pack)
        {
            XPathNodeIterator xpn = umbraco.library.GetXmlNodeByXPath("descendant::* [@isDoc and translate(packageGuid,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = translate('" + pack.ToString() + "','ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')]");

            if (xpn.MoveNext())
            {
                if (xpn.Current is IHasXmlNode)
                {
                    Node   node   = new Node(((IHasXmlNode)xpn.Current).GetNode());
                    string fileId = safeProperty(node, "file");
                    int    _id;

                    if (int.TryParse(fileId, out _id))
                    {
                        string cookieName = "ProjectFileDownload" + fileId;

                        //we clear the cookie on the server just to be sure the download is accounted for
                        if (HttpContext.Current.Request.Cookies[cookieName] != null)
                        {
                            HttpCookie myCookie = new HttpCookie(cookieName);
                            myCookie.Expires = DateTime.Now.AddDays(-1d);
                            HttpContext.Current.Response.Cookies.Add(myCookie);
                        }

                        WikiFile wf = new WikiFile(_id);
                        wf.UpdateDownloadCounter(true, true);

                        return(wf);
                    }
                }
            }

            return(null);
        }
コード例 #3
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)
            });
        }
コード例 #4
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());
        }
コード例 #5
0
        public void WikiFileUniquePathTest()
        {
            var root       = Path.GetTempPath();
            var wikiFile   = new WikiFile(root, "TestPage");
            var wikiFolder = Path.Combine(root, "files\\testResults\\TestPage");

            Directory.CreateDirectory(wikiFolder);
            var dir = new DirectoryInfo(wikiFolder);

            foreach (var file in dir.EnumerateFiles("*test*.rik"))
            {
                file.Delete();
            }
            var a = wikiFile.UniquePathFor("test.rik", 0);

            Assert.IsTrue(a.EndsWith("000101010000000000_test_1.rik", StringComparison.Ordinal), "test 1");
            File.Create(a).Close();
            var b = wikiFile.UniquePathFor("test.rik", 0);

            Assert.IsTrue(b.EndsWith("000101010000000000_test_2.rik", StringComparison.Ordinal), "test 2");
            Assert.IsTrue(wikiFile.UniquePathFor(string.Empty, 0).EndsWith("000101010000000000__1", StringComparison.Ordinal), "test 3");
            Assert.IsTrue(wikiFile.UniquePathFor(null, 0).EndsWith("000101010000000000__1", StringComparison.Ordinal), "test 4");
            Assert.IsTrue(wikiFile.UniquePathFor(".rik", 0).EndsWith("000101010000000000__1.rik", StringComparison.Ordinal), "test 5");
            File.Delete(a);
        }
コード例 #6
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.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].ToArray() : new WikiFile[] { };
                var projectVersions  = allCompatVersions.ContainsKey(project.Id) ? allCompatVersions[project.Id] : Enumerable.Empty <string>();

                yield return(MapProjectToSimpleDataIndexItem(project, simpleDataSet, indexType, projectKarma, projectFiles, projectDownloads, projectVersions));
            }
        }
コード例 #7
0
        private HttpResponseMessage GetPackageFile(Guid packageId, System.Version currUmbracoVersion, bool includeHidden)
        {
            var pckRepoService = new PackageRepositoryService(Umbraco, Members, DatabaseContext);

            var details = pckRepoService.GetDetails(packageId, currUmbracoVersion, includeHidden);

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

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

            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);

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(wf.ToByteArray())
            };

            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

            return(result);
        }
コード例 #8
0
ファイル: MediaProvider.cs プロジェクト: jango2015/OurUmbraco
        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);
        }
コード例 #9
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 downloadStats  = WikiFile.GetMonthlyDownloadStatsByProject(
                content.Id,
                DateTime.Now.Subtract(TimeSpan.FromDays(365)));

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

            simpleDataSet = ((ProjectNodeIndexDataService)simpleDataIndexer.DataService)
                            .MapProjectToSimpleDataIndexItem(downloadStats, DateTime.Now, 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");
        }
コード例 #10
0
        protected void OnFileBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                WikiFile f                  = (WikiFile)e.Item.DataItem;
                Image    _image             = (Image)e.Item.FindControl("img_image");
                Literal  _date              = (Literal)e.Item.FindControl("lt_date");
                Button   _delete            = (Button)e.Item.FindControl("bt_delete");
                Literal  _defaultScreenshot = (Literal)e.Item.FindControl("lt_default");

                Button _defaultScreenshotButton = (Button)e.Item.FindControl("bt_default");

                if (f.Path == _defaultFile)
                {
                    _defaultScreenshotButton.Visible = false;
                    _defaultScreenshot.Visible       = true;
                    _defaultScreenshot.Text          = "Default";
                }
                else
                {
                    _defaultScreenshotButton.Text            = "Make Default";
                    _defaultScreenshotButton.CommandArgument = f.Path;
                    _defaultScreenshot.Visible = false;
                }

                _image.ImageUrl         = f.Path + "?height=100";
                _date.Text              = f.CreateDate.ToShortDateString() + " - " + f.CreateDate.ToShortTimeString();
                _delete.CommandArgument = f.Id.ToString();
            }
        }
コード例 #11
0
        private void RebindFiles()
        {
            List <WikiFile> files = WikiFile.CurrentFiles(pageId);

            rp_files.DataSource = files;
            rp_files.Visible    = (files.Count > 0);
            rp_files.DataBind();
        }
コード例 #12
0
        public void ProcessRequest(HttpContext context)
        {
            HttpPostedFile file          = context.Request.Files["Filedata"];
            string         userguid      = context.Request.Form["USERGUID"];
            string         projectguid   = context.Request.Form["NODEGUID"];
            string         nodeId        = context.Request.Form["id"];
            string         fileType      = context.Request.Form["FILETYPE"];
            string         fileName      = context.Request.Form["FILENAME"];
            string         umbraoVersion = (context.Request.Form["UMBRACOVERSION"] != null) ? context.Request.Form["UMBRACOVERSION"] : "nan";
            string         dotNetVersion = (context.Request.Form["DOTNETVERSION"] != null) ? context.Request.Form["DOTNETVERSION"] : "nan";
            string         trustLevel    = (context.Request.Form["TRUSTLEVEL"] != null) ? context.Request.Form["TRUSTLEVEL"] : "nan";



            List <OurUmbraco.Wiki.BusinessLogic.UmbracoVersion> v = new List <OurUmbraco.Wiki.BusinessLogic.UmbracoVersion>()
            {
                OurUmbraco.Wiki.BusinessLogic.UmbracoVersion.DefaultVersion()
            };

            if (!string.IsNullOrEmpty(umbraoVersion))
            {
                v.Clear();
                v = WikiFile.GetVersionsFromString(umbraoVersion);
            }


            bool trust = false;

            if (trustLevel == "Medium")
            {
                trust = true;
            }


            if (!string.IsNullOrEmpty(userguid) && !string.IsNullOrEmpty(projectguid) && !string.IsNullOrEmpty(fileType) && !string.IsNullOrEmpty(fileName))
            {
                var nodeListingProvider = new OurUmbraco.MarketPlace.NodeListing.NodeListingProvider();
                var p = nodeListingProvider.GetListing(new Guid(projectguid));

                Member mem = new Member(new Guid(userguid));

                if (p.VendorId == mem.Id || Utils.IsProjectContributor(mem.Id, p.Id))
                {
                    var mediaProvider = new OurUmbraco.MarketPlace.Providers.MediaProvider();

                    var packageFileType = (FileType)Enum.Parse(typeof(FileType), (string)fileType, true);
                    // TODO: Don't know how else to get the bloody version
                    var version = UmbracoContext.Current.Application.Services.ContentService.GetById(p.Id).Version;
                    mediaProvider.CreateFile(fileName, version, mem.UniqueId, file, packageFileType, v, dotNetVersion, trust);
                }
                else
                {
                    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, 0, "wrong type or not a owner");
                }
            }
        }
コード例 #13
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));
            }
        }
コード例 #14
0
        protected void DeleteFile(object sender, CommandEventArgs e)
        {
            WikiFile wf = new WikiFile(int.Parse(e.CommandArgument.ToString()));

            //Member mem = Member.GetCurrentMember();

            //if (wf.CreatedBy == mem.Id)
            wf.Delete();

            RebindFiles();
        }
コード例 #15
0
        protected void DeleteFile(object sender, CommandEventArgs e)
        {
            WikiFile wf  = new WikiFile(int.Parse(e.CommandArgument.ToString()));
            Member   mem = Member.GetCurrentMember();

            if (wf.CreatedBy == mem.Id || Utils.IsProjectContributor(mem.Id, pageId))
            {
                wf.Delete();
            }

            RebindFiles();
        }
コード例 #16
0
        public void WikiFileWikiLinkTest()
        {
            var wikiFile = new WikiFile("c:\\test", "wiki");

            Assert.AreEqual(ImageCode("/test1"), wikiFile.WikiLink(@"c:\test\files\testResults\wiki\test1"), "simple test");
            Assert.AreEqual(ImageCode("/sub/test1"), wikiFile.WikiLink(@"c:\test\files\testResults\wiki\sub\test1"),
                            "test with subfolder");
            Assert.AreEqual(ImageCode("/test1.test2"), wikiFile.WikiLink(@"c:\test\files\testResults\wiki\test1.test2"),
                            "test with dots");
            Assert.IsNull(wikiFile.WikiLink("d:\\test1"), "test with different root");
            Assert.AreEqual(ImageCode(string.Empty), wikiFile.WikiLink(@"c:\test\files\testResults\wiki"), "empty test");
        }
コード例 #17
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");
        }
コード例 #18
0
        public string VerifyFile(int fileId)
        {
            if (Xslt.IsMemberInGroup("admin", Members.GetCurrentMember().Id))
            {
                var wikiFile = new WikiFile(fileId)
                {
                    Verified = true
                };
                wikiFile.Save();
            }

            return("");
        }
コード例 #19
0
        public static XPathNodeIterator FindPackageDocumentationForUmbracoVersion(int nodeid, string umbracoVersion)
        {
            XmlDocument xd = new XmlDocument();

            WikiFile wf = WikiFile.FindPackageDocumentationForUmbracoVersion(nodeid, umbracoVersion);

            if (wf != null)
            {
                xd.AppendChild(wf.ToXml(xd));
            }

            return(xd.CreateNavigator().Select("."));
        }
コード例 #20
0
ファイル: rest.cs プロジェクト: tomfulton/OurUmbraco
        public static string VerifyFile(int ID)
        {
            int _currentMember = HttpContext.Current.User.Identity.IsAuthenticated ? (int)Membership.GetUser().ProviderUserKey : 0;

            if (Xslt.IsMemberInGroup("admin", _currentMember))
            {
                WikiFile wf = new WikiFile(ID);
                wf.Verified = true;
                wf.Save();
            }

            return("");
        }
コード例 #21
0
        public static void SetMinimumUmbracoVersion(this WikiFile mediaFile)
        {
            var fileType = (FileType)Enum.Parse(typeof(FileType), mediaFile.FileType);

            if (fileType != FileType.package)
            {
                return;
            }

            System.Version minimumUmbracoVersion = null;

            var extractor  = new PackageExtraction();
            var filePath   = IOHelper.MapPath(mediaFile.Path);
            var packageXml = extractor.ReadTextFileFromArchive(filePath, Umbraco.Core.Constants.Packaging.PackageXmlFileName);

            if (string.IsNullOrWhiteSpace(packageXml))
            {
                return;
            }

            var packageXmlDoc = XDocument.Parse(packageXml);

            // The XPath query will detect if the 'requirements' element has the attribute that we're looking for,
            // and if the child elements also exist. [LK:2016-06-12@CGRT16]
            var requirements = packageXmlDoc.XPathSelectElement("/umbPackage/info/package/requirements");

            if (requirements == null)
            {
                return;
            }
            if (requirements.Attribute("type") == null || requirements.Attribute("type").Value.ToLowerInvariant() != "strict")
            {
                return;
            }

            if (requirements.Element("major") == null || requirements.Element("minor") == null || requirements.Element("patch") == null)
            {
                return;
            }

            var major = requirements.Element("major").Value;
            var minor = requirements.Element("minor").Value;
            var patch = requirements.Element("patch").Value;

            System.Version.TryParse(string.Format("{0}.{1}.{2}", major, minor, patch), out minimumUmbracoVersion);

            if (minimumUmbracoVersion != default(System.Version))
            {
                mediaFile.MinimumVersionStrict = minimumUmbracoVersion.ToString(3);
            }
        }
コード例 #22
0
 /// <summary>
 /// get page list default ?
 /// </summary>
 private static byte[] _WikiGetList(WikiFile wiki, WikiFileType type, string namesspace)
 {
     /*
      * Dictionary<string, List<WikiFileInfo>> dwf = null;
      * bool isNameSpace = namesspace.Contains(":");
      * switch (type)
      * {
      *  default:
      *  case WikiFileType.FileReadMd:
      *  case WikiFileType.FileWriteMd:
      *      {
      *          dwf = ((isNameSpace) ?
      *              wiki.GetFileListPages(namesspace) :
      *              wiki.GetFileListPages()
      *          );
      *          break;
      *      }
      *  case WikiFileType.FileReadBinary:
      *  case WikiFileType.FileWriteBinary:
      *      {
      *          dwf = ((isNameSpace) ?
      *              wiki.GetFileListMedia(namesspace) :
      *              wiki.GetFileListMedia()
      *          );
      *          break;
      *      }
      *  case WikiFileType.FileReadAttic:
      *  case WikiFileType.FileWriteAttic:
      *      {
      *          dwf = ((isNameSpace) ?
      *              wiki.GetFileListAttic(namesspace) :
      *              wiki.GetFileListAttic()
      *          );
      *          break;
      *      }
      *  case WikiFileType.FileWriteMeta:
      *  case WikiFileType.FileReadMeta:
      *      {
      *          throw new WikiNotImplementPageException(type.ToString());
      *      }
      * }
      * if (dwf == null)
      * {
      *  return null;
      * }
      * return Encoding.UTF8.GetBytes(
      *  wiki.PageListToMdString(dwf, null)
      * );
      */
     return(null);
 }
コード例 #23
0
        public void WikiFileUniquePathTest2()
        {
            const string format    = @"yyyyMMddHHmmssffff";
            var          culture   = CultureInfo.InvariantCulture;
            var          startTime = DateTime.Now.ToString(format, culture);
            var          file      = new WikiFile("c:\\", "Data").UniquePathFor(@"demofile");

            Assert.IsNotNull(file);
            var timestamp = Path.GetFileNameWithoutExtension(file).Substring(0, 18);
            var endTime   = DateTime.Now.ToString(format, culture);

            Assert.IsTrue(string.Compare(startTime, timestamp, StringComparison.Ordinal) <= 0, $"{startTime} <= {timestamp}");
            Assert.IsTrue(string.Compare(timestamp, endTime, StringComparison.Ordinal) <= 0, $"{timestamp} <= {endTime}");
        }
コード例 #24
0
        public ActionResult MarkFileAsCurrent(int id, int releaseFileId)
        {
            var nodeListingProvider = new NodeListingProvider();
            var project             = GetProjectForAuthorizedMember(id);

            project.CurrentReleaseFile = releaseFileId.ToString();
            var file = new WikiFile(releaseFileId);

            if (file.FileType == "screenshot")
            {
                project.DefaultScreenshot = file.Path;
            }
            nodeListingProvider.SaveOrUpdate(project);
            return(RedirectToCurrentUmbracoPage(Request.Url.Query));
        }
コード例 #25
0
        protected void ArchiveFile(object sender, CommandEventArgs e)
        {
            WikiFile wf = new WikiFile(int.Parse(e.CommandArgument.ToString()));

            if (e.CommandName == "Unarchive")
            {
                wf.Archived = false;
            }
            else
            {
                wf.Archived = true;
            }

            wf.Save();
            RebindFiles();
        }
コード例 #26
0
        public void ProcessRequest(HttpContext context)
        {
            //TODO: Authorize this request!!!

            HttpPostedFile file          = context.Request.Files["Filedata"];
            string         userguid      = context.Request.Form["USERGUID"];
            string         nodeguid      = context.Request.Form["NODEGUID"];
            string         fileType      = context.Request.Form["FILETYPE"];
            string         fileName      = context.Request.Form["FILENAME"];
            string         umbraoVersion = context.Request.Form["UMBRACOVERSION"];
            string         dotNetVersion = context.Request.Form["DOTNETVERSION"];

            List <UmbracoVersion> v = new List <UmbracoVersion>()
            {
                UmbracoVersion.DefaultVersion()
            };

            if (!string.IsNullOrEmpty(umbraoVersion))
            {
                v.Clear();
                v = WikiFile.GetVersionsFromString(umbraoVersion);
            }

            if (!string.IsNullOrEmpty(userguid) && !string.IsNullOrEmpty(nodeguid) && !string.IsNullOrEmpty(fileType) && !string.IsNullOrEmpty(fileName))
            {
                Document d   = new Document(Document.GetContentFromVersion(new Guid(nodeguid)).Id);
                Member   mem = new Member(new Guid(userguid));

                if (d.ContentType.Alias == "Project" && d.getProperty("owner") != null && (d.getProperty("owner").Value.ToString() == mem.Id.ToString() || Utils.IsProjectContributor(mem.Id, d.Id)))
                {
                    WikiFile.Create(fileName, new Guid(nodeguid), new Guid(userguid), file, fileType, v, dotNetVersion);

                    //the package publish handler will make sure we got the right versions info on the package node itself.
                    //ProjectsEnsureGuid.cs is the handler
                    if (fileType.ToLower() == "package")
                    {
                        d.Publish(new umbraco.BusinessLogic.User(0));
                        umbraco.library.UpdateDocumentCache(d.Id);
                    }
                }
                else
                {
                    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, 0, "wrong type or not a owner");
                }
            }
        }
コード例 #27
0
        public ActionResult AddFile(EditFileModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(CurrentUmbracoPage());
            }

            // Getting this despite not using it to verify that the member owns this file
            var project = GetProjectForAuthorizedMember(model.UploadFile.ProjectId);
            var member  = Members.GetCurrentMember();

            HttpPostedFile file;

            using (var target = new MemoryStream())
            {
                model.UploadFile.File.InputStream.CopyTo(target);
                byte[] data = target.ToArray();
                file = ConstructHttpPostedFile(data, model.UploadFile.File.FileName, model.UploadFile.File.ContentType);
            }

            var umbracoVersions    = new List <UmbracoVersion>();
            var allUmbracoVersions = UmbracoVersion.AvailableVersions().Values;

            foreach (var item in model.UploadFile.SelectedVersions)
            {
                var version = allUmbracoVersions.Single(x => x.Version == item);
                umbracoVersions.Add(version);
            }

            var contentService = Services.ContentService;
            var projectContent = contentService.GetById(project.Id);

            var wikiFile = WikiFile.Create(
                model.UploadFile.File.FileName,
                projectContent.PublishedVersionGuid,
                member.GetKey(),
                file,
                model.UploadFile.FileType,
                umbracoVersions,
                model.UploadFile.DotNetVersion
                );

            return(RedirectToCurrentUmbracoPage(Request.Url.Query));
        }
コード例 #28
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);
        }
コード例 #29
0
        protected void OnFileBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                WikiFile wf = (WikiFile)e.Item.DataItem;

                Literal _name    = (Literal)e.Item.FindControl("lt_name");
                Literal _date    = (Literal)e.Item.FindControl("lt_date");
                Button  _delete  = (Button)e.Item.FindControl("bt_delete");
                Literal _type    = (Literal)e.Item.FindControl("lt_type");
                Literal _version = (Literal)e.Item.FindControl("lt_version");

                Button _archive = (Button)e.Item.FindControl("bt_archive");

                _archive.CommandArgument = wf.Id.ToString();

                if (wf.Archived)
                {
                    _archive.Text        = "Unarchive";
                    _archive.CommandName = "Unarchive";
                }
                else
                {
                    _archive.Text        = "Archive";
                    _archive.CommandName = "Archive";
                }

                if (wf.FileType.Trim().ToLower() == "screenshot")
                {
                    _archive.Visible = false;
                }

                if (wf.Versions != null)
                {
                    _version.Text = WikiFile.ToVersionString(wf.Versions);
                }

                _type.Text = wf.FileType;
                _name.Text = "<a href='" + wf.Path + "'>" + wf.Name + "</a>";
                _date.Text = wf.CreateDate.ToShortDateString() + " - " + wf.CreateDate.ToShortTimeString();
                _delete.CommandArgument = wf.Id.ToString();
            }
        }
コード例 #30
0
        public ActionResult DeleteScreenshot(int id, int releaseFileId)
        {
            var nodeListingProvider = new NodeListingProvider();
            var project             = GetProjectForAuthorizedMember(id);

            var file = new WikiFile(releaseFileId);

            if (file.Path == project.DefaultScreenshot)
            {
                project.DefaultScreenshot = string.Empty;
                nodeListingProvider.SaveOrUpdate(project);
            }

            var mediaProvider = new MediaProvider();

            mediaProvider.Remove(file);

            return(RedirectToCurrentUmbracoPage(Request.Url.Query));
        }