Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="f"></param>
        public void Update(DataContext dc, ModelDashboard d)
        {
            Title    = d.Title;
            FolderId = d.FolderId;
            Data     = d.Data;

            Tags = new List <EntityTag>();

            if (null != d.Tags && d.Tags.Count() > 0)
            {
                Tags = d
                       .Tags
                       .Select(x => new EntityTag()
                {
                    Term = x
                })
                       .ToList();
            }

            if (!string.IsNullOrEmpty(d.Uid))
            {
                Uid = d.Uid;
            }

            Versions.Add(new DashboardVersion(d));

            DashboardAnalyzer.UpdateAlerts(dc, d, this);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        public static EntityDashboard   ToEntity(this ModelDashboard d, DataContext dc)
        {
            var e = new EntityDashboard()
            {
                Id       = d.Id,
                OrgId    = d.OrgId,
                Title    = d.Title,
                Uid      = d.Uid,
                Data     = d.Data,
                FolderId = d.FolderId
            };

            if (null != d.Tags)
            {
                e.Tags = d
                         .Tags
                         .Select(x => new DashboardTag()
                {
                    Term = x
                })
                         .ToList();
            }

            if (string.IsNullOrEmpty(e.Uid))
            {
                e.Uid = TestFactory.GetUid();
            }

            DashboardAnalyzer.UpdateAlerts(dc, d, e);

            return(e);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        public static void UpdateAlerts(DataContext dc,
                                        ModelDashboard model, EntityDashboard entity)
        {
            if (null == model.Data)
            {
                return;
            }

            var an    = new DashboardAnalyzer(dc, model);
            var rules = an.ExtractAlerts();

            var alerts = new List <Alert>();

            foreach (var r in rules)
            {
                var alert = entity
                            .Alerts?
                            .FirstOrDefault(x => x.PanelId == r.PanelId);

                if (null == alert)
                {
                    alert = r.ToEntity();
                }
                else
                {
                    alert.Update(r);
                }

                alert.OrgId = dc.ActiveOrgId;
                alerts.Add(alert);
            }

            entity.Alerts = alerts;
        }