本文整理汇总了C#中WorkItem类的典型用法代码示例。如果您正苦于以下问题:C# WorkItem类的具体用法?C# WorkItem怎么用?C# WorkItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WorkItem类属于命名空间,在下文中一共展示了WorkItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildItem
/// <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;
}
示例2: Cancel
/// <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;
}
}
}
示例3: GetStatus
/// <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;
}
}
}
示例4: NewLink_succeeds
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);
}
示例5: NewTask_succeeds
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);
}
示例6: WorkItemVisualizer
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));
}
示例7: Print
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);
}
示例8: Complete
public override void Complete(WorkItem workItem, WorkflowProvider provider)
{
completed.Add(workItem);
started.Remove(workItem);
processing.Remove(workItem);
provider.EndWorkItem(this, workItem);
}
示例9: EnqueueWorkItem
/// <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;
}
示例10: GetPivotalIdFromTFSWorkItem
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;
}
示例11: Cancel
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;
}
}
示例12: BuildItem
/// <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;
}
示例13: LauncherService
public LauncherService()
{
rootWorkItemService = SpringUtil.GetObject<IRootWorkItemService>("RootWorkItemService");
workItem = rootWorkItemService.RootWorkItem;
coordinator = workItem.Services.Get<ICoordinator>();
}
示例14: Abort
/// <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;
}
示例15: AssignOperands
/// <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);
}
}