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


C# ClientContext.ExecuteQueryRetry方法代码示例

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


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

示例1: ProvisionLists

        private static void ProvisionLists(ClientContext ctx)
        {
            Console.WriteLine("Provisioning lists:");
            Console.WriteLine("Events");
            List eventsList = ctx.Web.CreateList(ListTemplateType.Events, "Events", false, false, "Lists/Events", false);
            eventsList.CreateField(@"<Field Type=""Boolean"" DisplayName=""Registration Allowed"" ID=""{d395011d-07c9-40a5-99c2-cb4d4f209d13}"" Name=""OfficeDevPnPRegistrationAllowed""><Default>1</Default></Field>", false);
            ctx.Load(eventsList);
            ctx.ExecuteQueryRetry();

            Console.WriteLine("Event Registration");
            List regList = ctx.Web.CreateList(ListTemplateType.GenericList, "Event Registration", false, false, "Lists/Event Registration", false);
            Field field = regList.CreateField(@"<Field Type=""Lookup"" DisplayName=""Event"" ID=""{39e09239-3da4-455f-9f03-add53034de0a}"" Name=""OfficeDevPnPEventLookup"" />", false);
            ctx.Load(regList);
            ctx.Load(field);
            ctx.ExecuteQueryRetry();

            // configure event lookup field
            FieldLookup eventField = ctx.CastTo<FieldLookup>(field);
            eventField.LookupList = eventsList.Id.ToString();
            eventField.LookupField = "Title";
            eventField.Indexed = true;
            eventField.IsRelationship = true;
            eventField.RelationshipDeleteBehavior = RelationshipDeleteBehaviorType.Cascade;
            eventField.Update();
            ctx.ExecuteQueryRetry();
            // configure author field
            Field authorField = regList.Fields.GetFieldByName<Field>("Author");
            authorField.Indexed = true;
            authorField.Update();
            ctx.ExecuteQueryRetry();

            Console.WriteLine("");
        }
开发者ID:nishantpunetha,项目名称:PnP,代码行数:33,代码来源:Program.cs

示例2: DeleteFields

        // No need to have these as the engine is blocking creation and extraction of fields at web level
        #endregion

        #region Validation event handlers
        #endregion

        #region Helper methods
        private void DeleteFields(ClientContext cc)
        {
            cc.Load(cc.Web.Fields, f => f.Include(t => t.InternalName));
            cc.ExecuteQueryRetry();

            foreach (var field in cc.Web.Fields.ToList())
            {
                // First drop the fields that have 2 _'s...convention used to name the fields dependent on a lookup.
                if (field.InternalName.Replace("FLD_", "").IndexOf("_") > 0)
                {
                    if (field.InternalName.StartsWith("FLD_"))
                    {
                        field.DeleteObject();
                    }
                }
            }

            foreach (var field in cc.Web.Fields.ToList())
            {
                if (field.InternalName.StartsWith("FLD_"))
                {
                    field.DeleteObject();
                }
            }

            cc.ExecuteQueryRetry();
            
        }
开发者ID:stijnbrouwers,项目名称:PnP-Sites-Core,代码行数:35,代码来源:FieldTests.cs

示例3: CloseAllWebParts

        public static void CloseAllWebParts(ClientContext ctx, string relativePageUrl)
        {
            var webPartPage = ctx.Web.GetFileByServerRelativeUrl(relativePageUrl);
            ctx.Load(webPartPage);
            ctx.ExecuteQuery();

            if (webPartPage == null)
            {
                return;
            }

            LimitedWebPartManager limitedWebPartManager = webPartPage.GetLimitedWebPartManager(PersonalizationScope.Shared);
            ctx.Load(limitedWebPartManager.WebParts, wps => wps.Include(wp => wp.WebPart.Title));
            ctx.ExecuteQueryRetry();

            if (limitedWebPartManager.WebParts.Count >= 0)
            {
                for (int i = 0; i < limitedWebPartManager.WebParts.Count; i++)
                {
                    limitedWebPartManager.WebParts[i].CloseWebPart();
                    limitedWebPartManager.WebParts[i].SaveWebPartChanges();
                }
                ctx.ExecuteQuery();
            }
        }
开发者ID:Rtoribiog,项目名称:PnP-Transformation,代码行数:25,代码来源:SetupManager.cs

示例4: Launch

        // ===========================================================================================================
        /// <summary>
        /// Launches the current sequence by executing all it's templates 
        /// </summary>
        /// <param name="credentials">The credentials required for creating the client context</param>
        /// <param name="templateProvider">The <b>XMLTemplatePRovider</b> that is mapped to the client's working directory</param>
        // ===========================================================================================================
        public void Launch(ICredentials credentials, XMLTemplateProvider templateProvider)
        {
            if(!this.Ignore)
            {
                logger.Info("Launching sequence '{0}' ({1})", this.Name, this.Description);

                using (ClientContext ctx = new ClientContext(this.WebUrl))
                {
                    // --------------------------------------------------
                    // Sets the context with the provided credentials
                    // --------------------------------------------------
                    ctx.Credentials = credentials;
                    ctx.RequestTimeout = Timeout.Infinite;

                    // --------------------------------------------------
                    // Loads the full web for futur references (providers)
                    // --------------------------------------------------
                    Web web = ctx.Web;
                    ctx.Load(web);
                    ctx.ExecuteQueryRetry();

                    // --------------------------------------------------
                    // Launches the templates
                    // --------------------------------------------------
                    foreach (Template template in this.Templates)
                    {
                        template.Apply(web, templateProvider);
                    }
                }
            }
            else
            {
                logger.Info("Ignoring sequence '{0}' ({1})", this.Name, this.Description);
            }
        }
开发者ID:coupalm,项目名称:PnP,代码行数:42,代码来源:Sequence.cs

示例5: IsWebPartOnPage

        public static bool IsWebPartOnPage(ClientContext ctx, string relativePageUrl, string title)
        {
            var webPartPage = ctx.Web.GetFileByServerRelativeUrl(relativePageUrl);
            ctx.Load(webPartPage);
            ctx.ExecuteQuery();

            if (webPartPage == null)
            {
                return false;
            }

            LimitedWebPartManager limitedWebPartManager = webPartPage.GetLimitedWebPartManager(PersonalizationScope.Shared);
            ctx.Load(limitedWebPartManager.WebParts, wps => wps.Include(wp => wp.WebPart.Title));
            ctx.ExecuteQueryRetry();

            if (limitedWebPartManager.WebParts.Count >= 0)
            {
                for (int i = 0; i < limitedWebPartManager.WebParts.Count; i++)
                {
                    WebPart oWebPart = limitedWebPartManager.WebParts[i].WebPart;
                    if (oWebPart.Title.Equals(title, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:Rtoribiog,项目名称:PnP-Transformation,代码行数:29,代码来源:SetupManager.cs

示例6: AddPublishingPage

        public static void AddPublishingPage(PublishingPage page, ClientContext ctx, Web web)
        {
            SPPublishing.PublishingPage publishingPage = web.GetPublishingPage(page.FileName + ".aspx");

            RemovePublishingPage(publishingPage, page, ctx, web);

            web.AddPublishingPage(page.FileName, page.Layout, page.Title, false); //DO NOT Publish here or it will fail if library doesn't enable Minor versions (PnP bug)

            publishingPage = web.GetPublishingPage(page.FileName + ".aspx");

            Microsoft.SharePoint.Client.File pageFile = publishingPage.ListItem.File;
            pageFile.CheckOut();

            if (page.Properties != null && page.Properties.Count > 0)
            {
                ctx.Load(pageFile, p => p.Name, p => p.CheckOutType); //need these values in SetFileProperties
                ctx.ExecuteQuery();
                pageFile.SetFileProperties(page.Properties, false);
            }

            if (page.WebParts != null && page.WebParts.Count > 0)
            {
                Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr = pageFile.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);

                ctx.Load(mgr);
                ctx.ExecuteQuery();

                AddWebpartsToPublishingPage(page, ctx, mgr);
            }

            List pagesLibrary = publishingPage.ListItem.ParentList;
            ctx.Load(pagesLibrary);
            ctx.ExecuteQueryRetry();

            ListItem pageItem = publishingPage.ListItem;
            web.Context.Load(pageItem, p => p.File.CheckOutType);
            web.Context.ExecuteQueryRetry();            

            if (pageItem.File.CheckOutType != CheckOutType.None)
            {
                pageItem.File.CheckIn(String.Empty, CheckinType.MajorCheckIn);
            }

            if (page.Publish && pagesLibrary.EnableMinorVersions)
            {
                pageItem.File.Publish(String.Empty);
                if (pagesLibrary.EnableModeration)
                {
                    pageItem.File.Approve(String.Empty);
                }
            }


            if (page.WelcomePage)
            {
                SetWelcomePage(web, pageFile);
            }

            ctx.ExecuteQuery();
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:60,代码来源:PageHelper.cs

示例7: DeleteContentTypes

        private void DeleteContentTypes(ClientContext cc)
        {
            // Drop the content types
            cc.Load(cc.Web.ContentTypes, f => f.Include(t => t.Name));
            cc.ExecuteQueryRetry();

            foreach (var ct in cc.Web.ContentTypes.ToList())
            {
                if (ct.Name.StartsWith("CT_"))
                {
                    ct.DeleteObject();
                }
            }
            cc.ExecuteQueryRetry();

            // Drop the fields
            DeleteFields(cc);
        }
开发者ID:s-KaiNet,项目名称:PnP-Sites-Core,代码行数:18,代码来源:ContentTypeTests.cs

示例8: Initialize

        public void Initialize()
        {
            ctx = new ClientContext(Settings.Default.WebUrl);
            ctx.Credentials = new SharePointOnlineCredentials(Settings.Default.UserName, ProvisioningHelper.GetPasswordFromString(Settings.Default.Password));

            // Load web
            web = ctx.Web;
            ctx.Load(web);
            ctx.ExecuteQueryRetry();
        }
开发者ID:IvanParedes365,项目名称:PnP,代码行数:10,代码来源:ProvisioningHelperTest.cs

示例9: ProvisionDocumentLibraryRibbonExtensions

        static void ProvisionDocumentLibraryRibbonExtensions(ClientContext ctx)
        {
            Console.WriteLine("Provisioning document library ribbon extensions...");
            Console.WriteLine("> Registering custom actions");
            string ribbonFileName = @"Assets\document-library-ribbon.xml";
            bool isAdded = ctx.Site.AddCustomAction(new OfficeDevPnP.Core.Entities.CustomActionEntity
            {
                Name = "OfficeDevPnP Document Library Ribbon Extensions",
                Description = "OfficeDevPnP Document Library Ribbon Extensions",
                Location = "CommandUI.Ribbon",
                RegistrationId = "101",
                RegistrationType = UserCustomActionRegistrationType.List,
                CommandUIExtension = System.IO.File.ReadAllText(ribbonFileName)
            });
            ctx.ExecuteQueryRetry();

            Console.WriteLine("> Registering JSLink for script loader");
            ctx.Site.AddJsBlock("OfficeDevPnP.Core.ScriptLoader", @"
    Type.registerNamespace('OfficeDevPnP');
    Type.registerNamespace('OfficeDevPnP.Core');
    OfficeDevPnP.Core.loadScript = function (url, callback) {
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.src = url;

        // Attach handlers for all browsers 
        var done = false;
        script.onload = script.onreadystatechange = function () {
            if (!done && (!this.readyState
                                            || this.readyState == 'loaded'
                                            || this.readyState == 'complete')) {
                done = true;

                // Continue your code 
                callback();
                // Handle memory leak in IE 
                script.onload = script.onreadystatechange = null;
                head.removeChild(script);
            }
        };
        head.appendChild(script);
    }
", 1);

            Console.WriteLine("> Registering JSLink for ribbonmanager");
            ctx.Load(ctx.Web);
            ctx.ExecuteQueryRetry();
            string jsRibbonManagerUrl = ctx.Web.ServerRelativeUrl + "/SiteAssets/js/ribbonmanager.js";
            ctx.Site.AddJsLink("OfficeDevPnP.Core.RibbonManager", jsRibbonManagerUrl, 10);

            ctx.ExecuteQueryRetry();

            Console.WriteLine("Completed.");
            Console.WriteLine("");
        }
开发者ID:coupalm,项目名称:PnP,代码行数:55,代码来源:Program.cs

示例10: Initialize

        public void Initialize()
        {
            clientContext = TestCommon.CreateClientContext();

            _key = "TEST_KEY_" + DateTime.Now.ToFileTime();
            _value_string = "TEST_VALUE_" + DateTime.Now.ToFileTime();

            // Activate sideloading in order to test apps
            clientContext.Load(clientContext.Site, s => s.Id);
            clientContext.ExecuteQueryRetry();
            clientContext.Site.ActivateFeature(OfficeDevPnP.Core.Constants.APPSIDELOADINGFEATUREID);
        }
开发者ID:stijnbrouwers,项目名称:PnP-Sites-Core,代码行数:12,代码来源:WebExtensionsTests.cs

示例11: VerifyDocLib

        // This function will be triggered based on the schedule you have set for this WebJob
        public static void VerifyDocLib()
        {
            var url = ConfigurationManager.AppSettings["SpUrl"].ToString();
            var user = ConfigurationManager.AppSettings["SpUserName"].ToString();
            var pw = ConfigurationManager.AppSettings["SpPassword"].ToString();
            using (PnPMonitoredScope p = new PnPMonitoredScope())
            {
                p.LogInfo("Gathering connect info from web.config");
                p.LogInfo("SharePoint url is " + url);
                p.LogInfo("SharePoint user is " + user);
                try
                {
                    ClientContext cc = new ClientContext(url);
                    cc.AuthenticationMode = ClientAuthenticationMode.Default;
                    cc.Credentials = new SharePointOnlineCredentials(user, GetPassword(pw));
                    using (cc)
                    {
                        if (cc != null)
                        {
                            string listName = "Site Pages";
                            p.LogInfo("This is what a Monitored Scope log entry looks like in PNP, more to come as we try to validate a lists existence.");
                            p.LogInfo("Connect to Sharepoint");
                            ListCollection lists = cc.Web.Lists;
                            IEnumerable<List> results = cc.LoadQuery<List>(lists.Where(lst => lst.Title == listName));
                            p.LogInfo("Executing query to find the Site Pages library");
                            cc.ExecuteQuery();
                            p.LogInfo("Query Executed successfully.");
                            List list = results.FirstOrDefault();
                            if (list == null)
                            {
                                p.LogError("Site Pages library not found.");
                            }
                            else
                            {
                                p.LogInfo("Site Pages library found.");

                                ListItemCollection items = list.GetItems(new CamlQuery());
                                cc.Load(items, itms => itms.Include(item => item.DisplayName));
                                cc.ExecuteQueryRetry();
                                string pgs = "These pages were found, " + string.Join(", ", items.Select(x => x.DisplayName));
                                p.LogInfo(pgs);
                            }
                        }
                    }

                }
                catch (System.Exception ex)
                {
                    p.LogInfo("We had a problem: " + ex.Message);
                }
            }
        }
开发者ID:tandis,项目名称:PnP,代码行数:53,代码来源:Functions.cs

示例12: DeleteListsImplementation

        private static void DeleteListsImplementation(ClientContext cc)
        {
            cc.Load(cc.Web.Lists, f => f.Include(t => t.Title));
            cc.ExecuteQueryRetry();

            foreach (var list in cc.Web.Lists.ToList())
            {
                if (list.Title.StartsWith("LI_"))
                {
                    list.DeleteObject();
                }
            }
            cc.ExecuteQueryRetry();
        }
开发者ID:s-KaiNet,项目名称:PnP-Sites-Core,代码行数:14,代码来源:FilesTests.cs

示例13: Initialize

        public void Initialize()
        {
            clientContext = TestCommon.CreateClientContext();

            documentLibrary = clientContext.Web.GetListByTitle(DocumentLibraryName);

            if (documentLibrary == null)
            {
                documentLibrary = clientContext.Web.CreateList(ListTemplateType.DocumentLibrary, DocumentLibraryName, false);
            }

            clientContext.Load(documentLibrary.RootFolder.Folders);
            clientContext.ExecuteQueryRetry();
            foreach (Folder existingFolder in documentLibrary.RootFolder.Folders)
            {
                if (string.Equals(existingFolder.Name, FolderName, StringComparison.InvariantCultureIgnoreCase))
                {
                    folder = existingFolder;
                    break;
                }
            }

            if (folder == null)
            {
                folder = documentLibrary.RootFolder.CreateFolder(FolderName);
            }

            var fci = new FileCreationInformation();
            fci.Content = System.IO.File.ReadAllBytes(TestFilePath1);
            fci.Url = folder.ServerRelativeUrl + "/office365.png";
            fci.Overwrite = true;

            file = folder.Files.Add(fci);
            clientContext.Load(file);
            clientContext.ExecuteQueryRetry();
        }
开发者ID:LiyeXu,项目名称:PnP-Sites-Core,代码行数:36,代码来源:FileFolderExtensionsTests.cs

示例14: Initialize

        public void Initialize()
        {
            clientContext = TestCommon.CreateClientContext();

            documentLibrary = clientContext.Web.CreateList(ListTemplateType.DocumentLibrary, DocumentLibraryName, false);
            folder = documentLibrary.RootFolder.CreateFolder(FolderName);

            var fci = new FileCreationInformation();
            fci.Content = System.IO.File.ReadAllBytes(TestFilePath1);
            fci.Url = folder.ServerRelativeUrl + "/office365.png";
            fci.Overwrite = true;

            file = folder.Files.Add(fci);
            clientContext.Load(file);
            clientContext.ExecuteQueryRetry();
        }
开发者ID:ipbhattarai,项目名称:PnP,代码行数:16,代码来源:FileFolderExtensionsTests.cs

示例15: ProvisionSiteAssets

        static void ProvisionSiteAssets(ClientContext ctx)
        {
            Console.WriteLine("Provisioning files to SiteAssets library...");

            List listSiteAssets = ctx.Web.GetListByUrl("SiteAssets");
            ctx.Load(listSiteAssets);
            ctx.Load(listSiteAssets.RootFolder);
            ctx.ExecuteQueryRetry();

            string localAssetsFolderPath = @"Assets\SiteAssets\";
            System.IO.DirectoryInfo dirAssets = new System.IO.DirectoryInfo(localAssetsFolderPath);
            UploadFilesToLibrary(ctx, listSiteAssets.RootFolder, dirAssets);

            Console.WriteLine("Completed.");
            Console.WriteLine("");
        }
开发者ID:coupalm,项目名称:PnP,代码行数:16,代码来源:Program.cs


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