我有课Project,Resource and File.
where
A Project包含列表资源.
Each Resource包含以下列表Files特定类型的。
这被映射到 XML :
<Project>
<Resource id=1>
<File id="1" path="" type="A" />
<File id="2" path="" type="B" />
<File id="3" path="" type="B" />
<File id="4" path="" type="B" />
</Resource>
<Resource id=2>
<File id="1" path="" type="A" />
<File id="2" path="" type="B" />
<File id="3" path="" type="B" />
<File id="4" path="" type="B" />
</Resource>
</Project>
因此基本上每个资源最多只能有一个“A”类型的文件和任意数量的“B”类型的文件。文件类型由用户从对话框中选择,在该对话框中选择文件并将其添加到资源中。
问题是对于每个“A”类型的文件,我需要创建一个新的资源,因此需要在 XML 中创建新的节点。(我当前的代码无法做到这一点)
最初我带来了以下内容(为简洁起见)
Project p =new Project("Untitled project"); //Will happen once per project
Resource res = p.CreateProjectResource("resource1");
//various params to create resource
p.AddResource(res);
//now lets add files to a resource
AddFileHelper(res,"C:\myfile1.bin","A",guid.toString());
AddFileHelper(res,"C:\myfile32.bin","B",guid.toString());
AddFileHelper(res,"C:\myfile56.bin","B",guid.toString());
//The next statement should create a new resource and add the file to
//the new created design
AddFileHelper(res,"C:\myfile4.bin","A",guid.toString()); //
//some helper class :
//Adds a file of type "type" to a resource "res" with file ID as "id"
private AddFileHelper(Resource res,string path,FileType type,string id)
{
// path is user defined file path from OpenFile dialog,
//type is selected from a Dropdown (of Enum values "A","B",...)
//id is GUID
res.AddFile(path,type,id);
//************ OR it could be also written as *******
//ResFile file =new ResFile(path,type,id);
//res.AddFile(file);
//Update XML file here..
}
主要问题是用户没有“显式”创建资源(第一个资源除外),并且新资源的创建取决于用户添加的文件的类型。
此外,由于这种设计,很难根据文件 ID 找出资源。
唯一的跟踪方法是使用每个资源类中的文件集合。
有什么帮助吗?
谢谢大家。
这是参考我之前问过的一个问题post https://stackoverflow.com/questions/3116941/designhow-to-of-classes-containing-collections-of-other-classes