Beispiel #1
0
        public JsonNetResult UploadDropped()
        {
            string prefix = Request.Headers["X-Prefix"];

            RuntimeInfo info = RuntimeInfo.FromFormValue((string)Request.Headers["X-" + TypeContextUtilities.Compose(prefix, EntityBaseKeys.RuntimeInfo)]);

            string fileName = Request.Headers["X-FileName"];

            byte[] bytes               = Request.InputStream.ReadAllBytes();
            string fileType            = (string)Request.Headers["X-" + FileLineKeys.FileType];
            string calculatedDirectory = (string)Request.Headers["X-" + FileLineKeys.CalculatedDirectory];

            IFile file = FilesClient.ConstructFile(info.EntityType, new UploadedFileData
            {
                FileName            = fileName,
                Content             = bytes,
                FileType            = fileType,
                CalculatedDirectory = calculatedDirectory
            });

            RuntimeInfo ri = file is EmbeddedEntity ? new RuntimeInfo((EmbeddedEntity)file) : new RuntimeInfo((IEntity)file);

            return(this.JsonNet(new
            {
                file.FileName,
                FullWebPath = FilesClient.GetDownloadUrl(file),
                RuntimeInfo = ri.ToString(),
                EntityState = info.EntityType.IsEmbeddedEntity() ? Navigator.Manager.SerializeEntity((EmbeddedEntity)file) : null,
            }));
        }
Beispiel #2
0
        public ActionResult Download(string file)
        {
            if (file == null)
            {
                throw new ArgumentException("file");
            }

            RuntimeInfo ri = RuntimeInfo.FromFormValue(file);

            return(FilesClient.DownloadFileResult(ri));
        }
Beispiel #3
0
        public ActionResult Upload()
        {
            string singleFile = Request.Files.Cast <string>().Single();

            string prefix = singleFile.Substring(0, singleFile.IndexOf(FileLineKeys.File) - 1);

            RuntimeInfo info = RuntimeInfo.FromFormValue((string)Request.Form[TypeContextUtilities.Compose(prefix, EntityBaseKeys.RuntimeInfo)]);

            HttpPostedFileBase hpf = Request.Files[singleFile] as HttpPostedFileBase;

            string fileName = Path.GetFileName(hpf.FileName);

            byte[] bytes     = hpf.InputStream.ReadAllBytes();
            string fileType  = (string)Request.Form[TypeContextUtilities.Compose(prefix, FileLineKeys.FileType)];
            string extraData = (string)Request.Form[TypeContextUtilities.Compose(prefix, FileLineKeys.CalculatedDirectory)];

            IFile file = FilesClient.ConstructFile(info.EntityType, new UploadedFileData
            {
                FileName            = fileName,
                Content             = bytes,
                FileType            = fileType,
                CalculatedDirectory = extraData
            });

            StringBuilder sb = new StringBuilder();

            //Use plain javascript not to have to add also the reference to jquery in the result iframe
            sb.AppendLine("<html><head><title>-</title></head><body>");
            sb.AppendLine("<script type='text/javascript'>");
            RuntimeInfo ri = file is EmbeddedEntity ? new RuntimeInfo((EmbeddedEntity)file) : new RuntimeInfo((IEntity)file);

            sb.AppendLine("window.parent.$.data(window.parent.document.getElementById('{0}'), 'SF-control').onUploaded('{1}', '{2}', '{3}', '{4}')".FormatWith(
                              prefix,
                              file.FileName,
                              FilesClient.GetDownloadUrl(file),
                              ri.ToString(),
                              info.EntityType.IsEmbeddedEntity() ? Navigator.Manager.SerializeEntity((EmbeddedEntity)file) : null));
            sb.AppendLine("</script>");
            sb.AppendLine("</body></html>");

            return(Content(sb.ToString()));
        }
Beispiel #4
0
        internal static MvcHtmlString InternalFileLine(this HtmlHelper helper, FileLine fileLine)
        {
            if (!fileLine.Visible)
            {
                return(MvcHtmlString.Empty);
            }

            IFile value = fileLine.GetFileValue();

            HtmlStringBuilder sbg = new HtmlStringBuilder();

            using (sbg.SurroundLine(new HtmlTag("div").Id(fileLine.Prefix).Class("sf-field SF-control-container")))
            {
                sbg.AddLine(new HtmlTag("link").Attrs(new { rel = "stylesheet", type = "text/css", href = RouteHelper.New().Content("~/Files/Content/Files.css") }).ToHtmlSelf());

                if (value != null)
                {
                    sbg.AddLine(helper.Div(fileLine.Compose(EntityBaseKeys.Entity), null, "", new Dictionary <string, object> {
                        { "style", "display:none" }
                    }));
                }

                fileLine.ValueHtmlProps.AddCssClass("form-control");

                bool hasEntity = value != null && value.FileName.HasText();

                using (sbg.SurroundLine(new HtmlTag("div", fileLine.Compose("DivOld")).Attr("style", "display:" + (hasEntity ? "block" : "none"))))
                {
                    HtmlStringBuilder sb = new HtmlStringBuilder();
                    using (sb.SurroundLine(new HtmlTag("div", fileLine.Compose("inputGroup")).Class("input-group")))
                    {
                        if (fileLine.Download != DownloadBehaviour.None)
                        {
                            sb.AddLine(helper.Href(fileLine.Compose(EntityBaseKeys.Link),
                                                   value?.FileName,
                                                   hasEntity ? FilesClient.GetDownloadUrl(value) : null,
                                                   value?.FileName,
                                                   "form-control file-control",
                                                   fileLine.Download == DownloadBehaviour.View ? null :
                                                   new Dictionary <string, object> {
                                { "download", value?.FileName }
                            }));
                        }
                        else
                        {
                            sb.AddLine(helper.Span(fileLine.Compose(EntityBaseKeys.ToStr), value?.FileName ?? "", "form-control file-control", null));
                        }

                        if (fileLine.Type.IsEmbeddedEntity())
                        {
                            sb.AddLine(helper.Hidden(fileLine.Compose(EntityBaseKeys.EntityState), value?.Let(f => Navigator.Manager.SerializeEntity((ModifiableEntity)f))));
                        }

                        using (sb.SurroundLine(new HtmlTag("span", fileLine.Compose("shownButton")).Class("input-group-btn")))
                        {
                            sb.AddLine(EntityButtonHelper.Remove(helper, fileLine, btn: true));
                        }
                    }

                    sbg.AddLine(helper.FormGroup(fileLine,
                                                 fileLine.Download == DownloadBehaviour.None ? fileLine.Compose(EntityBaseKeys.Link) : fileLine.Compose(EntityBaseKeys.ToStr),
                                                 fileLine.LabelHtml ?? fileLine.LabelText.FormatHtml(), sb.ToHtml()));
                }

                using (sbg.SurroundLine(new HtmlTag("div", fileLine.Compose("DivNew"))
                                        .Class("sf-file-line-new")
                                        .Attr("style", "display:" + (hasEntity ? "none" : "block"))))
                {
                    HtmlStringBuilder sb = new HtmlStringBuilder();
                    sb.AddLine(helper.HiddenRuntimeInfo(fileLine));
                    if (!fileLine.ReadOnly)
                    {
                        sb.AddLine(MvcHtmlString.Create("<input type='file' id='{0}' name='{0}' class='form-control'/>".FormatWith(fileLine.Compose(FileLineKeys.File))));
                        sb.AddLine(MvcHtmlString.Create("<img src='{0}' id='{1}_loading' alt='loading' style='display:none'/>".FormatWith(RouteHelper.New().Content("~/Files/Images/loading.gif"), fileLine.Prefix)));
                    }


                    sbg.AddLine(helper.FormGroup(fileLine,
                                                 fileLine.Compose(FileLineKeys.File),
                                                 fileLine.LabelHtml ?? fileLine.LabelText.FormatHtml(), sb.ToHtml()));
                }

                if (!fileLine.ReadOnly)
                {
                    sbg.AddLine(fileLine.ConstructorScript(FilesClient.Module, "FileLine"));
                }
            }

            return(sbg.ToHtml());
        }