public void ProcessRequest(HttpContext context)
        {
            //TODO: Authorize this request!!!

            var file           = context.Request.Files["Filedata"];
            var userguid       = context.Request.Form["USERGUID"];
            var nodeguid       = context.Request.Form["NODEGUID"];
            var fileType       = context.Request.Form["FILETYPE"];
            var fileName       = context.Request.Form["FILENAME"];
            var umbracoVersion = context.Request.Form["UMBRACOVERSION"];

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

            if (string.IsNullOrWhiteSpace(umbracoVersion) == false)
            {
                versions.Clear();
                versions = WikiFile.GetVersionsFromString(umbracoVersion);
            }

            if (string.IsNullOrWhiteSpace(userguid) == false &&
                string.IsNullOrWhiteSpace(nodeguid) == false &&
                string.IsNullOrWhiteSpace(fileType) == false &&
                string.IsNullOrWhiteSpace(fileName) == false)
            {
                WikiFile.Create(fileName, new Guid(nodeguid), new Guid(userguid), file, fileType, versions);
            }
        }
Beispiel #2
0
        public WikiFile CreateFile(string fileName, Guid listingVersionGuid, Guid vendorGuid, HttpPostedFile file, FileType fileType, List <UmbracoVersion> v, string dotNetVersion, bool mediumTrust)
        {
            // we have to convert to the uWiki UmbracoVersion :(

            List <UmbracoVersion> vers = new List <UmbracoVersion>();

            foreach (var ver in v)
            {
                vers.Add(UmbracoVersion.AvailableVersions()[ver.Version]);
            }


            //Create the Wiki File
            var uWikiFile = WikiFile.Create(fileName, listingVersionGuid, vendorGuid, file, GetFileTypeAsString(fileType), vers);
            //return the IMediaFile

            //Convert to Deli Media file
            var mediaFile = GetFileById(uWikiFile.Id);

            mediaFile.SetMinimumUmbracoVersion();

            mediaFile.DotNetVersion = dotNetVersion;
            SaveOrUpdate(mediaFile);
            return(mediaFile);
        }
        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");
                }
            }
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public ActionResult AddScreenshot(EditScreenshotModel 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 contentService = Services.ContentService;
            var projectContent = contentService.GetById(project.Id);

            var wikiFile = WikiFile.Create(
                model.UploadFile.File.FileName,
                projectContent.PublishedVersionGuid,
                member.GetKey(),
                file,
                "screenshot",
                new List <UmbracoVersion> {
                UmbracoVersion.DefaultVersion()
            }
                );

            return(RedirectToCurrentUmbracoPage(Request.Url.Query));
        }
        public async Task <HttpResponseMessage> UpdatePackage()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string            root        = HttpContext.Current.Server.MapPath("~/App_Data/");
            var               workingDir  = CreateWorkingFolder(root, "TempPkgFiles");
            var               provider    = new MultipartFormDataStreamProvider(workingDir);
            MultipartFileData packageFile = null;

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                // verify that a file exist (and only one)
                if (provider.FileData.Count == 0)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "No file attached"));
                }
                else if (provider.FileData.Count > 1)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "You can only upload one file"));
                }
                else
                {
                    packageFile = provider.FileData.FirstOrDefault();
                    var fileName             = packageFile.Headers.ContentDisposition.FileName.Replace("\"", "");
                    var packageFileExtension = Path.GetExtension(fileName);
                    var fileType             = provider.FormData["fileType"];
                    var dotNetVersion        = provider.FormData["dotNetVersion"];
                    var umbracoVersions      = JsonConvert.DeserializeObject <List <UmbracoVersion> >(provider.FormData["umbracoVersions"]);
                    var isCurrent            = bool.Parse(provider.FormData["isCurrent"]);

                    var contentService = ApplicationContext.Services.ContentService;

                    // get package guid from id
                    var packageEntity = contentService.GetById(ProjectNodeId);
                    if (packageEntity != null)
                    {
                        var packageVersion = packageEntity.Version;

                        // create file
                        var file = WikiFile.Create(
                            fileName,
                            packageFileExtension,
                            packageVersion,
                            AuthenticatedMember.Key,
                            System.IO.File.ReadAllBytes(packageFile.LocalFileName),
                            fileType,
                            umbracoVersions,
                            dotNetVersion
                            );

                        file.Current = isCurrent;

                        if (isCurrent)
                        {
                            packageEntity.SetValue("file", file.Id);
                        }

                        packageEntity.SetValue("dotNetVersion", dotNetVersion);



                        contentService.SaveAndPublishWithStatus(packageEntity);

                        DeleteTempFile(packageFile);

                        return(Request.CreateResponse(HttpStatusCode.OK, "Package file updated"));
                    }
                }
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
            finally
            {
                // if there's any errors, make sure to delete the temp file
                DeleteTempFile(packageFile);
            }

            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }
Beispiel #7
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 = 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;

                        WikiFile wf = 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)
                        {
                            WikiFile doc = 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);
            }
        }