コード例 #1
0
ファイル: DaemonProcess.cs プロジェクト: MoysheBenRabi/setp
        public byte OnCloudParticipantIdentified(CloudBubble bubble, IdentifyRequestMessage message)
        {
            Guid   participantId           = message.ParticipantId;
            String participantIdentifier   = message.ParticipantIdentity;
            String participantIdentityType = message.ParticipantIdentityType;

            if (!participantIdentityType.Equals(IdentifyRequestMessage.OPEN_ID_IDENTITY))
            {
                return(MxpResponseCodes.UNSUPPORTED_OPERATION);
            }

            Participant participant = QueryUtil.First <DaemonLogic.Participant>(
                from p in entityContext.Participant where p.ParticipantId == participantId select p);

            if (participant != null)
            {
                if (participant.OpenIdUrl != participantIdentifier)
                {
                    return(MxpResponseCodes.RESERVED_ID);
                }
                else
                {
                    return(MxpResponseCodes.SUCCESS);
                }
            }

            participant = QueryUtil.First <DaemonLogic.Participant>(
                from p in entityContext.Participant where p.OpenIdUrl == participantIdentifier select p);
            if (participant != null)
            {
                return(MxpResponseCodes.UNAUTHORIZED_OPERATION);
            }

            participant = new Participant
            {
                ParticipantId = participantId,
                OpenIdUrl     = participantIdentifier,
            };

            entityContext.AddToParticipant(participant);
            entityContext.SaveChanges();

            return(MxpResponseCodes.SUCCESS);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: TestDataLayer.cs プロジェクト: MoysheBenRabi/setp
        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>());
            }
        }