/// <summary> /// Raises the load event. /// </summary> /// <param name="e"> /// The <see cref="System.EventArgs"/> instance containing the event data. /// </param> /// <remarks> /// This method notifies the server control that it should perform actions common to each HTTP /// request for the page it is associated with, such as setting up a database query. At this /// stage in the page lifecycle, server controls in the hierarchy are created and initialized, /// view state is restored, and form controls reflect client-side data. Use the IsPostBack /// property to determine whether the page is being loaded in response to a client postback, /// or if it is being loaded and accessed for the first time. /// </remarks> protected override void OnLoad([NotNull] EventArgs e) { Assert.ArgumentNotNull(e, "e"); this.CheckSecurity(); base.OnLoad(e); if (Context.ClientPage.IsEvent) { return; } var urlHandle = UrlHandle.Get(); var icon = urlHandle["ic"]; if (!string.IsNullOrEmpty(icon)) { this.Dialog["Icon"] = icon; } var header = WebUtil.SafeEncode(urlHandle["he"]); if (header.Length > 0) { this.Dialog["Header"] = header; } var text = WebUtil.SafeEncode(urlHandle["txt"]); if (text.Length > 0) { this.Dialog["Text"] = text; } var button = WebUtil.SafeEncode(urlHandle["btn"]); if (button.Length > 0) { this.Dialog["OKButton"] = button; } var filter = urlHandle["flt"]; var blobsList = LogStorageManager.ListBlobs(filter); foreach (var blob in blobsList) { var item = new ListviewItem(); this.FileLister.Controls.Add(item); item.ID = Control.GetUniqueID("I"); item.Header = blob.Uri.Segments.Last(); item.Icon = "Applications/16x16/document.png"; item.ServerProperties["Blob"] = blob.Name; item.ColumnValues["size"] = MainUtil.FormatSize(blob.Properties.Length); item.ColumnValues["modified"] = blob.Properties.LastModified.HasValue ? blob.Properties.LastModified.Value.LocalDateTime : DateTime.Now; } }
protected void ShowFileTooBig() { SheerResponse.Alert( Translate.Text( "The file is too big to be uploaded.\n\nThe maximum size of a file that can be uploaded is {0}.", MainUtil.FormatSize(Settings.Upload.MaximumDatabaseUploadSize))); OKButton.Disabled = true; CancelButton.Disabled = true; OKButton.Disabled = false; CancelButton.Disabled = false; }
protected void ShowFileTooBig(string filename) { Assert.ArgumentNotNullOrEmpty(filename, "filename"); SheerResponse.Alert( Translate.Text( "The file \"{0}\" is too big to be uploaded.\n\nThe maximum size of a file that can be uploaded is {1}.", filename, MainUtil.FormatSize(Settings.Upload.MaximumDatabaseUploadSize))); OKButton.Disabled = true; CancelButton.Disabled = true; OKButton.Disabled = false; CancelButton.Disabled = false; }
private void LiteralControlDataBinding(object sender, EventArgs e) { var target = (Literal)sender; Control container = target.NamingContainer; var dataItem = DataBinder.GetDataItem(container) as BaseItem; if (dataItem != null) { long fileSize = MainUtil.GetLong(dataItem[this.FieldName], 0); if (dataItem is FolderItem) { target.Text = string.Empty; } else { target.Text = MainUtil.FormatSize(fileSize); } } }
/// <summary>Called when the files has cancelled.</summary> /// <param name="packet">The packet.</param> /// <contract> /// <requires name="packet" condition="not null" /> /// </contract> protected void OnFilesCancelled(string packet) { Assert.ArgumentNotNullOrEmpty(packet, "packet"); ListString listString = new ListString(packet); Assert.IsTrue(listString.Count > 0, "Zero cancelled files posted"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("The following files are too big to be uploaded:"); stringBuilder.Append("\n\n"); foreach (string str in listString.Items) { stringBuilder.Append(str + "\n"); } string str1 = MainUtil.FormatSize(Math.Min(Settings.Media.MaxSizeInDatabase, Settings.Runtime.EffectiveMaxRequestLengthBytes)); stringBuilder.Append(Translate.Text("The maximum size of a file that can be uploaded is {0}.", (object)str1)); SheerResponse.Alert(stringBuilder.ToString()); }
/// <summary>Called when this instance has queued.</summary> /// <param name="filename">The filename.</param> /// <param name="lengthString">The length string.</param> protected void OnQueued(string filename, string lengthString) { Assert.IsNotNullOrEmpty(filename, "filename"); Assert.IsNotNullOrEmpty(lengthString, "lengthString"); int num = int.Parse(lengthString); long databaseUploadSize = Settings.Upload.MaximumDatabaseUploadSize; if ((long)num > databaseUploadSize) { string text = Translate.Text("The file \"{0}\" is too big to be uploaded.\n\nThe maximum size of a file that can be uploaded is {1}.", (object)filename, (object)MainUtil.FormatSize(databaseUploadSize)); this.WarningMessage = text; SheerResponse.Alert(text); } else { SheerResponse.SetInnerHtml("FilenameText", filename + " (" + MainUtil.FormatSize((long)num) + ")"); this.WarningMessage = string.Empty; SheerResponse.Eval("scUpload.start()"); } }
protected void ShowFileTooBig(string filename) { Assert.ArgumentNotNullOrEmpty(filename, "filename"); SheerResponse.Alert( Translate.Text(Sitecore.Texts.THE_FILE_0_IS_TOO_BIG_TO_BE_UPLOADED_THE_MAXIMUM_SIZE_FOR_UPLOADING_FILES_IS_1, filename, MainUtil.FormatSize(Settings.Upload.MaximumDatabaseUploadSize)) ); OKButton.Disabled = true; CancelButton.Disabled = true; OKButton.Disabled = false; CancelButton.Disabled = false; }
protected void ShowFileTooBig() { SheerResponse.Alert( Translate.Text(Sitecore.Texts.THE_FILE_IS_TOO_BIG_TO_BE_UPLOADED_THE_MAXIMUM_SIZE_FOR_UPLOADING_FILES_IS_0, MainUtil.FormatSize(Settings.Upload.MaximumDatabaseUploadSize)) ); OKButton.Disabled = true; CancelButton.Disabled = true; OKButton.Disabled = false; CancelButton.Disabled = false; }
public void Process(UploadArgs args) { Assert.ArgumentNotNull((object)args, "args"); if (args.Destination == UploadDestination.File) { return; } foreach (string index in (NameObjectCollectionBase)args.Files) { HttpPostedFile httpPostedFile = args.Files[index]; if (!string.IsNullOrEmpty(httpPostedFile.FileName) && this.IsRestrictedExtension(httpPostedFile.FileName) && (long)httpPostedFile.ContentLength > ImageUploadMaxSize.MaxImageSizeInDatabase) { string str = (string)(object)(httpPostedFile.ContentLength / 1024) + (object)"KB"; args.ErrorText = string.Format("The image \"{0}\" is too big to be uploaded. The maximum size for uploading images is {1}.", (object)(httpPostedFile.FileName + " (" + str + ")"), (object)MainUtil.FormatSize(ImageUploadMaxSize.MaxImageSizeInDatabase)); Log.Warn(args.ErrorText, (object)this); args.AbortPipeline(); break; } } }
private static bool ValidateFile(HttpPostedFileBase file, SitecoreViewModelResult result) { List <ErrorItem> list = new List <ErrorItem>(); int contentLength = file.ContentLength; bool flag = true; if (contentLength > CustomSpeakMediaController.MaxImageSizeInDatabase) { list.Add(new ErrorItem("size", contentLength.ToString(), string.Format(ClientHost.Globalization.Translate("The file \"{0} (size: {1} KB)\" exceeds the maximum size \"{2}\"."), file.FileName, (file.ContentLength / 1024f), (object)MainUtil.FormatSize(CustomSpeakMediaController.MaxImageSizeInDatabase)))); flag = false; } if (!flag) { ((dynamic)result.Result).errorItems = list; } return(flag); }
/// <summary> /// Sets the blob. /// </summary> /// <param name="blobName">The blob name.</param> /// <contract> /// <requires name="filename" condition="none" /> /// </contract> private void SetBlob([CanBeNull] string blobName) { if (string.IsNullOrEmpty(blobName)) { Context.ClientPage.ServerProperties["Blob"] = null; this.Document.SetSource("control:LogViewerDetails", string.Empty); Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarTitle", Translate.Text(Texts.LOG_FILES1)); Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarDescription", Translate.Text(Texts.THIS_TOOL_DISPLAYS_THE_CONTENT_OF_LOG_FILES)); this.HasFile.Disabled = true; return; } Context.ClientPage.ServerProperties["Blob"] = blobName; this.Document.SetSource("control:LogViewerDetails", "blob=" + HttpUtility.UrlEncode(blobName)); var blob = LogStorageManager.GetBlob(blobName); Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarTitle", Path.GetFileNameWithoutExtension(blob.Name)); var lastModified = blob.Properties.LastModified.HasValue ? blob.Properties.LastModified.Value.LocalDateTime : DateTime.Now; Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarDescription", Translate.Text(Translate.Text(Texts.LAST_ACCESS_0) + "<br/>", DateUtil.FormatShortDateTime(lastModified)) + Translate.Text(Texts.SIZE_0, MainUtil.FormatSize(blob.Properties.Length))); this.HasFile.Disabled = false; }
private void SetFile(string filename) { if (string.IsNullOrEmpty(filename)) { Context.ClientPage.ServerProperties["File"] = (object)null; this.Document.SetSource("control:UserLogDetails", string.Empty); Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarTitle", Translate.Text("Log Files")); Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarDescription", Translate.Text("This tool displays the content of log files.")); this.HasFile.Disabled = true; } else { Context.ClientPage.ServerProperties["File"] = (object)filename; this.Document.SetSource("control:UserLogDetails", "file=" + HttpUtility.UrlEncode(filename)); FileInfo fileInfo = new FileInfo(FileUtil.MapPath(filename)); Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarTitle", Path.GetFileNameWithoutExtension(filename)); Context.ClientPage.ClientResponse.SetInnerHtml("Commandbar_CommandbarDescription", Translate.Text(Translate.Text("Last access: {0}") + "<br/>", (object)DateUtil.FormatShortDateTime(DateUtil.ToServerTime(fileInfo.LastWriteTimeUtc))) + Translate.Text("Size: {0}", (object)MainUtil.FormatSize(fileInfo.Length))); this.HasFile.Disabled = false; } }
protected void Page_Load(object sender, EventArgs e) { rptSites.DataSource = SiteManager.Instance.GetAllSites(); rptSites.DataBind(); var siteContext = Factory.GetSite("habitat"); var filteredItemsCache = global::Sitecore.Caching.CacheManager.GetFilteredItemsCache(siteContext); var htmlCache = global::Sitecore.Caching.CacheManager.GetHtmlCache(siteContext); var registryCache = global::Sitecore.Caching.CacheManager.GetRegistryCache(siteContext); var viewStateCache = global::Sitecore.Caching.CacheManager.GetViewStateCache(siteContext); var xslCache = global::Sitecore.Caching.CacheManager.GetXslCache(siteContext); lblFilteredItemsCacheInfo.Text = $"Name: {filteredItemsCache.Name} Count:{filteredItemsCache.InnerCache.Count} Size:{MainUtil.FormatSize(filteredItemsCache.InnerCache.Size)} MaxSize:{MainUtil.FormatSize(filteredItemsCache.InnerCache.MaxSize)}"; rptFilteredItemCaches.DataSource = filteredItemsCache.InnerCache.GetCacheKeys(); rptFilteredItemCaches.DataBind(); lblHtmlCache.Text = $"Name: {htmlCache.Name} Count:{htmlCache.InnerCache.Count} Size:{MainUtil.FormatSize(htmlCache.InnerCache.Size)} MaxSize:{MainUtil.FormatSize(htmlCache.InnerCache.MaxSize)}"; rptHtmlCache.DataSource = htmlCache.InnerCache.GetCacheKeys(); rptHtmlCache.DataBind(); }
private void DisplayTotalSizeInfo(IReadOnlyCollection <CacheInfo> caches) { labelTotals.Text = $"Entries: {caches.Sum(x => x.Count)}, Size: {MainUtil.FormatSize(caches.Sum(x => x.Size))}"; labelCacheTitle.Text = $"Caches ({caches.Count})"; }
public new void Process(UploadArgs args) { if (Sitecore.UIUtil.IsIE()) { // We need to use the original functionality for IE base.Process(args); return; } Assert.ArgumentNotNull((object)args, "args"); if (args.Destination == UploadDestination.File) { return; } foreach (string index in (NameObjectCollectionBase)args.Files) { HttpPostedFile file = args.Files[index]; if (!string.IsNullOrEmpty(file.FileName)) { if (UploadProcessor.IsUnpack(args, file)) { ZipReader zipReader = new ZipReader(file.InputStream); try { foreach (ZipEntry zipEntry in zipReader.Entries) { if (!zipEntry.IsDirectory && zipEntry.Size > Settings.Media.MaxSizeInDatabase) { string text = file.FileName + "/" + zipEntry.Name; HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.browser.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" + StringUtil.EscapeJavascriptString(text) + ")')</script></head><body>Done</body></html>"); args.ErrorText = string.Format("The file \"{0}\" is too big to be uploaded. The maximum size for uploading files is {1}.", (object)text, (object)MainUtil.FormatSize(Settings.Media.MaxSizeInDatabase)); args.AbortPipeline(); return; } } } finally { file.InputStream.Position = 0L; } } else if ((long)file.ContentLength > Settings.Media.MaxSizeInDatabase) { string fileName = file.FileName; HttpContext.Current.Response.Write("<html><head><script type=\"text/JavaScript\" language=\"javascript\">window.top.scForm.browser.getTopModalDialog().frames[0].scForm.postRequest(\"\", \"\", \"\", 'ShowFileTooBig(" + StringUtil.EscapeJavascriptString(fileName) + ")')</script></head><body>Done</body></html>"); args.ErrorText = string.Format("The file \"{0}\" is too big to be uploaded. The maximum size for uploading files is {1}.", (object)fileName, (object)MainUtil.FormatSize(Settings.Media.MaxSizeInDatabase)); args.AbortPipeline(); break; } } } }
public void Process(AttachArgs args) { //if (!args.MediaItem.FileBased && (!this.IsRestrictedExtension(args.File.FileName) || args.File.InputStream.Length > ImageAttachMaxSize.MaxImageSizeInDatabase)) // throw new ClientAlertException(string.Format("The file is too big to be attached. The maximum size of a file that can be uploaded is {0}.", (object)MainUtil.FormatSize(ImageAttachMaxSize.MaxImageSizeInDatabase))); if (this.IsRestrictedExtension(args.File.FileName) && args.File.InputStream.Length > ImageAttachMaxSize.MaxImageSizeInDatabase) { throw new ClientAlertException(string.Format("The file is too big to be attached. The maximum size of a file that can be uploaded is {0}.", (object)MainUtil.FormatSize(ImageAttachMaxSize.MaxImageSizeInDatabase))); } }