상속: IAsyncResult
예제 #1
0
        public void NewLink_succeeds()
        {
            // prepare
            this.fixture.PushPolicies("NewObjects");

            string workItemTypeName = "Product Backlog Item";
            var targetType = this.fixture.Project.WorkItemTypes[workItemTypeName];
            var wiPBI = new WorkItem(targetType);
            wiPBI.Title = workItemTypeName + " NewLink_succeeds";
            wiPBI.Save();

            workItemTypeName = "Task";
            targetType = this.fixture.Project.WorkItemTypes[workItemTypeName];
            var wiTask = new WorkItem(targetType);
            wiTask.Title = workItemTypeName + " NewLink_succeeds";

            // trigger
            wiTask.Save();
            Thread.Sleep(3000);
            wiPBI.SyncToLatest();
            wiTask.SyncToLatest();

            // validate
            var hierarchyRelationship = this.fixture.WorkItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"];
            Assert.Equal(1, wiTask.WorkItemLinks.Count);
            var actualLink = wiTask.WorkItemLinks[0];
            Assert.Equal(hierarchyRelationship.ReverseEnd.ImmutableName, actualLink.LinkTypeEnd.ImmutableName);
            Assert.Equal(wiTask.Id, actualLink.SourceId);
            Assert.Equal(1, actualLink.TargetId);
        }
예제 #2
0
        /// <summary>
        /// 构建插件单元
        /// </summary>
        /// <param name="caller">调用者</param>
        /// <param name="context">上下文,用于存放在构建时需要的组件</param>
        /// <param name="element">插件单元</param>
        /// <param name="subItems">被构建的子对象列表</param>
        /// <returns>构建好的插件单元</returns>
        public object BuildItem(object caller, WorkItem context, AddInElement element, ArrayList subItems)
        {
            Guard.ArgumentNotNull(context, "插件构建上下文对象");

            if (element.Configuration.Attributes["label"] == null)
                throw new AddInException(String.Format("没有为类型为 \"{0}\" 的插件单元{1}提供label属性。",
                    element.ClassName, element.Id));

            string label = element.Configuration.Attributes["label"];
            Bar bar = context.Items.Get<Bar>(UIExtensionSiteNames.Shell_Bar_Mainmenu);
            if (bar == null)
                throw new UniframeworkException("没有定义系统主菜单条无法创建系统皮肤菜单项。");

            XtraSkinMenu item = new XtraSkinMenu(bar);
            item.Caption = label;
            item.Name = element.Name;
            BarManager barManager = BuilderUtility.GetBarManager(context);
            if (barManager != null)
                item.Id = barManager.GetNewItemId(); // 为BarItem设置Id方便正确的保存和恢复其状态

            BarItemExtend extend = new BarItemExtend();
            if (element.Configuration.Attributes["begingroup"] != null)
            {
                bool beginGroup = bool.Parse(element.Configuration.Attributes["begingroup"]);
                extend.BeginGroup = beginGroup;
            }
            if (element.Configuration.Attributes["insertbefore"] != null)
                extend.InsertBefore = element.Configuration.Attributes["insertbefore"];
            item.Tag = extend;

            if (!String.IsNullOrEmpty(element.Path) && context.UIExtensionSites.Contains(element.Path))
                context.UIExtensionSites[element.Path].Add(item);
            return item;
        }
예제 #3
0
파일: BaseState.cs 프로젝트: fm107/Shared
		public void Print(WorkItem wi)
		{
			Console.WriteLine("   Id:	{0}", wi.Id);
			Console.WriteLine("State:	{0}", wi.State);
			Console.WriteLine("Title:	{0}", wi.Title);
			Console.WriteLine(" Desc:	{0}", wi.Description);
		}
 public WorkItemVisualizer(WorkItem rootWorkItem, IVisualizer visualizer)
     : this()
 {
     _visualizer = visualizer;
     WorkItemAdded(this, new DataEventArgs<WorkItem>(visualizer.CabRootWorkItem));
     rootWorkItem.Workspaces["MainWorkspace"].Show(this, new SmartPartInfo("WorkItems", string.Empty));
 }
예제 #5
0
        /// <summary>
        /// 获取工具条管理器
        /// </summary>
        /// <param name="workItem">工作项</param>
        /// <returns>返回系统外壳定义的工具条管理器</returns>
        public static BarManager GetBarManager(WorkItem workItem)
        {
            Guard.ArgumentNotNull(workItem, "workItem");

            BarManager barManager = workItem.Items.Get<BarManager>(UIExtensionSiteNames.Shell_Bar_Manager);
            return barManager;
        }
예제 #6
0
        /// <summary>
        /// 构建插件单元
        /// </summary>
        /// <param name="caller">调用者</param>
        /// <param name="context">上下文,用于存放在构建时需要的组件</param>
        /// <param name="element">插件单元</param>
        /// <param name="subItems">被构建的子对象列表</param>
        /// <returns>构建好的插件单元</returns>
        public object BuildItem(object caller, WorkItem context, AddInElement element, ArrayList subItems)
        {
            if (element.Configuration.Attributes["label"] == null)
                throw new AddInException(String.Format("没有为类型为 \"{0}\" 的插件单元{1}提供label属性。",
                    element.ClassName, element.Id));

            string label = element.Configuration.Attributes["label"];
            BarManager barManager = context.Items.Get<BarManager>(UIExtensionSiteNames.Shell_Bar_Manager);
            if (barManager == null)
                throw new UniframeworkException("未定义框架外壳的工具条管理器。");

            Bar item = new Bar(barManager, label);
            item.BarName = element.Name;
            item.DockStyle = BarDockStyle.Top; // 默认停靠在顶部
            if (element.Configuration.Attributes["dockstyle"] != null) {
                string dockStyle = element.Configuration.Attributes["dockstyle"];
                item.DockStyle = (BarDockStyle)Enum.Parse(typeof(BarDockStyle), dockStyle);
            }

            // 是否让工具栏显示整行
            if (element.Configuration.Attributes["wholerow"] != null)
                item.OptionsBar.UseWholeRow = bool.Parse(element.Configuration.Attributes["wholerow"]);
            if (element.Configuration.Attributes["allowcustomization"] != null)
                item.OptionsBar.AllowQuickCustomization = bool.Parse(element.Configuration.Attributes["allowcustomization"]);
            if (element.Configuration.Attributes["register"] != null) {
                bool register = bool.Parse(element.Configuration.Attributes["register"]);
                if (register)
                    context.UIExtensionSites.RegisterSite(BuilderUtility.CombinPath(element.Path, element.Id), item); // 此处可能抛出异常
            }

            return item;
        }
예제 #7
0
 /// <summary>
 /// ���캯��
 /// </summary>
 /// <param name="workItem">�������</param>
 public AbstractCTIDriver(WorkItem workItem)
 {
     this.workItem = workItem;
     this.logger = this.workItem.Services.Get<ILog>();
     channels = null;
     confGroups = new Dictionary<int, List<int>>();
 }
        /// <summary>
        /// 构建插件单元
        /// </summary>
        /// <param name="caller">调用者</param>
        /// <param name="context">上下文,用于存放在构建时需要的组件</param>
        /// <param name="element">插件单元</param>
        /// <param name="subItems">被构建的子对象列表</param>
        /// <returns>构建好的插件单元</returns>
        public object BuildItem(object caller, WorkItem context, AddInElement element, ArrayList subItems)
        {
            if (element.Configuration.Attributes["label"] == null)
                throw new AddInException(String.Format("没有为类型为 \"{0}\" 的插件单元{1}提供label属性。",
                    element.ClassName, element.Id));

            string label = element.Configuration.Attributes["label"];
            NavBarItem item = new NavBarItem(BuilderUtility.GetStringRES(context, label));
            item.Name = element.Name;
            if (element.Configuration.Attributes["tooltip"] != null)
                item.Hint = element.Configuration.Attributes["tooltip"];

            if (element.Configuration.Attributes["largeimage"] != null) {
                string largeImage = element.Configuration.Attributes["largeimage"];
                item.LargeImage = BuilderUtility.GetBitmap(context, largeImage, 32, 32);
            }
            if (element.Configuration.Attributes["imagefile"] != null) {
                string image = element.Configuration.Attributes["imagefile"];
                item.SmallImage = BuilderUtility.GetBitmap(context, image, 16, 16);
            }

            if (!String.IsNullOrEmpty(element.Path) && context.UIExtensionSites.Contains(element.Path))
                context.UIExtensionSites[element.Path].Add(item);
            Command cmd = BuilderUtility.GetCommand(context, element.Command);
            if (cmd != null)
                cmd.AddInvoker(item, "LinkClicked");
            return item;
        }
        /// <summary>
        /// Assigns the operands.
        /// </summary>
        /// <param name="workItem">The work item.</param>
        private void AssignOperands(WorkItem workItem)
        {
            var operandStack = workItem.IncomingStack;
            var block = workItem.Block;

            operandStack = CreateMovesForIncomingStack(block, operandStack);

            //System.Diagnostics.Debug.WriteLine("IN:    Block: " + block.Label + " Operand Stack Count: " + operandStack.Count);
            AssignOperands(block, operandStack);

            //System.Diagnostics.Debug.WriteLine("AFTER: Block: " + block.Label + " Operand Stack Count: " + operandStack.Count);
            operandStack = CreateScheduledMoves(block, operandStack);

            outgoingStack[block.Sequence] = operandStack;
            processed.Set(block.Sequence, true);

            foreach (var b in block.NextBlocks)
            {
                if (enqueued.Get(b.Sequence))
                    continue;

                workList.Enqueue(new WorkItem(b, new Stack<Operand>(operandStack)));
                enqueued.Set(b.Sequence, true);
            }
        }
        /// <summary>
        /// 构建插件单元
        /// </summary>
        /// <param name="caller">调用者</param>
        /// <param name="context">上下文,用于存放在构建时需要的组件</param>
        /// <param name="element">插件单元</param>
        /// <param name="subItems">被构建的子对象列表</param>
        /// <returns>构建好的插件单元</returns>
        public object BuildItem(object caller, WorkItem context, AddInElement element, ArrayList subItems)
        {
            IContentMenuService cmbService = context.Services.Get<IContentMenuService>();
            if (cmbService == null)
                throw new UniframeworkException(String.Format("未注册IContentMenuBarService无法创建上下文菜单 \"{0}\"。", element.Name));

            BarSubItem item = new BarSubItem();
            item.Name = element.Name;
            item.Tag = element.Path;
            item.Manager = BuilderUtility.GetBarManager(context); // 设置工具栏管理器
            string exPath = BuilderUtility.CombinPath(element.Path, element.Id);
            cmbService.RegisterContentMenu(exPath, item);

            // 添加插件单元到系统中
            if (!String.IsNullOrEmpty(element.Path) && context.UIExtensionSites.Contains(element.Path))
                context.UIExtensionSites[element.Path].Add(item);
            if (!String.IsNullOrEmpty(element.Command))
            {
                Command cmd = BuilderUtility.GetCommand(context, element.Command);
                if (cmd != null)
                    cmd.AddInvoker(item, "Popup");
            }

            context.UIExtensionSites.RegisterSite(exPath, item);
            return item;
        }
        /// <summary>
        /// 构建插件单元
        /// </summary>
        /// <param name="caller">调用者</param>
        /// <param name="context">上下文,用于存放在构建时需要的组件</param>
        /// <param name="element">插件单元</param>
        /// <param name="subItems">被构建的子对象列表</param>
        /// <returns>构建好的插件单元</returns>
        public object BuildItem(object caller, WorkItem context, AddInElement element, ArrayList subItems)
        {
            Guard.ArgumentNotNull(context, "插件构建上下文对象");

            if (element.Configuration.Attributes["label"] == null)
                throw new AddInException(String.Format("没有为类型为 \"{0}\" 的插件单元{1}提供label属性。",
                    element.ClassName, element.Id));

            string label = element.Configuration.Attributes["label"];
            Form shell = context.Items.Get<Form>(UIExtensionSiteNames.Shell);
            Bar bar = context.Items.Get<Bar>(UIExtensionSiteNames.Shell_Bar_Mainmenu);
            XtraTabbedMdiManager mdiManager = context.Items.Get<XtraTabbedMdiManager>(UIExtensionSiteNames.Shell_Manager_TabbedMdiManager);
            Guard.ArgumentNotNull(bar, "Main menu bar.");
            Guard.ArgumentNotNull(shell, "Shell");
            Guard.ArgumentNotNull(mdiManager, "Tabbed mdi manager.");

            XtraWindowMenu item = new XtraWindowMenu(bar, mdiManager, shell);
            item.Caption = label;
            item.Name = element.Name;
            BarManager barManager = BuilderUtility.GetBarManager(context);
            if (barManager != null)
                item.Id = barManager.GetNewItemId(); // 为BarItem设置Id方便正确的保存和恢复其状态

            if (!String.IsNullOrEmpty(element.Path) && context.UIExtensionSites.Contains(element.Path))
                context.UIExtensionSites[element.Path].Add(item);
            // 注册插件单元
            if (element.Configuration.Attributes["register"] != null) {
                bool register = bool.Parse(element.Configuration.Attributes["register"]);
                if (register)
                    context.UIExtensionSites.RegisterSite(BuilderUtility.CombinPath(element.Path, element.Id), item);
            }
            return item;
        }
예제 #12
0
        public LauncherService()
        {
            rootWorkItemService = SpringUtil.GetObject<IRootWorkItemService>("RootWorkItemService");
            workItem = rootWorkItemService.RootWorkItem;

            coordinator = workItem.Services.Get<ICoordinator>();
        }
 internal Task(WorkItem item)
     : this()
 {
     ID = item.RunCount;
     Item = item;
     valid = true;
 }
예제 #14
0
        /// <summary>
        /// Cancels the specified Queue workitem.
        /// </summary>
        /// <param name="item">The item to cancel in thread pool.</param>
        /// <param name="allowAbort">if set to <see langword="true"/> [allow abort].</param>
        /// <returns>Status of item queue</returns>
        public static WorkItemStatus Cancel(WorkItem item, bool allowAbort)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            lock (CallbacksList)
            {
                LinkedListNode<WorkItem> node = CallbacksList.Find(item);

                if (node != null)
                {
                    CallbacksList.Remove(node);
                    return WorkItemStatus.Queued;
                }
                else if (ThreadList.ContainsKey(item))
                {
                    if (allowAbort)
                    {
                        ThreadList[item].Abort();
                        ThreadList.Remove(item);
                        return WorkItemStatus.Aborted;
                    }
                    else
                    {
                        return WorkItemStatus.Executing;
                    }
                }
                else
                {
                    return WorkItemStatus.Completed;
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Aborts a previously queued work item.
        /// </summary>
        /// <param name="item">The work item to abort.</param>
        /// <param name="unconditionalAbort">If <c>true</c> then abort will commence
        /// unconditionally. If <c>false</c> then the task will only be
        /// aborted if it hasn't started execution yet.</param>
        /// <returns>The status of the work item as it was before aborting.</returns>
        public static WorkItemStatus Abort(WorkItem item, bool unconditionalAbort)
        {
            if (item == null) throw new ArgumentNullException("item");

            Thread joiningThread = null;
            WorkItemStatus returnValue;
            lock (_callbacks)
            {
                LinkedListNode<WorkItem> node = _callbacks.Find(item);
                if (node != null)
                {
                    _callbacks.Remove(node);
                    returnValue = WorkItemStatus.Queued;
                }
                else if (_threads.ContainsKey(item))
                {
                    if (unconditionalAbort)
                    {
                        _threads[item].Abort();
                        joiningThread = _threads[item];
                        _threads.Remove(item);
                        returnValue = WorkItemStatus.Aborted;
                    }
                    else
                        returnValue = WorkItemStatus.Executing;
                }
                else
                    returnValue = WorkItemStatus.Completed;
            }
            if (joiningThread != null)
                joiningThread.Join(1000);
            return returnValue;
        }
예제 #16
0
        /// <summary>
        /// Get the status the specified Queue workitem.
        /// </summary>
        /// <param name="item">The item to get status in thread pool.</param>
        /// <returns>Status of item queue</returns>
        public static WorkItemStatus GetStatus(WorkItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            lock (CallbacksList)
            {
                LinkedListNode<WorkItem> node = CallbacksList.Find(item);

                if (node != null)
                {
                    return WorkItemStatus.Queued;
                }
                else if (ThreadList.ContainsKey(item))
                {
                    return WorkItemStatus.Executing;
                }
                else
                {
                    return WorkItemStatus.Completed;
                }
            }
        }
예제 #17
0
        public ParallelWorkQueue(XmlDocument doc)
        {
            foreach (XmlNode node in doc.DocumentElement.ChildNodes) {
                if (!(node is XmlElement))
                    continue;

                XmlElement xe = (XmlElement)node;

                if (xe.GetAttribute ("enabled") == "false")
                    continue;

                string id = xe.GetAttribute ("id");
                string dependson = xe.GetAttribute ("dependson");

                if (id == null || id.Trim ().Length == 0)
                    throw new ApplicationException ("Node is missing id attribute");

                WorkItem item = new WorkItem ();

                item.Id = id.Trim ();

                if (!string.IsNullOrEmpty (dependson))
                    item.Dependencies.AddRange (ParseDependsOn (dependson));

                item.Item = xe;

                items.Add (item.Id, item);
                dependencies.Add (item.Id);
            }
        }
예제 #18
0
		/// <summary>
		/// Enqueue a work item to the queue.
		/// </summary>
		public bool EnqueueWorkItem(WorkItem workItem) {
			// A work item cannot be null, since null is used in the WaitForWorkItem() method to indicate timeout or cancel
			if (workItem == null)
				throw new ArgumentNullException("workItem");

			bool enqueue = true;

			// First check if there is a wait entry waiting for work item. During 
			// the check, timed out waiters are ignored. If there is no waiter then the work item is queued.
			lock (this) {
				CheckDisposed();

				if (!_isWorkItemsQueueActive)
					return false;

				while (_waitersCount > 0) {
					// Dequeue a waiter.
					WaitEntry waitEntry = PopWaiter();
					// Signal the waiter. On success break the loop
					if (waitEntry.Signal(workItem)) {
						enqueue = false;
						break;
					}
				}

				if (enqueue) {
					// Enqueue the work item
					_workItems.Enqueue(workItem);
				}
			}
			return true;
		}
예제 #19
0
 public override void Complete(WorkItem workItem, WorkflowProvider provider)
 {
     completed.Add(workItem);
     started.Remove(workItem);
     processing.Remove(workItem);
     provider.EndWorkItem(this, workItem);
 }
        public void Transit(WorkItem workItem, IEngine engine)
        {
            var exceptionId = workItem.ExceptionId.Value;
            var exception = _dataStore.Get(exceptionId);
            var current = workItem;
            current = _repository.GetParent(current);

            while (current != null)
            {
                if (current.Status.IsFinal())
                    return;

                if (current.Type == WorkflowType.Retry) //todo: add unit test
                {
                    engine.Kick(current.Id);
                    return;
                }

                if (TryRescure(current, exception, exceptionId))
                    break;

                current = _repository.GetParent(current);
            }

            if (current == null)
            {
                engine.Kick(null);
                return;
            }

            engine.Kick(current.ParentId);
        }
예제 #21
0
        public void NewTask_succeeds()
        {
            // prepare
            this.fixture.PushPolicies("NewObjects");

            string workItemTypeName = "Bug";
            var targetType = this.fixture.Project.WorkItemTypes[workItemTypeName];
            var wiBug = new WorkItem(targetType);
            wiBug.Title = workItemTypeName + " NewLink_succeeds";

            // trigger
            wiBug.Save();
            Thread.Sleep(4000);
            wiBug.SyncToLatest();

            // validate
            var hierarchyRelationship = this.fixture.WorkItemStore.WorkItemLinkTypes["System.LinkTypes.Hierarchy"];
            Assert.Equal(1, wiBug.WorkItemLinks.Count);
            var actualLink = wiBug.WorkItemLinks[0];
            Assert.Equal(hierarchyRelationship.ForwardEnd.ImmutableName, actualLink.LinkTypeEnd.ImmutableName);
            Assert.Equal(wiBug.Id, actualLink.SourceId);
            var wiTask = fixture.WorkItemStore.GetWorkItem(actualLink.TargetId);
            Assert.NotNull(wiTask);
            Assert.Equal("Task", wiTask.Type.Name);
            Assert.Equal("Task auto-generated for " + wiBug.Title, wiTask.Title);
        }
예제 #22
0
		public WorkItemStatus Cancel(WorkItem item, bool allowAbort)
		{
			if (item == null)
				throw new ArgumentNullException("item");
			lock (_callbacks)
			{
				LinkedListNode<WorkItem> node = _callbacks.Find(item);
				if (node != null)
				{
					_callbacks.Remove(node);
					return WorkItemStatus.Queued;
				}
				else if (_threads.ContainsKey(item))
				{
					if (allowAbort)
					{
						_threads[item].Abort();
						_threads.Remove(item);
						return WorkItemStatus.Aborted;
					}
					else
						return WorkItemStatus.Executing;
				}
				else
					return WorkItemStatus.Completed;
			}
		}
예제 #23
0
 public void CompleteWork(WorkItem workItem)
 {
     if (/*_workAgent.started.Contains(workItem) &&*/ _workAgent.processing.Contains(workItem))
     {
         _workAgent.Complete(workItem, _workflow);
     }
 }
예제 #24
0
 public void AddWork(WorkItem workItem)
 {
     lock (_workAgent.started)
     {
         _avatar.AddTaskToQueue("STARTWORK:" + workItem.taskID);
     }
 }
예제 #25
0
        private static int GetPivotalIdFromTFSWorkItem(WorkItem item)
        {
            int num;
            var originalValue = (string) item.Fields["History"].Value;
            if (originalValue == string.Empty)
            {
                originalValue = (string) item.Fields["History"].OriginalValue;
            }

            if ((!string.IsNullOrEmpty(originalValue) && originalValue.Contains(PIVOTALID)) &&
                int.TryParse(
                    originalValue.Substring(originalValue.IndexOf(PIVOTALID) + PIVOTALID.Length).Replace(":", ""), out num))
            {
                return num;
            }

            var url = GetPivotalUrlFromTFSWorkItem(item);

            if (url == null)
                return -1;

            if (int.TryParse(url.Substring(url.LastIndexOf("/") + 1), out num))
                return num;

            return -1;
        }
예제 #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XtraGridPrintAdapter"/> class.
        /// </summary>
        /// <param name="adaptee">The adaptee.</param>
        /// <param name="workItem">The work item.</param>
        public XtraGridPrintAdapter(GridControl adaptee, WorkItem workItem)
        {
            this.adaptee = adaptee;
            this.workItem = workItem;
            xtrapService = new XtraPrintService(adaptee, adaptee.DefaultView.ViewCaption);

            RegisterEvent();
        }
예제 #27
0
 public void StartWork(WorkItem workItem)
 {
     lock (_workAgent.processing)
     {
         _workAgent.processing.Add(workItem);
     }
     AddWorkTasks(workItem);
 }
예제 #28
0
 internal void queue_work_item(WorkItem work_item)
 {
     lock (work_item_queue.SyncRoot)
     {
         work_item_queue.Enqueue(work_item);
         item_added.Set();
     }
 }
        public override object BuildUp(IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
        {
            workItem = StrategyUtility.GetWorkItem(context, existing);
            if (existing is Control)
                RegisterMouseEvent(existing as Control, true);

            return base.BuildUp(context, typeToBuild, existing, idToBuild);
        }
예제 #30
0
        public override void Run(WorkItem workItem)
        {
            Thread thread = new Thread(Callback);
            thread.Priority = workItem.Priority;

            thread.IsBackground = false;
            thread.Start(workItem);
        }
 public ShellExtensionService([ServiceDependency] WorkItem workItem)
 {
     _workItem  = workItem;
     _shellForm = _workItem.Items.Get <ShellForm>("ShellForm");
 }
예제 #32
0
        public async Task Can_add_self_to_cyclic_HasManyThrough_relationship()
        {
            // Arrange
            WorkItem existingWorkItem = _fakers.WorkItem.Generate();

            existingWorkItem.RelatedToItems = new List <WorkItemToWorkItem>
            {
                new WorkItemToWorkItem
                {
                    ToItem = _fakers.WorkItem.Generate()
                }
            };

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                dbContext.WorkItems.Add(existingWorkItem);
                await dbContext.SaveChangesAsync();
            });

            var requestBody = new
            {
                data = new[]
                {
                    new
                    {
                        type = "workItems",
                        id   = existingWorkItem.StringId
                    }
                }
            };

            string route = $"/workItems/{existingWorkItem.StringId}/relationships/relatedTo";

            // Act
            (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAsync <string>(route, requestBody);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);

            responseDocument.Should().BeEmpty();

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                // @formatter:wrap_chained_method_calls chop_always
                // @formatter:keep_existing_linebreaks true

                WorkItem workItemInDatabase = await dbContext.WorkItems
                                              .Include(workItem => workItem.RelatedToItems)
                                              .ThenInclude(workItemToWorkItem => workItemToWorkItem.ToItem)
                                              .FirstWithIdAsync(existingWorkItem.Id);

                // @formatter:keep_existing_linebreaks restore
                // @formatter:wrap_chained_method_calls restore

                int toItemId = existingWorkItem.RelatedToItems[0].ToItem.Id;

                workItemInDatabase.RelatedToItems.Should().HaveCount(2);
                workItemInDatabase.RelatedToItems.Should().OnlyContain(workItemToWorkItem => workItemToWorkItem.FromItem.Id == existingWorkItem.Id);
                workItemInDatabase.RelatedToItems.Should().ContainSingle(workItemToWorkItem => workItemToWorkItem.ToItem.Id == existingWorkItem.Id);
                workItemInDatabase.RelatedToItems.Should().ContainSingle(workItemToWorkItem => workItemToWorkItem.ToItem.Id == toItemId);
            });
        }
예제 #33
0
        public async Task Can_add_to_HasManyThrough_relationship_with_already_assigned_resources()
        {
            // Arrange
            List <WorkItem> existingWorkItems = _fakers.WorkItem.Generate(2);

            existingWorkItems[0].WorkItemTags = new[]
            {
                new WorkItemTag
                {
                    Tag = _fakers.WorkTag.Generate()
                }
            };

            existingWorkItems[1].WorkItemTags = new[]
            {
                new WorkItemTag
                {
                    Tag = _fakers.WorkTag.Generate()
                }
            };

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                dbContext.WorkItems.AddRange(existingWorkItems);
                await dbContext.SaveChangesAsync();
            });

            var requestBody = new
            {
                data = new[]
                {
                    new
                    {
                        type = "workTags",
                        id   = existingWorkItems[0].WorkItemTags.ElementAt(0).Tag.StringId
                    },
                    new
                    {
                        type = "workTags",
                        id   = existingWorkItems[1].WorkItemTags.ElementAt(0).Tag.StringId
                    }
                }
            };

            string route = $"/workItems/{existingWorkItems[0].StringId}/relationships/tags";

            // Act
            (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAsync <string>(route, requestBody);

            // Assert
            httpResponse.Should().HaveStatusCode(HttpStatusCode.NoContent);

            responseDocument.Should().BeEmpty();

            await _testContext.RunOnDatabaseAsync(async dbContext =>
            {
                // @formatter:wrap_chained_method_calls chop_always
                // @formatter:keep_existing_linebreaks true

                List <WorkItem> workItemsInDatabase = await dbContext.WorkItems
                                                      .Include(workItem => workItem.WorkItemTags)
                                                      .ThenInclude(workItemTag => workItemTag.Tag)
                                                      .ToListAsync();

                // @formatter:keep_existing_linebreaks restore
                // @formatter:wrap_chained_method_calls restore

                WorkItem workItemInDatabase1 = workItemsInDatabase.Single(workItem => workItem.Id == existingWorkItems[0].Id);

                int tagId1 = existingWorkItems[0].WorkItemTags.ElementAt(0).Tag.Id;
                int tagId2 = existingWorkItems[1].WorkItemTags.ElementAt(0).Tag.Id;

                workItemInDatabase1.WorkItemTags.Should().HaveCount(2);
                workItemInDatabase1.WorkItemTags.Should().ContainSingle(workItemTag => workItemTag.Tag.Id == tagId1);
                workItemInDatabase1.WorkItemTags.Should().ContainSingle(workItemTag => workItemTag.Tag.Id == tagId2);

                WorkItem workItemInDatabase2 = workItemsInDatabase.Single(workItem => workItem.Id == existingWorkItems[1].Id);

                workItemInDatabase2.WorkItemTags.Should().HaveCount(1);
                workItemInDatabase2.WorkItemTags.ElementAt(0).Tag.Id.Should().Be(tagId2);
            });
        }
예제 #34
0
 public void Run(WorkItem workProc, object o, int delay, int interval)
 {
     System.Threading.TimerCallback t = new System.Threading.TimerCallback(workProc);
     timer = new System.Threading.Timer(t, o, delay, interval);
 }
예제 #35
0
 public BugControl(MainViewModel viewModel, double left, double top, WorkItem item, Color color, double maxWidth, double maxHeight, bool flip = false)
     : base(viewModel, left, top, item, color, maxWidth, maxHeight, flip)
 {
     this.InitializeComponent();
 }
예제 #36
0
 public string FormatId(WorkItem workItem)
 => $"{workItem.ProjectCode}-{workItem.Id}";
예제 #37
0
 public string FormatShortLine(WorkItem workItem)
 => $"{FormatId(workItem)} ({workItem.WorkItemType}): {GetTitleProperty(workItem)}";
                protected override bool TryTakeAnyWork_NoLock(ProjectId preferableProjectId, out WorkItem workItem)
                {
                    if (preferableProjectId != null)
                    {
                        if (TryTake_NoLock(preferableProjectId, out workItem))
                        {
                            return(true);
                        }
                    }

                    // explicitly iterate so that we can use struct enumerator
                    foreach (var kvp in _projectWorkQueue)
                    {
                        workItem = kvp.Value;
                        return(_projectWorkQueue.Remove(kvp.Key));
                    }

                    workItem = default(WorkItem);
                    return(false);
                }