Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.2 kB
4
Indexable
Never
public List<ErrorModel> Get(int id)
		{
            List<NodeServer> nodes;

            using (var db = new CommonDatabaseManager("MySql"))
            {
                nodes = db.NodeServers.ToList();
            }

            using (var db = new StatusDatabaseManager("MySqlStatus"))
			{
				var query = from error in db.ServerErrors
				            where error.Time>=DateTime.UtcNow.AddHours(-id)
				            select new ErrorModel()
				            {
								ServerError = error,
					            ErrorType =error.ErrorType.ToString()
							};
				var res =new List<ErrorModel>();

				foreach (var errorModel in query)
				{
                    var existed = res.FirstOrDefault(t => t.ErrorType == errorModel.ErrorType && t.ServerError.Error == errorModel.ServerError.Error && t.ServerError.Account == errorModel.ServerError.Account);
                    
                    if (existed == null)
                    {
                        errorModel.NodeServer = nodes.FirstOrDefault(t => t.Id == errorModel.ServerError.NodeServer)??nodes.First();

						res.Add(errorModel);
					}
					else
						existed.ErrorsCount++;

				}

				return res;
			}
		}