WWF中Conditioned Activity Group的子Activity扩展CAG的WhenCondition属性代码解析

通过三个地方实现这个功能:这样放入CAG中的Activity在设计期间能在属性窗口中看到WhenCondition属性

1 CAG添加WhenCondition属性

2 实现设计时扩展接口 IExtenderProvider ConditionPropertyProviderExtender

3 ConditionedActivityGroupDesigner 关联Activity和扩展实现

关于实现IExtenderProvider 的示例可参考文章

部分代码如下:

1
[Designer(typeof(ConditionedActivityGroupDesigner), typeof(IDesigner)), ToolboxItem(typeof(ActivityToolboxItem)), SRDescription("ConstrainedGroupActivityDescription"), ToolboxBitmap(typeof(ConditionedActivityGroup), "Resources.cag.png"), ActivityValidator(typeof(ConditionedActivityGroupValidator)), SRCategory("Standard")]
public sealed class ConditionedActivityGroup : CompositeActivity, IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
{
 ......
  
public static readonly DependencyProperty WhenConditionProperty;
}

2

[ProvideProperty("WhenCondition"typeof(Activity)), ProvideProperty("UnlessCondition"typeof(Activity))]
internalsealedclassConditionPropertyProviderExtender : IExtenderProvider
{
    public bool CanExtend(
object extendee)
   {
       
if ((extendee != this&& (extendeeisActivity))
        {
           
return (((Activity) extendee).ParentisConditionedActivityGroup);
         }
         returnfalse;
    }
    
  
public ActivityCondition   GetWhenCondition(Activity activity)   
   {       
       
if (activity.ParentisConditionedActivityGroup)       
       {          
          
return (activity.GetValue(ConditionedActivityGroup.WhenConditionProperty) asActivityCondition);        
        }       
       return null;   
    }                                                                                                          
    
  
public  void  SetWhenCondition(Activity activity, ActivityCondition handler) 
   {
        
if (activity.ParentisConditionedActivityGroup)      
         {            
              activity.SetValue(ConditionedActivityGroup.WhenConditionProperty, handler);      
         }   
   }

 3

//ConditionedActivityGroupDesigner的Initialize方法: 
protected override void Initialize(Activity activity)
{
      
base.Initialize(activity);
      IExtenderListService service1 
= (IExtenderListService) base.GetService(typeof(IExtenderListService));
      
if (service1 != null)
      {
            
bool flag1 = false;
            IExtenderProvider[] providerArray1 
= service1.GetExtenderProviders();
            
for (int num1 = 0; num1 < providerArray1.Length; num1++)
            {
                  IExtenderProvider provider1 
= providerArray1[num1];
                  
if (provider1.GetType() == typeof(ConditionPropertyProviderExtender))
                  {
                        flag1 
= true;
                  }
            }
            
if (!flag1)
            {
                  IExtenderProviderService service2 
= (IExtenderProviderService) base.GetService(typeof(IExtenderProviderService));
                  
if (service2 != null)
                  {
                        service2.AddExtenderProvider(
new ConditionPropertyProviderExtender());
                  }
            }
      }
}

posted on 2006-03-23 19:17  周 金根  阅读(681)  评论(0编辑  收藏  举报

导航