static void SSOMConsoleAppSample(string[] args) { var siteUrl = "http://tesla-dev:31415/"; // define fields var clientDescriptionField = new FieldDefinition { Title = "Client Description", InternalName = "dcs_ClientDescription", Group = "SPMeta2.Samples", Id = new Guid("06975b67-01f5-47d7-9e2e-2702dfb8c217"), FieldType = BuiltInFieldTypes.Note, }; var clientNumberField = new FieldDefinition { Title = "Client Number", InternalName = "dcs_ClientNumber", Group = "SPMeta2.Samples", Id = new Guid("22264486-7561-45ec-a6bc-591ba243693b"), FieldType = BuiltInFieldTypes.Number, }; // define content type var customerAccountContentType = new ContentTypeDefinition { Name = "Customer Account", Id = new Guid("ddc46a66-19a0-460b-a723-c84d7f60a342"), ParentContentTypeId = BuiltInContentTypeId.Item, Group = "SPMeta2.Samples", }; // define relationships and the model var siteModel = SPMeta2Model.NewSiteModel(site => { site .AddField(clientDescriptionField) .AddField(clientNumberField) .AddContentType(customerAccountContentType, contentType => { contentType .AddContentTypeFieldLink(clientDescriptionField) .AddContentTypeFieldLink(clientNumberField); }); }); using (var spSite = new SPSite(siteUrl)) { // deploy the model to the SharePoint site over CSOM var ssomProvisionService = new SSOMProvisionService(); ssomProvisionService.DeploySiteModel(spSite, siteModel); } }
public void Deploy_SiteModel_SSOM() { // setup url var siteUrl = ""; // create you model var siteModel = SPMeta2Model.NewSiteModel(site => { }); using (var spSite = new SPSite(siteUrl)) { // deploy site model with SharePoint Foundation SSOM API var foundationProvisionService = new SSOMProvisionService(); foundationProvisionService.DeploySiteModel(spSite, siteModel); // deploy site model with SharePoint Standard SSOM API var standardProvisionService = new StandardSSOMProvisionService(); standardProvisionService.DeploySiteModel(spSite, siteModel); } }
static void Main(string[] args) { var siteUrl = "http://portal"; var consoleUtils = new ConsoleUtils(); consoleUtils.WithSSOMContext(siteUrl, (site, web) => { // replace it with your M2 models var siteModel = default(ModelNode); var rotWebModel = default(ModelNode); // create a provision service - SSOMProvisionService or StandardSSOMProvisionService var provisionService = new SSOMProvisionService(); // little nice thing, tracing the progress consoleUtils.TraceDeploymentProgress(provisionService); // deploy! provisionService.DeploySiteModel(site, siteModel); provisionService.DeployWebModel(web, rotWebModel); }); }
private static void CreateOrUpdateSubSite(SPSite spSite, string siteName, int itemId, SPFieldUserValue director, SPFieldUserValueCollection members) { const string securityGroupNameFormat = "{0} - {1}"; string siteUrl = "user-web-" + itemId; var newWebDef = new WebDefinition { Title = siteName, Description = "", Url = siteUrl, WebTemplate = BuiltInWebTemplates.Collaboration.TeamSite }; var newWebBreakRoleInheritance = new BreakRoleInheritanceDefinition { CopyRoleAssignments = false }; var ownersGroup = new SecurityGroupDefinition { Name = string.Format(securityGroupNameFormat, siteName, Constants.SecurityGroups.OfficeOwners), Owner = director.LoginName }; var membersGroup = new SecurityGroupDefinition { Name = string.Format(securityGroupNameFormat, siteName, Constants.SecurityGroups.OfficeMembers), Owner = director.LoginName }; var visitorsGroup = new SecurityGroupDefinition { Name = string.Format(securityGroupNameFormat, siteName, Constants.SecurityGroups.OfficeVisitors), Owner = director.LoginName }; // site model with the groups var siteModel = SPMeta2Model.NewSiteModel(site => { site.AddSecurityGroup(ownersGroup); site.AddSecurityGroup(membersGroup); site.AddSecurityGroup(visitorsGroup); }); // web model var webModel = SPMeta2Model.NewWebModel(web => { web.AddWeb(newWebDef, publicProjectWeb => { publicProjectWeb.AddBreakRoleInheritance(newWebBreakRoleInheritance, newResetWeb => { // add group with owner permission newResetWeb.AddSecurityGroupLink(ownersGroup, group => { group.AddSecurityRoleLink(new SecurityRoleLinkDefinition { SecurityRoleType = BuiltInSecurityRoleTypes.Administrator }); }); // add group with contributor permission newResetWeb.AddSecurityGroupLink(membersGroup, group => { group.AddSecurityRoleLink(new SecurityRoleLinkDefinition { SecurityRoleType = BuiltInSecurityRoleTypes.Contributor }); }); // add group with reader permission newResetWeb.AddSecurityGroupLink(visitorsGroup, group => { group.AddSecurityRoleLink(new SecurityRoleLinkDefinition { SecurityRoleType = BuiltInSecurityRoleTypes.Reader }); }); }); }); }); var csomProvisionService = new SSOMProvisionService(); csomProvisionService.DeploySiteModel(spSite, siteModel); csomProvisionService.DeployWebModel(spSite.RootWeb, webModel); SPWeb existWeb = spSite.AllWebs.SingleOrDefault(w => w.Url.Contains(siteUrl)); if (existWeb == null) { return; } // add users to members group SPGroup spOwnerGroup = existWeb.SiteGroups.Cast <SPGroup>().FirstOrDefault(siteGroup => siteGroup.Name == string.Format(securityGroupNameFormat, siteName, Constants.SecurityGroups.OfficeOwners)); if (spOwnerGroup != null) { spOwnerGroup.AddUser(director.User); } SPGroup spMembersGroup = existWeb.SiteGroups.Cast <SPGroup>().FirstOrDefault(siteGroup => siteGroup.Name == string.Format(securityGroupNameFormat, siteName, Constants.SecurityGroups.OfficeMembers)); if (spMembersGroup != null) { foreach (SPFieldUserValue member in members) { spMembersGroup.AddUser(member.User); } } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { const string assembly = "SkillWillCorp.SP.Offices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f54f8a30b400bb4c"; const string eventReceiverClasss = "SkillWillCorp.SP.Offices.EventReceiver.OfficesEventReceiver"; var spWeb = properties.Feature.Parent as SPWeb; if (spWeb == null) { throw new Exception("Critical error: SPWeb is not found."); } Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Initialize fields"); var nameField = new FieldDefinition { Title = "Name", InternalName = Constants.Fields.NameFieldInternalName, Group = "SWC.Offices", Id = new Guid(Constants.Fields.NameFieldInternalNameId), AddToDefaultView = true, FieldType = BuiltInFieldTypes.Text, Required = true }; var directorField = new FieldDefinition { Title = "Director (User)", InternalName = Constants.Fields.DirectorFieldInternalName, Group = "SWC.Offices", Id = new Guid(Constants.Fields.DirectorFieldInternalNameId), AddToDefaultView = true, FieldType = BuiltInFieldTypes.User, Required = true }; var descriptionField = new FieldDefinition { Title = "Description", InternalName = "swc_Description", Group = "SWC.Offices", Id = new Guid("ADD8A4AF-0BDD-438E-886F-7767368B56FB"), AddToDefaultView = true, FieldType = BuiltInFieldTypes.Note }; var officeCodeField = new FieldDefinition { Title = "Office Code", InternalName = "swc_OfficeCode", Group = "SWC.Offices", Id = new Guid("438893A6-3D5C-4B84-86B8-C0C8D8F1183B"), AddToDefaultView = true, FieldType = BuiltInFieldTypes.Text }; var officeMembersField = new FieldDefinition { Title = "Office Members (Users)", InternalName = Constants.Fields.MembersFieldInternalName, Group = "SWC.Offices", Id = new Guid(Constants.Fields.MembersFieldInternalNameId), AddToDefaultView = true, FieldType = BuiltInFieldTypes.UserMulti, Required = true, AdditionalAttributes = new List <FieldAttributeValue>(new List <FieldAttributeValue> { new FieldAttributeValue("Mult", "TRUE") }) }; var fieldIsCopiedField = new FieldDefinition { Title = "Field is copied", InternalName = Constants.Fields.FieldIsCopiedFieldInternalName, Group = "SWC.Offices", AddToDefaultView = false, Hidden = true, Id = new Guid(Constants.Fields.FieldIsCopiedFieldInternalNameId), FieldType = BuiltInFieldTypes.Boolean }; Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Initialize Lists"); var officesList = new ListDefinition { Title = "Offices", Description = "", TemplateType = BuiltInListTemplateTypeId.GenericList, Url = "Offices", OnQuickLaunch = true }; var officesList2 = new ListDefinition { Title = "Offices2", Description = "", TemplateType = BuiltInListTemplateTypeId.GenericList, Url = "Offices2", OnQuickLaunch = true }; Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Initialize EventReceivers"); var officesEventReceiverItemAdded = new EventReceiverDefinition { Assembly = assembly, Class = eventReceiverClasss, Synchronization = BuiltInEventReceiverSynchronization.Synchronous, Type = BuiltInEventReceiverType.ItemAdded, Name = "officesEventReceiverItemAdded", SequenceNumber = 10000 }; var officesEventReceiverItemDeleted = new EventReceiverDefinition { Assembly = assembly, Class = eventReceiverClasss, Synchronization = BuiltInEventReceiverSynchronization.Synchronous, Type = BuiltInEventReceiverType.ItemDeleted, Name = "officesEventReceiverItemDeleted", SequenceNumber = 10000 }; var officesEventReceiverItemUpdated = new EventReceiverDefinition { Assembly = assembly, Class = eventReceiverClasss, Synchronization = BuiltInEventReceiverSynchronization.Synchronous, Type = BuiltInEventReceiverType.ItemUpdated, Name = "officesEventReceiverItemUpdated", SequenceNumber = 10000 }; Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Initialize site model"); var siteModel = SPMeta2Model.NewWebModel(site => { site.AddFields(new List <FieldDefinition> { nameField, directorField, descriptionField, officeCodeField, officeMembersField, fieldIsCopiedField }); }); Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Initialize web model"); var model = SPMeta2Model.NewWebModel(web => { web.AddList(officesList, list => { list.AddField(nameField); list.AddField(directorField); list.AddField(descriptionField); list.AddField(officeCodeField); list.AddField(officeMembersField); list.AddField(fieldIsCopiedField); list.AddEventReceivers(new List <EventReceiverDefinition> { officesEventReceiverItemAdded, officesEventReceiverItemUpdated, officesEventReceiverItemDeleted }); }); web.AddList(officesList2, list => { list.AddField(nameField); list.AddField(directorField); }); }); Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Initialize SSOMProvisionService"); var csomProvisionService = new SSOMProvisionService(); Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Deploy siteModel"); csomProvisionService.DeploySiteModel(spWeb.Site, siteModel); Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Deploy webModel"); csomProvisionService.DeployWebModel(spWeb, model); Logger.WriteMessage("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Create timer jobs"); CreateDeleteJob(spWeb); } catch (Exception ex) { Logger.WriteError("SkillWillCorp.SP.Offices.SkillWillCorpSPOfficesEventReceiver: Error on feature activating", ex, TraceSeverity.Unexpected); throw; } }