示例#1
0
        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);
            }
        }