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 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; } }