Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {           
            AlertController controller = new AlertController();
            AlertSelectCriteria criteria = new AlertSelectCriteria();

            criteria.AlertLevelEnum.EqualTo(AlertLevelEnum.Critical);
            criteria.InsertTime.SortDesc(1);

            AlertsCount.Text = controller.GetAlertsCount(criteria).ToString();

            alerts = controller.GetAlerts(criteria);

            if (alerts.Count > 0) {

                int rows = 0;
                foreach (Alert alert in alerts)
                {
                    TableRow alertRow = new TableRow();

                    alertRow.Attributes.Add("class", "AlertTableCell");

                    TableCell component = new TableCell();
                    TableCell source = new TableCell();
                    TableCell description = new TableCell();

                    description.Wrap = false;

                    component.Text = alert.Component;
                    component.Wrap = false;
                    source.Text = alert.Source;
                    source.Wrap = false;

                    string content = alert.Content.GetElementsByTagName("Message").Item(0).InnerText;
                    description.Text = content.Length < 50 ? content : content.Substring(0, 50);
                    description.Text += " ...";
                    description.Wrap = false;

                    alertRow.Cells.Add(component);
                    alertRow.Cells.Add(source);
                    alertRow.Cells.Add(description);

                    AlertTable.Rows.Add(alertRow);

                    rows++;
                    if (rows == 5) break;
                }
            }
        }
 public AlertSelectCriteria(AlertSelectCriteria other)
 : base(other)
 {}
		private bool ArchiveLogs(ServerFilesystemInfo archiveFs)
		{
			string archivePath = Path.Combine(archiveFs.Filesystem.FilesystemPath, "AlertLog");

			DateTime cutOffTime = Platform.Time.Date.AddDays(ServiceLockSettings.Default.AlertCachedDays*-1);
			AlertSelectCriteria criteria = new AlertSelectCriteria();
			criteria.InsertTime.LessThan(cutOffTime);
			criteria.InsertTime.SortAsc(0);

			using (ServerExecutionContext context = new ServerExecutionContext())
			{
				IAlertEntityBroker broker = context.ReadContext.GetBroker<IAlertEntityBroker>();

				ImageServerLogWriter<Alert> writer = new ImageServerLogWriter<Alert>(archivePath, "Alert");

				List<ServerEntityKey> keyList = new List<ServerEntityKey>(500);
				try
				{
					broker.Find(criteria, delegate(Alert result)
					                      	{
					                      		keyList.Add(result.Key);

					                      		// If configured, don't flush to disk.  We just delete the contents of keyList below.
					                      		if (!ServiceLockSettings.Default.AlertDelete)
					                      		{
					                      			if (writer.WriteLog(result, result.InsertTime))
					                      			{
					                      				// The logs been flushed, delete the log entries cached.
					                      				using (
					                      					IUpdateContext update =
					                      						PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush)
					                      					)
					                      				{
					                      					IApplicationLogEntityBroker updateBroker =
					                      						update.GetBroker<IApplicationLogEntityBroker>();
					                      					foreach (ServerEntityKey key in keyList)
					                      						updateBroker.Delete(key);
					                      					update.Commit();
					                      				}
					                      				keyList = new List<ServerEntityKey>();
					                      			}
					                      		}
					                      	});

					writer.FlushLog();

					if (keyList.Count > 0)
					{
						using (
							IUpdateContext update =
								PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
						{
							IAlertEntityBroker updateBroker = update.GetBroker<IAlertEntityBroker>();
							foreach (ServerEntityKey key in keyList)
								updateBroker.Delete(key);
							update.Commit();
						}
					}
				}
				catch (Exception e)
				{
					Platform.Log(LogLevel.Error, e, "Unexpected exception when purging Alert log files.");
					writer.Dispose();
					return false;
				}
				writer.Dispose();

				return true;
			}
		}
Exemplo n.º 4
0
 public int GetAlertsCount(AlertSelectCriteria criteria)
 {
     return _adaptor.GetCount(criteria);
 }
Exemplo n.º 5
0
 public IList<Alert> GetRangeAlerts(AlertSelectCriteria criteria, int startIndex, int maxRows)
 {
     return _adaptor.GetRange(criteria, startIndex, maxRows);
 }
Exemplo n.º 6
0
 public IList<Alert> GetAlerts(AlertSelectCriteria criteria)
 {
     return _adaptor.Get(criteria);
 }
Exemplo n.º 7
0
 public IList<Alert> GetAllAlerts()
 {
     AlertSelectCriteria searchCriteria = new AlertSelectCriteria();
     searchCriteria.InsertTime.SortAsc(0);
     return GetAlerts(searchCriteria);
 }
Exemplo n.º 8
0
		private AlertSelectCriteria GetSelectCriteria()
		{
			var criteria = new AlertSelectCriteria();

            QueryHelper.SetGuiStringCondition(criteria.Component, Component);
          
			if (!String.IsNullOrEmpty(InsertTime))
			{
				DateTime lowerDate = DateTime.ParseExact(InsertTime, DateFormats, null);
				DateTime upperDate = DateTime.ParseExact(InsertTime, DateFormats, null).Add(new TimeSpan(23, 59, 59));
				criteria.InsertTime.Between(lowerDate, upperDate);
			}

			if (Level != null)
				criteria.AlertLevelEnum.EqualTo(Level);
			if (Category != null)
				criteria.AlertCategoryEnum.EqualTo(Category);
			return criteria;
		}
Exemplo n.º 9
0
 public AlertSelectCriteria(AlertSelectCriteria other)
     : base(other)
 {
 }