public async Task <List <EventDto> > GetEvents()
        {
            var events = await _eventsRepository.GetEvents();

            var eventDtos = events.Select(e => _mapper.Map <Event, EventDto>(e)).OrderBy(x => x.Start).ToList();

            return(eventDtos);
        }
示例#2
0
        public IActionResult View(string id, string name)
        {
            // TODO: I thought MVC did this automatically...
            // Remove any extra percent coding
            var unescapedRuleName = Uri.UnescapeDataString(name);


            var device = repo.GetDevice(id);

            if (device == null)
            {
                throw new ArgumentOutOfRangeException();
            }

            var rules        = HttpContext.Session.GetJson <List <Agent.Generic.Models.Rule> >("rules");
            var selectedRule = rules.FirstOrDefault(r => r.Name == unescapedRuleName);

            // TODO: Add to UI
            if (selectedRule.Direction == Agent.Generic.Models.Direction.Out)
            {
                ushort?tmp = selectedRule.LocalPort;
                selectedRule.LocalPort  = selectedRule.RemotePort;
                selectedRule.RemotePort = tmp;
            }

            ICollection <PacketDroppedEvent> events = null;

            if (selectedRule.FilterID != null)
            {
                events = eventsRepo.GetEvents(device.Id, selectedRule.FilterID);
                ViewData["MostTriggeredBy"] = eventsRepo.RuleMostTriggeredBy(device.Id, selectedRule.FilterID) ?? "Untriggered";

                var data        = eventsRepo.GetEventsForTheLast24Hours(device.Id, selectedRule.FilterID);
                var last24Hours = GoogleChartHelpers.To24HourArray(data);
                ViewData["Last24Hours"] = GoogleChartHelpers.ToGoogleChartString(last24Hours, "Hour", "Count");
            }
            else
            {
                events = eventsRepo.GetEvents(device.Id, selectedRule.RemoteAddress, Convert.ToInt32(selectedRule.LocalPort));
                ViewData["MostTriggeredBy"] = eventsRepo.RuleMostTriggeredBy(device.Id, selectedRule.RemoteAddress, Convert.ToInt32(selectedRule.LocalPort))
                                              ?? "Untriggered";

                var data        = eventsRepo.GetEventsForTheLast24Hours(device.Id, selectedRule.RemoteAddress, Convert.ToInt32(selectedRule.LocalPort));
                var last24Hours = GoogleChartHelpers.To24HourArray(data);
                ViewData["Last24Hours"] = GoogleChartHelpers.ToGoogleChartString(last24Hours, "Hour", "Count");
            }

            ViewData["TimesFired"] = events.Count;
            ViewData["LastFired"]  = events.FirstOrDefault()?.Time.ToString() ?? "Never";

            return(View(selectedRule));
        }
示例#3
0
        public async new Task <IActionResult> View(string id)
        {
            Device device = deviceRepo.GetDevice(id);
            var    events = eventsRepo.GetEvents(device.Id, 5);

            ViewVM viewModel = new ViewVM();

            viewModel.Device = device;
            viewModel.Events = events;

            AgentApiClient client = new AgentApiClient();

            try
            {
                var response = await client.GetConfiguration(device.Address);

                var hoursWithActivity = eventsRepo.GetEventsForTheLast24Hours(device.Id);
                var last24Hours       = GoogleChartHelpers.To24HourArray(hoursWithActivity);
                ViewData["Last24Hours"] = GoogleChartHelpers.ToGoogleChartString(last24Hours, "Hour", "Count");

                viewModel.Online          = true;
                viewModel.FirewallEnabled = response.FirewallEnabled;
            }
            catch (System.Net.Http.HttpRequestException)
            {
                viewModel.Online = false;
            }

            return(View(viewModel));
        }
        public EventsResponse GetEvents(EventSearchRequest searchRequest)
        {
            var validator = new EventSearchVallidator().Validate(searchRequest).ToResponse();

            if (!validator.Result)
            {
                return new EventsResponse {
                           Result = false, Errors = validator.Errors
                }
            }
            ;

            var response = new EventsResponse();

            try
            {
                response = _eventsRepository.GetEvents(searchRequest);
            }
            catch (Exception ex)
            {
                _logger.Error(ExceptionMessages.GetEventsException, ex);
                response.Result = false;
                response.Errors.Add(new ResponseError {
                    Name = "GetEventsException", Error = ExceptionMessages.GetEventsException
                });
                return(response);
            }

            return(response);
        }
示例#5
0
        public IEnumerable <Event> GetEvents(List <int> serverIds, string baseUrl, string searchKey, DateTime startDate, DateTime endDate, bool cutEvents = true)
        {
            List <Event> allEvents = new List <Event>();
            //Get Cache duration
            int cacheDuration = _options.Value.CacheEventsDurationInSeconds;
            Uri u             = new Uri(baseUrl);

            foreach (int serverId in serverIds)
            {
                //Set CacheKey
                string cacheKey = $"{_options.Value.CacheEventsKey}_{u.Host}_{serverId}_{startDate.ToString("yyyyMMdd")}";
                IEnumerable <Event> events;
                if (!_cacheProvider.TryGetValue <IEnumerable <Event> >(cacheKey, out events))
                {
                    //Get Events From Repo
                    events = _eventsRepository.GetEvents(serverId, baseUrl, startDate, endDate, cutEvents);
                    if (events != null)
                    {//Set Cache
                        _cacheProvider.Add(cacheKey, events, cacheDuration);
                    }
                    else
                    {
                        events = new List <Event>();
                    }
                }
                //Add to news collection
                allEvents.AddRange(searchKey == "" ? events : events.Where(e => e.Name.Contains(searchKey)));
            }

            return(allEvents.OrderBy(x => x.StartTime));
        }
示例#6
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                log.Info("C# HTTP trigger function processed a request.");

                // parse query parameter
                string eventId = req.GetQueryNameValuePairs()
                                 .FirstOrDefault(q => string.Compare(q.Key, "eventId", true) == 0)
                                 .Value;

                IEventsRepository eventsRepository = RepositoryFactory.GetEventsRepository();

                if (!string.IsNullOrEmpty(eventId))
                {
                    // Get of a specific event
                    var guid   = Guid.Parse(eventId);
                    var @event = eventsRepository.GetEvent(guid);
                    return(@event != null?req.CreateResponse(HttpStatusCode.Found, @event) : req.CreateErrorResponse(HttpStatusCode.NotFound, "Event not found"));
                }


                // Get request body
                dynamic data = await req.Content.ReadAsAsync <object>();

                List <IEvent> events = eventsRepository.GetEvents((string)data?.category, (IAddress)data?.location, (DateTime?)data?.fromDate, (DateTime?)data?.toDate);

                return(req.CreateResponse(HttpStatusCode.OK, events));
            }
            catch (Exception ex)
            {
                log.Error("Error", ex, "GetEvents.cs");
                return(req.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public async Task <int> GetSpentHours(string color)
        {
            int hours  = 0;
            var events = await _eventsRepository.GetEvents();

            var groupedEvents = events.Where(x => x.Color == color).ToList();

            foreach (var groupEvent in groupedEvents)
            {
                if (groupEvent.Start.HasValue)
                {
                    var start      = groupEvent.Start.Value.Hour;
                    var end        = groupEvent.End.Value.Hour;
                    var hoursToAdd = end - start;
                    hours += hoursToAdd;
                }
            }
            return(hours);
        }
示例#8
0
        public IActionResult Index()
        {
            var events    = eventRepo.GetEvents(10);
            var ports     = eventRepo.GetViolationsByPortNumber();
            var addresses = eventRepo.GetRemoteIpAddresses();

            ViewData["TopPorts"]     = GoogleChartHelpers.ToGoogleChartString(ports, "Port No", "Count");
            ViewData["TopAddresses"] = addresses;

            return(View(events));
        }
        public JsonResult UpdatePopUp(int id, bool state)
        {
            var allEvents = eventsRepository.GetEvents();

            foreach (var item in allEvents)
            {
                item.PopupState = false;
                eventsRepository.UpdateEvent(item);
            }

            var ev = eventsRepository.GetEvent(id);

            if (ev != null)
            {
                ev.PopupState = state;
                eventsRepository.UpdateEvent(ev);
                return(Json(1));
            }
            else
            {
                return(Json(-1));
            }
        }
示例#10
0
        public void Test_Events_Reposity_Get_Separated_Events()
        {
            var news = GetSampleEvents(10, "Repo", true).AsEnumerable();

            mockHttpClientProvider = new Mock <IHttpClientProvider>();
            mockHttpClientProvider.Setup(p => p.SoapPostData <Event>("http://test.url/" + "common/controls/workspacecalendar/ws/workspacecalendarws.asmx/geteventsbyserverid",
                                                                     It.IsAny <object>(), "PresenceApi")).Returns(news);

            _eventsRepository = new APIEventsRepository(mockHttpClientProvider.Object);

            var events = _eventsRepository.GetEvents(1234, "http://test.url/", DateTime.Today, DateTime.Today.AddMonths(12));

            Assert.NotEmpty(events);
            Assert.Equal(16, events.Count());
        }
示例#11
0
        public IActionResult Index(string id)
        {
            var device = deviceRepo.GetDevice(id);

            if (device == null)
            {
                throw new ArgumentException();
            }

            var events = eventRepo.GetEvents(id);

            return(View(new ViewModels.Events.IndexVM()
            {
                Device = device,
                Events = events
            }));
        }
示例#12
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                await _dateTimeService.WaitToTomorrow(stoppingToken);

                var userStates = await _userStateRepository.GetSubscribedUsers(stoppingToken);

                var eventInfos = await _eventsRepository.GetEvents(DateTime.UtcNow.DayOfWeek, stoppingToken);

                if (eventInfos.Count == 0)
                {
                    return;
                }

                var notifies = GetNotifies(userStates, eventInfos);
                await SendNotifies(stoppingToken, notifies);
            }
        }
        public async Task <IEnumerable <EventDto> > GetEvents()
        {
            var eventResult = await _eventsRepository.GetEvents();

            return(eventResult.Select(x => new EventDto(x)));
        }
示例#14
0
 public IEnumerable <Event> Get()
 {
     return(_repository.GetEvents());
 }
示例#15
0
 private Task <List <EventInfo> > GetEventInfos(EventsCommand command)
 {
     return(command.OneDay ? _repository.GetEvents(command.DayOfWeek) : _repository.GetAllEvents());
 }
 public IEnumerable <EventModel> GetEvents()
 {
     return(_eventsRepository.GetEvents().Result);
 }
 public IActionResult Index()
 {
     return(View(eventsRepository.GetEvents().ToList()));
 }
 public async Task <IReadOnlyCollection <EventItem> > GetEvents(CancellationToken cancellationToken)
 {
     return(await _eventsRepository.GetEvents(_userId, cancellationToken));
 }
示例#19
0
        /// <summary>
        /// Creates the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public AggregateRoot <TEntity, TId> GetById(TId id)
        {
            var entityEventSource = _repository.GetEvents(id);

            return(entityEventSource != null?CreateAggregateRoot(id, entityEventSource) : null);
        }