Skip to content
This repository
Browse code

add a ResourceMove() and a ResourceCopy() method to DataFile

  • Loading branch information...
commit b77801e5e363b57fd96b55c9c892d48d0662e884 1 parent eff7b03
maul.esel authored
2  ChameleonCoder.Abstract/Files/IDataFile.cs
@@ -45,6 +45,8 @@ public interface IDataFile : IAppComponent
45 45
46 46 void ResourceDelete(IResource resource);
47 47 void ResourceInsert(IResource resource, IResource parent);
  48 + void ResourceMove(IResource resource, IResource newParent);
  49 + IResource ResourceCopy(IResource resource, IResource newParent);
48 50
49 51 void ResourceSetCreatedDate(IResource resource);
50 52 void ResourceSetCreatedDate(IResource resource, DateTime time);
22 ChameleonCoder.Core/Files/DataFile.cs
@@ -454,6 +454,28 @@ public void ResourceInsert(IResource resource, IResource parent)
454 454 AddPrivateResourceData(resource, element);
455 455 }
456 456
  457 + public void ResourceMove(IResource resource, IResource newParent)
  458 + {
  459 + if (resource != null)
  460 + {
  461 + DeleteResourceElement(resource); // remove old XML element
  462 + RemovePrivateResourceData(resource); // remove all references to the resource
  463 +
  464 + ResourceInsert(resource, newParent); // add new XML element and add references
  465 + }
  466 + }
  467 +
  468 + public IResource ResourceCopy(IResource resource, IResource newParent)
  469 + {
  470 + if (resource != null)
  471 + {
  472 + IResource newResource = App.ResourceTypeMan.CreateInstanceOf(App.ResourceTypeMan.GetKey(resource.GetType()), resource.Attributes.Clone(), newParent, this);
  473 + ResourceInsert(newResource, newParent);
  474 + return newResource;
  475 + }
  476 + throw new ArgumentNullException("resource");
  477 + }
  478 +
457 479 private void DeleteResourceElement(IResource resource)
458 480 {
459 481 XmlElement element = mappings[resource.Attributes];

0 comments on commit b77801e

Please sign in to comment.
Something went wrong with that request. Please try again.