当前位置: 首页>>代码示例>>C#>>正文


C# ClientContext.ExecuteQueryWithExponentialRetry方法代码示例

本文整理汇总了C#中ClientContext.ExecuteQueryWithExponentialRetry方法的典型用法代码示例。如果您正苦于以下问题:C# ClientContext.ExecuteQueryWithExponentialRetry方法的具体用法?C# ClientContext.ExecuteQueryWithExponentialRetry怎么用?C# ClientContext.ExecuteQueryWithExponentialRetry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClientContext的用法示例。


在下文中一共展示了ClientContext.ExecuteQueryWithExponentialRetry方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessWebRecursively

        /// <summary>
        /// This method will recurse through a tree of Web objects
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="web"></param>
        private static void ProcessWebRecursively(ClientContext clientContext, Web web)
        {
            ProcessLibrariesInWeb(clientContext, web);

            var subWebs = web.Webs;
            clientContext.Load(subWebs);
            clientContext.ExecuteQueryWithExponentialRetry(5, 30000);

            foreach (var subWeb in subWebs)
            {
                ProcessWebRecursively(clientContext, subWeb);
            }
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:18,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            string serverUrl = "<URL>";
            String login = "<USERNAME>";
            String password = "<PASSWORD>";
            string listUrlName = "Shared%20Documents";

            using (var ctx = new ClientContext(serverUrl))
            {
                //Provide acocunt and pwd for connecting to the source
                var passWord = new SecureString();
                foreach (char c in password.ToCharArray()) passWord.AppendChar(c);
                ctx.Credentials = new SharePointOnlineCredentials(login, passWord);

                try
                {
                    int number = 0;
                    // This loop will be executed 1000 times, which will cause throttling to occur
                    while (number < 1000)
                    {
                        // Let's try to create new folder based on Ticks to the given list as an example process
                        var folder = ctx.Site.RootWeb.GetFolderByServerRelativeUrl(listUrlName);
                        ctx.Load(folder);
                        folder = folder.Folders.Add(DateTime.Now.Ticks.ToString());
                        // Extension method for executing query with throttling checks
                        ctx.ExecuteQueryWithExponentialRetry(5, 30000); //5 retries, with a base delay of 10 secs.
                        // Status indication for execution.
                        Console.WriteLine("CSOM request successful.");
                        // For loop handling.
                        number = number + 1;
                    }
                }
                catch (MaximumRetryAttemptedException mex)
                {
                    // Exception handling for the Maximum Retry Attempted
                    Console.WriteLine(mex.Message);
                }
            }
        }
开发者ID:AaronSaikovski,项目名称:PnP,代码行数:39,代码来源:Program.cs

示例3: SetUserProfileDataWithUserContext

        private static void SetUserProfileDataWithUserContext(Uri sharePointAdminUri, SyncConfiguration configuration, List<GraphApi.IUser> users)
        {
            string tenantAdminLoginName = ConfigurationManager.AppSettings["TenantAdminLogin"];
            string tenantAdminPassword = ConfigurationManager.AppSettings["TenantAdminPassword"];

            using (ClientContext clientContext = new ClientContext(sharePointAdminUri.ToString()))
            {
                //authenticate with SPOCredentials
                SecureString password = new SecureString();
                foreach (char c in tenantAdminPassword.ToCharArray()) password.AppendChar(c);
                clientContext.Credentials = new SharePointOnlineCredentials(tenantAdminLoginName, password);
                clientContext.ExecuteQuery();

                // Get the people manager instance for tenant context
                PeopleManager peopleManager = new PeopleManager(clientContext);

                foreach (GraphApi.User user in users)
                {
                    foreach (Property prop in configuration.Properties)
                    {
                        try
                        {
                            UpdateProperty(peopleManager, user, prop);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    clientContext.ExecuteQueryWithExponentialRetry(10, 30000); //implemented with throttling
                }
            }
        }
开发者ID:tandis,项目名称:PnP,代码行数:34,代码来源:Program.cs

示例4: GetAllDocumentLibrariesInWeb

        /// <summary>
        ///     Return all document libraries from specified web
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="web"></param>
        private static IEnumerable<List> GetAllDocumentLibrariesInWeb(ClientContext clientContext, Web web)
        {
            //Retrieve all lists from specified web
            var lists = web.Lists;
            clientContext.Load(lists);
            //clientContext.ExecuteQuery(); // Commented out in favor of next line and execution throttling
            clientContext.ExecuteQueryWithExponentialRetry(5, 30000); //5 retries, with a base delay of 30 secs.

            //Filter out only document libraries and append to return list collection
            var libraries = new List<List>();
            foreach (var list in lists)
            {
                if (list.BaseType.ToString() == "DocumentLibrary")
                {
                    libraries.Add(list);
                }
            }
            Console.WriteLine("The number of libraries found: " + libraries.Count);
            return libraries;
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:25,代码来源:Program.cs

示例5: ApplyRetentionPolicy

        /// <summary>
        /// This method executes a CAML query to get all old documents by content type
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="documentLibrary"></param>
        /// <param name="contentTypeName"></param>
        /// <param name="retentionPeriod"></param>
        private static void ApplyRetentionPolicy(ClientContext clientContext, List documentLibrary,
            object contentTypeId, int retentionPeriodDays)
        {
            //Calculate validation date. Any document modified before that date is considered old
            var validationDate = DateTime.Now.AddDays(-retentionPeriodDays);
            var camlDate = validationDate.ToString("yyyy-MM-ddTHH:mm:ssZ");

            //Get old documents in the library that are matching requested content type
            if (documentLibrary.ItemCount > 0)
            {
                var camlQuery = new CamlQuery();

                //This CAML query uses Content Type ID with BeginsWith.
                //You can replace with ContentType for CT Display Name, for example
                //<Eq><FieldRef Name='ContentType' /><Value Type='Computed'>{0}</Value></Eq>
                camlQuery.ViewXml = String.Format(
                    @"<View>
                        <Query>
                            <Where><And>
                                <BeginsWith><FieldRef Name='ContentTypeId'/><Value Type='ContentTypeId'>{0}</Value></BeginsWith>
                                <Lt><FieldRef Name='Modified' /><Value Type='DateTime'>{1}</Value></Lt>
                            </And></Where>
                        </Query>
                    </View>", contentTypeId, camlDate);

                var listItems = documentLibrary.GetItems(camlQuery);
                clientContext.Load(listItems,
                    items => items.Include(
                        item => item.Id,
                        item => item.DisplayName,
                        item => item.ContentType));

                //clientContext.ExecuteQuery(); // Commented out in favor of next line and execution throttling
                clientContext.ExecuteQueryWithExponentialRetry(10, 30000); //10 retries, with a base delay of 30 secs.

                foreach (var listItem in listItems)
                {
                    Console.WriteLine("Document '{0}' has been modified earlier than {1}. Retention policy will be applied.", listItem.DisplayName, validationDate);
                    ApplyRetentionActions(clientContext, listItem);
                }

                //perform Retention Actions
                clientContext.ExecuteQueryWithExponentialRetry(10, 30000);
            }
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:52,代码来源:Program.cs


注:本文中的ClientContext.ExecuteQueryWithExponentialRetry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。