public void Shutdown() { if (service != null) { lock (this) { LogUtil.Info("Daemon Process shutdown..."); CloudService cloudService = service; try { foreach (DaemonParticipant daemonParticipant in bubbleDaemons.Values) { daemonParticipant.Shutdown(); } cloudService.Shutdown(); } finally { // Removing process state info from database. if (localProcessStateEntity != null) { entityContext.DeleteObject(localProcessStateEntity); entityContext.SaveChanges(); } } service = null; LogUtil.Info("Daemon Process shutdown done."); } } }
public void TestParticipantDatabase() { using (DaemonEntities daemonEntities = new DaemonEntities("metadata=res://*/Daemon.csdl|res://*/Daemon.ssdl|res://*/Daemon.msl;provider=System.Data.SqlClient;provider connection string=';Data Source=.\\SQLEXPRESS;AttachDbFilename=" + Directory.GetParent(this.GetType().Assembly.Location).Parent.Parent.Parent.FullName + "\\CloudDaemonWeb\\App_Data\\CloudDaemonWeb.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True'")) { Guid participantId = Guid.NewGuid(); string openIdUrl = "http://testid.openid.com/"; Participant newParticipant = new Participant { ParticipantId = participantId, OpenIdUrl = openIdUrl }; daemonEntities.AddToParticipant(newParticipant); daemonEntities.SaveChanges(); IQueryable <Participant> participantQuery = from p in daemonEntities.Participant where p.ParticipantId == participantId select p; Assert.AreEqual(1, participantQuery.Count <Participant>()); IEnumerator <Participant> enumerator = participantQuery.GetEnumerator(); enumerator.MoveNext(); Participant loadedParticipant = enumerator.Current; enumerator.Dispose(); Assert.AreEqual(participantId, loadedParticipant.ParticipantId); Assert.AreEqual(openIdUrl, loadedParticipant.OpenIdUrl); daemonEntities.DeleteObject(loadedParticipant); daemonEntities.SaveChanges(); Assert.AreEqual(0, (from p in daemonEntities.Participant where p.ParticipantId == participantId select p).Count <Participant>()); } }
private void timer_Tick(object state) { try { DaemonEntities entityContext = new DaemonEntities(); List <LocalProcess> localProcessEntities = ( from lp in entityContext.LocalProcess select lp).ToList <LocalProcess>(); foreach (LocalProcess localProcessEntity in localProcessEntities) { LocalProcessState localProcessState = QueryUtil.First <LocalProcessState>( from lps in entityContext.LocalProcessState where lps.LocalProcess.LocalProcessId == localProcessEntity.LocalProcessId select lps); if (localProcessEntity.Enabled) { if (localProcessState == null) { Process process = Process.Start(Directory.GetParent(this.GetType().Assembly.Location).FullName + "\\DaemonProcess.exe", localProcessEntity.LocalProcessId.ToString() + " --db-log"); } } if (localProcessState != null) { if (DateTime.Now - localProcessState.Modified > new TimeSpan(0, 0, 60)) { entityContext.DeleteObject(localProcessState); entityContext.SaveChanges(); } } } } catch (Exception e) { Trace.TraceError("Error in process guard loop: " + e.ToString() + " : " + e.StackTrace); Thread.Sleep(1000); } }
public void OnInteractRequest(InteractRequestMessage interactRequest) { if (interactRequest.InteractionFragment.InteractionName == "TypeList") { InteractResponseMessage interactionResponse = (InteractResponseMessage)MessageFactory.Current.ReserveMessage(typeof(InteractResponseMessage)); interactionResponse.RequestMessageId = interactRequest.MessageId; interactionResponse.FailureCode = MxpResponseCodes.SUCCESS; interactionResponse.InteractionFragment.InteractionName = "TypeList"; interactionResponse.InteractionFragment.TargetParticipantId = interactRequest.InteractionFragment.SourceParticipantId; interactionResponse.InteractionFragment.SourceParticipantId = interactRequest.InteractionFragment.TargetParticipantId; OmTypeListResponseExt responseExt = new OmTypeListResponseExt(); List <DaemonLogic.ObjectType> objectTypes = (from t in entityContext.ObjectType orderby t.Name select t).ToList <DaemonLogic.ObjectType>(); foreach (DaemonLogic.ObjectType objectType in objectTypes) { OmObjectType omObjectType = new OmObjectType(); omObjectType.TypeId = objectType.ObjectTypeId.ToString(); omObjectType.TypeName = objectType.Name; responseExt.ObjectType.Add(omObjectType); } interactionResponse.SetExtension <OmTypeListResponseExt>(responseExt); client.SendInteractResponse(interactionResponse); } if (interactRequest.InteractionFragment.InteractionName == "ObjectInsert") { OmInsertRequestExt requestExt = interactRequest.GetExtension <OmInsertRequestExt>(); Guid typeId = new Guid(requestExt.TypeId); ObjectType objectType = QueryUtil.First <DaemonLogic.ObjectType>(from t in entityContext.ObjectType where t.ObjectTypeId == typeId select t); entityContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, objectType); Participant participant = QueryUtil.First <DaemonLogic.Participant>(from p in entityContext.Participant where p.ParticipantId == interactRequest.InteractionFragment.SourceParticipantId select p); DaemonLogic.CloudObject cloudObject = new DaemonLogic.CloudObject { CloudObjectId = Guid.NewGuid(), Participant = participant, ObjectType = objectType, Bubble = bubble, Name = "New " + objectType.Name, Radius = objectType.Radius, Mass = objectType.Mass, ModelUrl = objectType.ModelUrl, ModelScale = objectType.ModelScale, X = requestExt.Location.X, Y = requestExt.Location.Y, Z = requestExt.Location.Z, OX = requestExt.Orientation.X, OY = requestExt.Orientation.Y, OZ = requestExt.Orientation.Z, OW = requestExt.Orientation.W, Created = DateTime.Now, Modified = DateTime.Now, Enabled = true }; entityContext.AddToCloudObject(cloudObject); entityContext.SaveChanges(); InjectOrUpdateObject(cloudObject); InteractResponseMessage interactionResponse = (InteractResponseMessage)MessageFactory.Current.ReserveMessage(typeof(InteractResponseMessage)); interactionResponse.RequestMessageId = interactRequest.MessageId; interactionResponse.FailureCode = MxpResponseCodes.SUCCESS; interactionResponse.InteractionFragment.InteractionName = "ObjectInsert"; interactionResponse.InteractionFragment.TargetParticipantId = interactRequest.InteractionFragment.SourceParticipantId; interactionResponse.InteractionFragment.SourceParticipantId = interactRequest.InteractionFragment.TargetParticipantId; OmInsertResponseExt responseExt = new OmInsertResponseExt(); responseExt.ObjectId = cloudObject.CloudObjectId.ToString(); interactionResponse.SetExtension <OmInsertResponseExt>(responseExt); client.SendInteractResponse(interactionResponse); } if (interactRequest.InteractionFragment.InteractionName == "ObjectUpdate") { OmUpdateRequestExt requestExt = interactRequest.GetExtension <OmUpdateRequestExt>(); Guid objectId = new Guid(requestExt.ObjectId); byte failureCode = MxpResponseCodes.SUCCESS; if (IdObjectDictionary.ContainsKey(objectId)) { DaemonLogic.CloudObject cloudObject = IdObjectDictionary[objectId]; if (cloudObject.Participant.ParticipantId != interactRequest.InteractionFragment.SourceParticipantId && bubble.Participant.ParticipantId != interactRequest.InteractionFragment.SourceParticipantId) { failureCode = MxpResponseCodes.UNAUTHORIZED_OPERATION; } else { cloudObject.Name = requestExt.Name; cloudObject.Radius = requestExt.Scale; cloudObject.X = requestExt.Location.X; cloudObject.Y = requestExt.Location.Y; cloudObject.Z = requestExt.Location.Z; cloudObject.OX = requestExt.Orientation.X; cloudObject.OY = requestExt.Orientation.Y; cloudObject.OZ = requestExt.Orientation.Z; cloudObject.OW = requestExt.Orientation.W; cloudObject.Modified = DateTime.Now; entityContext.SaveChanges(); InjectOrUpdateObject(cloudObject); } } else { failureCode = MxpResponseCodes.UNKNOWN_ID; } InteractResponseMessage interactionResponse = (InteractResponseMessage)MessageFactory.Current.ReserveMessage(typeof(InteractResponseMessage)); interactionResponse.RequestMessageId = interactRequest.MessageId; interactionResponse.FailureCode = failureCode; interactionResponse.InteractionFragment.InteractionName = "ObjectUpdate"; interactionResponse.InteractionFragment.TargetParticipantId = interactRequest.InteractionFragment.SourceParticipantId; interactionResponse.InteractionFragment.SourceParticipantId = interactRequest.InteractionFragment.TargetParticipantId; client.SendInteractResponse(interactionResponse); } if (interactRequest.InteractionFragment.InteractionName == "ObjectDelete") { OmDeleteRequestExt requestExt = interactRequest.GetExtension <OmDeleteRequestExt>(); Guid objectId = new Guid(requestExt.ObjectId); byte failureCode = MxpResponseCodes.SUCCESS; if (this.IdObjectDictionary.ContainsKey(objectId)) { DaemonLogic.CloudObject cloudObject = IdObjectDictionary[objectId]; if (cloudObject.Participant.ParticipantId != interactRequest.InteractionFragment.SourceParticipantId && bubble.Participant.ParticipantId != interactRequest.InteractionFragment.SourceParticipantId) { failureCode = MxpResponseCodes.UNAUTHORIZED_OPERATION; } else { entityContext.DeleteObject(cloudObject); entityContext.SaveChanges(); EjectObject(cloudObject); } } else { failureCode = MxpResponseCodes.UNKNOWN_ID; } InteractResponseMessage interactionResponse = (InteractResponseMessage)MessageFactory.Current.ReserveMessage(typeof(InteractResponseMessage)); interactionResponse.RequestMessageId = interactRequest.MessageId; interactionResponse.FailureCode = failureCode; interactionResponse.InteractionFragment.InteractionName = "ObjectDelete"; interactionResponse.InteractionFragment.TargetParticipantId = interactRequest.InteractionFragment.SourceParticipantId; interactionResponse.InteractionFragment.SourceParticipantId = interactRequest.InteractionFragment.TargetParticipantId; client.SendInteractResponse(interactionResponse); } }