void ImageBtnDelete_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(FileUrl) && !string.IsNullOrEmpty(ContainerName))
            {
                //Trim Url down to filename
                int    lastSlash = FileUrl.LastIndexOf("/") + 1;
                string fileName  = FileUrl.Substring(lastSlash);

                //Delete file from container here
                Factory factory = new Factory(Options.Username, Options.ApiKey);
                factory.DeleteItemFromContainer(ContainerName, fileName);

                //TODO Need to trigger Save() for datatype to remove saved data from property
                //NOTE Maybe set the ID from datatype to this control, load Content object and set property-alias-value to string.empty. But where does the alias come from?
                if (Data != null)
                {
                    //Clear the current datatypes property
                    Property property = new Property(Data.PropertyId)
                    {
                        Value = string.Empty
                    };
                    //Clear file from controls properties
                    FileUrl           = string.Empty;
                    FileUrlField.Text = string.Empty;
                }
            }
        }
        private bool CanViewCommand(object aObject)
        {
            if (FileUrl == null)
            {
                string manufactureNumberTemp  = manufactureNumber.TrimEnd();
                string rmanufactureNumberTemp = "";
                if (!String.IsNullOrEmpty(rmanufactureNumber))
                {
                    rmanufactureNumberTemp = rmanufactureNumber.TrimEnd();
                }
                FileUrl = (CustomUri.GetAbsoluteUrl(String.IsNullOrEmpty(rmanufactureNumber) ? manufactureNumberTemp : rmanufactureNumberTemp) + "/" + fileName);
            }

            if (FileUrl != null)
            {
                int lastDot = FileUrl.LastIndexOf(".");
                if (lastDot <= 0)
                {
                    return(false);
                }
                String lExt = FileUrl.Substring(lastDot, FileUrl.Length - lastDot).ToLower();
                if (lExt == ".pdf" ||
                    lExt == ".doc" ||
                    lExt == ".docx" ||
                    lExt == ".xls" ||
                    lExt == ".xlsx" ||
                    lExt == ".jpeg" ||
                    lExt == ".jpg" ||
                    lExt == ".png" ||
                    lExt == ".bmp" ||
                    lExt == ".tiff" ||
                    lExt == ".tif" ||
                    lExt == ".gif")
                {
                    DateTime lToday = DateTime.Now;
                    if (lToday.Year == fileUpdateTime.Value.Year && lToday.Month == fileUpdateTime.Value.Month && lToday.Day == fileUpdateTime.Value.Day)
                    {
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        private bool CanViewCommand(object aObject)
        {
            if (FileUrl == null)
            {
                FileUrl = CustomUri.GetAbsoluteUrl("PlanOutline/" + fileName);
            }

            if (FileUrl != null)
            {
                int    lastDot = FileUrl.LastIndexOf(".");
                String lExt    = FileUrl.Substring(lastDot, FileUrl.Length - lastDot).ToLower();
                if (lExt == ".pdf" ||
                    lExt == ".doc" ||
                    lExt == ".docx" ||
                    lExt == ".xls" ||
                    lExt == ".xlsx" ||
                    lExt == ".jpeg" ||
                    lExt == ".png" ||
                    lExt == ".bmp" ||
                    lExt == ".tiff" ||
                    lExt == ".gif")
                {
                    DateTime lToday = DateTime.Now;
                    if (lToday.Year == fileUploadTime.Year && lToday.Month == fileUploadTime.Month && lToday.Day == fileUploadTime.Day)
                    {
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        private string PopulateWithMetaData()
        {
            if (string.IsNullOrEmpty(ContainerName) || string.IsNullOrEmpty(FileUrlField.Text))
            {
                return(string.Empty);
            }

            //Trim Url down to filename
            int    lastSlash = FileUrl.LastIndexOf("/") + 1;
            string fileName  = FileUrl.Substring(lastSlash);

            Factory factory   = new Factory(Options.Username, Options.ApiKey);
            var     cloudFile = factory.GetStorageItemInformation(ContainerName, fileName);

            StringBuilder sb = new StringBuilder();

            sb.Append("</span>");
            sb.Append("</div>"); //close propertyItemContent
            sb.Append("</div>"); //close propertyItem

            sb.Append("<div class=\"propertyItem\">");
            sb.Append("<div class=\"propertyItemheader\">Content Type</div>");
            sb.Append("<div class=\"propertyItemContent\">");
            sb.Append(cloudFile.ContentType);
            sb.Append("</div>"); //close propertyItemContent
            sb.Append("</div>"); //close propertyItem

            sb.Append("<div class=\"propertyItem\">");
            sb.Append("<div class=\"propertyItemheader\">Content Length</div>");
            sb.Append("<div class=\"propertyItemContent\">");
            sb.Append(cloudFile.ContentLength);
            sb.Append("</div>"); //close propertyItemContent
            sb.Append("</div>"); //close propertyItem

            sb.Append("<div><div><span>");

            return(sb.ToString());
        }
Exemple #5
0
        /// <summary>
        /// Saves the edit model.
        /// </summary>
        public bool SaveAll(bool draft)
        {
            var context = HttpContext.Current;
            var hasfile = UploadedFile != null || ServerFile != null;

            byte[]    data = null;
            WebClient web  = new WebClient();

            // Check if the original URL has been updated, and if so
            if (!Content.IsNew && !String.IsNullOrEmpty(Content.OriginalUrl))
            {
                var old = Content.GetSingle(Content.Id);
                if (old != null)
                {
                    if (Content.OriginalUrl != old.OriginalUrl)
                    {
                        FileUrl = Content.OriginalUrl;
                    }
                }
            }

            // Download file from web
            if (!hasfile && !String.IsNullOrEmpty(FileUrl))
            {
                data = web.DownloadData(FileUrl);
                Content.OriginalUrl = FileUrl;
                Content.LastSynced  = Convert.ToDateTime(web.ResponseHeaders[HttpResponseHeader.LastModified]);
            }

            var media = new MediaFileContent();

            if (hasfile)
            {
                if (UploadedFile != null)
                {
                    media.Filename    = UploadedFile.FileName;
                    media.ContentType = UploadedFile.ContentType;
                    using (var reader = new BinaryReader(UploadedFile.InputStream)) {
                        media.Body = reader.ReadBytes(Convert.ToInt32(UploadedFile.InputStream.Length));
                    }
                }
                else
                {
                    media.Filename    = ServerFile.Name;
                    media.ContentType = MimeType.Get(ServerFile.Name);
                    using (var stream = ServerFile.OpenRead()) {
                        media.Body = new byte[ServerFile.Length];
                        stream.Read(media.Body, 0, media.Body.Length);
                    }
                }
            }
            else if (data != null)
            {
                media.Filename    = FileUrl.Substring(FileUrl.LastIndexOf('/') + 1);
                media.ContentType = web.ResponseHeaders["Content-Type"];
                media.Body        = data;
            }
            else
            {
                media = null;
            }

            var saved = false;

            if (!Content.IsFolder)
            {
                // Only save permalinks for non-folders
                var filename = !String.IsNullOrEmpty(Content.Filename) ? Content.Filename : (!String.IsNullOrEmpty(media.Filename) ? media.Filename : "");
                if (Permalink.IsNew && String.IsNullOrEmpty(Permalink.Name))
                {
                    Permalink.Name = Permalink.Generate(!Content.IsFolder ? filename : Content.Name, Models.Permalink.PermalinkType.MEDIA);
                }
                try {
                    Permalink.Save();
                } catch (DuplicatePermalinkException) {
                    if (Permalink.IsNew)
                    {
                        Permalink.Name = Content.Id + Permalink.Name.Substring(Permalink.Name.LastIndexOf('.'));
                        Permalink.Save();
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                Content.PermalinkId = Guid.Empty;
            }

            if (draft)
            {
                saved = Content.Save(media);
            }
            else
            {
                saved = Content.SaveAndPublish(media);
            }

            if (saved)
            {
                // Save related information
                Relation.DeleteByDataId(Content.Id);
                List <Relation> relations = new List <Relation>();
                ContentCategories.ForEach(c => relations.Add(new Relation()
                {
                    DataId = Content.Id, RelatedId = c, IsDraft = false, Type = Relation.RelationType.CONTENTCATEGORY
                })
                                          );
                relations.ForEach(r => r.Save());

                // Save extensions
                foreach (var ext in Extensions)
                {
                    // Call OnSave
                    ext.Body.OnManagerSave(Content);

                    ext.ParentId = Content.Id;
                    ext.Save();
                    if (!draft)
                    {
                        if (Extension.GetScalar("SELECT COUNT(extension_id) FROM extension WHERE extension_id=@0 AND extension_draft=0", ext.Id) == 0)
                        {
                            ext.IsNew = true;
                        }
                        ext.IsDraft = false;
                        ext.Save();
                    }
                }
                // Reset file url
                FileUrl = "";

                return(true);
            }
            return(false);
        }