Example #1
0
        public static CSOMOperation CreateWeb(this CSOMOperation operation, string title, int?lcid, string url = "", string template = "")
        {
            operation.LogInfo($"Creating web {title}");

            url = url.IsNotNullOrEmpty() ? url : operation.NormalizeUrl(title);
            Web rootWeb = operation.DecideWeb();

            lcid = (int)((uint?)lcid ?? operation.DecideWeb().Language);

            operation.LogDebug($"Web creation information set to Title: {title}, Url: {url}, Lcid: {lcid}, Template: {template}");
            WebCreationInformation webInformation = new WebCreationInformation
            {
                Title       = title,
                Url         = url,
                WebTemplate = template,
                Language    = lcid.Value
            };

            var web = rootWeb.Webs.Add(webInformation);

            operation.LoadWebWithDefaultRetrievals(web);

            operation.SetLevel(OperationLevels.Web, web);
            operation.ActionQueue.Enqueue(new DeferredAction {
                ClientObject = web, Action = DeferredActions.Load
            });

            return(operation);
        }
Example #2
0
        public static CSOMOperation LoadList(this CSOMOperation operation, string name, Action <ClientContext, Microsoft.SharePoint.Client.List> listLoader = null)
        {
            operation.LogDebug($"Loading list {name}");

            var web  = operation.DecideWeb();
            var list = web.Lists.GetByTitle(name);

            operation.LoadListRequired(list);

            if (listLoader != null)
            {
                listLoader(operation.Context, list);
            }
            else
            {
                operation.Context.Load(list);
            }

            operation.SetLevel(OperationLevels.List, list);
            operation.ActionQueue.Enqueue(new DeferredAction {
                ClientObject = operation.LastList, Action = DeferredActions.Load
            });

            return(operation);
        }
Example #3
0
        public static CSOMOperation LoadWebByUrl(this CSOMOperation operation, string url,
                                                 params Expression <Func <Web, object> >[] retrievals)
        {
            operation.LogDebug($"Loading web with url: {url}");

            var web = operation.LastSite.OpenWebUsingPath(ResourcePath.FromDecodedUrl(url));

            return(LoadWeb(operation, web, retrievals));
        }
Example #4
0
        public static CSOMOperation LoadWeb(this CSOMOperation operation, string name,
                                            params Expression <Func <Web, object> >[] retrievals)
        {
            operation.LogDebug($"Loading web");

            var web = operation.LastSite.OpenWeb(name);

            return(LoadWeb(operation, web, retrievals));
        }
Example #5
0
        /// <summary>
        /// This method first loads all items valid for <paramref name="query"/> and then enqueue removal actions
        /// </summary>
        /// <param name="operation">Not context execution method</param>
        /// <param name="query"><see cref="CamlQuery"/> parameter used for list item selection</param>
        /// <returns></returns>
        public static CSOMOperation DeleteItems(this CSOMOperation operation, CamlQuery query)
        {
            operation.LogInfo("Deleting items");
            operation.LogDebug($"Query:\n{query}");

            var items = operation.LastList.GetItems(query);

            operation.Context.Load(items);
            operation.ActionQueue.Enqueue(new DeferredAction {
                ClientObject = items, Action = DeferredActions.Delete
            });

            return(operation);
        }
Example #6
0
        public static CSOMOperation SelectWeb(this CSOMOperation operation, string url)
        {
            var key = url.ToLower();

            operation.LogDebug($"Selecting web with url: {key}");
            if (operation.LoadedWebs.ContainsKey(key))
            {
                operation.SetLevel(OperationLevels.Web, operation.LoadedWebs[key]);
            }
            else
            {
                throw new ArgumentException($"Web with URL {key} doesn't exists");
            }

            return(operation);
        }
Example #7
0
        public static CSOMOperation LoadWeb(this CSOMOperation operation, Web web,
                                            params Expression <Func <Web, object> >[] retrievals)
        {
            operation.LogDebug($"Loading web");

            operation.Context.Load(web, retrievals.Length > 0
                                        ? retrievals
                                        : CSOMOperation.DefaultRetrievals.Web);

            operation.SetLevel(OperationLevels.Web, web);
            operation.ActionQueue.Enqueue(new DeferredAction {
                ClientObject = web, Action = DeferredActions.Load
            });

            return(operation);
        }
Example #8
0
        public static CSOMOperation LoadWebs(this CSOMOperation operation, params Expression <Func <Microsoft.SharePoint.Client.Web, object> >[] keysToLoad)      // todo add custom loader
        {
            operation.LogDebug("Loading all webs");

            var webs = operation.DecideWeb().Webs;

            operation.Context.Load(webs, CSOMOperation.DefaultRetrievals.WebCollection);

            if (keysToLoad.Length > 0)
            {
                operation.Context.Load(webs, w => w.Include(keysToLoad));
            }

            operation.ActionQueue.Enqueue(new DeferredAction {
                ClientObject = webs, Action = DeferredActions.Load
            });

            return(operation);
        }
Example #9
0
        /// <summary>
        /// Get items from the last loaded list using standard <see cref="CamlQuery"/>
        /// </summary>
        /// <param name="operation">Beware! Context executing method</param>
        /// <param name="query">Query used in GetItems method</param>
        /// <param name="retrievals"></param>
        /// <returns>Loaded list items in standard CSOM <see cref="ListItemCollection"/></returns>
        public static ListItemCollection GetItems(this CSOMOperation operation, CamlQuery query, params Expression <Func <ListItem, object> >[] retrievals)
        {
            operation.LogInfo("Getting items");
            operation.LogDebug($"Query:\n{query.ViewXml}");

            var listItems = operation.LastList.GetItems(query);

            if (retrievals != null)
            {
                operation.Context.Load(listItems, collection => collection.Include(retrievals));
            }
            else
            {
                operation.Context.Load(listItems);
            }

            operation.Execute();

            return(listItems);
        }