コード例 #1
0
        public void PersistentSession_SerializationTest()
        {
            int numberOfHistoryEvents = 256;

            var events = new List <HistoryEvent>();

            events.Add(new ExecutionStartedEvent(-1, "TestInput"));
            for (int i = 0; i < numberOfHistoryEvents; i++)
            {
                events.Add(new TaskScheduledEvent(-1));
                events.Add(new TaskCompletedEvent(-1, -1, $"Task {i} Result"));
            }
            events.Add(new ExecutionCompletedEvent(-1, "FinalResult", OrchestrationStatus.Completed));

            var instance = new OrchestrationInstance()
            {
                InstanceId  = "testSession",
                ExecutionId = Guid.NewGuid().ToString("N")
            };

            PersistentSession testSession = PersistentSession.Create(instance, events.ToImmutableList());

            var actual = Measure.DataContractSerialization(testSession);

            Assert.IsNotNull(actual);
            Assert.AreEqual(instance.InstanceId, actual.SessionId.InstanceId);
            Assert.AreEqual(instance.ExecutionId, actual.SessionId.ExecutionId);
            Assert.AreEqual(numberOfHistoryEvents * 2 + 2, actual.SessionState.Count);
        }
コード例 #2
0
        /// <summary>
        /// 创建持久Identity
        /// </summary>
        /// <param name="id"></param>
        /// <param name="expiresDate"></param>
        /// <param name="newToken"></param>
        public void CreatePersistentIdentity(SSOIdentity id, DateTime expiresDate, Guid?newToken = null)
        {
            Guid token = Guid.ParseExact(id.Token, "N");

            using (var context = base.CreateUserContext())
            {
                if (newToken == null)
                {
                    var dataObj = new PersistentSession()
                    {
                        Token       = token,
                        UserID      = id.UserID,
                        ExpiresDate = expiresDate
                    };
                    context.PersistentSessions.Add(dataObj);
                }
                else
                {
                    var dataObj = context.PersistentSessions.Where(t => t.Token == token).Single();
                    dataObj.Token = newToken.Value;
                }
                context.SaveChanges();
            }
        }