Hi,
I'll give you a quick run through, if you want to know more then let me know:
Basically every node that can synchronise implements this interface
public interface ISynchronisable
{
void Synchronise(Section updateSection, IContent content);
void SynchroniseSection(Section newSection);
}
Our IContent interface is simply a marker interface to tag content and not as defined as the one on svn:
public interface IContent
{
int Id { get; set; }
}
Then each module implements it's own concrete implementation:
Then in the BaseModule we had:
protected virtual void SynchroniseContent(IContent content)
{
if ((!(this is ISynchronisable)) || (Section.Node == null) || (!Section.Node.CanSynchronise) || (!Section.Synchronised) || (Section.Node.ChildNodes.Count == 0))
return;
foreach (Node childNode in Section.Node.ChildNodes)
{
if (childNode.ShowInNavigation)
{
Section updateSection = childNode.GetSectionByModuleAndTitle(Section);
if (updateSection != null)
((ISynchronisable)this).Synchronise(updateSection, content);
}
if (childNode.ChildNodes.Count > 0)
SynchroniseChildNodes(childNode.ChildNodes, content);
}
}
protected virtual void SynchroniseChildNodes(IList childNodes, IContent content)
{
if (!(this is ISynchronisable))
return;
foreach (Node childNode in childNodes)
{
if (childNode.ShowInNavigation)
{
Section updateSection = childNode.GetSectionByModuleAndTitle(Section);
if (updateSection != null)
((ISynchronisable)this).Synchronise(updateSection, content);
}
if (childNode.ChildNodes.Count > 0)
SynchroniseChildNodes(childNode.ChildNodes, content);
}
}
Then whenever content is saved in a module it calls the base method passing in the new content like so:
SynchroniseContent(content);
and it replciates to all child nodes
We had to add the if(childNode.ShowInNavigation) conditional statement because the Closerdiets site has grown to such a size that an update to a section was causing SqlTimeOuts!! This was our best way round it.
As far as cloning nodes goes, we made node, section and any content that needs to be copied impliment IClonable to return a deep copy.
The user picks the node they want to clone from a modable window that is displayed when the user is in the NodeEdit.aspx page.
Then the following code runs:
[Transaction(TransactionMode.RequiresNew)]
public Node CloneNode(Node parentNode, Node nodeToClone, string newNodeTitle)
{
Node clonedNode = (Node)nodeToClone.Clone();
IList rootNodes = _nodeService.GetRootNodes(clonedNode.Site);
clonedNode.ParentNode = parentNode;
clonedNode.CalculateNewPosition(rootNodes);
clonedNode.Title = newNodeTitle;
clonedNode.CreateShortDescription();
parentNode.ChildNodes.Add(nodeToClone);
_nodeService.SaveNode(clonedNode);
foreach (Section sectionToClone in nodeToClone.Sections)
{
ModuleBase module = _moduleLoader.GetModuleFromSection(sectionToClone);
if (!(module is ISynchronisable))
continue;
Section clonedSection = (Section)sectionToClone.Clone();
clonedSection.Node = clonedNode;
clonedSection.CopyRolesFromNode();
clonedSection.Node.Sections.Add(clonedSection);
_sectionService.SaveSection(clonedSection);
((ISynchronisable)module).SynchroniseSection(clonedSection);
}
return clonedNode;
}
The preview facility worked something like this were we created a new node each time but it was in fact what we called a versioned node which was an NHibernate joined-subclass to stop it coming back in the normal list of nodes.
I am definitely not saying this is the best way of doing things but just how we got the project out.
I hope it gives people some thoughts about how to achieve things better and if you need to know more then let me know.
Paul