void OnCompleteProgress(Request_CompleteProgress e) { var req = _request.Get(e.Id); switch (e.CompletedStatus) { case RequestStatus.Awaiting: { var origin = req.IsMainRequest ? null : _request.GetMainRequestForUser(req.Owner).Target; var target = _server.GetServerForRequest(req); if (target != null) { req.ToIncoming(origin, target, _rules.GetNetworkTime(target)); return; } _user.OnRequestFailed(req.Owner); req.ToFinished(); } break; case RequestStatus.Incoming: { if (_break.IsServerBreaked(req.Target.Id)) { return; } _server.ReleaseResource(req.Target, req.Target.Network, req.WantedNetwork); } break; case RequestStatus.Processing: { if (req.IsMainRequest) { // Wait for any other related requests var reqs = _request.GetRequestsForUser(req.Owner); foreach (var r in reqs) { if (r != req) { return; } } } req.ToOutgoing(_rules.GetNetworkTime(req.Target)); } break; case RequestStatus.Outgoing: { req.ToFinished(); } break; } }
void OnRequestNewStatus(Request_NewStatus e) { if (e.IsMainRequest && (e.NewStatus == RequestStatus.Finished)) { var req = _request.Get(e.Id); var user = req.Owner; var client = user.Client; var change = _rules.CalculateClientMoodChange(user.Mood); _logger.MessageFormat("Update client {0} mood to: {1} (from user mood: {2})", client, change, user.Mood); _client.UpdateMood(client, change); var newMood = _client.Get(client)?.Mood; _logger.MessageFormat("New client {0} mood is {1}", client, newMood); if (newMood <= 0) { _client.RemoveClient(client); } } }
void OnCompleteProgress(Request_CompleteProgress e) { var req = _request.Get(e.Id); var target = req.Target; switch (e.CompletedStatus) { case RequestStatus.Incoming: { if ( _server.TryLockResource(target, target.Network, req.WantedNetwork) && _server.TryLockResource(target, target.CPU, req.WantedCPU) && _server.TryLockResource(target, target.RAM, req.WantedRAM) ) { if (req.IsMainRequest) { _request.AddRelatedRequests(req); } req.ToProcessing(_rules.GetProcessTime(req.Target)); return; } _user.OnRequestFailed(req.Owner); req.ToOutgoing(_rules.GetNetworkTime(req.Target)); } break; case RequestStatus.Processing: { if (_break.IsServerBreaked(target.Id)) { return; } _server.ReleaseResource(target, target.CPU, req.WantedCPU); _server.ReleaseResource(target, target.RAM, req.WantedRAM); } break; } }