public static RemoteProcess AddRemoteProcess(Participant participant, LocalProcess locaProcess) { using (DaemonEntities entities = new DaemonEntities()) { try { entities.Attach(locaProcess); entities.Attach(participant); RemoteProcess remoteProcess = new RemoteProcess { RemoteProcessId = Guid.NewGuid(), LocalProcess = locaProcess, Participant = participant, Address = "127.0.0.1", HubPort = MxpConstants.DefaultHubPort, Trusted = false }; entities.AddToRemoteProcess(remoteProcess); entities.SaveChanges(); entities.Detach(remoteProcess); return(remoteProcess); } finally { entities.Detach(locaProcess); entities.Detach(participant); } } }
public static Bubble AddBuble(Participant participant, LocalProcess localProcess) { using (DaemonEntities entities = new DaemonEntities()) { try { entities.Attach(participant); entities.Attach(localProcess); Bubble bubble = new Bubble { BubbleId = Guid.NewGuid(), Participant = participant, LocalProcess = localProcess, Name = "New Bubble", Range = 100, PerceptionRange = 150, Published = false }; entities.AddToBubble(bubble); entities.SaveChanges(); entities.Detach(bubble); return(bubble); } finally { entities.Detach(participant); entities.Detach(localProcess); } } }
public static ObjectType AddObjectType(Participant participant) { using (DaemonEntities entities = new DaemonEntities()) { try { entities.Attach(participant); ObjectType objectType = new ObjectType { ObjectTypeId = Guid.NewGuid(), Participant = participant, Name = "New Object Type", Radius = 11, Mass = 10, ModelUrl = "http://", ModelScale = 10, Published = false }; entities.AddToObjectType(objectType); entities.SaveChanges(); entities.Detach(objectType); return(objectType); } finally { entities.Detach(participant); } } }
public static LocalProcess GetLocalProcess(Guid localProcessId) { using (DaemonEntities entities = new DaemonEntities()) { LocalProcess localProcess = QueryUtil.First <LocalProcess>((from p in entities.LocalProcess where p.LocalProcessId == localProcessId select p)); entities.Detach(localProcess); return(localProcess); } }
public static ObjectType GetObjectType(Guid objectTypeId) { using (DaemonEntities entities = new DaemonEntities()) { ObjectType objectType = QueryUtil.First <ObjectType>((from o in entities.ObjectType where o.ObjectTypeId == objectTypeId select o)); entities.Detach(objectType); return(objectType); } }
public static Participant GetParticipant(Guid participantId) { using (DaemonEntities entities = new DaemonEntities()) { Participant participant = QueryUtil.First <Participant>(from p in entities.Participant where p.ParticipantId == participantId select p); entities.Detach(participant); return(participant); } }
public static Bubble GetBubble(Guid bubbleId) { using (DaemonEntities entities = new DaemonEntities()) { Bubble bubble = QueryUtil.First <Bubble>((from b in entities.Bubble where b.BubbleId == bubbleId select b)); entities.Detach(bubble); return(bubble); } }
public static CloudObject AddObject(Participant participant, ObjectType objectType, Bubble bubble) { using (DaemonEntities entities = new DaemonEntities()) { try { entities.Attach(participant); entities.Attach(objectType); entities.Attach(bubble); CloudObject cloudObject = new 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 = 0, Y = 0, Z = 0, OX = 0, OY = 0, OZ = 0, OW = 0, Created = DateTime.Now, Modified = DateTime.Now, Enabled = false }; entities.AddToCloudObject(cloudObject); entities.SaveChanges(); entities.Detach(cloudObject); return(cloudObject); } finally { entities.Detach(participant); entities.Detach(objectType); entities.Detach(bubble); } } }
public static void ClearLoginSecret(Participant participant) { using (DaemonEntities entities = new DaemonEntities()) { entities.Attach(participant); participant.LoginSecret = null; participant.LoginSecretExpires = null; entities.SaveChanges(); entities.Detach(participant); } }
public static void GetLoginSecret(Participant participant) { using (DaemonEntities entities = new DaemonEntities()) { entities.Attach(participant); participant.LoginSecret = Guid.NewGuid().ToString("N"); participant.LoginSecretExpires = DateTime.Now.Add(new TimeSpan(0, 0, 0, 10)); entities.SaveChanges(); entities.Detach(participant); } }
public static LocalProcess ReserveLocalProcess(Participant participant, string address) { using (DaemonEntities entities = new DaemonEntities()) { entities.Attach(participant); try { int serverPort = MxpConstants.DefaultServerPort; if ((from l in entities.LocalProcess select l).Count() > 0) { serverPort = (from l in entities.LocalProcess select l).Max(l => l.ServerPort) + 2; } int hubPort = serverPort + 1; LocalProcess localProcess = new LocalProcess { LocalProcessId = Guid.NewGuid(), Participant = participant, Name = "(" + serverPort + "," + hubPort + ")", Address = address, ServerPort = serverPort, HubPort = hubPort, Enabled = false }; entities.AddToLocalProcess(localProcess); entities.SaveChanges(); entities.Detach(localProcess); return(localProcess); } finally { entities.Detach(participant); } } }
public static BubbleLink AddBubleLink(Participant participant, Bubble bubble) { using (DaemonEntities entities = new DaemonEntities()) { try { entities.Attach(participant); entities.Attach(bubble); if (bubble.Participant != participant) { throw new UnauthorizedAccessException("You are not owner of this bubble."); } BubbleLink bubbleLink = new BubbleLink { BubbleLinkId = Guid.NewGuid(), RemoteBubbleId = Guid.Empty, Bubble = bubble, Name = "New Bubble Link", Address = "127.0.0.1", Port = MxpConstants.DefaultHubPort, X = 50, Y = 50, Z = 0, Enabled = false }; entities.AddToBubbleLink(bubbleLink); entities.SaveChanges(); entities.Detach(bubbleLink); return(bubbleLink); } finally { entities.Detach(bubble); entities.Detach(participant); } } }
public static void UpdateObject(CloudObject cloudObject) { using (DaemonEntities entities = new DaemonEntities()) { try { entities.Attach(cloudObject); ObjectType objectType = QueryUtil.First <ObjectType>(from o in entities.CloudObject where o.CloudObjectId == cloudObject.CloudObjectId select o.ObjectType); Participant participant = QueryUtil.First <Participant>(from o in entities.CloudObject where o.CloudObjectId == cloudObject.CloudObjectId select o.Participant); cloudObject.Modified = DateTime.Now; entities.SaveChanges(); } finally { entities.Detach(cloudObject); } } }
public static Participant AttachParticipantProfileToOpenIdIdentity(int userId, string openIdUrl) { using (DaemonEntities entities = new DaemonEntities()) { OpenIdUser user = (from u in entities.OpenIdUser where u.UserId == userId select u).First <OpenIdUser>(); Participant participant = QueryUtil.First <Participant>(from p in entities.Participant where p.User.UserId == user.UserId select p); // If participant is not attached try to find existing participant with openIdUrl if (participant == null) { participant = QueryUtil.First <Participant>(from p in entities.Participant where p.OpenIdUrl == openIdUrl select p); if (participant != null) { // If participant is not attached to user then attach it. if (participant.User == null) { participant.User = user; entities.SaveChanges(); } else { throw new ArgumentException("Participant exists with the same OpenId but already connected to different user."); } } } // If participant is still null then create new participant and attach to user. if (participant == null) { participant = new Participant { ParticipantId = new Guid(UUIDGenerator.Current.GenerateNameBasedUUID(new UUID(MxpConstants.MxpNamespaceId.ToString()), openIdUrl).ToString()), OpenIdUrl = openIdUrl, User = user }; entities.AddToParticipant(participant); entities.SaveChanges(); } entities.Detach(participant); return(participant); } }