示例#1
0
        public static WebCreationParameters Create(string name, NewWebParameters parameters)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            var created = new WebCreationParameters {
                Name     = name, Title = parameters.Title, Description = parameters.Description,
                Template = parameters.Template, Language = parameters.Language,
                Locale   = parameters.Locale, CollationLocale = parameters.CollationLocale,
            };

            if (parameters.UniquePermissions.IsPresent)
            {
                created.UniquePermissions = parameters.UniquePermissions;
            }
            if (parameters.Anonymous.IsPresent)
            {
                created.Anonymous = parameters.Anonymous;
            }
            if (parameters.Presence.IsPresent)
            {
                created.Presence = parameters.Presence;
            }
            return(created);
        }
示例#2
0
        protected override XmlElement RawAddWeb(WebInfo web, WebCreationParameters parameters)
        {
            var name = web.Name;

            if (string.IsNullOrEmpty(name))
            {
                name = parameters.Title;
            }
            var title = web.Title;

            if (string.IsNullOrEmpty(title))
            {
                title = name;
            }
            Log.Verbose("Adding the web {0} to /{1}.", name, web.Path);
            var result = GetService <Sites>(web.Path).CreateWeb(
                name, title, parameters.Description, parameters.Template,
                parameters.Language, parameters.Language > 0,
                parameters.Locale, parameters.Locale > 0,
                parameters.CollationLocale, parameters.CollationLocale > 0,
                parameters.UniquePermissions.GetValueOrDefault(),
                parameters.UniquePermissions.HasValue,
                parameters.Anonymous.GetValueOrDefault(), parameters.Anonymous.HasValue,
                parameters.Presence.GetValueOrDefault(), parameters.Presence.HasValue);

            return(QueryWeb(PathUtility.JoinPath(web.Path, parameters.Name)));
        }
示例#3
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);
        }
示例#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);
        }
示例#5
0
文件: Info.cs 项目: prantlf/SharePosh
 public WebInfo AddWeb(WebCreationParameters parameters)
 {
     return Connector.GetModifying().AddWeb(this, parameters);
 }
示例#6
0
 protected abstract WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters);
示例#7
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;
 }
示例#8
0
 public WebInfo AddWeb(WebCreationParameters parameters)
 {
     return(Connector.GetModifying().AddWeb(this, parameters));
 }
示例#9
0
        // Item creation

        protected override void NewItem(string path, string itemTypeName, object newItemValue)
        {
            EnsureLog();
            path = PathUtility.NormalizePath(path);
            if (ShouldProcess(path, "New Item"))
            {
                string name;
                var    parent = PathUtility.GetParentPath(path, out name);
                var    target = GetObject(parent);
                // The type of the parameters object returned by the NewItemDynamicParameters
                // method decides the type of the object that is going to be created.
                Info added;
                var  webParameters = DynamicParameters as NewWebParameters;
                if (webParameters != null)
                {
                    var web = target as WebInfo;
                    if (web == null)
                    {
                        throw new ApplicationException("Parent cannot contain a web.");
                    }
                    added = web.AddWeb(WebCreationParameters.Create(name, webParameters));
                }
                else
                {
                    var listParameters = DynamicParameters as NewListParameters;
                    if (listParameters != null)
                    {
                        var listContainer = target as ListContainerInfo;
                        if (listContainer == null)
                        {
                            throw new ApplicationException("Parent cannot contain a list.");
                        }
                        added = listContainer.AddList(
                            ListCreationParameters.Create(name, listParameters));
                    }
                    else
                    {
                        var itemContainer = target as ItemContainerInfo;
                        if (itemContainer == null)
                        {
                            throw new ApplicationException("Parent cannot contain an item.");
                        }
                        var folderParameters = DynamicParameters as NewFolderParameters;
                        if (folderParameters != null)
                        {
                            added = itemContainer.AddFolder(name);
                        }
                        else
                        {
                            var fileParameters = DynamicParameters as NewFileParameters;
                            if (fileParameters != null)
                            {
                                var contentContainer = target as ContentContainerInfo;
                                if (contentContainer == null)
                                {
                                    throw new ApplicationException(
                                              "Parent cannot contain a file.");
                                }
                                newItemValue = newItemValue.GetBaseObject();
                                using (var content = GetContent(newItemValue, fileParameters))
                                    added = contentContainer.AddFile(name, content);
                            }
                            else
                            {
                                var itemParameters = (NewItemParameters)DynamicParameters;
                                added = itemContainer.AddItem(name);
                            }
                        }
                    }
                }
                WriteItemObject(added);
            }
        }
示例#10
0
 protected abstract XmlElement RawAddWeb(WebInfo web, WebCreationParameters parameters);
示例#11
0
        protected override WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters)
        {
            var path = PathUtility.JoinPath(web.Path, parameters.Name);

            return(CreateWebInfo(path, RawAddWeb(web, parameters)));
        }
示例#12
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;
 }
示例#13
0
 protected override WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters)
 {
     var path = PathUtility.JoinPath(web.Path, parameters.Name);
     return CreateWebInfo(path, RawAddWeb(web, parameters));
 }
示例#14
0
 protected abstract XmlElement RawAddWeb(WebInfo web, WebCreationParameters parameters);
示例#15
0
 protected abstract WebInfo AddWebDirectly(WebInfo web, WebCreationParameters parameters);
示例#16
0
 public static WebCreationParameters Create(string name, NewWebParameters parameters)
 {
     if (name == null)
         throw new ArgumentNullException("name");
     if (parameters == null)
         throw new ArgumentNullException("parameters");
     var created = new WebCreationParameters {
         Name = name, Title = parameters.Title, Description = parameters.Description,
         Template = parameters.Template, Language = parameters.Language,
         Locale = parameters.Locale, CollationLocale = parameters.CollationLocale,
     };
     if (parameters.UniquePermissions.IsPresent)
         created.UniquePermissions = parameters.UniquePermissions;
     if (parameters.Anonymous.IsPresent)
         created.Anonymous = parameters.Anonymous;
     if (parameters.Presence.IsPresent)
         created.Presence = parameters.Presence;
     return created;
 }