1

我在使用客户端对象模型在文档库中创建文件时遇到困难。我的自定义 Visual Studio 2010 工作流未检测到我在创建文件列表项后对其进行的更新。

我想给出一个基础设施的想法来回答一些可能的问题:

  • 将文档上传到 Web 服务,该服务负责将文档实际插入到库中并配置其列表列的值
  • Web 服务正在使用客户端对象模型执行此操作
  • Web 服务使用为商业智能自动化创建的帐户对 SharePoint 站点进行身份验证,该帐户在与 SharePoint 交互时不作为系统帐户运行;但是,它是 SharePoint 所有者的成员
  • 自定义工作流程中的操作取决于文件的列表项列被填充,然后才能继续将任务分配给其中两个列中的用户;出于这个原因,我创建了一个 While 活动来监视列表项中的更改,直到这两列不再为空

以下是 Web 服务正在执行的操作的示例。它以商业智能用户身份在 IIS 中运行。我添加了一些评论,说明我预期工作流会适当响应哪些操作。

Using client As New ClientContext(My.Settings.SharePointSiteURL)

    // Pre-processing to determine appropriate user ID values for columns

    Dim fci As New FileCreationInformation() With {
        .Content = IO.File.ReadAllBytes(storagePath),
        .Overwrite = True,
        .Url = String.Format("{0}/{1}", theList.RootFolder.ServerRelativeUrl, theFileName)
    }

    Dim theFile As Microsoft.SharePoint.Client.File = theList.RootFolder.Files.Add(fci)

    // Expecting the workflow to be activated here
    client.ExecuteQuery()

    theFile.ListItemAllFields("Project_x0020_Manager") = pmId
    theFile.ListItemAllFields("Project_x0020_Accountant") = paId
    theFile.ListItemAllFields.Update()

    // Expecting the onWorkflowItemChanged activity to be invoked here
    client.ExecuteQuery()
End Using

当文件上传并继续等待来自 SharePoint 的更改事件时,工作流会激活,但该事件永远不会作为 Web 服务操作的直接结果到达。我能够手动修改该项目并成功继续。

使用可能会阻止这些事件正常触发的客户端对象模型时是否有考虑?

4

1 回答 1

0

Seems like some weird race condition. I was able to partially reproduce your problem with some sample code:

using (var client = new ClientContext(ConfigurationManager.AppSettings["Site"]))
{
    client.Load(client.Site);
    client.Load(client.Site.RootWeb);
    var list = client.Site.RootWeb.Lists.GetByTitle("Shared Documents");
    client.Load(list);
    client.Load(list.RootFolder);
    client.ExecuteQuery();
    var fci = new FileCreationInformation()
              {
                  Content = File.ReadAllBytes(ConfigurationManager.AppSettings["File"]),
                  Overwrite = true,
                  Url = list.RootFolder.ServerRelativeUrl + "/" + "file.xml"
               };
    var file = list.RootFolder.Files.Add(fci);
    client.ExecuteQuery();

    //If following 3 lines are commented out, problem you described may or may not occur. I wasn't able to run into problems, when i loaded file and list item before.
    //client.Load(file);
    //client.Load(file.ListItemAllFields);
    //client.ExecuteQuery();

    //Problem also doesn't occur, when i put here
    //System.Threading.Thread.Sleep(1000); 

    //If code just runs here without delay, sometimes i run into issue you described. 
    var itm = file.ListItemAllFields;
    itm["SampleColumn"] = "Test content!";
    itm.Update();
    client.ExecuteQuery();
}

and workflow:

public Workflow1()
{
    InitializeComponent();
}

public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
    var comment = "Workflow started!, item SampleColumn is: " +
    workflowProperties.Item["SampleColumn"];
    SPWorkflow.CreateHistoryEvent(workflowProperties.Web, WorkflowInstanceId, 0, workflowProperties.Web.CurrentUser, new TimeSpan(), "Update", comment, string.Empty);
}

private void onWorkflowItemChanged1_Invoked(object sender, ExternalDataEventArgs e)
{
    var comment = "Workflow continous!, item Title is: " +                           workflowProperties.Item["SampleColumn"];
    SPWorkflow.CreateHistoryEvent(workflowProperties.Web, WorkflowInstanceId, 0, workflowProperties.Web.CurrentUser, new TimeSpan(), "Update", comment, string.Empty);
 }

And workflow itself

Workflow screenshot

If you had something different, please let me know. I had myself some problems with declarative workflows which were running on SharePoint library and most of the time i was not able to find nice solution.

于 2012-11-20T13:18:06.087 回答