Beispiel #1
0
        public Environment Save(Environment environment)
        {
            _context.Add(environment);
            _context.SaveChanges();

            return(environment);
        }
Beispiel #2
0
        public User Save(User user)
        {
            _context.Add(user);
            _context.SaveChanges();

            return(user);
        }
Beispiel #3
0
        public Error Save(Error error)
        {
            _context.Add(error);
            _context.SaveChanges();

            return(error);
        }
Beispiel #4
0
        public Level Save(Level level)
        {
            _context.Add(level);
            _context.SaveChanges();

            return(level);
        }
        public ActionResult Create([Bind(Include = "TemperatureId,Time,Celcius,Location")] TemperatureModel temperatureModel)
        {
            if (ModelState.IsValid)
            {
                Temperature temperature = new Temperature()
                {
                    Celcius = temperatureModel.Celcius, Time = temperatureModel.Time, Location = temperatureModel.Location
                };

                db.Temperatures.Add(temperature);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(temperatureModel));
        }
Beispiel #6
0
 /// <summary>
 /// Saves the service to the database.
 /// </summary>
 /// <param name="service">The service object wanting to be saved.</param>
 private static void SaveService(Service service)
 {
     Log.Information("Creating new service for {applicationId}", service.ApplicationId);
     using (var context = new MonitorContext())
     {
         context.Services.Add(service);
         context.SaveChanges();
     }
 }
Beispiel #7
0
        public MonController(MonitorContext context)
        {
            _context = context;

            if (_context.MonitorItems.Count() == 0)
            {
                _context.MonitorItems.Add(new MonitorItem {
                    ClientID = "INIT ENTRY"
                });
                _context.SaveChanges();
            }
        }
 public JsonResult DeleteMonitorResult(int id)
 {
     try
     {
         var del = _dbContext.Monitor.Where(p => p.Id == id);
         _dbContext.RemoveRange(del);
         _dbContext.SaveChanges();
         return(new JsonResult(new Response("OK", 0)));
     }
     catch (Exception e)
     {
         return(new JsonResult(new Response(e.Message, 1)));
     }
 }
Beispiel #9
0
        public static async void ResultToDataBase(object sender, PingerEventArgs args)
        {
            lock (lockObject)
            {
                if (count % 100 == 0)
                {
                    if (MonitorContext != null)
                    {
                        MonitorContext.Dispose();
                    }
                    count++;
                    GC.Collect();
                    MonitorContext = UpkServices.ServiceProvider.GetService <MonitorContext>();
                    MonitorContext.ChangeTracker.AutoDetectChangesEnabled = false;
                    MonitorContext.ChangeTracker.QueryTrackingBehavior    = QueryTrackingBehavior.NoTracking;
                    MonitorContext.ChangeTracker.LazyLoadingEnabled       = false;
                }
            }
            await MonitorContext.Logs.AddRangeAsync(args.PingResults);

            MonitorContext.SaveChanges();
        }
Beispiel #10
0
        /// <summary>
        /// Checks for valid request, then records the new monitor item
        /// </summary>
        /// <param name="version"></param>
        /// <param name="monitorItem"></param>
        /// <returns></returns>
        private IActionResult RecordMonitorItem(string version, MonitorItem monitorItem)
        {
            if (version.ToUpper() == "V1")
            {
                if (monitorItem.IsValid())
                {
                    _context.MonitorItems.Add(monitorItem);
                    _context.SaveChanges();

                    // * write to console
                    Console.WriteLine(monitorItem.ToString());
                    return(new ObjectResult(monitorItem.ToString()));
                }
                else
                {
                    return(new ObjectResult(monitorItem.GetMsg()));
                }
            }
            else
            {
                return(new ObjectResult("ERROR - Version not supported"));
            }
        }
Beispiel #11
0
        public ResultObj SaveData(MonitorContext monitorContext)
        {
            _isSaving = true;
            while (_isPinging)
            {
                Console.WriteLine("Waiting for Ping to stop in MonitorPingService.Save");
                Thread.Sleep(1000);
            }
            ResultObj result = new ResultObj();

            result.Success = false;
            Console.WriteLine("Starting MonitorPingService.Save");
            try
            {
                int maxDataSetID = 0;
                try { maxDataSetID = monitorContext.MonitorPingInfos.Max(m => m.DataSetID); }
                catch { }

                maxDataSetID++;

                foreach (MonitorPingInfo monitorPingInfo in _monitorPingInfos)
                {
                    monitorPingInfo.ID        = 0;
                    monitorPingInfo.DataSetID = maxDataSetID;
                    monitorContext.Add(monitorPingInfo);
                }
                monitorContext.SaveChanges();

                foreach (MonitorPingInfo monitorPingInfo in _monitorPingInfos)
                {
                    foreach (PingInfo pingInfo in monitorPingInfo.pingInfos)
                    {
                        pingInfo.MonitorPingInfoID = monitorPingInfo.ID;
                    }
                }

                foreach (MonitorPingInfo monitorPingInfo in _monitorPingInfos)
                {
                    foreach (PingInfo pingInfo in monitorPingInfo.pingInfos)
                    {
                        pingInfo.ID = 0;
                        monitorContext.Add(pingInfo);
                    }
                }

                monitorContext.SaveChanges();


                _netStatsService.stop();
                List <NetStat> netStatsData = new List <NetStat>(_netStatsService.NetStatData);
                foreach (NetStat netStat in netStatsData)
                {
                    //netStat.ID = 0;
                    netStat.DataSetID = maxDataSetID;
                    monitorContext.Add(netStat);
                }

                monitorContext.SaveChanges();


                result.Message = "DB Update Success in MonitorPinService.SaveData.";
                result.Success = true;
            }
            catch (Exception e)
            {
                result.Message = "DB Update Failed in MonitorPinService.SaveData. Error was : " + e.Message;
            }
            finally
            {
                // Make sure the reset of the MonitorPingService Object is run just before the next schedule.
                init(false);
                _netStatsService.resetData();
                _isSaving = false;
                Console.WriteLine("Finished MonitorPingService.Save");
            }


            return(result);
        }