0

我正在尝试构建用于工作流中的SharePoint 2010的自定义活动。在设计师中,我可以在“自定义活动”下的功能区中的“操作”下拉菜单中看到活动。然而,这个元素从来没有在设计中体现出来,我不知道如何调试这个问题。调试SharePoint 2010自定义活动

我曾尝试将一个Debugger.Break()放入事件处理程序中,但这会导致应用程序事件日志中的条目An unhandled exception ('Launch for user') occurred in w3wp.exe [xxxx]. Just-In-Time debugging this exception failed with the following error: Not enough storage is available to complete this operation.此外,将调试程序附加到w3wp.exe进程不会在任何中断点上停止。

我已经打开了SharePoint 2010内部的详细日志记录(并且日志记录非常详细!),但它似乎没有包含任何有关该组件的信息或设计人员未加载组件的原因。

这是这个非常基本的活动的相关代码片段。我在这里做错了什么?

using System; 
using System.ComponentModel; 
using System.Diagnostics; 
using System.IO; 
using System.Workflow.ComponentModel; 
using System.Workflow.Activities; 
using Microsoft.SharePoint; 
using Microsoft.SharePoint.WorkflowActions; 

namespace SharePoint.Activities.IO 
{ 
    public partial class CopyFile : SequenceActivity 
    { 
     public CopyFile() 
     { 
      InitializeComponent(); 
     } 

     public static DependencyProperty SourceDirectoryProperty = DependencyProperty.Register("SourceDirectory", typeof(string), typeof(CopyFile)); 
     public static DependencyProperty TargetDirectoryProperty = DependencyProperty.Register("TargetDirectory", typeof(string), typeof(CopyFile)); 
     public static DependencyProperty ResultProperty = DependencyProperty.Register("Result", typeof(string), typeof(CopyFile)); 
     public static DependencyProperty CreateDateProperty = DependencyProperty.Register("CreateDate", typeof(DateTime), typeof(CopyFile)); 
     public static DependencyProperty CompletionDateProperty = DependencyProperty.Register("CompletionDate", typeof(DateTime), typeof(CopyFile)); 
     public static DependencyProperty WFContextProperty = DependencyProperty.Register("WFContext", typeof(WorkflowContext), typeof(CopyFile)); 

     [Description("Path the files to perform the operation on")] 
     [Browsable(true)] 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
     public string SourceDirectory 
     { 
      get { return (string)GetValue(SourceDirectoryProperty); } 
      set { SetValue(SourceDirectoryProperty, value); } 
     } 
     [Description("Path the files are copied to")] 
     [Browsable(true)] 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
     public string TargetDirectory 
     { 
      get { return (string)GetValue(TargetDirectoryProperty); } 
      set { SetValue(TargetDirectoryProperty, value); } 
     } 
     [Description("Once the the operation completes, this is set to OK or the exception information")] 
     [Browsable(true)] 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
     public string Result 
     { 
      get { return (string)GetValue(ResultProperty); } 
      set { SetValue(ResultProperty, value); } 
     } 
     [Description("When the request was created")] 
     [Browsable(true)] 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
     public DateTime CreateDate 
     { 
      get { return (DateTime)GetValue(CreateDateProperty); } 
      set { SetValue(CreateDateProperty, value); } 
     } 
     [Description("When execution stoped")] 
     [Browsable(true)] 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
     public DateTime CompletionDateDate 
     { 
      get { return (DateTime)GetValue(CompletionDateProperty); } 
      set { SetValue(CompletionDateProperty, value); } 
     } 

     [Browsable(true)] 
     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
     public WorkflowContext WFContext { get { return (WorkflowContext)GetValue(WFContextProperty); } set { SetValue(WFContextProperty, value); } } 

     protected override void Initialize(IServiceProvider provider) 
     { 
      TraceIn(); 
      base.Initialize(provider); 
      TraceOut(); 
     } 


     protected override void Uninitialize(IServiceProvider provider) 
     { 
      TraceIn(); 
      base.Uninitialize(provider); 
      TraceOut(); 
     } 
     public override string ToString() 
     { 
      TraceIn(); 
      var result = base.ToString(); 
      TraceOut(); 
      return result; 
     } 
     public override int GetHashCode() 
     { 
      TraceIn(); 
      // ReSharper disable BaseObjectGetHashCodeCallInGetHashCode 
      var result = base.GetHashCode(); 
      // ReSharper restore BaseObjectGetHashCodeCallInGetHashCode 
      TraceOut(); 
      return result; 
     } 
     public override bool Equals(object obj) 
     { 
      TraceIn(); 
      // ReSharper disable BaseObjectEqualsIsObjectEquals 
      var result = base.Equals(obj); 
      // ReSharper restore BaseObjectEqualsIsObjectEquals 
      TraceOut(); 
      return result; 
     } 
     //This code causes the compiler to blow up! :) 
     //protected override void Dispose(bool disposing) 
     //{ 
     // TraceIn(); 
     // base.Dispose(disposing); 
     //} 
     protected override void SetBoundValue(ActivityBind bind, object value) 
     { 
      TraceIn(); 
      base.SetBoundValue(bind, value); 
      TraceOut(); 
     } 
     protected override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext) 
     { 
      TraceIn(); 
      base.OnWorkflowChangesCompleted(executionContext); 
      TraceOut(); 
     } 
     protected override void OnSequenceComplete(ActivityExecutionContext executionContext) 
     { 
      TraceIn(); 
      base.OnSequenceComplete(executionContext); 
      TraceOut(); 
     } 
     protected override void OnListChanging(ActivityCollectionChangeEventArgs e) 
     { 
      TraceIn(); 
      base.OnListChanging(e); 
      TraceOut(); 
     } 
     protected override void OnListChanged(ActivityCollectionChangeEventArgs e) 
     { 
      TraceIn(); 
      base.OnListChanged(e); 
      TraceOut(); 
     } 
     protected override void OnClosed(IServiceProvider provider) 
     { 
      TraceIn(); 
      base.OnClosed(provider); 
      TraceOut(); 
     } 
     protected override void OnActivityExecutionContextUnload(IServiceProvider provider) 
     { 
      TraceIn(); 
      base.OnActivityExecutionContextUnload(provider); 
      TraceOut(); 
     } 
     protected override void OnActivityExecutionContextLoad(IServiceProvider provider) 
     { 
      TraceIn(); 
      base.OnActivityExecutionContextLoad(provider); 
      TraceOut(); 
     } 
     protected override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity) 
     { 
      TraceIn(); 
      base.OnActivityChangeRemove(executionContext, removedActivity); 
      TraceOut(); 
     } 
     protected override void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity) 
     { 
      TraceIn(); 
      base.OnActivityChangeAdd(executionContext, addedActivity); 
      TraceOut(); 
     } 
     protected override ActivityExecutionStatus HandleFault(ActivityExecutionContext executionContext, Exception exception) 
     { 
      TraceIn(); 
      var result = base.HandleFault(executionContext, exception); 
      TraceOut(); 
      return result; 
     } 
     protected override object GetBoundValue(ActivityBind bind, Type targetType) 
     { 
      TraceIn(); 
      var result = base.GetBoundValue(bind, targetType); 
      TraceOut(); 
      return result; 
     } 
     protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext) 
     { 
      TraceIn(); 
      var result = base.Cancel(executionContext); 
      TraceOut(); 
      return result; 
     } 
     protected override void InitializeProperties() 
     { 
      TraceIn(); 
      base.InitializeProperties(); 
      TraceOut(); 
     } 
     protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) 
     { 
      TraceIn(); 

      var isSiteAdmin = false; 
      CreateDate = DateTime.Now; 
      try 
      { 
       // Needs administrative credentials to get the web application properties ino 
       SPSecurity.RunWithElevatedPrivileges(delegate 
                 { 
                  using (var site = new SPSite(WFContext.Site.ID)) 
                  { 
                   using (var web = site.AllWebs[WFContext.Web.ID]) 
                   { 
                    isSiteAdmin = web.CurrentUser.IsSiteAdmin; 
                    if (string.IsNullOrEmpty(SourceDirectory)) throw new ArgumentException("SourceDirectory cannot be null or empty"); 
                    if (!Directory.Exists(SourceDirectory)) throw new DirectoryNotFoundException("Could not find source directory: \"" + SourceDirectory + "\""); 

                    if (string.IsNullOrEmpty(TargetDirectory)) throw new ArgumentException("TargetDirectory cannot be null or empty"); 
                    if (!Directory.Exists(TargetDirectory)) throw new DirectoryNotFoundException("Could not find target directory: \"" + TargetDirectory + "\""); 
                    // Do something 

                   } 
                  } 
                 }); 

       Result = "OK"; 
      } 
      catch (Exception ex) 
      { 
       Result = isSiteAdmin ? ex.ToString() : ex.Message; 
      } 
      CompletionDateDate = DateTime.Now; 

      var result = base.Execute(executionContext); 
      TraceOut(); 
      return result; 
     } 

     private static void TraceIn() 
     { 
      Trace("Entering"); 
     } 

     private static void TraceOut() 
     { 
      Trace("Exiting"); 
     } 

     private static void Trace(string direction) 
     { 
      Debugger.Launch(); 
      var stackTrace = new StackTrace(2, false); 
      var frame = stackTrace.GetFrame(0); 
      Debug.WriteLine(direction + " " + frame.GetMethod().Name); 
     } 
    } 
} 

借助内置的跟踪,任何时候我尝试将活动添加到工作流设计器中,我看到的GetHashCode()和equals(),并没有别的电话。

下面是它的.actions文件。

<?xml version="1.0" encoding="utf-8" ?> 
<WorkflowInfo> 
    <Actions 
     Sequential="then" 
     Parallel="and"> 
     <Action 
      Name="IO Activities" 
      ClassName="SharePoint.Activities.IO" 
      Assembly="SharePoint.Activities.IO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abfb622251cf6982" 
      Category="Custom Actions" 
      AppliesTo="all"> 
      <RuleDesigner 
       Sentence="CopyFile %1"> 
       <FieldBind 
        Field="SourceDirectory,TargetDirectory,Result,CreateDate,CompletionDate" 
        Text="Copy the files" 
        DesignerType="CopyFile" 
        Id="1"/> 
      </RuleDesigner> 
      <Parameters> 
       <Parameter 
        Name="SourceDirectory" 
        Type="System.String, mscorlib" 
        Direction="In" 
        DesignerType="StringBuilder" 
        Description="Directory where the source files are to move" /> 
       <Parameter 
        Name="TargetDirectory" 
        Type="System.String, mscorlib" 
        Direction="In" 
        DesignerType="StringBuilder" 
        Description="Directory where the files will be placed" /> 
       <Parameter 
        Name="Result" 
        Type="System.String, mscorlib" 
        Direction="Out" /> 
       <Parameter 
        Name="CreateDate" 
        Type="System.DateTime, mscorlib" 
        Direction="Out" /> 
       <Parameter 
        Name="CompletionDate" 
        Type="System.DateTime, mscorlib" 
        Direction="Out" /> 

       <Parameter 
        Name="WFContext" 
        Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" 
        Direction="In" 
        DesignerType="Hide" /> 
      </Parameters> 
     </Action> 
    </Actions> 
</WorkflowInfo> 

您可能会提供的任何帮助将大大appreaciated。

回答

0

我们从来没有找到调试问题的方法,似乎SharePoint只是在默默地失败。

事实证明,失败的原因很简单,而且令人尴尬。

<Action 
    Name="IO Activities" 
    ClassName="SharePoint.Activities.IO" 
    Assembly="SharePoint.Activities.IO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abfb622251cf6982" 
    Category="Custom Actions" 
    AppliesTo="all"> 

感兴趣的是ClassName="SharePoint.Activities.IO"。那是什么遗漏?实际的班级名称。它应该是ClassName="SharePoint.Activities.IO.FileCopy"。在做完事情并确保web.config和.actions文件中的项目名称是正确的之后,该操作现在会在设计器中加载和渲染。