private void AddGoalToPiwikAndWriteToPropertyBag(PiwikPROServiceOperations pso, bool?goalTrack, string idSite, string propBagName, string goalAction, SPPropertyBag currentBag, SPWeb webToPropertyBag) { try { // if (goalTrack != null && goalTrack == true) // { // int DocumentAddedGoalId = pso.AddGoalToPiwik(idSite, goalAction); if (currentBag.ContainsKey(propBagName) && currentBag[propBagName] != null) { if (String.IsNullOrEmpty(currentBag[propBagName])) { int DocumentAddedGoalId = pso.AddGoalToPiwik(idSite, goalAction); currentBag[propBagName] = Convert.ToString(DocumentAddedGoalId); currentBag.Update(); } // currentBag[propBagName] = Convert.ToString(DocumentAddedGoalId); // currentBag.Update(); // webToPropertyBag.Properties.Update(); // webToPropertyBag.Update(); } else { int DocumentAddedGoalId = pso.AddGoalToPiwik(idSite, goalAction); currentBag.Add(propBagName, Convert.ToString(DocumentAddedGoalId)); currentBag.Update(); } // } } catch (Exception ex) { //Logger.WriteLog(Logger.Category.Unexpected, "Piwik AddGoalToPiwikAndWriteToPropertyBag", ex.Message); } }
private static void CreateOrUpdateValueInPropertyBag(string value, SPWeb webToPropertyBag, SPPropertyBag currentBag, string propertyBagKey) { if (currentBag.ContainsKey(propertyBagKey) && currentBag[propertyBagKey] != null) { currentBag[propertyBagKey] = value; currentBag.Update(); webToPropertyBag.Properties.Update(); webToPropertyBag.Update(); } else { currentBag.Add(propertyBagKey, value); currentBag.Update(); } }
public void ExecuteEmptyTopLevelSiteRelativeUrlTest() { SPSite fakeSite = Isolate.Fake.Instance <SPSite>(Members.ReturnRecursiveFakes); Isolate.Swap.NextInstance <SPSite>().With(fakeSite); SPWeb fakeWeb = fakeSite.RootWeb.Webs.Add("", "", "", uint.MinValue, "", false, false); Isolate.WhenCalled(() => fakeWeb.Url).WillReturn("http://localhost/unittest"); SPPropertyBag fakePropertyBag = fakeWeb.Properties; CreateSubSiteActivity_Accessor target = new CreateSubSiteActivity_Accessor(); target.BusinessEvent = "unittest"; target.BusinessEventId = "1"; target.BusinessEventIdKey = "unittestid"; target.SiteCollectionUrl = "http://localhost"; target.SiteTemplateName = "testtemplate"; ActivityExecutionContext executionContext = null; ActivityExecutionStatus expected = new ActivityExecutionStatus(); expected = ActivityExecutionStatus.Closed; ActivityExecutionStatus actual; actual = target.Execute(executionContext); Isolate.Verify.WasCalledWithAnyArguments(() => fakeSite.RootWeb.Webs.Add("", "", "", uint.MinValue, "", false, false)); Isolate.Verify.WasCalledWithExactArguments(() => fakePropertyBag["unittestid"] = "1"); Isolate.Verify.WasCalledWithAnyArguments(() => fakePropertyBag.Update()); Assert.AreEqual(target.SubSiteUrl, "http://localhost/unittest"); Assert.AreEqual(expected, actual); }
protected override void ProcessRecord() { base.ProcessRecord(); using (GlymaConfiguration configuration = new GlymaConfiguration(Identity, this)) { if (string.IsNullOrEmpty(configuration.SecurityDbName) || string.IsNullOrEmpty(configuration.SecurityDbServer)) { WriteWarning("The provided site doesn't have a valid Security database server or Security database name declared. Aborting securable context creation."); return; } string connectionString = "Data Source=" + configuration.SecurityDbServer + ";Initial Catalog=" + configuration.SecurityDbName + ";Integrated Security=True"; using (SecurityDatabaseDataContext dataContext = new SecurityDatabaseDataContext(connectionString)) { SecurableContext securableContext = new SecurableContext(); securableContext.SecurableContextName = SecurableContextName; securableContext.SecurableContextUid = Guid.NewGuid(); securableContext.SiteSPID = configuration.Site.ID; dataContext.SecurableContexts.InsertOnSubmit(securableContext); dataContext.SubmitChanges(); SPPropertyBag properties = configuration.SecurityWeb.Properties; properties["Glyma.SecurableContextId"] = securableContext.SecurableContextId.ToString(); properties.Update(); configuration.SecurityWeb.Update(); } } }
protected override void ProcessRecord() { base.ProcessRecord(); SPWeb webToConfigure = GetWebFromIdentity(Identity); if (webToConfigure == null) { WriteWarning("No valid 'Identity' specified. Identity must be a SPSite, SPWeb, site/web URL, or site colleciton ID."); } string transactionDatabaseServer; if (string.IsNullOrEmpty(TransactionDatabaseServer)) { transactionDatabaseServer = DatabaseServer; } else { transactionDatabaseServer = TransactionDatabaseServer; } string securityDatabaseServer; if (string.IsNullOrEmpty(SecurityDatabaseServer)) { securityDatabaseServer = DatabaseServer; } else { securityDatabaseServer = TransactionDatabaseServer; } SPPropertyBag propertyBag = webToConfigure.Properties; propertyBag["Glyma.DatabaseServer"] = DatabaseServer; propertyBag["Glyma.DatabaseName"] = MapDatabaseName; propertyBag["Glyma.TransactionDatabaseServer"] = transactionDatabaseServer; propertyBag["Glyma.TransactionDatabaseName"] = TransactionDatabaseName; propertyBag["Glyma.SecurityDatabaseServer"] = securityDatabaseServer; propertyBag["Glyma.SecurityDatabaseName"] = SecurityDatabaseName; propertyBag["Glyma.DefaultPage"] = DefaultPageUrl; propertyBag.Update(); webToConfigure.Update(); }
/// <summary> /// Get the Blacklist Items from PropertyBag as String Array /// </summary> /// <param name="siteUrl">The Url of the Site Collection</param> /// <returns></returns> public static string[] GetBlackList(string siteUrl) { using (SPSite site = new SPSite(siteUrl)) { SPPropertyBag props = site.RootWeb.Properties; // Property is already there if (props.ContainsKey(Names.PROPBAG_BLACKLIST_KEY)) { return(props[Names.PROPBAG_BLACKLIST_KEY].Split(';')); } // Property is not set -> set it from default Value else { props.Add(Names.PROPBAG_BLACKLIST_KEY, string.Join(";", Names.BLACKLIST_DOCUMENTLIBRARIES)); props.Update(); return(Names.BLACKLIST_DOCUMENTLIBRARIES); } } }
public void ExecuteTest() { SPSite fakeSite = Isolate.Fake.Instance <SPSite>(Members.ReturnRecursiveFakes); Isolate.Swap.NextInstance <SPSite>().With(fakeSite); SPWeb fakeWeb = fakeSite.OpenWeb(); SPPropertyBag fakePropertyBag = fakeWeb.Properties; SynchronizeStatusActivity_Accessor target = new SynchronizeStatusActivity_Accessor(); target.Status = "active"; target.TargetWebUrl = "http://localhost"; ActivityExecutionContext executionContext = null; ActivityExecutionStatus expected = ActivityExecutionStatus.Closed; ActivityExecutionStatus actual; actual = target.Execute(executionContext); Isolate.Verify.WasCalledWithExactArguments(() => fakePropertyBag["Status"] = "active"); Isolate.Verify.WasCalledWithAnyArguments(() => fakePropertyBag.Update()); Assert.AreEqual(expected, actual); }
protected override void ProcessRecord() { base.ProcessRecord(); SPWeb webToConfigure = GetRootWebFromIdentity(Identity); if (webToConfigure == null) { WriteWarning("No valid 'Identity' specified. Identity must be a SPSite, SPWeb, site/web URL, or site colleciton ID."); } bool hasProjectManagerRole = false; bool hasMapManagerRole = false; bool hasAuthorRole = false; bool hasReaderRole = false; foreach (SPRoleDefinition definition in webToConfigure.RoleDefinitions) { if (definition.Name == GlymaProjectManagerRoleName) { hasProjectManagerRole = true; } if (definition.Name == GlymaMapManagerRoleName) { hasMapManagerRole = true; } if (definition.Name == GlymaAuthorRoleName) { hasAuthorRole = true; } if (definition.Name == GlymaReaderRoleName) { hasReaderRole = true; } if (hasProjectManagerRole && hasMapManagerRole && hasReaderRole && hasAuthorRole) { break; } } if (!hasProjectManagerRole) { SPRoleDefinition glymaProjectManagerRole = new SPRoleDefinition(); glymaProjectManagerRole.Name = GlymaProjectManagerRoleName; glymaProjectManagerRole.Description = "Users have access to create and modify projects in a Glyma map database."; glymaProjectManagerRole.BasePermissions = SPBasePermissions.EmptyMask; webToConfigure.RoleDefinitions.Add(glymaProjectManagerRole); } if (!hasMapManagerRole) { SPRoleDefinition glymaMapManagerRole = new SPRoleDefinition(); glymaMapManagerRole.Name = GlymaMapManagerRoleName; glymaMapManagerRole.Description = "Users have access to create and modify root maps in a Glyma Project."; glymaMapManagerRole.BasePermissions = SPBasePermissions.EmptyMask; webToConfigure.RoleDefinitions.Add(glymaMapManagerRole); } if (!hasAuthorRole) { SPRoleDefinition glymaAuthorRole = new SPRoleDefinition(); glymaAuthorRole.Name = GlymaAuthorRoleName; glymaAuthorRole.Description = "Users have access to create and modify Glyma maps."; glymaAuthorRole.BasePermissions = SPBasePermissions.EmptyMask; webToConfigure.RoleDefinitions.Add(glymaAuthorRole); } if (!hasReaderRole) { SPRoleDefinition glymaReaderRole = new SPRoleDefinition(); glymaReaderRole.Name = GlymaReaderRoleName; glymaReaderRole.Description = "Users have access to read Glyma maps."; glymaReaderRole.BasePermissions = SPBasePermissions.EmptyMask; webToConfigure.RoleDefinitions.Add(glymaReaderRole); } SPPropertyBag propertyBag = webToConfigure.Properties; propertyBag["Glyma.RolesDefined"] = "true"; propertyBag.Update(); if (!hasReaderRole || !hasAuthorRole) { webToConfigure.Update(); } }
public void Update() { m_propertyBag.Update(); }
public void AddRoleDefinitions() { bool hasProjectManagerRole = false; bool hasMapManagerRole = false; bool hasAuthorRole = false; bool hasReaderRole = false; foreach (SPRoleDefinition definition in Site.RoleDefinitions) { if (definition.Name == GlymaProjectManagerRoleName) { hasProjectManagerRole = true; } if (definition.Name == GlymaMapManagerRoleName) { hasMapManagerRole = true; } if (definition.Name == GlymaAuthorRoleName) { hasAuthorRole = true; } if (definition.Name == GlymaReaderRoleName) { hasReaderRole = true; } if (hasProjectManagerRole && hasMapManagerRole && hasReaderRole && hasAuthorRole) { break; } } if (!hasProjectManagerRole) { SPRoleDefinition glymaProjectManagerRole = new SPRoleDefinition(); glymaProjectManagerRole.Name = GlymaProjectManagerRoleName; glymaProjectManagerRole.Description = "Users have access to create and modify projects in a Glyma map database."; glymaProjectManagerRole.BasePermissions = SPBasePermissions.EmptyMask; Site.RoleDefinitions.Add(glymaProjectManagerRole); } if (!hasMapManagerRole) { SPRoleDefinition glymaMapManagerRole = new SPRoleDefinition(); glymaMapManagerRole.Name = GlymaMapManagerRoleName; glymaMapManagerRole.Description = "Users have access to create and modify root maps in a Glyma Project."; glymaMapManagerRole.BasePermissions = SPBasePermissions.EmptyMask; Site.RoleDefinitions.Add(glymaMapManagerRole); } if (!hasAuthorRole) { SPRoleDefinition glymaAuthorRole = new SPRoleDefinition(); glymaAuthorRole.Name = GlymaAuthorRoleName; glymaAuthorRole.Description = "Users have access to create and modify Glyma maps."; glymaAuthorRole.BasePermissions = SPBasePermissions.EmptyMask; Site.RoleDefinitions.Add(glymaAuthorRole); } if (!hasReaderRole) { SPRoleDefinition glymaReaderRole = new SPRoleDefinition(); glymaReaderRole.Name = GlymaReaderRoleName; glymaReaderRole.Description = "Users have access to read Glyma maps."; glymaReaderRole.BasePermissions = SPBasePermissions.EmptyMask; Site.RoleDefinitions.Add(glymaReaderRole); } SPPropertyBag propertyBag = Site.Properties; propertyBag["Glyma.RolesDefined"] = "true"; propertyBag.Update(); if (!hasReaderRole || !hasAuthorRole) { Site.Update(); } }
public override void ItemUpdated(SPItemEventProperties properties) { try { SPListItem item = properties.ListItem; if (item != null) { //check if item is master file if (properties.ListItem.File.Name.ToLower().EndsWith(".master")) { //in case of publish if (Convert.ToString(properties.AfterProperties["vti_doclibmodstat"]) == Convert.ToString((int)SPModerationStatusType.Approved)) { //in case if the list requires check out of document if (properties.List.ForceCheckout) { AddJSToMasterFileAndCheckinAndPublish(properties, true, true); } else { AddJSToMasterFileAndCheckinAndPublish(properties, false, true); } } //in case of upload new doc else { //in case if the list requires check out of document if (properties.List.ForceCheckout) { if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null) { AddJSToMasterFileAndCheckinAndPublish(properties, true, false); } } else { SPPropertyBag currentBag = item.Web.Properties; string docID = item.UniqueId.ToString(); if ((currentBag.ContainsKey(docID) && currentBag[docID] != null) || properties.ListItem.File.Versions.Count == 0) { currentBag[docID] = null; currentBag.Update(); item.Web.Update(); AddJSToMasterFileAndCheckinAndPublish(properties, false, false); } else { currentBag.Add(docID, "added"); currentBag.Update(); } } } } } } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, "Piwik ItemUpdated", ex.Message); } base.ItemUpdated(properties); }