CSOM CreateSPAsyncReadJob 保持队列状态

CSOM CreateSPAsyncReadJob stays in Queue state

我指的是允许使用 CSOM 在 SharePoint 上创建读取作业的 Migration Asynchronous Read API。我能够成功创建读取作业,但不幸的是,该作业长期以来一直处于队列状态。

函数returns包括UniqueJobIDAzureContainerManifestUriAzureQueueReportUriEncryptionKey

Object

通过使用 clientContext.Site.GetMigrationJobStatus 方法,我能够检查始终 returns Queued

的读取作业状态

下面是示例代码供参考:

using (var clientContext = new ClientContext(siteUrl))
{
    clientContext.Credentials = new SharePointOnlineCredentials(userName, password);

    var result = clientContext.Site.CreateSPAsyncReadJob($"{siteUrl}/List/MyList", new AsyncReadOptions { });
    clientContext.ExecuteQuery();

    MigrationJobState state;
    do
    {
        var status = clientContext.Site.GetMigrationJobStatus(result[0].JobId);
        clientContext.ExecuteQuery();
        state = status.Value;
    } while (state == MigrationJobState.Queued);
}

我还尝试连接到 AzureQueueReportUri 队列,该队列包含带有加密内容的邮件。我不确定我们如何解密内容以使其可读。这是示例消息:

{
    "Label": "Encrypted",
    "JobId": "079ece4a-cfd2-4676-a27d-2662beb5bb0a",
    "IV": "RYc+ZA2feX1hnAcVWR1R+w==",
    "Content": "qbjTBbb2N+DkNumLoCJSAAfwj8etDLgjxp+b2T9k03L9WfRJKlFBIZO457q+CbHA+8DHJS7VbPzVMoW6ybo2GxgteTYVP+yVUOPPvz57VGQJyzg2gss+Bsjn73GTWWUfwC/W+oWnEpt8PawZysCjSNf6A4HKZKewkskCshN/pND8ZpevrGt2qq0dTt0NkTIkuYv5AvIP7DSWjdl7nN/W5x4c2nR0sPFqKYom41a4tIqrruzwCDEEjWLFtuXAQ+UN2TMV9PWabRFe9n/P1RHrAJaNU+JjJiJm+lE1dQChz+7OuQoJsYnbjYTbqEE8CnIB0/E0zTrc3zLc6th8MBsKpZJjd31ovqr/Xez6zCnvMKotSdScFtTgQqHxmVDBMfMgi2mm8cKQpdKwRufP/YhaDQlvFkmj2FQN0KAMNxwFBh/MWCVhz5uCJ50CGhChcn4h"
}

我也无法连接 AzureContainerManifestUri blob 容器。它因错误 Authentication Error. Signature did not match.

而失败

任何人都可以指导我如何继续吗?

方法参数已更改。这是最新更新的文档:https://docs.microsoft.com/en-us/sharepoint/dev/apis/export-amr-api

示例代码:https://gist.github.com/techmadness/484e7de0a7c51e5faf952a79f1eacb85

using System;
using System.Linq;
using System.Security;
using System.Threading;
using Microsoft.SharePoint.Client;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Queue;

namespace ConsoleApp1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var userName = "admin@tenant.onmicrosoft.com";
            var password = GetSecurePassword("password");
            var siteUrl = "https://tenant.sharepoint.com/sites/testsite";
            var listUrl = $"{siteUrl}/testlist";
            var azStorageConnectionStrong = "DefaultEndpointsProtocol=https;AccountName=abcd;AccountKey=xyz";

            using (var clientContext = new ClientContext(siteUrl))
            {
                clientContext.Credentials = new SharePointOnlineCredentials(userName, password);

                var azManifestContainer = CreateContainerIfNotExists(azStorageConnectionStrong, "spread-manifest-container");
                var azReportQueue = CreateQueueIfNotExists(azStorageConnectionStrong, "spread-report-queue");

                var azManifestContainerUrl = GetSASUrl(azManifestContainer);
                var azReportQueueUrl = GetSASUrl(azReportQueue);

                var output = clientContext.Site.CreateSPAsyncReadJob(
                    listUrl,
                    new AsyncReadOptions
                    {
                        IncludeDirectDescendantsOnly = true,
                        IncludeSecurity = true,
                    },
                    null,
                    azManifestContainerUrl,
                    azReportQueueUrl);
                clientContext.ExecuteQuery();

                CloudQueueMessage message;
                do
                {
                    Thread.Sleep(TimeSpan.FromSeconds(10));
                    message = azReportQueue.GetMessage();
                    if (message != null)
                    {
                        Console.WriteLine(message.AsString);
                        azReportQueue.DeleteMessage(message);

                    }
                } while (message != null);

                Console.ReadLine();
            }
        }

        private static SecureString GetSecurePassword(string pwd)
        {
            SecureString securePassword = new SecureString();
            foreach (var ch in pwd.ToArray())
            {
                securePassword.AppendChar(ch);
            }
            return securePassword;
        }

        private static CloudBlobContainer CreateContainerIfNotExists(string storageConnectionString, string containerName)
        {
            var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(containerName);
            container.CreateIfNotExistsAsync().GetAwaiter().GetResult();
            return container;
        }

        private static CloudQueue CreateQueueIfNotExists(string storageConnectionString, string queueName)
        {
            var cloudStorageAccount = CloudStorageAccount.Parse(storageConnectionString);
            var queueClient = cloudStorageAccount.CreateCloudQueueClient();
            var queue = queueClient.GetQueueReference(queueName);
            queue.CreateIfNotExistsAsync().GetAwaiter().GetResult();
            return queue;
        }

        public static string GetSASUrl(CloudBlobContainer container)
        {
            var sharedAccessSignature = container.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write,
                SharedAccessStartTime = DateTime.UtcNow.AddDays(-1),
                SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7),
            });
            return container.StorageUri.PrimaryUri + sharedAccessSignature;
        }

        public static string GetSASUrl(CloudQueue queue)
        {
            var sharedAccessSignature = queue.GetSharedAccessSignature(new SharedAccessQueuePolicy
            {
                Permissions = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.Read,
                SharedAccessStartTime = DateTime.UtcNow.AddDays(-1),
                SharedAccessExpiryTime = DateTime.UtcNow.AddDays(7)
            });
            return queue.StorageUri.PrimaryUri + sharedAccessSignature;
        }
    }
}