/// <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; }
public void Delete([NotNull] ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var blobName = StringUtil.GetString(Context.ClientPage.ServerProperties["Blob"]); if (args.IsPostBack) { if (args.Result == "yes") { if (string.IsNullOrEmpty(blobName)) { return; } try { var blob = LogStorageManager.GetBlob(blobName); blob.DeleteAsync(); Log.Audit($"Delete the '{blob.Name}' cloud blob.", this); this.SetBlob(string.Empty); } catch (Exception ex) { SheerResponse.Alert(Texts.THE_FILE_COULD_NOT_BE_DELETED_ERROR_MESSAGE + ex.Message); } } } else { if (Context.ClientPage.ServerProperties["Blob"] == null) { Context.ClientPage.ClientResponse.Alert(Texts.YOU_MUST_OPEN_A_LOG_FILE_FIRST); return; } var blob = LogStorageManager.GetBlob(blobName); blobName = blob.Uri.Segments.Last(); SheerResponse.Confirm(Translate.Text(Texts.ARE_YOU_SURE_YOU_WANT_TO_DELETE_0, blobName)); args.WaitForPostBack(); } }
/// <summary> /// Raises the load event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <contract> /// <requires name="e" condition="not null"/> /// </contract> protected override void OnLoad([NotNull] EventArgs e) { Assert.ArgumentNotNull(e, "e"); Assert.CanRunApplication("/sitecore/content/Applications/Tools/Log Viewer"); base.OnLoad(e); if (Context.ClientPage.IsEvent) { return; } string blobName = WebUtil.GetQueryString("blob"); if (string.IsNullOrEmpty(blobName)) { return; } var blob = LogStorageManager.GetBlob(blobName); var data = string.Empty; if (blob.BlobType == BlobType.AppendBlob) { this.TextPanel.Visible = false; data = ((CloudAppendBlob)blob).DownloadText(LogStorageManager.DefaultTextEncoding); } if (string.IsNullOrEmpty(data)) { this.LogViewer.Controls.Add(new LiteralControl(Translate.Text(Texts.THIS_FILE_IS_EMPTY_OR_CANNOT_BE_OPENED_FOR_READING))); return; } data = HttpUtility.HtmlEncode(data).Replace("\n", "<br/>"); this.LogViewer.Controls.Add(new LiteralControl(data)); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load"></see> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"></see> object that contains the event data.</param> /// <contract> /// <requires name="e" condition="not null" /> /// </contract> protected override void OnLoad([NotNull] EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); string blobHandle = WebUtil.GetQueryString("blob"); if (!string.IsNullOrEmpty(blobHandle)) { var blobName = BlobHandle.GetBlobName(blobHandle); if (!string.IsNullOrEmpty(blobName)) { var blob = LogStorageManager.GetBlob(blobName); var response = HttpContext.Current.Response; using (var stream = new MemoryStream()) { blob.DownloadToStream(stream); response.ClearHeaders(); response.ContentType = blob.Properties.ContentType; response.AddHeader("Content-Disposition", "attachment; filename=\"" + blob.Name + "\""); response.AddHeader("Content-Length", blob.Properties.Length.ToString(CultureInfo.InvariantCulture)); response.AddHeader("Content-Transfer-Encoding", "binary"); response.CacheControl = "private"; response.BinaryWrite(stream.ToArray()); response.End(); } } } }