Beispiel #1
0
        internal static uWiki.Businesslogic.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);
                        }

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

                        return(wf);
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        //public static WikiFile Create(string name, string ext, Guid node, Guid member, byte[] file, string filetype)
        //{
        //    return Create(name, ext, node, member, file, filetype, UmbracoVersion.AvailableVersions()["v45"]);
        //}

        public static WikiFile Create(string name, string ext, Guid node, Guid member, byte[] file, string filetype, List <UmbracoVersion> versions)
        {
            try
            {
                Content d = Document.GetContentFromVersion(node);
                Member  m = new Member(member);

                if (d != null && m != null)
                {
                    WikiFile wf = new WikiFile();
                    wf.Name        = name;
                    wf.NodeId      = d.Id;
                    wf.NodeVersion = d.Version;
                    wf.FileType    = filetype;
                    wf.CreatedBy   = m.Id;
                    wf.Downloads   = 0;
                    wf.Archived    = false;
                    wf.Versions    = versions;
                    wf.Version     = versions[0];
                    wf.Verified    = false;

                    string path = "/media/wiki/" + d.Id.ToString();

                    if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(path)))
                    {
                        System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));
                    }

                    string filename  = name;
                    string extension = ext;

                    filename = filename.Substring(0, filename.LastIndexOf('.') + 1);
                    path     = path + "/" + DateTime.Now.Ticks.ToString() + "_" + umbraco.cms.helpers.url.FormatUrl(filename) + "." + extension;

                    System.IO.FileStream fs1 = null;
                    fs1 = new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Create);
                    fs1.Write(file, 0, file.Length);
                    fs1.Close();
                    fs1 = null;

                    wf.Path = path;
                    wf.Save();

                    return(wf);
                }
            }
            catch (Exception ex)
            {
                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString());
            }

            return(null);
        }
Beispiel #3
0
        internal static uWiki.Businesslogic.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);
                        }

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

                        return wf;
                    }
                }
            }

            return null;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["id"] != null)
            {

                int fileId = int.Parse(Request["id"]);

                WikiFile wf = new WikiFile(fileId);

                wf.UpdateDownloadCounter(false, Request["release"] != null);

            //                HttpCookie cookie = HttpContext.Current.Request.Cookies["ProjectFileDownload" + fileId];
            //                if (cookie == null)
            //                {
            //                    int downloads = 0;
            //                    downloads = BL.Application.SqlHelper.ExecuteScalar<int>(
            //                        "Select downloads from wikiFiles where id = @id;",
            //                        BL.Application.SqlHelper.CreateParameter("@id", fileId));

            //                    downloads = downloads + 1;

            //                    BL.Application.SqlHelper.ExecuteNonQuery(
            //                        "update wikiFiles set downloads = @downloads where id = @id;",
            //                         BL.Application.SqlHelper.CreateParameter("@id", fileId),
            //                         BL.Application.SqlHelper.CreateParameter("@downloads", downloads));

            //                    int _currentMember = 0;
            //                    Member m = Member.GetCurrentMember();
            //                    if(m != null)
            //                        _currentMember = m.Id;

            //                    WikiFile wf = new WikiFile(fileId);

            //                    if (Request["release"] != null)
            //                    {

            //                        BL.Application.SqlHelper.ExecuteNonQuery(
            //                            @"insert into projectDownload(projectId,memberId,timestamp)
            //                        values((select nodeId from wikiFiles where id = @id) ,@memberId, getdate())",
            //                                 BL.Application.SqlHelper.CreateParameter("@id", fileId),
            //                                 BL.Application.SqlHelper.CreateParameter("@memberId", _currentMember));
            //                    }

            //                    cookie = new HttpCookie("ProjectFileDownload" + fileId);
            //                    cookie.Expires = DateTime.Now.AddHours(1);
            //                    HttpContext.Current.Response.Cookies.Add(cookie);

            //                }
                string path = BL.Application.SqlHelper.ExecuteScalar<string>(
                        "Select path from wikiFiles where id = @id;",
                        BL.Application.SqlHelper.CreateParameter("@id", fileId));

                string file = BL.Application.SqlHelper.ExecuteScalar<string>(
                   "Select name from wikiFiles where id = @id;",
                   BL.Application.SqlHelper.CreateParameter("@id", fileId));

                System.IO.FileInfo fileinfo = new System.IO.FileInfo(Server.MapPath(path));

                string extension = System.IO.Path.GetExtension(Server.MapPath(path));
                string type = "";
                // set known types based on file extension
                if (extension != null)
                {
                    switch (extension.ToLower())
                    {
                        case ".tif":
                        case ".tiff":
                            type = "image/tiff";
                            break;
                        case ".jpg":
                        case ".jpeg":
                            type = "image/jpeg";
                            break;
                        case ".gif":
                            type = "image/gif";
                            break;
                        case ".docx":
                        case ".doc":
                        case ".rtf":
                            type = "Application/msword";
                            break;
                        case ".pdf":
                            type = "Application/pdf";
                            break;
                        case ".png":
                            type = "image/png";
                            break;
                        case ".bmp":
                            type = "image/bmp";
                            break;
                        default:
                            type = "application/octet-stream";
                            break;
                    }
                }

                Response.Clear();

                Response.AddHeader("Content-Disposition", "attachment; filename= " + MakeSafeFileName(file));
                Response.AddHeader("Content-Length", fileinfo.Length.ToString());
                Response.ContentType = type;
                Response.WriteFile(path);
            }
        }
Beispiel #5
0
        //used by the repo webservice
        public static SubmitStatus SubmitPackageAsProject(string authorGuid, string packageGuid, byte[] packageFile, byte[] packageDoc, byte[] packageThumbnail, string name, string description)
        {
            try
            {
                if (packageFile.Length == 0)
                {
                    return(SubmitStatus.Error);
                }

                umbraco.cms.businesslogic.member.Member mem = new umbraco.cms.businesslogic.member.Member(new Guid(authorGuid));
                Package packageNode = uRepo.Packages.GetPackageByGuid(new Guid(packageGuid));

                if (mem != null)
                {
                    //existing package...
                    if (packageNode != null)
                    {
                        return(SubmitStatus.Exists);
                    }
                    else
                    {
                        Document d = Document.MakeNew(name, DocumentType.GetByAlias(_projectAlias), new umbraco.BusinessLogic.User(0), _projectsRoot);

                        d.getProperty("version").Value     = "1.0";
                        d.getProperty("description").Value = description;

                        d.getProperty("stable").Value = false;

                        d.getProperty("demoUrl").Value    = "";
                        d.getProperty("sourceUrl").Value  = "";
                        d.getProperty("websiteUrl").Value = "";

                        d.getProperty("licenseUrl").Value  = "";
                        d.getProperty("licenseName").Value = "";

                        d.getProperty("vendorUrl").Value = "";

                        d.getProperty("owner").Value       = mem.Id;
                        d.getProperty("packageGuid").Value = packageGuid;

                        uWiki.Businesslogic.WikiFile wf = uWiki.Businesslogic.WikiFile.Create(name, "zip", d.UniqueId, mem.UniqueId, packageFile, "package", new List <UmbracoVersion>()
                        {
                            UmbracoVersion.DefaultVersion()
                        });
                        d.getProperty("file").Value = wf.Id;

                        //Create Documentation
                        if (packageDoc.Length > 0)
                        {
                            uWiki.Businesslogic.WikiFile doc = uWiki.Businesslogic.WikiFile.Create("documentation", "pdf", d.UniqueId, mem.UniqueId, packageDoc, "docs", new List <UmbracoVersion>()
                            {
                                UmbracoVersion.DefaultVersion()
                            });
                            d.getProperty("documentation").Value = doc.Id;
                        }

                        d.XmlGenerate(new XmlDocument());
                        d.Save();

                        d.Publish(new umbraco.BusinessLogic.User(0));
                        umbraco.library.UpdateDocumentCache(d.Id);

                        return(SubmitStatus.Complete);
                    }
                }
                else
                {
                    return(SubmitStatus.NoAccess);
                }
            }
            catch (Exception ex)
            {
                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString());
                return(SubmitStatus.Error);
            }
        }
Beispiel #6
0
        public static WikiFile Create(string fileName, string extension, Guid node, Guid memberGuid, byte[] file, string filetype, List<UmbracoVersion> versions)
        {
            try
            {
                if (ExtensionNotAllowed(extension))
                    return null;

                var content = Content.GetContentFromVersion(node);
                var member = new Member(memberGuid);

                if (content != null)
                {
                    var wikiFile = new WikiFile
                                   {
                                       Name = fileName,
                                       NodeId = content.Id,
                                       NodeVersion = content.Version,
                                       FileType = filetype,
                                       CreatedBy = member.Id,
                                       Downloads = 0,
                                       Archived = false,
                                       Versions = versions,
                                       Version = versions[0],
                                       Verified = false
                                   };

                    var path = string.Format("/media/wiki/{0}", content.Id);

                    if (Directory.Exists(HttpContext.Current.Server.MapPath(path)) == false)
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));

                    fileName = fileName.Substring(0, fileName.LastIndexOf('.') + 1);
                    path = string.Format("{0}/{1}_{2}.{3}", path, DateTime.Now.Ticks, umbraco.cms.helpers.url.FormatUrl(fileName), extension);

                    using (var fileStream = new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Create))
                        fileStream.Write(file, 0, file.Length);

                    wikiFile.Path = path;
                    wikiFile.Save();

                    return wikiFile;
                }
            }
            catch (Exception ex)
            {
                Log.Add(LogTypes.Debug, -1, ex.ToString());
            }

            return null;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["id"] != null)
            {
                var fileId = int.Parse(Request["id"]);

                var wikiFile = new WikiFile(fileId);

                wikiFile.UpdateDownloadCounter(false, wikiFile.FileType == "package");

                var path = BL.Application.SqlHelper.ExecuteScalar<string>(
                        "Select path from wikiFiles where id = @id;",
                        BL.Application.SqlHelper.CreateParameter("@id", fileId));

                var file = BL.Application.SqlHelper.ExecuteScalar<string>(
                   "Select name from wikiFiles where id = @id;",
                   BL.Application.SqlHelper.CreateParameter("@id", fileId));

                var fileinfo = new System.IO.FileInfo(Server.MapPath(path));

                var extension = System.IO.Path.GetExtension(Server.MapPath(path));
                var type = "";
                // set known types based on file extension
                if (extension != null)
                {
                    switch (extension.ToLower())
                    {
                        case ".tif":
                        case ".tiff":
                            type = "image/tiff";
                            break;
                        case ".jpg":
                        case ".jpeg":
                            type = "image/jpeg";
                            break;
                        case ".gif":
                            type = "image/gif";
                            break;
                        case ".docx":
                        case ".doc":
                        case ".rtf":
                            type = "Application/msword";
                            break;
                        case ".pdf":
                            type = "Application/pdf";
                            break;
                        case ".png":
                            type = "image/png";
                            break;
                        case ".bmp":
                            type = "image/bmp";
                            break;
                        default:
                            type = "application/octet-stream";
                            break;
                    }
                }

                Response.Clear();

                Response.AddHeader("Content-Disposition", "attachment; filename= " + MakeSafeFileName(file));
                Response.AddHeader("Content-Length", fileinfo.Length.ToString());
                Response.ContentType = type;
                Response.WriteFile(path);
            }
        }
Beispiel #8
0
        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 "";
        }
Beispiel #9
0
        /// <summary>
        /// Gets all wiki files for all nodes
        /// </summary>
        /// <returns></returns>
        public static Dictionary<int, IEnumerable<WikiFile>> CurrentFiles(IEnumerable<int> nodeIds)
        {
            var wikiFiles = new Dictionary<int, List<WikiFile>>();

            //we can only have 2000 (actually 2100) SQL parameters used at once, so we need to group them
            var nodeBatches = nodeIds.InGroupsOf(2000);

            foreach (var nodeBatch in nodeBatches)
            {
                foreach (var result in ApplicationContext.Current.DatabaseContext.Database.Query<dynamic>("SELECT * FROM wikiFiles WHERE nodeId IN (@nodeIds)", new { nodeIds = nodeBatch }))
                {
                    var file = new WikiFile
                    {
                        Id = result.id,
                        Path = result.path,
                        Name = result.name,
                        FileType = result.type,
                        RemovedBy = result.removedBy,
                        CreatedBy = result.createdBy,
                        NodeVersion = result.version,
                        NodeId = result.nodeId,
                        CreateDate = result.createDate,
                        DotNetVersion = result.dotNetVersion,
                        Downloads = result.downloads,
                        Archived = result.archived,
                        Verified = result.verified,
                        Versions = GetVersionsFromString(result.umbracoVersion)
                    };

                    file.Version = file.Versions.Any()
                        ? GetVersionsFromString(result.umbracoVersion)[0]
                        : UmbracoVersion.DefaultVersion();

                    if (wikiFiles.ContainsKey(result.nodeId))
                    {
                        var list = wikiFiles[result.nodeId];
                        list.Add(file);
                    }
                    else
                    {
                        wikiFiles.Add(result.nodeId, new List<WikiFile>(new[] { file }));
                    }
                }
            }

            return wikiFiles.ToDictionary(x => x.Key, x => (IEnumerable<WikiFile>)x.Value);
        }
Beispiel #10
0
        public string VerifyFile(int fileId)
        {
            if (Xslt.IsMemberInGroup("admin", Members.GetCurrentMember().Id))
            {
                var wikiFile = new WikiFile(fileId) { Verified = true };
                wikiFile.Save();
            }

            return "";
        }
Beispiel #11
0
        //public static WikiFile Create(string name, string ext, Guid node, Guid member, byte[] file, string filetype)
        //{
        //    return Create(name, ext, node, member, file, filetype, UmbracoVersion.AvailableVersions()["v45"]);
        //}
        public static WikiFile Create(string name, string ext, Guid node, Guid member, byte[] file, string filetype, List<UmbracoVersion> versions)
        {
            try
            {
                Content d = Document.GetContentFromVersion(node);
                Member m = new Member(member);

                if (d != null && m != null)
                {

                    WikiFile wf = new WikiFile();
                    wf.Name = name;
                    wf.NodeId = d.Id;
                    wf.NodeVersion = d.Version;
                    wf.FileType = filetype;
                    wf.CreatedBy = m.Id;
                    wf.Downloads = 0;
                    wf.Archived = false;
                    wf.Versions = versions;
                    wf.Version = versions[0];
                    wf.Verified = false;

                    string path = "/media/wiki/" + d.Id.ToString();

                    if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(path)))
                        System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));

                    string filename = name;
                    string extension = ext;

                    filename = filename.Substring(0, filename.LastIndexOf('.') + 1);
                    path = path + "/" + DateTime.Now.Ticks.ToString() + "_" + umbraco.cms.helpers.url.FormatUrl(filename) + "." + extension;

                    System.IO.FileStream fs1 = null;
                    fs1 = new FileStream( HttpContext.Current.Server.MapPath(path) , FileMode.Create);
                    fs1.Write(file, 0, file.Length);
                    fs1.Close();
                    fs1 = null;

                    wf.Path = path;
                    wf.Save();

                    return wf;
                }

            }
            catch (Exception ex)
            {
                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString());

            }

            return null;
        }