/// <summary> /// Gets and updates abuse report. Called when the "Get and update report" button is pressed. /// Expects the LogEvent method to be run first. /// </summary> private bool GetAndUpdateEvent() { // Create new instance of event log provider EventLogProvider eventLog = new EventLogProvider(); // Get top 1 event matching the where condition string where = "EventCode = 'APIEXAMPLE'"; int topN = 1; DataSet events = eventLog.GetAllEvents(where, null, topN, null); if (!DataHelper.DataSourceIsEmpty(events)) { // Create the object from DataRow EventLogInfo updateEvent = new EventLogInfo(events.Tables[0].Rows[0]); // Update the properties updateEvent.EventDescription = updateEvent.EventDescription.ToLower(); // Save the changes eventLog.SetEventLogInfo(updateEvent); return(true); } return(false); }
/// <summary> /// Gets and bulk updates eventss. Called when the "Get and bulk update events" button is pressed. /// Expects the LogEvent method to be run first. /// </summary> private bool GetAndBulkUpdateEvents() { // Create new instance of event log provider EventLogProvider eventLog = new EventLogProvider(); // Get events matching the where condition string where = "EventCode = 'APIEXAMPLE'"; DataSet events = eventLog.GetAllEvents(where, null); if (!DataHelper.DataSourceIsEmpty(events)) { // Loop through the individual items foreach (DataRow eventDr in events.Tables[0].Rows) { // Create the object from DataRow EventLogInfo updateEvent = new EventLogInfo(eventDr); // Update the properties updateEvent.EventDescription = updateEvent.EventDescription.ToUpper(); // Save the changes eventLog.SetEventLogInfo(updateEvent); } return true; } return false; }
/// <summary> /// Gets and bulk updates eventss. Called when the "Get and bulk update events" button is pressed. /// Expects the LogEvent method to be run first. /// </summary> private bool GetAndBulkUpdateEvents() { // Create new instance of event log provider EventLogProvider eventLog = new EventLogProvider(); // Get events matching the where condition string where = "EventCode = 'APIEXAMPLE'"; DataSet events = eventLog.GetAllEvents(where, null); if (!DataHelper.DataSourceIsEmpty(events)) { // Loop through the individual items foreach (DataRow eventDr in events.Tables[0].Rows) { // Create the object from DataRow EventLogInfo updateEvent = new EventLogInfo(eventDr); // Update the properties updateEvent.EventDescription = updateEvent.EventDescription.ToUpper(); // Save the changes eventLog.SetEventLogInfo(updateEvent); } return(true); } return(false); }
/// <summary> /// Returns last 20 events from EventLog. /// </summary> private string GetEventLog() { StringBuilder sb = new StringBuilder(); sb.Append("<div>"); EventLogProvider eventProvider = new EventLogProvider(); DataSet ds = eventProvider.GetAllEvents("EventType = 'E' OR EventType = 'W'", "EventTime DESC", 20, null); if (!DataHelper.DataSourceIsEmpty(ds)) { sb.Append("<table style=\"width: 100%;\">"); sb.AppendLine("<tr>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.EventType") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.EventCode") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.UserName") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.IPAddress") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.DocumentName") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.SiteName") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.EventMachineName") + "</strong></td>"); sb.AppendLine("</tr>"); string evenStyle = " background-color: rgb(244, 244, 244);"; int i = 0; foreach (DataRow dr in ds.Tables[0].Rows) { string siteName = SiteInfoProvider.GetSiteName(ValidationHelper.GetInteger(dr["SiteID"], 0)); sb.AppendLine("<tr style=\"cursor: pointer;" + (i % 2 == 0 ? evenStyle : "") + "\" onclick=\"document.getElementById('table_event_" + i + "').style.display = (this.hide ? 'none' : 'block'); this.hide = !this.hide; return false;\">"); sb.AppendLine("<td>" + dr["EventType"] + "</td>"); sb.AppendLine("<td>" + dr["EventCode"] + "</td>"); sb.AppendLine("<td>" + dr["UserName"] + "</td>"); sb.AppendLine("<td>" + dr["IPAddress"] + "</td>"); sb.AppendLine("<td>" + dr["DocumentName"] + "</td>"); sb.AppendLine("<td>" + siteName + "</td>"); sb.AppendLine("<td>" + dr["EventMachineName"] + "</td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr><td colspan=\"7\">"); string item = "<table style=\"display: none;\" id=\"table_event_" + i + "\">"; foreach (DataColumn col in ds.Tables[0].Columns) { item += GetEventLogItem(col.ColumnName, dr); } item += "</table>"; sb.AppendLine(item); sb.AppendLine("</td></tr>"); i++; } sb.Append("</table>"); } sb.Append("</div>"); return(sb.ToString()); }
protected void Page_Load(object sender, EventArgs e) { if (SystemContext.DevelopmentMode) { // Restart application menu.AddAction(new HeaderAction { Text = GetString("administration-system.btnrestart"), ButtonStyle = ButtonStyle.Default, Tooltip = GetString("administration-system.btnrestart"), OnClientClick = "function RestartPerformed() {return alert('" + GetString("administration-system.restartsuccess") + "');} if (confirm('" + GetString("system.restartconfirmation") + "')) {" + Page.ClientScript.GetCallbackEventReference(this, "'restart'", "RestartPerformed", String.Empty, true) + "}" }); // Clear cache menu.AddAction(new HeaderAction { Text = GetString("administration-system.btnclearcache"), ButtonStyle = ButtonStyle.Default, Tooltip = GetString("administration-system.btnclearcache"), OnClientClick = "function ClearCachePerformed() {return alert('" + GetString("administration-system.clearcachesuccess") + "');} if (confirm('" + GetString("system.clearcacheconfirmation") + "')) {" + Page.ClientScript.GetCallbackEventReference(this, "'clearcache'", "ClearCachePerformed", String.Empty, true) + "}" }); // Event log HeaderAction eventLog = new HeaderAction { Text = GetString("administration.ui.eventlog"), ButtonStyle = ButtonStyle.Default, Tooltip = GetString("administration.ui.eventlog"), RedirectUrl = "~/CMSModules/EventLog/EventLog.aspx", Target = "_blank" }; // Event log items DataSet ds = EventLogProvider.GetAllEvents(null, "EventTime DESC", 10, "EventTime, EventType, Source, EventCode"); foreach (DataRow row in ds.Tables[0].Rows) { HeaderAction ev = new HeaderAction { Text = string.Format("{0} {1} {2} {3}", row["EventTime"], row["EventType"], row["Source"], row["EventCode"]), ButtonStyle = ButtonStyle.Default }; eventLog.AlternativeActions.Add(ev); } menu.AddAction(eventLog); // Debug menu.AddAction(new HeaderAction { Text = GetString("Administration-System.Debug"), ButtonStyle = ButtonStyle.Default, Tooltip = GetString("Administration-System.Debug"), RedirectUrl = URLHelper.AppendQuery(UIContextHelper.GetElementUrl(ModuleName.CMS, "Debug"), "displaytitle=true"), Target = "_blank" }); // Submit defect menu.AddAction(new HeaderAction { Text = "Submit defect", ButtonStyle = ButtonStyle.Default, Tooltip = "Submit defect", RedirectUrl = "https://kentico.atlassian.net/secure/CreateIssue!default.jspa", Target = "_blank" }); // Virtual site HeaderAction sites = new HeaderAction { Text = GetString("devmenu.sites"), ButtonStyle = ButtonStyle.Default, Tooltip = GetString("devmenu.sites"), Inactive = true }; // Site items var sitesDs = SiteInfoProvider.GetSites().Columns("SiteName", "SiteDisplayName").OrderBy("SiteDisplayName"); foreach (SiteInfo s in sitesDs) { // Prepare the parameters NameValueCollection values = new NameValueCollection(); values.Add(VirtualContext.PARAM_SITENAME, s.SiteName); HeaderAction site = new HeaderAction { Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(s.DisplayName)), ButtonStyle = ButtonStyle.Default, RedirectUrl = VirtualContext.GetVirtualContextPath(Request.Path, values), Target = "_blank" }; sites.AlternativeActions.Add(site); } menu.AddAction(sites); } else { Visible = false; } }
/// <summary> /// Gets and updates abuse report. Called when the "Get and update report" button is pressed. /// Expects the LogEvent method to be run first. /// </summary> private bool GetAndUpdateEvent() { // Create new instance of event log provider EventLogProvider eventLog = new EventLogProvider(); // Get top 1 event matching the where condition string where = "EventCode = 'APIEXAMPLE'"; int topN = 1; DataSet events = eventLog.GetAllEvents(where, null, topN, null); if (!DataHelper.DataSourceIsEmpty(events)) { // Create the object from DataRow EventLogInfo updateEvent = new EventLogInfo(events.Tables[0].Rows[0]); // Update the properties updateEvent.EventDescription = updateEvent.EventDescription.ToLower(); // Save the changes eventLog.SetEventLogInfo(updateEvent); return true; } return false; }
/// <summary> /// Runs example. /// </summary> public void Run() { try { if (RunExample != null) { bool success = RunExample(); if (!success) { // Display error message lblError.Text = ErrorMessage; lblError.Visible = true; return; } } else if (RunExampleSimple != null) { RunExampleSimple(); } } catch (CMSAPIExampleException ex) { lblError.Text = String.IsNullOrWhiteSpace(ex.Message) ? ErrorMessage : ex.Message; lblError.Visible = true; return; } catch (Exception ex) { // Log exception EventLogProvider.LogException("APIExample", "EXCEPTION", ex); string msg = ""; // Try to find id of last interesting log string where = EventLogProvider.ProviderObject.GetSiteWhereCondition(0) + " AND (Source = 'APIExample') AND (IPAddress = '" + RequestContext.UserHostAddress + "')"; string orderBy = "EventTime DESC, EventID DESC"; DataSet ds = EventLogProvider.GetAllEvents(where, orderBy, 1, "EventID"); // Get id int eventId = 0; if (!DataHelper.DataSourceIsEmpty(ds)) { eventId = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["EventID"], 0); } if (eventId != 0) { string identifier = Guid.NewGuid().ToString(); Hashtable mParameters = new Hashtable(); mParameters["where"] = where; mParameters["orderby"] = orderBy; WindowHelper.Add(identifier, mParameters); string queryString = "?params=" + identifier; queryString = URLHelper.AddParameterToUrl(queryString, "hash", QueryHelper.GetHash(queryString)); queryString = URLHelper.AddParameterToUrl(queryString, "eventid", eventId.ToString()); // Add link to event details in event log msg = String.Format("The API example failed. See event log for <a href=\"\" onclick=\"modalDialog('" + ResolveUrl("~/CMSModules/EventLog/EventLog_Details.aspx") + queryString + "', 'eventdetails', 920, 700); return false;\">more details</a>."); } else { // Add link to Event log msg = String.Format("The API example failed. See <a href=\"" + ResolveUrl("~/CMSModules/EventLog/EventLog.aspx") + "\" target=\"_blank\">event log</a> for more details."); } // Display error message lblError.Text = msg; lblError.ToolTip = ex.Message; lblError.Visible = true; return; } //Display info message lblInfo.Text = InfoMessage; lblInfo.Visible = true; }
/// <summary> /// Returns last 20 events from EventLog. /// </summary> private string GetEventLog() { StringBuilder sb = new StringBuilder(); sb.Append("<div>"); EventLogProvider eventProvider = new EventLogProvider(); DataSet ds = eventProvider.GetAllEvents("EventType = 'E' OR EventType = 'W'", "EventTime DESC", 20, null); if (!DataHelper.DataSourceIsEmpty(ds)) { sb.Append("<table style=\"width: 100%;\">"); sb.AppendLine("<tr>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.EventType") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.EventCode") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.UserName") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.IPAddress") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.DocumentName") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.SiteName") + "</strong></td>"); sb.AppendLine("<td><strong>" + ResHelper.GetString("cmstesting.eventlog.EventMachineName") + "</strong></td>"); sb.AppendLine("</tr>"); string evenStyle = " background-color: rgb(244, 244, 244);"; int i = 0; foreach (DataRow dr in ds.Tables[0].Rows) { string siteName = SiteInfoProvider.GetSiteName(ValidationHelper.GetInteger(dr["SiteID"], 0)); sb.AppendLine("<tr style=\"cursor: pointer;" + (i % 2 == 0 ? evenStyle : "") + "\" onclick=\"document.getElementById('table_event_" + i + "').style.display = (this.hide ? 'none' : 'block'); this.hide = !this.hide; return false;\">"); sb.AppendLine("<td>" + dr["EventType"] + "</td>"); sb.AppendLine("<td>" + dr["EventCode"] + "</td>"); sb.AppendLine("<td>" + dr["UserName"] + "</td>"); sb.AppendLine("<td>" + dr["IPAddress"] + "</td>"); sb.AppendLine("<td>" + dr["DocumentName"] + "</td>"); sb.AppendLine("<td>" + siteName + "</td>"); sb.AppendLine("<td>" + dr["EventMachineName"] + "</td>"); sb.AppendLine("</tr>"); sb.AppendLine("<tr><td colspan=\"7\">"); string item = "<table style=\"display: none;\" id=\"table_event_" + i + "\">"; foreach (DataColumn col in ds.Tables[0].Columns) { item += GetEventLogItem(col.ColumnName, dr); } item += "</table>"; sb.AppendLine(item); sb.AppendLine("</td></tr>"); i++; } sb.Append("</table>"); } sb.Append("</div>"); return sb.ToString(); }
/// <summary> /// Runs example. /// </summary> public void Run() { try { if (RunExample != null) { bool success = RunExample(); if (!success) { // Display error message lblError.Text = ErrorMessage; lblError.Visible = true; return; } } } catch (Exception ex) { // Log exception EventLogProvider ep = new EventLogProvider(); ep.LogEvent("APIExample", "EXCEPTION", ex); string msg = ""; // Try to find id of last interesting log string where = ep.GetSiteWhereCondition(0) + " AND (Source = 'APIExample') AND (IPAddress = '" + HTTPHelper.UserHostAddress + "')"; string orderBy = "EventTime DESC, EventID DESC"; DataSet ds = ep.GetAllEvents(where, orderBy, 1, "EventID"); // Get id int eventId = 0; if (!DataHelper.DataSourceIsEmpty(ds)) { eventId = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["EventID"], 0); } if(eventId != 0) { string identificator = Guid.NewGuid().ToString(); Hashtable mParameters = new Hashtable(); mParameters["where"] = where; mParameters["orderby"] = orderBy; WindowHelper.Add(identificator, mParameters); string queryString = "?params=" + identificator; queryString = URLHelper.AddParameterToUrl(queryString, "hash", QueryHelper.GetHash(queryString)); queryString = URLHelper.AddParameterToUrl(queryString, "eventid", eventId.ToString()); // Add link to event details in event log msg = String.Format("The API example failed. See event log for <a href=\"\" onclick=\"modalDialog('" + ResolveUrl("~/CMSModules/EventLog/EventLog_Details.aspx") + queryString + "', 'eventdetails', 920, 700); return false;\">more details</a>."); } else { // Add link to Event log msg = String.Format("The API example failed. See <a href=\"" + ResolveUrl("~/CMSModules/EventLog/EventLog.aspx") + "\" target=\"_blank\">event log</a> for more details."); } // Display error message lblError.Text = msg; lblError.ToolTip = ex.Message; lblError.Visible = true; return; } //Display info message lblInfo.Text = InfoMessage; lblInfo.Visible = true; }