public void NodeEvent_OverriddenCreating() { if (ActiveSchema.NodeTypes[EventTestNode.DefaultNodeTypeName] == null) { ContentTypeInstaller.InstallContentType(EventTestNode.ContentTypeDefinition); } _eventLog = new StringBuilder(); Node node = NodeType.CreateInstance(EventTestNode.DefaultNodeTypeName, _testRoot); node.Creating += new CancellableNodeEventHandler(Node_OverriddenCreating); try { node.Save(); } catch (CancelNodeEventException e) { LogEvent(e.Data["CancelMessage"].ToString()); } node.Index = 12; node.Save(); node.Creating -= new CancellableNodeEventHandler(Node_OverriddenCreating); string expectedLog = String.Concat("Index cannot be 0", Environment.NewLine, "Node_OverriddenCreating", Environment.NewLine); Assert.IsTrue(_eventLog.ToString() == expectedLog); }
public void NodeEvent_CreatingModifying() { ContentType.GetByName("Folder"); Node node = NodeType.CreateInstance("Folder", _testRoot); node.Creating += new CancellableNodeEventHandler(Node_Creating); node.Created += new EventHandler <NodeEventArgs>(Node_Created); node.Modifying += new CancellableNodeEventHandler(Node_Modifying); node.Modified += new EventHandler <NodeEventArgs>(Node_Modified); _eventLog = new StringBuilder(); TestObserver.ResetLog(); node.Save(); node.Index = 2; node.Save(); node.Creating -= new CancellableNodeEventHandler(Node_Creating); node.Created -= new EventHandler <NodeEventArgs>(Node_Created); node.Modifying -= new CancellableNodeEventHandler(Node_Modifying); node.Modified -= new EventHandler <NodeEventArgs>(Node_Modified); string cr = Environment.NewLine; string expectedLog = String.Concat("Node_Creating", cr, "Node_Created", cr, "Node_Modifying", cr, "Node_Modified", cr); string expectedStaticLog = String.Concat("TestObserver.OnNodeCreating", cr, "TestObserver.OnNodeCreated", cr, "TestObserver.OnNodeModifying", cr, "TestObserver.OnNodeModified", cr); Assert.IsTrue(_eventLog.ToString() == expectedLog, "#1"); Assert.IsTrue(TestObserver.GetLog() == expectedStaticLog, "#2"); }
public static void Initialize(TestContext tc) { var node = Node.LoadNode(TestRootPath); if (node == null) { node = NodeType.CreateInstance("SystemFolder", Node.LoadNode("/Root")); node.Name = TestRootName; node.Save(); } }
protected void BtnEdit_Click(object sender, EventArgs e) { var templateName = (sender as Button).CommandArgument; var contextNode = PortalContext.Current.ContextNode; var templateNode = contextNode.GetReference <Node>(string.Concat(templateName, "Page")); var templateNodePath = templateNode.Path; if (templateNodePath.Contains("System/SystemPlugins")) { var targetPath = RepositoryPath.Combine(contextNode.Path, "configuration"); if (!Node.Exists(targetPath)) { var folder = new Folder(contextNode, "Folder") { Name = "configuration", DisplayName = "Configuration" }; folder.Save(); } var wcd = NodeType.CreateInstance("WebContentDemo", Node.LoadNode(targetPath)); wcd["Name"] = templateNode["Name"]; wcd["DisplayName"] = templateNode["DisplayName"]; wcd["Subtitle"] = templateNode["Subtitle"]; wcd["Body"] = templateNode["Body"]; wcd.Save(); templateNodePath = wcd.Path; contextNode.SetReference(string.Concat(templateName, "Page"), wcd); contextNode.Save(); } Response.Redirect(ActionFramework.GetActionUrl(templateNodePath, "EditSurveyTemplate", PortalContext.Current.BackUrl)); }
private static void CreateContentRecursive(Content sourceContent, Node targetContainer) { var sourceNode = sourceContent.ContentHandler; var alreadyExisting = Node.LoadNode(targetContainer.Path + "/" + sourceNode.Name); if (alreadyExisting != null && alreadyExisting.NodeType.Name != sourceNode.NodeType.Name) { throw new Exception("The target node already exists with a different type."); } var target = alreadyExisting ?? NodeType.CreateInstance(sourceNode.NodeType.Name, targetContainer); target.Name = sourceNode.Name; target.DisplayName = sourceNode.DisplayName; target.Index = sourceNode.Index; target.NodeOperation = NodeOperation.TemplateChildCopy; var targetContent = Content.Create(target); //We do not want to set the current user here but the user we 'inherited' //from the parent (the template). In case of user profiles (my site) the //creator will be the user itself. var realCreatorUser = targetContainer.CreatedBy; var realModifierUser = targetContainer.ModifiedBy; var now = DateTime.UtcNow; target.CreatedBy = realCreatorUser; target.VersionCreatedBy = realCreatorUser; target.ModificationDate = now; target.ModifiedBy = realModifierUser; target.VersionModificationDate = now; target.VersionModifiedBy = realModifierUser; foreach (var propertyType in sourceNode.PropertyTypes.Where(pt => !pt.IsContentListProperty)) { switch (propertyType.DataType) { case DataType.Binary: var sourceBinaryData = sourceNode.GetBinary(propertyType); var targetBinaryData = new BinaryData(); targetBinaryData.CopyFrom(sourceBinaryData); target.SetBinary(propertyType.Name, targetBinaryData); break; //case DataType.Reference: // break; default: target[propertyType] = sourceNode[propertyType]; break; } } // Iterate through content list fields and set their value on the target node separately. // This is needed because the same content list fields may have a different property name // (e.g. #String_0 and #String_1) in the source and target content lists. foreach (var field in sourceContent.Fields.Values.Where(f => f.Name.StartsWith("#"))) { // this should give us the name of the source property (e.g. #String_0) var sourcePropertyName = field.FieldSetting.Bindings.FirstOrDefault(); if (string.IsNullOrEmpty(sourcePropertyName)) { continue; } // this should give us the name of the target property (e.g. #String_1) var targetPropertyName = targetContent.Fields[field.Name].FieldSetting.Bindings.FirstOrDefault(); if (string.IsNullOrEmpty(targetPropertyName)) { continue; } if (field is BinaryField) { var sourceBinaryData = sourceNode.GetBinary(sourcePropertyName); var targetBinaryData = new BinaryData(); targetBinaryData.CopyFrom(sourceBinaryData); target.SetBinary(targetPropertyName, targetBinaryData); } else { target[targetPropertyName] = sourceNode[sourcePropertyName]; } } //workaround for content lists: content list type needs to be refreshed var contentList = target as ContentList; if (contentList != null) { contentList.ContentListDefinition = contentList.ContentListDefinition; } target.Save(); // inherit explicit permissions from template using (new SystemAccount()) { foreach (SecurityEntry se in sourceNode.Security.GetExplicitEntries()) { target.Security.SetPermissions(se.PrincipalId, se.Propagates, se.PermissionValues); } } //This is to make sure that only those children are copied //that are really under this content. E.g. SmartFolder may //contain real children and queried children too. foreach (var childNode in sourceNode.PhysicalChildArray.Where(ch => ch.InFolder(sourceNode.Path))) { CreateContentRecursive(Content.Create(childNode), target); } }
private static void CreateContentRecursive(Node sourceNode, Node targetContainer) { var target = NodeType.CreateInstance(sourceNode.NodeType.Name, targetContainer); target.Name = sourceNode.Name; target.DisplayName = sourceNode.DisplayName; target.Index = sourceNode.Index; target.NodeOperation = NodeOperation.TemplateChildCopy; //We do not want to set the current user here but the user we 'inherited' //from the parent (the template). In case of user profiles (my site) the //creator will be the user itself. var realCreatorUser = targetContainer.CreatedBy; var realModifierUser = targetContainer.ModifiedBy; var now = DateTime.Now; target.NodeCreationDate = now; target.NodeCreatedBy = realCreatorUser; target.CreationDate = now; target.CreatedBy = realCreatorUser; target.NodeModificationDate = now; target.NodeModifiedBy = realModifierUser; target.ModificationDate = now; target.ModifiedBy = realModifierUser; foreach (var propertyType in sourceNode.PropertyTypes) { switch (propertyType.DataType) { case DataType.Binary: var sourceBinaryData = sourceNode.GetBinary(propertyType); var targetBinaryData = new BinaryData(); targetBinaryData.CopyFrom(sourceBinaryData); target.SetBinary(propertyType.Name, targetBinaryData); break; //case DataType.Reference: // break; default: target[propertyType] = sourceNode[propertyType]; break; } } //workaround for content lists: content list type needs to be refreshed var contentList = target as ContentList; if (contentList != null) { contentList.ContentListDefinition = contentList.ContentListDefinition; } target.Save(); // inherit explicit permissions from template using (new SystemAccount()) { foreach (SecurityEntry se in sourceNode.Security.GetExplicitEntries()) { target.Security.SetPermissions(se.PrincipalId, se.Propagates, se.PermissionValues); } } foreach (var childNode in sourceNode.PhysicalChildArray) { CreateContentRecursive(childNode, target); } }