Example #1
0
 WebInfo FindWeb(WebInfo web, string[] parts, ref int index, bool skipWildcards)
 {
     // We continue appending the current part of the path and advancing to the next one as
     // long as we succeed in resolving a web with that path. The last successful result is
     // returned and if the already the first part failed the starting web is returned.
     try {
         do
         {
             var name = parts[index];
             if (skipWildcards && name == "*")
             {
                 break;
             }
             web = GetWeb(PathUtility.JoinPath(web.Path, name));
         } while (++index < parts.Length);
     } catch {}
     return(web);
 }
Example #2
0
        // Implementation of the rest of the NavigatingConnector interface.

        public override IEnumerable <WebInfo> GetWebs(WebInfo web)
        {
            if (web == null)
            {
                throw new ArgumentNullException("web");
            }
            // I wouldn't so aggressively store the child webs but calling Get-ChildItem cmdlet
            // checks multiple times the existence of a "*" child. Because this triggers the
            // children retrieval I'd better cache them. The cache stores resolved SharePoint
            // objects by their path. I could adapt the cache to accommodate the collections of
            // children too but it was easier to utilize an internal property in the parent web
            // instance, which even performs better.
            if (web.Webs == null || !Cache.Check())
            {
                web.Webs = GetWebsDirectly(web);
            }
            return(web.Webs);
        }
Example #3
0
        public ListInfo AddList(WebInfo web, ListCreationParameters parameters)
        {
            if (web == null)
            {
                throw new ArgumentNullException("web");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            parameters.Check();
            var list = AddListDirectly(web, parameters);

            if (web.Lists != null)
            {
                web.Lists = web.Lists.Concat(new[] { list }).ToList();
            }
            return(list);
        }
Example #4
0
        public WebInfo AddWeb(WebInfo web, WebCreationParameters parameters)
        {
            if (web == null)
            {
                throw new ArgumentNullException("web");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            parameters.Check();
            var newWeb = AddWebDirectly(web, parameters);

            if (web.Webs != null)
            {
                web.Webs = web.Webs.Concat(new[] { newWeb }).ToList();
            }
            return(newWeb);
        }
Example #5
0
        // Implementation of the ModifyingConnector interface support which performs modifications
        // by calling SharePoint web services.

        protected override void RemoveWebDirectly(WebInfo web)
        {
            // A web cannot be deleted if it contains any child webs. All child webs have to be
            // deleted before the parent web. Let's get all webs on the entire site collection
            // and filter out all ancestor webs which shouldn't be deleted.
            var webUrl = PathUtility.JoinPath(Drive.WebUrl, web.Path);
            var webs   = GetAllWebs(web).Where(item => item.StartsWithCI(webUrl + "/"));

            webs = webs.Concat(new[] { webUrl });
            foreach (var child in webs.OrderByDescending(item => item.Length))
            {
                var childPath = child.Substring(webUrl.Length).TrimStart('/');
                childPath = PathUtility.JoinPath(web.Path, childPath);
                // Deleting a web site can be done by Sites.DeleteWeb() but this method is not
                // available in SharePoint 2007. Deleting  document workspace - which is actually
                // a web - is a nice alternative working on any SharePoint server version.
                Log.Verbose("Removing web at /{0}.", childPath);
                GetService <Dws>(childPath).DeleteDws();
            }
        }
Example #6
0
        ListInfo CreateListInfo(WebInfo web, XmlElement source)
        {
            var path = PathUtility.JoinPath(web.Path, GetListName(source));
            var list = new ListInfo(web, path);

            list.ID           = GetListID(source);
            list.Title        = GetListTitle(source);
            list.Created      = GetListCreated(source);
            list.LastModified = GetListLastModified(source);
            list.LastDeleted  = GetListLastDeleted(source);
            list.ItemCount    = GetListItemCount(source);
            if (HasListFields(source))
            {
                list.Fields = GetListFields(source).ToList();
            }
            if (web.ID.IsEmpty())
            {
                web.ID = GetListWebID(source);
            }
            FinalizeInfo(list, source);
            return(list);
        }
Example #7
0
 public IEnumerable<WebFolderInfo> GetWebFolders(WebInfo web)
 {
     if (web == null)
         throw new ArgumentNullException("web");
     // Web folders are artificial objects that cannot be queried by the SharePoint object
     // model. They can contain only lists and because all lists on a web can be obtained
     // we infer web folders by cutting parent container names from list relative paths.
     var names = GetAllLists(web).Select(list =>
             PathUtility.GetParentPath(list.WebRelativePath)).
         Distinct(ConfigurableComparer<string>.CaseInsensitive).Where(name => name.Any());
     return names.Select(name => InferWebFolder(web, name)).ToList();
 }
Example #8
0
 protected abstract WebFolderInfo InferWebFolder(WebInfo web, string name);
Example #9
0
 public ListInfo(WebInfo web, string path)
     : base(web, path)
 {
     if (web == null)
         throw new ArgumentNullException("web");
     Web = web;
 }
Example #10
0
 protected abstract IEnumerable <XmlElement> QueryLists(WebInfo web);
Example #11
0
 // Abstract methods to support the direct SharePoint object retrieval. They must call the
 // Finalizeinfo method so that the returned object is correctly put to the cache.
 protected abstract IEnumerable<WebInfo> GetWebsDirectly(WebInfo web);
Example #12
0
        // Abstract methods modifying the actual SharePoint objects.

        protected abstract void RemoveWebDirectly(WebInfo web);
Example #13
0
 protected abstract ListInfo AddListDirectly(WebInfo web,
                                             ListCreationParameters parameters);
Example #14
0
 public ListInfo AddList(WebInfo web, ListCreationParameters parameters)
 {
     if (web == null)
         throw new ArgumentNullException("web");
     if (parameters == null)
         throw new ArgumentNullException("parameters");
     parameters.Check();
     var list = AddListDirectly(web, parameters);
     if (web.Lists != null)
         web.Lists = web.Lists.Concat(new[] { list }).ToList();
     return list;
 }
Example #15
0
 Info GetListOrWebFolder(WebInfo web, string name)
 {
     // Direct children of a web are either web folders or lists. Although the GetAllLists
     // methods returns the same count of objects - web folders are inferred from lists
     // which are not placed directly below the web - we want to walk through objects that
     // are placed directly below the web.
     var folders = GetWebFolders(web).Cast<Info>();
     var lists = GetLists(web).Cast<Info>();
     var listOrFolder = folders.Concat(lists).FirstOrDefault(item =>
                                                                 item.Name.EqualsCI(name));
     if (listOrFolder == null)
         throw new ApplicationException("No list or web folder found.");
     return listOrFolder;
 }
Example #16
0
 protected abstract WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters);
Example #17
0
 protected abstract ListInfo AddListDirectly(WebInfo web,
                                             ListCreationParameters parameters);
Example #18
0
 XmlElement GetWebXml(WebInfo web)
 {
     return(QueryWeb(web.Path));
 }
Example #19
0
 protected override XmlElement RawAddList(WebInfo web, ListCreationParameters parameters)
 {
     Log.Verbose("Adding the list {0} to /{1}.", parameters.Name, web.Path);
     return((XmlElement)GetService <Lists>(web.Path).AddList(
                parameters.Name, parameters.Description, parameters.Template));
 }
Example #20
0
 // Implementation of the rest of the NavigatingConnector interface.
 public override IEnumerable<WebInfo> GetWebs(WebInfo web)
 {
     if (web == null)
         throw new ArgumentNullException("web");
     // I wouldn't so aggressively store the child webs but calling Get-ChildItem cmdlet
     // checks multiple times the existence of a "*" child. Because this triggers the
     // children retrieval I'd better cache them. The cache stores resolved SharePoint
     // objects by their path. I could adapt the cache to accommodate the collections of
     // children too but it was easier to utilize an internal property in the parent web
     // instance, which even performs better.
     if (web.Webs == null || !Cache.Check())
         web.Webs = GetWebsDirectly(web);
     return web.Webs;
 }
Example #21
0
 WebFolderInfo CreateWebFolderInfo(WebInfo web, string path)
 {
     var folder = new WebFolderInfo(web, path);
     folder.Title = "";
     FinalizeInfo(folder);
     return folder;
 }
Example #22
0
 protected override IEnumerable<ListInfo> GetAllLists(WebInfo web)
 {
     // The cache stores resolved SharePoint objects by their path. I could adapt the
     // cache to accommodate the collections of children too but it was easier to utilize
     // an internal property in the parent web instance, which even performs better.
     if (web.Lists == null || !Cache.Check())
         web.Lists = GetAllListsDirectly(web);
     return web.Lists;
 }
Example #23
0
 // Methods creating informational objects to be returned by the drive provider which will
 // represent particular SharePoint objects in the PowerShell space. They are responsible
 // to add the resulting object to the cache by calling the parent's FinalizeInfo.
 WebInfo CreateWebInfo(WebInfo web, XmlElement source)
 {
     var path = PathUtility.JoinPath(web.Path, GetWebName(source));
     return CreateWebInfo(path, source);
 }
Example #24
0
 protected abstract WebFolderInfo InferWebFolderDirectly(WebInfo web, string path);
Example #25
0
 WebInfo CreateWebInfo(string path, XmlElement source)
 {
     var web = new WebInfo(this, path);
     web.ID = GetWebID(source);
     web.Title = GetWebTitle(source);
     FinalizeInfo(web, source);
     return web;
 }
Example #26
0
 protected abstract IEnumerable <ListInfo> GetAllLists(WebInfo web);
Example #27
0
 protected override ListInfo AddListDirectly(WebInfo web,
                                             ListCreationParameters parameters)
 {
     return CreateListInfo(web, RawAddList(web, parameters));
 }
Example #28
0
 protected abstract WebFolderInfo InferWebFolderDirectly(WebInfo web, string path);
Example #29
0
 protected override WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters)
 {
     var path = PathUtility.JoinPath(web.Path, parameters.Name);
     return CreateWebInfo(path, RawAddWeb(web, parameters));
 }
Example #30
0
        // Methods creating informational objects to be returned by the drive provider which will
        // represent particular SharePoint objects in the PowerShell space. They are responsible
        // to add the resulting object to the cache by calling the parent's FinalizeInfo.

        WebInfo CreateWebInfo(WebInfo web, XmlElement source)
        {
            var path = PathUtility.JoinPath(web.Path, GetWebName(source));

            return(CreateWebInfo(path, source));
        }
Example #31
0
 protected override IEnumerable<ListInfo> GetAllListsDirectly(WebInfo web)
 {
     return QueryLists(web).Select(source => CreateListInfo(web, source)).ToList();
 }
Example #32
0
 // Implementation of the NavigatingConnector. Methods retrieving lists and web folders
 // can be implemented here already because of the protected abstract GetAllLists method.
 // The SharePoint object model doesn't offer getter for lists by their URL and that's why
 // even getting a single web folder or list is performed by enumerating all lists of the
 // web. Descendants are encouraged to cache the lists at least for a single PowerShell
 // operation because the GetAllLists can be called multiple times even within this class.
 public abstract IEnumerable<WebInfo> GetWebs(WebInfo web);
Example #33
0
 // Implementation of the direct object information retrieval which will be recognized in
 // the GetXxx methods below to extract concrete object properties from.
 protected override IEnumerable<XmlElement> QueryWebs(WebInfo web)
 {
     return GetWebXml(web).SelectNodes("Web").OfType<XmlElement>();
 }
Example #34
0
 WebInfo FindWeb(WebInfo web, string[] parts, ref int index, bool skipWildcards)
 {
     // We continue appending the current part of the path and advancing to the next one as
     // long as we succeed in resolving a web with that path. The last successful result is
     // returned and if the already the first part failed the starting web is returned.
     try {
         do {
             var name = parts[index];
             if (skipWildcards && name == "*")
                 break;
             web = GetWeb(PathUtility.JoinPath(web.Path, name));
         } while (++index < parts.Length);
     } catch {}
     return web;
 }
Example #35
0
 protected override XmlElement RawAddList(WebInfo web, ListCreationParameters parameters)
 {
     var target = GetWebXml(web);
     if (HasWebXml(target, parameters.Name))
         throw new ApplicationException("Web with the same name found.");
     if (HasWebFolderXml(target, parameters.Name))
         throw new ApplicationException("WebFolder with the same name found.");
     if (HasListXml(target, parameters.Name))
         throw new ApplicationException("List with the same name found.");
     var source = target.OwnerDocument.CreateElement("List");
     source.SetAttribute("ID", Guid.NewGuid().ToString("D"));
     source.SetAttribute("Name", parameters.Name);
     if (string.IsNullOrEmpty(parameters.Description))
         source.SetAttribute("Description", parameters.Description);
     source.SetAttribute("Template", parameters.Template.ToStringI());
     source.SetAttribute("Created", DateForNow);
     target.AppendChild(source);
     SaveSite(target);
     return source;
 }
Example #36
0
 protected override IEnumerable <XmlElement> QueryLists(WebInfo web)
 {
     return(GetWebXml(web).SelectNodes("List").OfType <XmlElement>());
 }
Example #37
0
 protected override XmlElement RawAddWeb(WebInfo web, WebCreationParameters parameters)
 {
     var target = GetWebXml(web);
     if (HasWebXml(target, parameters.Name))
         throw new ApplicationException("Web with the same name found.");
     if (HasWebFolderXml(target, parameters.Name))
         throw new ApplicationException("WebFolder with the same name found.");
     if (HasListXml(target, parameters.Name))
         throw new ApplicationException("List with the same name found.");
     var source = target.OwnerDocument.CreateElement("Web");
     source.SetAttribute("ID", Guid.NewGuid().ToString("D"));
     source.SetAttribute("Name", parameters.Name);
     source.SetAttribute("Title", parameters.Title);
     if (string.IsNullOrEmpty(parameters.Description))
         source.SetAttribute("Description", parameters.Description);
     source.SetAttribute("Template", parameters.Template);
     if (parameters.Language > 0)
         source.SetAttribute("Language", parameters.Language.ToStringI());
     if (parameters.Locale > 0)
         source.SetAttribute("Locale", parameters.Locale.ToStringI());
     if (parameters.CollationLocale > 0)
         source.SetAttribute("CollationLocale", parameters.CollationLocale.ToStringI());
     if (parameters.UniquePermissions.HasValue)
         source.SetAttribute("UniquePermissions",
                                         parameters.UniquePermissions.Value.ToStringI());
     if (parameters.Anonymous.HasValue)
         source.SetAttribute("Anonymous", parameters.Anonymous.Value.ToStringI());
     if (parameters.Presence.HasValue)
         source.SetAttribute("Presence", parameters.Presence.Value.ToStringI());
     source.SetAttribute("Created", DateForNow);
     target.AppendChild(source);
     SaveSite(target);
     return source;
 }
Example #38
0
 public WebFolderInfo(WebInfo web, string path) : base(web, path)
 {
     Web = web;
 }
Example #39
0
 // Implementation of the ModifyingConnector interface support which performs modifications
 // in the in-memory XML document initialized from assembly resources.
 protected override void RemoveWebDirectly(WebInfo web)
 {
     var source = GetWebXml(web);
     var parent = (XmlElement) source.ParentNode;
     source.Remove();
     SaveSite(parent);
 }
Example #40
0
 public WebInfo AddWeb(WebInfo web, WebCreationParameters parameters)
 {
     if (web == null)
         throw new ArgumentNullException("web");
     if (parameters == null)
         throw new ArgumentNullException("parameters");
     parameters.Check();
     var newWeb = AddWebDirectly(web, parameters);
     if (web.Webs != null)
         web.Webs = web.Webs.Concat(new[] { newWeb }).ToList();
     return newWeb;
 }
Example #41
0
 XmlElement GetWebXml(WebInfo web)
 {
     return QueryWeb(web.Path);
 }
Example #42
0
 // Implementation of the ModifyingConnector interface. The methods remove the existing
 // item from cache, call the descendant to perform the actual operation and/or return
 // the new object similarly to the item getting and listing methods.
 public void RemoveWeb(WebInfo web)
 {
     if (web == null)
         throw new ArgumentNullException("web");
     Cache.RemoveObject(web);
     if (web.Webs != null)
         web.Webs = web.Webs.Where(item => item.ID != web.ID).ToList();
     RemoveWebDirectly(web);
 }
Example #43
0
        protected override WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters)
        {
            var path = PathUtility.JoinPath(web.Path, parameters.Name);

            return(CreateWebInfo(path, RawAddWeb(web, parameters)));
        }
Example #44
0
 protected abstract WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters);
Example #45
0
 protected override ListInfo AddListDirectly(WebInfo web,
                                             ListCreationParameters parameters)
 {
     return(CreateListInfo(web, RawAddList(web, parameters)));
 }
Example #46
0
 protected abstract IEnumerable<ListInfo> GetAllListsDirectly(WebInfo web);
Example #47
0
 protected abstract XmlElement RawAddWeb(WebInfo web, WebCreationParameters parameters);
Example #48
0
 protected override WebFolderInfo InferWebFolder(WebInfo web, string name)
 {
     var path = PathUtility.JoinPath(web.Path, name);
     return (WebFolderInfo) Cache.GetObjectOrDefault(path) ??
         InferWebFolderDirectly(web, name);
 }
Example #49
0
 protected abstract XmlElement RawAddList(WebInfo web, ListCreationParameters parameters);
Example #50
0
 // Abstract methods modifying the actual SharePoint objects.
 protected abstract void RemoveWebDirectly(WebInfo web);
Example #51
0
        // Implementation of the rest of the NavigatingConnector interface.

        protected override IEnumerable <WebInfo> GetWebsDirectly(WebInfo web)
        {
            return(QueryWebs(web).Select(source => CreateWebInfo(web, source)).ToList());
        }
Example #52
0
        // Implementation of the NavigatingConnector. Methods retrieving lists and web folders
        // can be implemented here already because of the protected abstract GetAllLists method.
        // The SharePoint object model doesn't offer getter for lists by their URL and that's why
        // even getting a single web folder or list is performed by enumerating all lists of the
        // web. Descendants are encouraged to cache the lists at least for a single PowerShell
        // operation because the GetAllLists can be called multiple times even within this class.

        public abstract IEnumerable <WebInfo> GetWebs(WebInfo web);
Example #53
0
 protected override IEnumerable <ListInfo> GetAllListsDirectly(WebInfo web)
 {
     return(QueryLists(web).Select(source => CreateListInfo(web, source)).ToList());
 }
Example #54
0
 protected abstract WebFolderInfo InferWebFolder(WebInfo web, string name);
Example #55
0
 protected override WebFolderInfo InferWebFolderDirectly(WebInfo web, string name)
 {
     return(CreateWebFolderInfo(web, PathUtility.JoinPath(web.Path, name)));
 }
Example #56
0
 public WebFolderInfo(WebInfo web, string path)
     : base(web, path)
 {
     Web = web;
 }
Example #57
0
        // Abstract methods to support the direct SharePoint object retrieval. They must call the
        // Finalizeinfo method so that the returned object is correctly put to the cache.

        protected abstract IEnumerable <WebInfo> GetWebsDirectly(WebInfo web);