sharepoint自定义工作流活动什么都不做,甚至不记录日志消息

时间:2011-01-19 16:54:52

标签: sharepoint sharepoint-2007 sharepoint-workflow

我正在尝试创建一个自定义工作流活动,它为我提供了我在列表中存储的收件人列表。但是,一旦我部署并启动工作流程,就不会发生任何事情,即使是日志消息也不会发生。所以我试图调试代码,但没有设置断点,我收到错误“断点当前不会被命中。没有为此文档加载符号。”任何人都可以帮我解决这个问题。

以下是我在创建此活动时所遵循的步骤。 1.创建了一个工作流活动库。 (请附上我的代码文件)

  1. 将.dll添加到GAC
  2. 更新了web.config和WSS.actions文件。
  3. 现在我在设计师中看到了这个动作,所以我使用设计师创建了一个工作流程。
  4. 在项目上手动设置工作流程。
  5. 这里什么也没发生,甚至没有错误。如果您需要任何进一步的信息,请与我们联系。

    请找到以下代码。

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Drawing;
    using System.Linq;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;
    using Microsoft.SharePoint;
    using System.Diagnostics;
    using Microsoft.SharePoint.Workflow;
    using Microsoft.SharePoint.WorkflowActions;
    
    namespace CustomWorkflowActivityLibrary
    {
        public partial class CustomWorkflowActivity: SequenceActivity
        {
            SPList _list;
            private EventLog _log;
            SPFieldUserValueCollection objUserFieldValueCol;
            string semailsettingKeyword1;
            string semailsettingKeyword2;
            public CustomWorkflowActivity()
            {
                InitializeComponent();
            }
    
            public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(CustomWorkflowActivity));
            [DescriptionAttribute("__Context")]
            [BrowsableAttribute(true)]
            [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    
            public WorkflowContext __Context
            {
                get { return ((WorkflowContext)(base.GetValue(CustomWorkflowActivity.__ContextProperty))); }
                set { base.SetValue(CustomWorkflowActivity.__ContextProperty, value); }
            }
            public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(CustomWorkflowActivity));
            [DescriptionAttribute("ListId")]
            [BrowsableAttribute(true)]
            [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
            public string ListId
            {
                get { return ((string)(base.GetValue(CustomWorkflowActivity.ListIdProperty))); }
                set { base.SetValue(CustomWorkflowActivity.ListIdProperty, value); }
            }
            public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(int), typeof(CustomWorkflowActivity));
            [DescriptionAttribute("ListItem")]
            [BrowsableAttribute(true)]
            [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
            public int ListItem
            {
                get { return ((int)(base.GetValue(CustomWorkflowActivity.ListItemProperty))); }
                set { base.SetValue(CustomWorkflowActivity.ListItemProperty, value); }
            }
            private void codeActivity1_ExecuteCode(object sender, EventArgs e)
            {
            }
            protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
            {
                _log = new EventLog("Add Description");
                _log.Source = "Share Point Workflows";
                try
                {
                    //Execute method as a elevated method                 
                    SPSecurity.CodeToRunElevated elevatedExecuteMethod = new SPSecurity.CodeToRunElevated(ExecuteMethod);
                    SPSecurity.RunWithElevatedPrivileges(elevatedExecuteMethod);
                }
                catch (Exception ex)
                {
                    _log.WriteEntry("Error" + ex.Message.ToString(), EventLogEntryType.Error);
                }
                return ActivityExecutionStatus.Closed;
            }
            private void ExecuteMethod()
            {
                try
                {
                    //retrieveing the Site object       
                    SPSite _site = new SPSite(__Context.Site.Url);
                    //retrieveing the Web object                 
                    SPWeb _web = (SPWeb)(__Context.Web);
                    //retrieveing the list object                 
                    _list = _web.Lists[new Guid(this.ListId)];
                    //retrieveing the list item object              
                    SPListItem _listItem = _list.GetItemById(this.ListItem);
                    _site.AllowUnsafeUpdates = true;
                    _web.AllowUnsafeUpdates = true;
                    string semailsubject = _listItem["E-Mail Subject"].ToString();
                    string semailfrom = _listItem["emailfrom"].ToString();
                    _log = new EventLog("get vendor info");
                    _log.WriteEntry("semailsubject");
                    _log.WriteEntry("semailfrom");
    
                    /* _listItem.Update();
                     _list.Update();
                     _site.AllowUnsafeUpdates = false;
                     _web.AllowUnsafeUpdates = false;*/
                    using (SPSite mysite = new SPSite("http://dlglobaltest.dl.com/Admin/IT/Application%20Development%20Group/LibraryEmailDistribution"))
                    {
                        using (SPWeb myweb = mysite.OpenWeb())
                        {
                            SPList settingsList = myweb.Lists["EmailDistributionSettings"];
                            SPQuery oQuery = new SPQuery();
                            oQuery.Query = "<Where><Eq><FieldRef Name='Sender' /><Value Type='Text'>" + semailfrom + "</Value></Eq></Where>";
                            SPListItemCollection ColListItems = settingsList.GetItems(oQuery);
                            foreach (SPListItem oListItem in ColListItems)
                            {
                                semailsettingKeyword1 = oListItem["Keyword1"].ToString();
                                semailsettingKeyword2 = oListItem["Keyword2"].ToString();
                                //SPFieldUserValue objUserFieldValue = new SPFieldUserValue(myweb, oListItem["Recipients"].ToString());
    
                                if ((semailsubject.Contains(semailsettingKeyword1)) || (semailsubject.Contains(semailsettingKeyword2)))
                                {
                                    objUserFieldValueCol = new SPFieldUserValueCollection(myweb, oListItem["Recipients"].ToString());
                                    _log = new EventLog(objUserFieldValueCol.ToString());
    
                                }
                            }
                        }
                    }
    
                }
                catch (Exception ex)
                { }
            }
        }
    }
    

    Web.Config中:

    <authorizedType Assembly="CustomWorkflowActivityLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a95e146fc1062337" Namespace="CustomWorkflowActivityLibrary" TypeName="*" Authorized="True" />
    

    WSS.Actions:

    <Action Name="Get Recipients" 
                ClassName="CustomWorkflowActivityLibrary.CustomWorkflowActivity"
                Assembly="CustomWorkflowActivityLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a95e146fc1062337" 
                AppliesTo="all" Category="Custom">
                <RuleDesigner Sentence="Get Recipients for %1 "> 
               <FieldBind Field="ListId,ListItem" Text="this list" Id="1" DesignerType="ChooseListItem" />
            </RuleDesigner>   
             <Parameters> 
            <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext" Direction="In" /> 
            <Parameter Name="ListId" Type="System.String, mscorlib" Direction="In" /> 
            <Parameter Name="ListItem" Type="System.Int32, mscorlib" Direction="In" /> 
                </Parameters> 
    
        </Action>
    

    谢谢,

2 个答案:

答案 0 :(得分:0)

我不确定这是否会有所帮助,但您可以尝试更改代码中的以下行:

SPSecurity.RunWithElevatedPrivileges(elevatedExecuteMethod); 

对此:

SPSecurity.RunWithElevatedPrivileges(delegate(){
    ExecuteMethod();
}); 

答案 1 :(得分:0)

另一个黑暗的回答:

尝试将您继承的类(http://msdn.microsoft.com/en-us/library/ms173149(v=VS.80).aspx)从SequenceActivity更改为Activity(SequenceActivity继承自CompositeActivity,后者本身继承自Activity。请参阅:http://msdn.microsoft.com/en-us/library/system.workflow.activities.sequenceactivity(v=VS.90).aspx

如果这不起作用,请尝试完全删除构造函数。你应该能够使用base(Sequence)Activity构造函数(因为你继承了类,没有实现它)

希望有帮助...