/// <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; }
/// <summary> /// Gets the candidate blobs for cleaning up. /// </summary> /// <param name="container">The cloud blob container.</param> /// <param name="searchPattern">The search pattern of a BLOB name.</param> /// <returns></returns> protected ICollection <ICloudBlob> GetCandidateBlobs(CloudBlobContainer container, string searchPattern) { Assert.ArgumentNotNull(container, "container"); Assert.ArgumentNotNull(searchPattern, "searchPattern"); var blobList = LogStorageManager.ListBlobs(container, searchPattern); Log.Info($"Scheduling.BlobsCleanupAgent: The '{container.Name}' cloud blob container includes '{blobList.Count()}' blobs that match the '{searchPattern}' search pattern.", this); var candidateBlobList = new List <ICloudBlob>(); foreach (ICloudBlob blob in blobList) { if (blob != null) { DateTime utcMaxTime = this.GetBlobLastModifiedDate(blob).Add(this.maxAge); if (DateTime.UtcNow > utcMaxTime) { candidateBlobList.Add(blob); } } } if (candidateBlobList.Any()) { Log.Info($"Scheduling.BlobsCleanupAgent: The '{container.Name}' cloud blob container includes '{candidateBlobList.Count()}' out-to-date blobs that match the '{searchPattern}' search pattern.", this); } return(candidateBlobList); }
/// <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; } }
/// <summary> /// Gets the new cloud blob for diagnostic messages. /// </summary> /// <returns> /// The cloud blob. /// </returns> protected virtual ICloudBlob GetNewBlob() { var blob = LogStorageManager.CreateBlob(this.ConstructBlobNameByDate()); if (blob.Exists()) { blob = LogStorageManager.CreateBlob(this.ConstructBlobNameByDateTime()); } return(blob); }
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(); } } } }