public async Task <IActionResult> Create([Bind("Id,Description,Ip,ReloadDate")] Server server) { if (ModelState.IsValid) { _context.Add(server); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(server)); }
public async Task <IActionResult> Create([Bind("Id,ServerId,Text,ProcessingDate,Type,Priority,LoadLevel")] Message message) { if (ModelState.IsValid) { _context.Add(message); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewBag.Types = new SelectList(func.TypeList.AsEnumerable()); ViewData["ServerId"] = new SelectList(_context.Set <Server>(), "Id", "Id", message.ServerId); return(View(message)); }
public void XmlLoad(string filename) { XDocument xdoc = XDocument.Load(filename); ClearServers(_context.Server); foreach (XElement serverElem in xdoc.Element("root").Elements("server")) { XAttribute idAttr = serverElem.Attribute("id"); XElement descriptionElem = serverElem.Element("description"); XElement ipElem = serverElem.Element("ip"); XElement reloadDateElem = serverElem.Element("reload_date"); if (descriptionElem != null && ipElem != null && reloadDateElem != null) { Server server = new Server(); server.prevId = int.Parse(idAttr.Value); server.Description = descriptionElem.Value; server.Ip = ipElem.Value; if (reloadDateElem.Value != "") { server.ReloadDate = DateTime.Parse(reloadDateElem.Value); } _context.Add(server); } } _context.SaveChanges(); foreach (XElement messageElem in xdoc.Element("root").Elements("message")) { //XAttribute idAttr = messageElem.Attribute("id"); XElement serverIdElem = messageElem.Element("server_id"); XElement textElem = messageElem.Element("text"); XElement processingDateElem = messageElem.Element("processing_date"); XElement typeElem = messageElem.Element("type"); XElement priorityElem = messageElem.Element("priority"); XElement loadLevelElem = messageElem.Element("load_level"); if (serverIdElem != null && textElem != null && processingDateElem != null && typeElem != null && priorityElem != null && loadLevelElem != null) { Message message = new Message(); message.Server = _context.Server.First(s => s.prevId == int.Parse(serverIdElem.Value)); message.ServerId = message.Server.Id; message.Text = textElem.Value; if (processingDateElem.Value != "") { message.ProcessingDate = DateTime.Parse(processingDateElem.Value); } message.Type = typeElem.Value; message.Priority = int.Parse(priorityElem.Value); message.LoadLevel = float.Parse(loadLevelElem.Value); _context.Add(message); } } _context.SaveChanges(); }
public void Main() { func.XmlCreate("wwwroot/xml/temp.xml"); func.ClearServers(_context.Server); demoString += "Demo:\n\n"; int num = func.random.Next(3, 7); for (int i = 1; i <= num; i++) { _context.Add(func.GenerateRandomServer()); } demoString += num + " servers added;\n\n"; _context.SaveChanges(); num = func.random.Next(10, 20); for (int i = 0; i <= num; i++) { _context.Add(func.GenerateRandomMessage()); } demoString += num + " messages added;\n\n"; _context.SaveChanges(); PrintServers(_context.Server); PrintMessages(_context.Message); string searchNameM = func.RandomString(2); demoString += "\nSearch messages by name \"" + searchNameM + "\":\n"; PrintMessages(func.SearchMessages(searchNameM, null, null, null, ""), 1); int maxPr = func.random.Next(200); int minPr = func.random.Next(maxPr); demoString += "\nSearch messages by priority range: (from " + minPr + " to " + maxPr + "):\n"; PrintMessages(func.SearchMessages("", null, minPr, maxPr, ""), 1); DateTime dateTimeM = func.RandomDateTime(DateTime.Today); demoString += "\nSearch messages by date: (after " + dateTimeM + "):\n"; PrintMessages(func.SearchMessages("", dateTimeM, null, null, ""), 1); string searchNameS = func.RandomString(2); demoString += "\nSearch servers by name \"" + searchNameS + "\":\n"; PrintServers(func.SearchServers(searchNameS, null, null, null), 1); DateTime dateTimeS2 = func.RandomDateTime(DateTime.Today); DateTime dateTimeS1 = func.RandomDateTime(dateTimeS2); float minLoadLvl = (float)func.random.NextDouble(); demoString += "\nSearch servers by messages with date range (from " + dateTimeS1 + " to " + dateTimeS2 + ") and Load level higher than " + minLoadLvl + ":\n"; PrintServers(func.SearchServers("", dateTimeS1, dateTimeS2, minLoadLvl), 1); demoString += "\nDeleting servers found earlier by messages;\n"; func.ClearServers(func.SearchServers("", dateTimeS1, dateTimeS2, minLoadLvl)); demoString += "\nDeleting messages found earlier by date;\n\n"; func.ClearMessages(func.SearchMessages("", dateTimeM, null, null, "")); PrintServers(_context.Server); PrintMessages(_context.Message); demoString += "Saving data to .xml file;\n"; func.XmlCreate("wwwroot/xml/demo.xml"); demoString += "Saving data to .bin file;\n\n"; func.BinCreate("wwwroot/dat/demo.bin"); demoString += "Clearing all data, print:\n"; func.ClearServers(_context.Server); PrintServers(_context.Server); PrintMessages(_context.Message); demoString += '\n'; demoString += "Loading data from .xml file, print:\n"; func.XmlLoad("wwwroot/xml/demo.xml"); PrintServers(_context.Server); PrintMessages(_context.Message); demoString += "Clearing all data, print:\n"; func.ClearServers(_context.Server); PrintServers(_context.Server); PrintMessages(_context.Message); demoString += '\n'; demoString += "Loading data from .bin file, print:\n"; func.BinLoad("wwwroot/dat/demo.bin"); PrintServers(_context.Server); PrintMessages(_context.Message); demoString += "\nDemo finished;"; StreamWriter sw = new StreamWriter(@"wwwroot/demo/result.txt", false); sw.Write(demoString); sw.Close(); func.ClearServers(_context.Server); func.XmlLoad("wwwroot/xml/temp.xml"); }