Exemplo n.º 1
0
        private IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string channelId, AlertsQuery query)
        {
            var chid          = channelId.NimbusIdToGuid();
            var channelAlerts = GetAlertsFromCache <ChannelAlert>(chid.ToString());

            if (channelAlerts == null)
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                channelAlerts = dataAccess.GetChannelAlerts(chid.ToString(), query.StatusLevels, query.MetricTypes);
            }


            IEnumerable <MetricAlert> alerts = null;

            if (channelAlerts != null)
            {
                alerts = channelAlerts.Select(chAlt => new MetricAlert
                {
                    AlertID     = chAlt.AlertID,
                    Name        = chAlt.ChannelName,
                    Date        = chAlt.AlertDate.AddTicks(chAlt.AlertTime.Ticks),
                    Description = chAlt.Details,
                    Status      = chAlt.ErrorLevel
                });
            }
            return(alerts);
        }
 public void GetChannelAlertsByAccountIDTest()
 {
     _dataAccess = new AzureDataAccess(App.Config.Content.ContentProviders[0].MediaServicesSets[0].DataStorageConnections);
     try
     {
         var alerts = _dataAccess.GetChannelAlerts(1);
         Assert.IsNotNull(alerts, "Data Problem found");
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message, ex);
     }
 }
        private IEnumerable <MetricAlert> Get(MediaServicesSetConfig config, string channelId, AlertsQuery query)
        {
            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddHours(-1);

            HealthStatus[] healthLevels = null;
            MetricType[]   metricTypes  = null;

            if (query != null)
            {
                if (query.StartTime != default(DateTime))
                {
                    startTime = query.StartTime.ToUniversalTime();
                }
                if (query.EndTime != default(DateTime))
                {
                    endTime = query.EndTime.ToUniversalTime();
                }
                if (endTime <= startTime)
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.BadRequest);
                }
                metricTypes  = query.MetricTypes;
                healthLevels = query.StatusLevels;
            }

            var    chid        = channelId.NimbusIdToGuid();
            string alertstring = CloudCache.Get(chid + "Alerts");
            List <ChannelAlert> channelAlerts;

            if (alertstring != null)
            {
                channelAlerts = JsonConvert.DeserializeObject <List <ChannelAlert> >(alertstring);
            }
            else
            {
                var dataAccess = new AzureDataAccess(config.DataStorageConnections);
                channelAlerts = dataAccess.GetChannelAlerts(chid.ToString(), healthLevels, metricTypes);
                #region Not used
                //channelAlerts = dataAccess.ExecuteReadQuery(context =>
                //{
                //    var dbAlerts = context.ChannelAlerts.Where(alert =>
                //       alert.ChannelId == channelId &&
                //       alert.AlertDate >= startTime.AddTicks(alert.AlertTime.Ticks) &&
                //       alert.AlertDate <= endTime);

                //    if (healthLevels != null)
                //    {
                //        var predicate = CreatePredicate(healthLevels, "ErrorLevel");
                //        dbAlerts = dbAlerts.Where(predicate);
                //    }
                //    if (metricTypes != null)
                //    {
                //        var condition = CreatePredicate(metricTypes, "MetricType");
                //        dbAlerts = dbAlerts.Where(condition);
                //    }



                //    return dbAlerts.ToList();
                //});
                #endregion
            }
            List <MetricAlert> alerts = new List <MetricAlert>();
            if (channelAlerts != null)
            {
                foreach (var chAlt in channelAlerts)
                {
                    alerts.Add(new MetricAlert
                    {
                        AlertID     = chAlt.AlertID,
                        Name        = chAlt.ChannelName,
                        Date        = chAlt.AlertDate.AddTicks(chAlt.AlertTime.Ticks),
                        Description = chAlt.Details,
                        Status      = chAlt.ErrorLevel
                    });
                }
            }
            return(alerts);
        }