Copy/Paste is tightly related to Clone. This is how it can be done :

ProjectService.CopyTo(IFolderItem sourceItem ,IFolderItem targetContainer)
{
   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.DeepClone();
   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.RelocateTo(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
  • CopyTo should be called when paste is done
The hard part/possible issues:
  • Clone of function needs knowlegde about IFilebase stores (do we want to move this knowledge to IFunctionStore.ShouldSetValueIfCloned?)
  • 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
  • No labels