当前位置: 首页>>代码示例>>C#>>正文


C# Task.Claim方法代码示例

本文整理汇总了C#中System.Threading.Task.Claim方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Claim方法的具体用法?C# Task.Claim怎么用?C# Task.Claim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Task的用法示例。


在下文中一共展示了Task.Claim方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestReadyToReserved

        public void TestReadyToReserved()
        {
            IdentityId initiatorId = new IdentityId();
            IdentityId potentialOwner = new IdentityId();
            IdentityId businessAdminId = new IdentityId();
            IPrincipal initiator = new ClaimsPrincipal(initiatorId.GetIdentity());
            _mapStorage[potentialOwner.Id] = new Account(potentialOwner, "s-1-2-3-4-5", "auth", AccountType.User);
            _mapStorage[businessAdminId.Id] = new Account(businessAdminId, "s-55-2-3-4-5", "auth", AccountType.User);

            ILoggingService loggingService = SetupLoggerMock(new List<TaskHistoryEvent> {
                                                                     new TaskHistoryEvent
                                                                         {
                                                                             Event = "Create",
                                                                             OldStatus = TaskStatus.None,
                                                                             NewStatus = TaskStatus.Created,
                                                                             OldPriority = Priority.Normal,
                                                                             NewPriority = Priority.Normal,
                                                                             Comment = "",
                                                                             TimeStamp = DateTime.UtcNow,
                                                                             UserId = initiatorId
                                                                         }
            });

            Thread.CurrentPrincipal = initiator;
            Task task = new Task(new TaskId(), TaskStatus.Created, string.Empty,
                                 string.Empty, Priority.Normal, false,
                                 DateTime.UtcNow, initiator.Identity,
                                 null, null, null)
            {
                LoggingService = loggingService
            };
            task.PotentialOwners.Add(potentialOwner.GetIdentity());
            task.PotentialOwners.Add(new IdentityId().GetIdentity());
            task.BusinessAdministrators.Add(businessAdminId.GetIdentity());
            IPrincipal businessAdmin = new ClaimsPrincipal(businessAdminId.GetIdentity());
            Thread.CurrentPrincipal = businessAdmin;
            task.Activate();
            Assert.AreEqual(TaskStatus.Ready, task.Status);
            Assert.IsNull(task.ActualOwner);
            IPrincipal owner = new ClaimsPrincipal(potentialOwner.GetIdentity());
            Thread.CurrentPrincipal = owner;
            task.Claim();
            Assert.AreEqual(TaskStatus.Reserved, task.Status);
            Assert.IsNotNull(task.ActualOwner);
            Assert.AreEqual(potentialOwner.GetIdentity(), task.ActualOwner);

            Assert.IsNotNull(task.History);
            Assert.AreEqual(3, task.History.Count());
            TaskHistoryEvent history = task.History.ElementAt(0);
            Assert.IsNotNull(history);
            Assert.AreEqual(TaskStatus.None, history.OldStatus);
            Assert.AreEqual(TaskStatus.Created, history.NewStatus);
            Assert.AreEqual(initiatorId, history.UserId);

            history = task.History.ElementAt(1);
            Assert.IsNotNull(history);
            Assert.AreEqual(TaskStatus.Created, history.OldStatus);
            Assert.AreEqual(TaskStatus.Ready, history.NewStatus);
            Assert.AreEqual(businessAdminId, history.UserId);
            history = task.History.ElementAt(2);
            Assert.IsNotNull(history);
            Assert.AreEqual(TaskStatus.Ready, history.OldStatus);
            Assert.AreEqual(TaskStatus.Reserved, history.NewStatus);
            Assert.AreEqual(potentialOwner, history.UserId);
        }
开发者ID:KlaudWerk,项目名称:WSHumanTask,代码行数:65,代码来源:TaskStateTransitionsTest.cs

示例2: TestTaskReady

        public void TestTaskReady()
        {
            TaskEntity entity = new TaskEntity
            {
                TaskId = new TaskId(),
                Initiator = new IdentityId().GetIdentity(),
                Priority = Priority.Normal,
                Status = TaskStatus.Created,
                Created = DateTime.UtcNow,
                Name = "Name",
                Subject = "Subject"
            };

            Task task = new Task(entity)
            {
                LoggingService = new Mock<ILoggingService>().Object,
                Priority = Priority.High

            };

            TaskDao dao = new TaskDao(SessionFactory);
            task.Accept(dao);
            Task loaded;
            using (ISession session = SessionFactory.OpenSession())
            {
                TaskEntity te = session.Query<TaskEntity>().Where(t => t.TaskId == entity.TaskId).FirstOrDefault();
                loaded=new Task(te);
            }
            Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            IPrincipal p = Thread.CurrentPrincipal;
            loaded.Start();
            task.Accept(dao);
            loaded.Claim();
            task.Accept(dao);
        }
开发者ID:KlaudWerk,项目名称:WSHumanTask,代码行数:35,代码来源:HibernateTaskPersistenceTest.cs


注:本文中的System.Threading.Task.Claim方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。