public async Task <IActionResult> PutEventGroups(Guid id, EventGroups eventGroups)
        {
            if (id != eventGroups.Id)
            {
                return(BadRequest());
            }

            _context.Entry(eventGroups).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventGroupsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,EventId,GroupId")] EventGroups eventGroups)
        {
            if (id != eventGroups.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eventGroups);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EventGroupsExists(eventGroups.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Id", eventGroups.EventId);
            ViewData["GroupId"] = new SelectList(_context.Groups, "Id", "Id", eventGroups.GroupId);
            return(View(eventGroups));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("Id,EventId,GroupId")] EventGroups eventGroups)
        {
            if (ModelState.IsValid)
            {
                eventGroups.Id = Guid.NewGuid();
                _context.Add(eventGroups);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EventId"] = new SelectList(_context.Events, "Id", "Id", eventGroups.EventId);
            ViewData["GroupId"] = new SelectList(_context.Groups, "Id", "Id", eventGroups.GroupId);
            return(View(eventGroups));
        }
        public void AddEventGroup(EventGroup eg)
        {
            var g = EventGroups.ToSyncArray().FirstOrDefault(x => x.Name == eg.Name);

            if (g != null)
            {
                foreach (var ev in eg.Events)
                {
                    g.AddEvent(ev);
                }
            }
            else
            {
                EventGroups.Add(eg);
            }
        }
        public async Task <ActionResult <EventGroups> > PostEventGroups(EventGroups eventGroups)
        {
            _context.EventGroups.Add(eventGroups);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (EventGroupsExists(eventGroups.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetEventGroups", new { id = eventGroups.Id }, eventGroups));
        }
Beispiel #6
0
        /// <summary>
        /// Загрузить конфигурацию из файла
        /// </summary>
        public bool Load(string fileName, out string errMsg)
        {
            SetToDefault();

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

                // загрузка параметров
                XmlNode paramsNode = xmlDoc.DocumentElement.SelectSingleNode("Params");

                if (paramsNode != null)
                {
                    foreach (XmlElement paramElem in paramsNode.ChildNodes)
                    {
                        string name = paramElem.GetAttribute("name").ToLowerInvariant();
                        string val  = paramElem.GetAttribute("value");

                        if (name == "serverpath")
                        {
                            ServerPath = val;
                        }
                        else if (name == "usecertificate")
                        {
                            UseCertificate = Convert.ToBoolean(val);
                        }
                        else if (name == "applicationname")
                        {
                            ApplicationName = val;
                        }
                    }
                }

                // загрузка групп чтения данных
                XmlNode dataGroupsNode = xmlDoc.DocumentElement.SelectSingleNode("DataGroups");

                if (dataGroupsNode != null)
                {
                    foreach (XmlElement dataGroupElem in dataGroupsNode.ChildNodes)
                    {
                        DataGroup dataGroup = new DataGroup();
                        dataGroup.Name   = dataGroupElem.GetAttribute("name");
                        dataGroup.Active = dataGroupElem.GetAttrAsBool("active");

                        XmlNodeList dataItemNodes = dataGroupElem.SelectNodes("DataItem");
                        foreach (XmlElement dataItemElem in dataItemNodes)
                        {
                            DataItem dataItem = new DataItem();
                            dataItem.Name   = dataItemElem.GetAttribute("name");
                            dataItem.Id     = dataItemElem.GetAttribute("id");
                            dataItem.Active = dataItemElem.GetAttrAsBool("active");
                            dataItem.Signal = dataItemElem.GetAttrAsInt("updateRate");
                            dataItem.Mode   = dataItemElem.GetAttribute("mode");
                            dataGroup.DataItems.Add(dataItem);
                        }

                        DataGroups.Add(dataGroup);
                    }
                }

                // загрузка групп приёма событий
                XmlNode eventGroupsNode = xmlDoc.DocumentElement.SelectSingleNode("EventGroups");

                if (eventGroupsNode != null)
                {
                    foreach (XmlElement eventGroupElem in eventGroupsNode.ChildNodes)
                    {
                        EventGroup eventGroup = new EventGroup();
                        eventGroup.Name            = eventGroupElem.GetAttribute("name");
                        eventGroup.UpdateRate      = eventGroupElem.GetAttrAsInt("updateRate");
                        eventGroup.MaxSize         = eventGroupElem.GetAttrAsInt("maxSize");
                        eventGroup.SimpleEvents    = eventGroupElem.GetAttrAsBool("simpleEvents");
                        eventGroup.TrackingEvents  = eventGroupElem.GetAttrAsBool("trackingEvents");
                        eventGroup.ConditionEvents = eventGroupElem.GetAttrAsBool("conditionEvents");
                        eventGroup.HighSeverity    = eventGroupElem.GetAttrAsInt("highSeverity");
                        eventGroup.LowSeverity     = eventGroupElem.GetAttrAsInt("lowSeverity");

                        XmlNodeList catNodes = eventGroupElem.SelectNodes("Category");
                        foreach (XmlElement catElem in catNodes)
                        {
                            eventGroup.Categories.Add(catElem.GetAttribute("name"), catElem.GetAttrAsInt("id"));
                        }

                        EventGroups.Add(eventGroup);
                    }
                }

                // загрузка команд
                XmlNode commandsNode = xmlDoc.DocumentElement.SelectSingleNode("Commands");

                if (commandsNode != null)
                {
                    foreach (XmlElement commandElem in commandsNode.ChildNodes)
                    {
                        Command command = new Command();
                        command.ItemName = commandElem.GetAttribute("itemName");
                        command.ItemPath = commandElem.GetAttribute("itemPath");
                        command.TypeName = commandElem.GetAttribute("typeName");
                        command.CmdNum   = commandElem.GetAttrAsInt("cmdNum");
                        Commands.Add(command);
                    }
                }

                errMsg = "";
                return(true);
            }
            catch (Exception ex)
            {
                errMsg = CommPhrases.LoadKpSettingsError + ":\r\n" + ex.Message;
                return(false);
            }
        }
 public void ClearEvents()
 {
     EventGroups.Clear();
     SpecialEvents.Clear();
 }