Copy/Paste is tightly related to Clone. This is how it can be done :
ProjectService.CopyTo(IFolderItem targetContainer,IFolderItem sourceItem) { if (!targetContainer can accept sourceItem) return;//should never get here we try to paste a folder in a model or something //clone the sourceItem var target = sourceItem.Clone(); var fileItems = target.GetAllItemsRecursive<IFileBased>(); foreach (IFileBased fileBasedItem in fileItems) { //create a copy of the file if it is projectdata to prevent unwanted relations if (item is projectdata/internal) { string newPath = GetSomeNewGuidName(); //this will copy internal and reconnect the file to the new source fileBasedItem.Relocate(newPath); } } }
A few things to note:
If a a function is Cloned() it should only cal SetValues/GetValues if the source store is memory
A clone of a filebased functionstore (netCdf/GDal) is a new functionstore of the same type pointing at the same file
The hard part/possible issues:
- Relocate should work in all possible states of the store.
- If we do this we NetworkCoverage (Sobek) the reference to the branches will be shallow (no deepcopy here), this problem will be fixed later on