Ejemplo n.º 1
0
        public void End(EndSessionRequest request)
        {
            using (ApplicationDbContext context = new ApplicationDbContext())
            {
                string version = request.Version.ToString();
                //Session session = context.Sessions.Single(x => x.SessionId == request.SessionId);
                Session session = context.Sessions.Single(x => x.SessionId == request.SessionId);

                //check if the request is no longer valid
                if (session.Version != request.Version.ToString())
                {
                    _logger.InfoFormat("EndSessionRequest for Sessionid: {0} was ignored because Removed: {1} and Version: {2}",
                        request.SessionId, session.Removed, request.Version);
                    return;
                }

                _logger.InfoFormat("Deleting VMs for SessionId: {0} ({1} - {2})",
                        session.SessionId, session.StartDate, session.EndDate);

                Subscription subscription = context.Subscriptions
                    .Single(x => x.SubscriptionId == session.SubscriptionId);

                IVMManagement vmManagement = AzureFacadeFactory.VMManagement(subscription.AzureSubscriptionId,
                    subscription.Certificate, subscription.CertificateKey, subscription.BlobStorageName,
                    subscription.BlobStorageKey);

                //TODO: need to keep service name in the session
                string vmNameBase = "tn" + session.SessionId + "vm";
                vmManagement.DeleteService(vmNameBase);

                foreach (VirtualMachine vm in session.VirtualMachines.Where(x => !x.Deleted))
                {
                    vm.Deleted = true;
                }

                context.SaveChanges();

                _logger.InfoFormat("Deleted VMs for SessionId: {0} ({1} - {2})",
                    session.SessionId, session.StartDate, session.EndDate);
            }
        }
Ejemplo n.º 2
0
		private void Receive(EndSessionRequest request)
		{
			Sessions.End(request);
		}
Ejemplo n.º 3
0
		public void SendSession(DateTimeOffset start, DateTimeOffset end, int sessionId, Guid version)
		{
			//TODO: errors at this level should be treated as critical
            DateTime utcActualStart = start.Subtract(Settings.SessionWarmUp).UtcDateTime;
            _logger.InfoFormat("Sending StartSessionRequest with SessionId: {0} Version: {1} Start(UTC): {2}",
                version, sessionId, utcActualStart);
			StartSessionRequest startRequest = new StartSessionRequest { Version = version, SessionId = sessionId};
            Send(startRequest, utcActualStart);

            DateTime utcActualEnd = end.Add(Settings.SessionCoolDown).UtcDateTime;
            _logger.InfoFormat("Sending EndSessionRequest with SessionId: {0} Version: {1} End(UTC): {2}",
                version, sessionId, utcActualEnd);
			EndSessionRequest endRequest = new EndSessionRequest { Version = version, SessionId = sessionId };
            Send(endRequest, utcActualEnd);
		}