Ejemplo n.º 1
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            timer.Stop();

            var browser = filterContext.HttpContext.Request.Browser;

            using (var monitorDb = new MonitorDbContext())
            {
                var diagnostic = new Diagnostic
                {
                    DiagnosticID     = Guid.NewGuid(),
                    ApplicationName  = "QA Forum",
                    WebServer        = HttpContext.Current.Request.ServerVariables["SERVER_NAME"],
                    Browser          = browser.Browser + "-" + browser.Version,
                    TargetController = filterContext.RouteData.Values["controller"].ToString(),
                    TargetAction     = filterContext.RouteData.Values["action"].ToString(),
                    DiagnosticTime   = DateTime.Now,
                    ExecutionTime    = timer.ElapsedMilliseconds
                };

                monitorDb.Diagnostics.Add(diagnostic);
                monitorDb.SaveChanges();
            }

            base.OnActionExecuted(filterContext);
        }
Ejemplo n.º 2
0
        // id 参数名应该与控件上设置的 DataKeyNames 值匹配
        public void lvDepartmentMonitor_UpdateItem(Int64 id)
        {
            TextBox txtEditValue = new TextBox();

            txtEditValue = (TextBox)lvDepartmentMonitor.EditItem.FindControl("txtValue");
            var value = txtEditValue?.Text;

            if (String.IsNullOrEmpty(value))
            {
                return;
            }
            using (MonitorDbContext context = new MonitorDbContext())
            {
                IMS.Models.DepartmentMonitor item = null;
                // 在此加载该项,例如 item = MyDataLayer.Find(id);
                item = context.DepartmentMonitors.Find(id);
                if (item == null)
                {
                    // 未找到该项
                    ModelState.AddModelError("", String.Format("未找到 id 为 {0} 的项", id));
                    return;
                }
                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    // 在此保存更改,例如 MyDataLayer.SaveChanges();
                    item.Value = value;
                    //database win
                    bool saveFailed;
                    do
                    {
                        saveFailed = false;
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException ex)
                        {
                            saveFailed = true;
                            // Update the values of the entity that failed to save from the store
                            ex.Entries.Single().Reload();
                        }
                    } while (saveFailed);
                }
            }
        }
        public static void UpdateServersList(this MonitorDbContext dbContext,
                                             IEnumerable <SecurityServerData> serversList)
        {
            using (var transaction = dbContext.Database.BeginTransaction())
            {
                var localCache = dbContext.Servers.ToList();
                var forRemove  = localCache.Where(server => !serversList.Any(server.SameAs)).ToList();
                dbContext.Servers.RemoveRange(forRemove);

                var forAdd = serversList.Where(incomingServer => !localCache.Any(incomingServer.SameAs))
                             .ToList().ConvertAll(it => it.AsEntity());

                dbContext.Servers.AddRange(forAdd);
                dbContext.SaveChanges();
                transaction.Commit();
            }
        }
Ejemplo n.º 4
0
        // id 参数名应该与控件上设置的 DataKeyNames 值匹配
        public void lvDepartmentMonitor_DeleteItem(Int64 id)
        {
            using (MonitorDbContext context = new MonitorDbContext())
            {
                IMS.Models.DepartmentMonitor item = null;
                item = context.DepartmentMonitors.Find(id);
                if (item == null)
                {
                    // 未找到该项
                    ModelState.AddModelError("", String.Format("未找到 id 为 {0} 的项", id));
                    return;
                }

                TryUpdateModel(item);
                if (ModelState.IsValid)
                {
                    // 在此保存更改,例如 MyDataLayer.SaveChanges();
                    context.DepartmentMonitors.Remove(item);
                    //database win
                    bool saveFailed;
                    do
                    {
                        saveFailed = false;
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException ex)
                        {
                            saveFailed = true;
                            // Update the values of the entity that failed to save from the store
                            ex.Entries.Single().Reload();
                        }
                    } while (saveFailed);
                }
            }
        }
        public void Initialize()
        {
            _ctx.Database.EnsureCreated();

            // Look for any existing data.
            if (_ctx.Servers.Any())
            {
                return;   // DB has been seeded
            }

            var testDataServers = Extensions.GetTestData("Servers.txt")
                                  .GetLines()
                                  .Select(s => new
            {
                Id     = s.GetTabIndexInt(0),
                Server = new ServerDataModel()
                {
                    //                    Id = s.GetTabIndexInt(0),
                    Identifier = s.GetTabIndexGuid(1),
                    Name       = s.GetTabIndexString(2),
                    Domain     = s.GetTabIndexString(3),
                    UpdatedUtc = s.GetTabIndexDate(4)
                },
            }).ToList();

            var testServersById = testDataServers.ToDictionary(k => k.Id, v => v.Server);

            _ctx.Servers.AddRange(testDataServers.Select(s => s.Server));

            _ctx.SaveChanges();

            _ctx.ServerData.AddRange(Extensions.GetTestData("ServerData.txt")
                                     .GetLines()
                                     .Select(s => new ServerDataDataModel()
            {
                //Id = s.GetTabIndexInt(0),
                Identifier = s.GetTabIndexGuid(1),
                //Server = _ctx.Servers.Single(ss => ss.Id == s.GetTabIndexInt(2)),
                DataKey = s.GetTabIndexString(3),
                Data    = s.GetTabIndexString(4),
                Server  = testServersById[s.GetTabIndexInt(2)],
            })
                                     .ToList());

            _ctx.ServerDataAgregates.AddRange(Extensions.GetTestData("ServerDataAgregate.txt")
                                              .GetLines()
                                              .Select(s => new ServerDataAgregateDataModel()
            {
                //Id = s.GetTabIndexInt(0),
                Identifier = s.GetTabIndexGuid(1),
                //Server = _ctx.Servers.Single(ss => ss.Id == s.GetTabIndexInt(2)),
                DataKey = s.GetTabIndexString(3),
                Data    = s.GetTabIndexString(4),
                Server  = testServersById[s.GetTabIndexInt(2)],
            })
                                              .ToList());

            _ctx.Settings.AddRange(Extensions.GetTestData("Settings.txt")
                                   .GetLines()
                                   .Select(s => new SettingsDataModel()
            {
                //Id = s.GetTabIndexInt(0),
                Identifier = s.GetTabIndexGuid(1),
                DataKey    = s.GetTabIndexString(2),
                Data       = s.GetTabIndexString(3),
            })
                                   .ToList());

            _ctx.SaveChanges();
        }