• R/O
  • SSH
  • HTTPS

freetrain: Commit


Commit MetaInfo

Revision106 (tree)
Zeit2013-10-26 21:33:49
Autorc477

Log Message

load Plugin/Contributions through ParamsReader.

Ändern Zusammenfassung

Diff

--- NeoFT/xna/NFT.XNA/XnaGraphicManager.cs (revision 105)
+++ NeoFT/xna/NFT.XNA/XnaGraphicManager.cs (revision 106)
@@ -172,20 +172,11 @@
172172 GraphicsDeviceService graphicsDeviceService;
173173 ServiceContainer services;
174174
175- public XnaGraphicManager(XmlNode node)
175+ public XnaGraphicManager(ParamsReader node)
176176 {
177177 string atr_name, atr_desc;
178- XmlAttribute a = node.Attributes["name"];
179- if (a != null)
180- atr_name = a.Value;
181- else
182- atr_name = "XNA4.0 GraphicsManager";
183- XmlNode n = node.SelectSingleNode("description");
184- if (n != null)
185- atr_desc = n.InnerText;
186- else
187- atr_desc = "GraphicManager Powered by Microsoft XNA4.0 (ShaderModel2.0 Required)";
188-
178+ atr_name = node["name"].InnerTextOr("XNA4.0 GraphicsManager");
179+ atr_desc = node["description"].InnerTextOr("GraphicManager Powered by Microsoft XNA4.0 (ShaderModel2.0 Required)");
189180 Initialize(atr_name, atr_desc);
190181 ConfigureService.OnSystemInfoRequested += new AdditonalSystemInfoHandler(ConfigureService_OnSystemInfoRequested);
191182 }
--- NeoFT/core/contributions/graphics/CtbImageResourceFactory.cs (revision 105)
+++ NeoFT/core/contributions/graphics/CtbImageResourceFactory.cs (revision 106)
@@ -22,12 +22,18 @@
2222 /// </summary>
2323 public class CtbImageResouceFactory : CtbCustomCtbFactory
2424 {
25- public CtbImageResouceFactory(Plugin p, XmlElement contrib)
25+ public CtbImageResouceFactory(Plugin p, ParamsReader contrib)
2626 : base(p, contrib) {
2727 }
2828
29- protected override Contribution Create(Plugin owner, XmlElement e)
29+ protected override Contribution Create(Plugin owner, ParamsReader e)
3030 {
31+ ParamsReader src = e["src"];
32+ if(!src.IsNull){
33+ e.OverWrite("name","Image:"+src.InnerText);
34+ } else {
35+ e.OverWrite("name","<unknown>");
36+ }
3137 return new CtbImageResource(owner, e);
3238 }
3339
--- NeoFT/core/contributions/graphics/CtbImageResource.cs (revision 105)
+++ NeoFT/core/contributions/graphics/CtbImageResource.cs (revision 106)
@@ -20,14 +20,13 @@
2020 protected bool auto_color_key;
2121 protected string src_text;
2222
23- public CtbImageResource(Plugin owner, XmlElement contrib) :base(owner, contrib,
24- "file:"+XmlUtil.GetSingleNodeText(contrib, "src", "<unknwon>"), "")
23+ public CtbImageResource(Plugin owner, ParamsReader contrib) :base(owner, contrib)
2524 {
2625 reffer = null;
27- XmlNode nd = contrib.SelectSingleNode("src");
26+ ParamsReader nd = contrib["src"];
2827 src_text = nd.InnerText;
29- string attext = XmlUtil.GetAttribute(nd, "colorkey", null);
30- auto_color_key = attext==null;
28+ ParamsReader ckey = nd["colorkey"];
29+ auto_color_key = ckey.IsNull;
3130 if (auto_color_key)
3231 {
3332 colorkey = Color.Transparent;
@@ -34,7 +33,7 @@
3433 }
3534 else
3635 {
37- colorkey = StringParseUtil.CreateColor(attext);
36+ colorkey = StringParseUtil.CreateColor(ckey.InnerText);
3837 }
3938
4039 }
--- NeoFT/core/contributions/terrain/CtbHeightCutPlaneTexture.cs (revision 105)
+++ NeoFT/core/contributions/terrain/CtbHeightCutPlaneTexture.cs (revision 106)
@@ -19,12 +19,12 @@
1919 public readonly Color BaseColor;
2020 protected HeightCutPlaneImgSet imgSet;
2121
22- public CtbHeightCutPlaneTexture(Plugin p, CtbHeightCutPlaneTextureFactory factory, XmlElement ctb)
22+ public CtbHeightCutPlaneTexture(Plugin p, CtbHeightCutPlaneTextureFactory factory, ParamsReader ctb)
2323 : base(p, ctb) {
2424 if (HeightCutPlaneImgSet.textureFactory == null) {
2525 HeightCutPlaneImgSet.textureFactory = factory;
2626 }
27- string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null);
27+ string text = ctb["basecolor"].InnerText;
2828 BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text));
2929 CreateAndRegister(BaseColor, out imgSet);
3030 }
@@ -99,12 +99,12 @@
9999 public readonly Color BaseColor;
100100 protected HeightCutSlopeImgSet imgSet;
101101
102- public CtbHeightCutSlopeTexture(Plugin p, CtbHeightCutSlopeTextureFactory factory, XmlElement ctb)
102+ public CtbHeightCutSlopeTexture(Plugin p, CtbHeightCutSlopeTextureFactory factory, ParamsReader ctb)
103103 : base(p, ctb) {
104104 if (HeightCutSlopeImgSet.textureFactory == null) {
105105 HeightCutSlopeImgSet.textureFactory = factory;
106106 }
107- string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null);
107+ string text = ctb["basecolor"].InnerText;
108108 BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text));
109109 CreateAndRegister(BaseColor, out imgSet);
110110 }
--- NeoFT/core/contributions/terrain/CtbGroundTextureFactory.cs (revision 105)
+++ NeoFT/core/contributions/terrain/CtbGroundTextureFactory.cs (revision 106)
@@ -34,7 +34,7 @@
3434 // Template set of Ground Images. Used for like a clipping mask.
3535 protected PlainGroundImgSet imageSet;
3636
37- public CtbGroundTextureFactory(Plugin p, XmlElement contrib)
37+ public CtbGroundTextureFactory(Plugin p, ParamsReader contrib)
3838 : base(p, contrib) {
3939 imageSet = new PlainGroundImgSet(DataDirectory);
4040 }
@@ -50,7 +50,7 @@
5050 imageSet.PrepareCache();
5151 }
5252
53- protected override Contribution Create(Plugin owner, XmlElement e)
53+ protected override Contribution Create(Plugin owner, ParamsReader e)
5454 {
5555 //TODO:将来テクスチャ画像対応の地形テクスチャも…
5656 return new CtbSimpleGroundTexture(owner, this, e);
--- NeoFT/core/contributions/terrain/CtbSimpleGroundTexture.cs (revision 105)
+++ NeoFT/core/contributions/terrain/CtbSimpleGroundTexture.cs (revision 106)
@@ -19,9 +19,9 @@
1919 public readonly Color BaseColor;
2020 protected SimpleGroundPlateSet plateSet;
2121
22- public CtbSimpleGroundTexture(Plugin p, CtbGroundTextureFactory factory, XmlElement ctb)
22+ public CtbSimpleGroundTexture(Plugin p, CtbGroundTextureFactory factory, ParamsReader ctb)
2323 : base(p, ctb) {
24- string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null);
24+ string text = ctb["basecolor"].InnerText;
2525 BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text));
2626 CreateAndRegister(this, BaseColor, out plateSet);
2727 }
--- NeoFT/core/contributions/terrain/CtbCliffTextureFactory.cs (revision 105)
+++ NeoFT/core/contributions/terrain/CtbCliffTextureFactory.cs (revision 106)
@@ -33,7 +33,7 @@
3333 // Template set of Cliff Images. Used for like a clipping mask.
3434 protected PlainCliffImgSet imageSet;
3535
36- public CtbCliffTextureFactory(Plugin p, XmlElement contrib)
36+ public CtbCliffTextureFactory(Plugin p, ParamsReader contrib)
3737 : base(p, contrib) {
3838 imageSet = new PlainCliffImgSet(DataDirectory);
3939 }
@@ -54,7 +54,7 @@
5454 textureCache = new Dictionary<Int32, ITextureOld>(num);
5555 }
5656
57- protected override Contribution Create(Plugin owner, XmlElement e)
57+ protected override Contribution Create(Plugin owner, ParamsReader e)
5858 {
5959 //TODO:将来テクスチャ画像対応の地形テクスチャも…
6060 return new CtbSimpleCliffTexture(owner, this, e);
--- NeoFT/core/contributions/terrain/CtbHeightCutPlaneTextureFactory.cs (revision 105)
+++ NeoFT/core/contributions/terrain/CtbHeightCutPlaneTextureFactory.cs (revision 106)
@@ -26,12 +26,12 @@
2626 //public static ITexture GetSilhouetteTexture(Scaler scl, short id) {
2727 // return theInstance.GetTexture(scl, id);
2828 //}
29-
30- public CtbHeightCutPlaneTextureFactory(Plugin p, XmlElement contrib)
29+
30+ public CtbHeightCutPlaneTextureFactory(Plugin p, ParamsReader contrib)
3131 : base(p, contrib) {
3232 }
3333
34- protected override Contribution Create(Plugin owner, XmlElement e)
34+ protected override Contribution Create(Plugin owner, ParamsReader e)
3535 {
3636 //TODO:将来テクスチャ画像対応の地形テクスチャも…
3737 return new CtbHeightCutPlaneTexture(owner, this, e);
@@ -39,11 +39,11 @@
3939 }
4040
4141 public class CtbHeightCutSlopeTextureFactory : CtbCustomCtbFactory {
42- public CtbHeightCutSlopeTextureFactory(Plugin p, XmlElement contrib)
42+ public CtbHeightCutSlopeTextureFactory(Plugin p, ParamsReader contrib)
4343 : base(p, contrib) {
4444 }
4545
46- protected override Contribution Create(Plugin owner, XmlElement e) {
46+ protected override Contribution Create(Plugin owner, ParamsReader e) {
4747 //TODO:将来テクスチャ画像対応の地形テクスチャも…
4848 return new CtbHeightCutSlopeTexture(owner, this, e);
4949 }
--- NeoFT/core/contributions/terrain/CtbSimpleCliffTexture.cs (revision 105)
+++ NeoFT/core/contributions/terrain/CtbSimpleCliffTexture.cs (revision 106)
@@ -19,9 +19,9 @@
1919 public readonly Color BaseColor;
2020 protected SimpleCliffPlateSet plateSet;
2121
22- public CtbSimpleCliffTexture(Plugin p, CtbCliffTextureFactory factory, XmlElement ctb)
22+ public CtbSimpleCliffTexture(Plugin p, CtbCliffTextureFactory factory, ParamsReader ctb)
2323 : base(p, ctb) {
24- string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null);
24+ string text = ctb["basecolor"].InnerText;
2525 BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text));
2626 CreateAndRegister(this, BaseColor, out plateSet);
2727 }
--- NeoFT/core/contributions/game/CtbImageImportTerrainGenerator.cs (revision 105)
+++ NeoFT/core/contributions/game/CtbImageImportTerrainGenerator.cs (revision 106)
@@ -13,6 +13,7 @@
1313 using System.Runtime.InteropServices;
1414 using System.Diagnostics;
1515 using nft.framework.plugin;
16+using nft.framework;
1617
1718 namespace nft.contributions.game {
1819 public class CtbImageImportTerrainGenerator : CtbTerrainGenerator, ITerrainGenerator
@@ -24,7 +25,7 @@
2425 public const string KEY_COLOR_CHANNEL = "UseColorChannel";
2526 public const string KEY_SEA_LEVEL_HEIGHT = "SeaLevelHeight";
2627
27- public CtbImageImportTerrainGenerator(Plugin p, XmlElement contrib) : base(p, contrib) { }
28+ public CtbImageImportTerrainGenerator(Plugin p, ParamsReader contrib) : base(p, contrib) { }
2829 public override ITerrainGenerator Generator { get { return this; } }
2930
3031 #region ITerrainGenerator メンバ
--- NeoFT/core/contributions/game/CtbTerrainGenerator.cs (revision 105)
+++ NeoFT/core/contributions/game/CtbTerrainGenerator.cs (revision 106)
@@ -19,7 +19,7 @@
1919 /// </summary>
2020 public abstract class CtbTerrainGenerator : CtbMapGenerator, ITerrainGenerator
2121 {
22- public CtbTerrainGenerator(Plugin p, XmlElement contrib) : base(p, contrib) { }
22+ public CtbTerrainGenerator(Plugin p, ParamsReader contrib) : base(p, contrib) { }
2323 public abstract ITerrainGenerator Generator { get; }
2424 public static Array ListEnabled()
2525 {
@@ -38,7 +38,7 @@
3838 public const string KEY_MAX_HEIGHT = "MaxHeight";
3939 public const string KEY_GROUND_LEVEL = "GroundLevel";
4040
41- public CtbFlatTerrainGenerator(Plugin p, XmlElement contrib) : base(p, contrib) { }
41+ public CtbFlatTerrainGenerator(Plugin p, ParamsReader contrib) : base(p, contrib) { }
4242 public override ITerrainGenerator Generator { get { return this; } }
4343
4444 #region ITerrainGenerator メンバ
--- NeoFT/core/contributions/game/CtbWorldDivider.cs (revision 105)
+++ NeoFT/core/contributions/game/CtbWorldDivider.cs (revision 106)
@@ -17,7 +17,7 @@
1717 /// </summary>
1818 public abstract class CtbWorldDivider : CtbMapGenerator, IWorldDivider
1919 {
20- public CtbWorldDivider(Plugin p, XmlElement contrib) : base(p, contrib) { }
20+ public CtbWorldDivider(Plugin p, ParamsReader contrib) : base(p, contrib) { }
2121 public abstract IWorldDivider Divider { get; }
2222 public static Array ListEnabled()
2323 {
@@ -33,7 +33,7 @@
3333
3434 public class CtbSimpleDivider : CtbWorldDivider
3535 {
36- public CtbSimpleDivider(Plugin p, XmlElement contrib) : base(p, contrib) { }
36+ public CtbSimpleDivider(Plugin p, ParamsReader contrib) : base(p, contrib) { }
3737 public override IWorldDivider Divider { get { return this; } }
3838
3939 #region IWorldDivider メンバ
--- NeoFT/core/debug/TestBinaryModule.cs (revision 105)
+++ NeoFT/core/debug/TestBinaryModule.cs (revision 106)
@@ -4,10 +4,11 @@
44 using nft.framework.plugin;
55 using System.Xml;
66 using System.Diagnostics;
7+using nft.framework;
78
89 namespace nft.debug {
910 class TestBinaryModule :BinaryModule {
10- public TestBinaryModule(Plugin p, XmlElement e)
11+ public TestBinaryModule(Plugin p, ParamsReader e)
1112 : base(p, e) {
1213 Debug.WriteLine("TestBinaryModule Constructed");
1314 }
--- NeoFT/core/core/game/IMapGenerators.cs (revision 105)
+++ NeoFT/core/core/game/IMapGenerators.cs (revision 106)
@@ -53,11 +53,11 @@
5353 protected Type typeSetupUI = null;
5454 protected IMapGeneSetupPanel pnlSetupUI;
5555
56- public CtbMapGenerator(Plugin p, XmlElement contrib)
56+ public CtbMapGenerator(Plugin p, ParamsReader contrib)
5757 : base(p, contrib) {
58- XmlNode node = contrib.SelectSingleNode("setup");
59- if (node != null) {
60- Type t = PluginUtil.loadTypeFromManifest(node as XmlElement);
58+ ParamsReader node = contrib["setup"];
59+ if (!node.IsNull) {
60+ Type t = PluginUtil.loadTypeFromManifest(node);
6161 if (typeof(IMapGeneSetupPanel).IsAssignableFrom(t)) {
6262 typeSetupUI = t;
6363 } else {
--- NeoFT/framework/contributions/ui/CtbMenuItem.cs (revision 105)
+++ NeoFT/framework/contributions/ui/CtbMenuItem.cs (revision 106)
@@ -22,13 +22,13 @@
2222 ///
2323 /// This contribution can add several items at once.
2424 /// </summary>
25- public CtbMenuItem(Plugin p, XmlElement e)
25+ public CtbMenuItem(Plugin p, ParamsReader e)
2626 : base(p, e)
2727 {
28- XmlElement parent = (XmlElement)XmlUtil.SelectSingleNode(e, "location");
29- XmlUtil.SetAttribute(parent, "id", ""); // set dummy id to parse successfuly
28+ ParamsReader parent = e["location"];
29+ parent.OverWrite("id", ""); // set dummy id to parse successfuly
3030 CommandPathHint hint = new CommandPathHint(parent);
31- XmlNode entries = XmlUtil.SelectSingleNode(e,"entries");
31+ ParamsReader entries = e["entries"];
3232 if ("ROOT".Equals(hint.Parent))
3333 hint.Parent = "";
3434 location = hint.Parent;
@@ -35,31 +35,28 @@
3535 parseNode(entries, hint);
3636 }
3737
38- protected void parseNode(XmlNode node, CommandPathHint hint)
38+ protected void parseNode(ParamsReader node, CommandPathHint hint)
3939 {
40- foreach( XmlNode cn in node.ChildNodes )
40+ foreach (ParamsReader cn in node.EnumChildren("item"))
4141 {
42- if(cn.Name.Equals("item"))
42+ string mid = cn["mid"].InnerTextOr("").Trim();
43+ CommandUI cui = parseItem(cn);
44+ hint.ID = mid;
45+ CommandManager.TheInstance.RegisterCommand(this, mid, cui, hint, null);
46+ if(!cn["item"].IsNull)
4347 {
44- string mid = XmlUtil.GetAttribute(cn, "mid", "").Trim();
45- CommandUI cui = parseItem(cn);
46- hint.ID = mid;
47- CommandManager.TheInstance.RegisterCommand(this, mid, cui, hint, null);
48- if(cn.ChildNodes.Count!=0)
49- {
50- CommandPathHint h2 = new CommandPathHint("");
51- h2.Parent = hint.Parent + CommandManager.PathSepalator + mid;
52- //string p2 = Main.mainFrame.RegisterMenuNode(_id,path,_cap,after,before);
53- parseNode(cn, h2);
54- }
48+ CommandPathHint h2 = new CommandPathHint("");
49+ h2.Parent = hint.Parent + CommandManager.PathSepalator + mid;
50+ //string p2 = Main.mainFrame.RegisterMenuNode(_id,path,_cap,after,before);
51+ parseNode(cn, h2);
5552 }
5653 }
5754
5855 }
5956
60- protected CommandUI parseItem(XmlNode item)
57+ protected CommandUI parseItem(ParamsReader item)
6158 {
62- string _cap = XmlUtil.GetAttribute(item, "caption", "").Trim();
59+ string _cap = item["caption"].InnerTextOr("").Trim();
6360 TriggerCommandUI cui = new TriggerCommandUI(_cap, item.InnerText, null);
6461 return cui;
6562 }
--- NeoFT/framework/contributions/ui/CtbCommandUIGroup.cs (revision 105)
+++ NeoFT/framework/contributions/ui/CtbCommandUIGroup.cs (revision 106)
@@ -23,14 +23,14 @@
2323 ///
2424 /// This contribution can add several items at once.
2525 /// </summary>
26- public CtbCommandUIGroup(Plugin p, XmlElement e)
26+ public CtbCommandUIGroup(Plugin p, ParamsReader e)
2727 : base(p, e)
2828 {
29- string cap = XmlUtil.GetSingleNodeText(e, "caption", null);
30- string scap = XmlUtil.GetSingleNodeText(e, "short-caption", cap);
31- string lcap = XmlUtil.GetSingleNodeText(e, "long-caption", cap);
32- string desc = XmlUtil.GetSingleNodeText(e, "description", lcap);
33- string iconpath = XmlUtil.GetSingleNodeText(e, "icon", cap);
29+ string cap = e["caption"].InnerText;
30+ string scap = e["short-caption"].InnerTextOr(cap);
31+ string lcap = e["long-caption"].InnerTextOr(cap);
32+ string desc = e["description"].InnerTextOr(lcap);
33+ string iconpath = e["icon"].InnerTextOr(cap);
3434 ImageRef imgref = PluginImageManager.GetBundledImageRef(this, iconpath);
3535 }
3636
--- NeoFT/framework/contributions/ui/CtbToolButton.cs (revision 105)
+++ NeoFT/framework/contributions/ui/CtbToolButton.cs (revision 106)
@@ -21,24 +21,23 @@
2121 ///
2222 /// This contribution can add several items at once.
2323 /// </summary>
24- public CtbToolButton(Plugin p, XmlElement e)
24+ public CtbToolButton(Plugin p, ParamsReader e)
2525 : base(p, e) {
26- XmlElement bar = (XmlElement)XmlUtil.SelectSingleNode(e, "bar");
26+ ParamsReader bar = e["bar"];
2727 parseNode(bar);
2828 }
2929
30- protected void parseNode(XmlElement ebar)
30+ protected void parseNode(ParamsReader ebar)
3131 {
32- string barname = XmlUtil.GetAttribute(ebar, "name", "MAIN");
33- XmlUtil.SetAttribute(ebar, "parent", barname);
34- XmlUtil.SetAttribute(ebar, "id", ""); // set dummy id to parse successfuly
32+ string barname = ebar["name"].InnerTextOr("MAIN");
33+ ebar.OverWrite("parent", barname);
34+ ebar.OverWrite("id", ""); // set dummy id to parse successfuly
3535 CommandPathHint hint = new CommandPathHint(ebar);
36- foreach (XmlNode cn in ebar.ChildNodes)
36+ foreach (ParamsReader cn in ebar.EnumChildren("button"))
3737 {
38- if(!cn.Name.Equals("button")) continue;
3938 //ButtonCreationInfo info = parseButton(cn);
4039 //Main.mainFrame.AddToolButton(info,barname,after,before);
41- hint.ID = XmlUtil.GetAttribute(cn, "bid", "").Trim();
40+ hint.ID = cn["bid"].InnerTextOr("").Trim();
4241 CommandUI cui = parseButton(cn);
4342 CommandManager.TheInstance.RegisterCommand(this, cui, null, hint);
4443
@@ -46,14 +45,14 @@
4645
4746 }
4847
49- protected CommandUI parseButton(XmlNode item)
48+ protected CommandUI parseButton(ParamsReader item)
5049 {
51- string _img = XmlUtil.GetAttribute(item,"image").Trim();
50+ string _img = item["image"].InnerText.Trim();
5251 ImageRef iref = PluginImageManager.GetBundledImageRef(this, _img);
53- string _cap = XmlUtil.GetAttribute(item, "caption", "").Trim();
52+ string _cap = item["caption"].InnerTextOr("").Trim();
5453 TriggerCommandUI cui = new TriggerCommandUI(_cap, item.InnerText, iref);
55- XmlAttribute aidx = item.Attributes["index"];
56- if (aidx != null) {
54+ ParamsReader aidx = item["index"];
55+ if (!aidx.IsNull) {
5756 cui.IconIndex = int.Parse(aidx.InnerText);
5857 }
5958 return cui;
--- NeoFT/framework/contributions/ui/CtbCommandEntity.cs (revision 105)
+++ NeoFT/framework/contributions/ui/CtbCommandEntity.cs (revision 106)
@@ -22,20 +22,21 @@
2222 protected readonly string methodName;
2323 private string path;
2424
25- public CtbCommandEntity(Plugin p, XmlElement contrib ) : base(p, contrib)
25+ public CtbCommandEntity(Plugin p, ParamsReader contrib)
26+ : base(p, contrib)
2627 {
27- path = contrib.OwnerDocument.BaseURI;
28- XmlNode cls = XmlUtil.SelectSingleNode(contrib,"class");
29- targetType = PluginUtil.loadTypeFromManifest((XmlElement)cls);
28+ path = contrib.SourceURI;
29+ ParamsReader cls = contrib["class"];
30+ targetType = PluginUtil.loadTypeFromManifest(cls);
3031
31- XmlNode mn = contrib.SelectSingleNode("method");
32- XmlNode cmd = XmlUtil.SelectSingleNode( contrib, "command" );
33- commandType = XmlUtil.GetAttribute( cmd, "type", "entity" );
32+ ParamsReader mn = contrib["method"];
33+ ParamsReader cmd = contrib["command"];
34+ commandType = cmd["type"].InnerTextOr("entity");
3435
35- if( mn!=null )
36+ if(!mn.IsNull)
3637 {
37- methodName = XmlUtil.GetAttribute( mn, "name", null);
38- if( bool.Parse(XmlUtil.GetAttribute(mn,"static","false")) )
38+ methodName = mn["name"].InnerText;
39+ if (bool.Parse(mn["static"].InnerTextOr("false")))
3940 methodType = MethodType.Static;
4041 else
4142 methodType = MethodType.Instance;
@@ -43,7 +44,7 @@
4344 if( methodName == null )
4445 {
4546 string templ = Main.resources["xml.attribute_not_found"].stringValue;
46- throw new Exception(string.Format(templ,mn,"name",contrib.OwnerDocument.BaseURI));
47+ throw new Exception(string.Format(templ,"method","name",contrib.SourceURI));
4748 }
4849 }
4950 else
@@ -53,7 +54,7 @@
5354 PluginUtil.RegisterCommand( id, entity, cmd );
5455 }
5556
56- protected virtual ICommandEntity_Old CreateEntity( XmlElement contrib )
57+ protected virtual ICommandEntity_Old CreateEntity( ParamsReader contrib )
5758 {
5859 if( commandType.Equals("ModalForm"))
5960 return new ModalFormCommand(targetType);
--- NeoFT/framework/contributions/ui/CtbCommandUI.cs (revision 105)
+++ NeoFT/framework/contributions/ui/CtbCommandUI.cs (revision 106)
@@ -24,16 +24,16 @@
2424 ///
2525 /// This contribution can add several items at once.
2626 /// </summary>
27- public CtbCommandUI(Plugin p, XmlElement e)
27+ public CtbCommandUI(Plugin p, ParamsReader e)
2828 : base(p, e)
2929 {
3030 object[] args = new object[] { this, e };
3131 CommandUI cui = (CommandUI)PluginUtil.loadObjectFromManifest(e, args, singleDefault);
32- XmlNode ndSetup = e.SelectSingleNode("setup");
33- if (ndSetup != null) {
34- XmlElement ndMenu = (XmlElement)ndSetup.SelectSingleNode("menu-item");
32+ ParamsReader ndSetup = e["setup"];
33+ if (!ndSetup.IsNull) {
34+ ParamsReader ndMenu = ndSetup["menu-item"];
3535 ConfirmIDAttribute(ndMenu);
36- XmlElement ndTool = (XmlElement)ndSetup.SelectSingleNode("tool-item");
36+ ParamsReader ndTool = ndSetup["tool-item"];
3737 ConfirmIDAttribute(ndTool);
3838 CommandPathHint hint = new CommandPathHint(ndMenu);
3939 CommandPathHint hint2 = new CommandPathHint(ndTool);
@@ -41,10 +41,9 @@
4141 }
4242 }
4343
44- protected void ConfirmIDAttribute(XmlElement e) {
45- XmlAttribute a = e.Attributes["id"];
46- if (a == null) {
47- XmlUtil.SetAttribute(e, "id", this.id);
44+ protected void ConfirmIDAttribute(ParamsReader e) {
45+ if (e["id"].IsNull) {
46+ e.OverWrite("id", this.id);
4847 }
4948 }
5049 }
--- NeoFT/framework/contributions/ui/CtbSubform.cs (revision 105)
+++ NeoFT/framework/contributions/ui/CtbSubform.cs (revision 106)
@@ -57,10 +57,10 @@
5757 /// </summary>
5858 protected readonly Type windowType;
5959
60- public CtbSubform(Plugin p, XmlElement e)
60+ public CtbSubform(Plugin p, ParamsReader e)
6161 : base(p, e) {
6262 options = LoadOptions(e);
63- windowType = PluginUtil.loadTypeFromManifest((XmlElement)XmlUtil.SelectSingleNode(e,"class"));
63+ windowType = PluginUtil.loadTypeFromManifest(e["class"]);
6464 if (IsSingleton) {
6565 contentMap = new Dictionary<string, SubformHolder>(1);
6666 } else {
@@ -68,8 +68,8 @@
6868 }
6969 }
7070
71- protected virtual IList<string> LoadOptions(XmlElement e) {
72- String optstr = XmlUtil.GetSingleNodeText(e, "options", "").ToLower();
71+ protected virtual IList<string> LoadOptions(ParamsReader e) {
72+ String optstr = e["options"].InnerTextOr("").ToLower();
7373 String[] sarr = optstr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
7474
7575 return new List<string>(sarr);
--- NeoFT/framework/framework/drawing/ImageRef.cs (revision 105)
+++ NeoFT/framework/framework/drawing/ImageRef.cs (revision 106)
@@ -111,7 +111,6 @@
111111 protected virtual Image CreateImage() {
112112 //return Image.FromFile(((LocalFile)source).AbsolutePath);
113113 Stream s = source.OpenRead();
114- Encoder enc = Encoder.Version;
115114 Image img = Bitmap.FromStream(s);
116115 s.Close();
117116 s.Dispose();
@@ -180,14 +179,16 @@
180179 /// <param name="filename"></param>
181180 /// <returns></returns>
182181 public static ImageRef FromFile(string filename) {
183- string path = Path.GetFullPath(filename);
182+ FileInfo info = new FileInfo(new Uri(filename).LocalPath);
183+ string keypath = info.FullName;
184184 ImageRef refObj = null;
185- if (!pathlist.TryGetValue(path, out refObj)) {
186- FileInfo info = new FileInfo(path);
185+ if (!pathlist.TryGetValue(keypath, out refObj)) {
187186 if (info.Exists) {
188187 IFileSource src = new LocalFile(info.FullName);
189188 refObj = new ImageRef(src);
190- pathlist.Add(path, refObj);
189+ pathlist.Add(keypath, refObj);
190+ } else {
191+ Debug.WriteLine("Image file not found for path="+info.FullName);
191192 }
192193 }
193194 return refObj;
--- NeoFT/framework/framework/GlobalModules.cs (revision 105)
+++ NeoFT/framework/framework/GlobalModules.cs (revision 106)
@@ -7,6 +7,7 @@
77 using nft.framework.plugin;
88 using nft.util;
99 using System.IO;
10+using nft.framework.loader;
1011
1112 namespace nft.framework
1213 {
@@ -21,8 +22,9 @@
2122
2223 static public void Initialize(){
2324 XmlDocument doc = XmlUtil.LoadFile(Directories.AppBaseDir+"core_modules.xml");
24- XmlNode root = XmlUtil.SelectSingleNode( doc, "modules");
25- foreach(XmlNode cn in root.SelectNodes("module") ){
25+ ParamsReader reader = new ParamsReader(doc.BaseURI, new XmlParamParser(doc));
26+ ParamsReader root = reader["modules"];
27+ foreach (ParamsReader cn in root.EnumChildren("module")) {
2628 try{
2729 GlobalModuleEntry gm = loadModule(cn);
2830 if(gm!=null){
@@ -41,11 +43,11 @@
4143 /// The "codeBase" attribute and the "name" attribute of
4244 /// a class element are used to determine the class to be loaded.
4345 /// </summary>
44- private static GlobalModuleEntry loadModule(XmlNode node) {
45- XmlElement el = (XmlElement)XmlUtil.SelectSingleNode(node,"class");
46+ private static GlobalModuleEntry loadModule(ParamsReader node) {
47+ ParamsReader el = node["class"];
4648 Type t = PluginUtil.loadTypeFromManifest(el);
47- string name = XmlUtil.GetAttribute(node, "name");
48- string desc = XmlUtil.GetSingleNodeText(node, "description", "");
49+ string name = node["name"].InnerText;
50+ string desc = node["description"].InnerTextOr("");
4951
5052 GlobalModuleEntry entry = new GlobalModuleEntry(null, null, name, desc);
5153 object result = null;
@@ -56,11 +58,11 @@
5658 Debug.WriteLine(e.Message);
5759 Debug.WriteLine(e.StackTrace);
5860 string templ = Main.resources["xml.class_load_error"].stringValue;
59- throw new Exception(string.Format(templ,t.FullName,node.OwnerDocument.BaseURI),e);
61+ throw new Exception(string.Format(templ,t.FullName,node.SourceURI),e);
6062 }
6163 if(!(result is IGlobalModule)){
6264 string templ = Main.resources["xml.class_cast_error"].stringValue;
63- object[] args = new object[]{t.FullName,"IGlobalModule",node.OwnerDocument.BaseURI};
65+ object[] args = new object[] { t.FullName, "IGlobalModule", node.SourceURI };
6466 throw new InvalidCastException(string.Format(templ,args));
6567 }
6668 entry.ModuleInstance = (IGlobalModule)result;
--- NeoFT/framework/framework/plugin/FixedClassContributionFactory.cs (revision 105)
+++ NeoFT/framework/framework/plugin/FixedClassContributionFactory.cs (revision 106)
@@ -20,14 +20,13 @@
2020 /// <summary>
2121 /// Constructor for the use in plugin.xml
2222 /// </summary>
23- public FixedClassContributionFactory( XmlElement e) :
24- this( PluginUtil.loadTypeFromManifest(
25- (XmlElement)XmlUtil.SelectSingleNode(e,"implementation") ) ) {}
23+ public FixedClassContributionFactory(ParamsReader e) :
24+ this( PluginUtil.loadTypeFromManifest(e["implementation"])){}
2625
2726 private readonly Type concreteType;
2827 public Type OutputType { get{ return concreteType; } }
2928
30- public Contribution load( Plugin owner, XmlElement e ) {
29+ public Contribution load(Plugin owner, ParamsReader e) {
3130 return (Contribution)Activator.CreateInstance(concreteType,new object[]{owner, e});
3231 }
3332 }
--- NeoFT/framework/framework/plugin/InheritableContributionFactory.cs (revision 105)
+++ NeoFT/framework/framework/plugin/InheritableContributionFactory.cs (revision 106)
@@ -20,15 +20,14 @@
2020 this.baseType = baseType;
2121 }
2222
23- public InheritableContributionFactory( XmlElement e) :
24- this( PluginUtil.loadTypeFromManifest(
25- (XmlElement)XmlUtil.SelectSingleNode(e,"basetype") ) ) {}
23+ public InheritableContributionFactory( ParamsReader e) :
24+ this( PluginUtil.loadTypeFromManifest(e["basetype"])) {}
2625
2726
2827 private readonly Type baseType;
2928 public Type OutputType { get{ return baseType; } }
3029
31- public Contribution load( Plugin owner, XmlElement e )
30+ public Contribution load(Plugin owner, ParamsReader e)
3231 {
3332 Contribution contrib = PluginUtil.createContributionObject(owner, e) as Contribution;
3433 if( baseType.IsInstanceOfType(contrib) )
--- NeoFT/framework/framework/plugin/Contribution.cs (revision 105)
+++ NeoFT/framework/framework/plugin/Contribution.cs (revision 106)
@@ -24,17 +24,17 @@
2424 // Contribution ID will be used as a part of filepath.
2525 // {Plugin_id}\{Contribution_short_id}
2626 static public readonly string PID_Sepalator = "\\";
27- static string GenerateID( XmlElement contrib )
27+ static string GenerateID( ParamsReader contrib )
2828 {
29- string short_id = XmlUtil.GetAttribute( contrib, "id", null);
29+ string short_id = contrib["id"].InnerText;
3030 if( short_id == null )
3131 {
3232 string templ = Main.resources["xml.attribute_not_found"].stringValue;
3333 throw new PluginXmlException(contrib,string.Format(
34- templ,contrib.Name,"name",contrib.OwnerDocument.BaseURI));
34+ templ,"contribution","name",contrib.SourceURI));
3535 }
3636
37- string pname = PluginUtil.GetPruginDirName(contrib);
37+ string pname = PluginUtil.GetPluginDirName(contrib);
3838 return pname + PID_Sepalator + short_id;
3939 }
4040 static string GenerateID(Plugin owner, string short_id)
@@ -44,14 +44,14 @@
4444 }
4545 #endregion
4646
47- protected Contribution( Plugin owner, XmlElement contrib ) : this(owner, contrib,
48- XmlUtil.GetSingleNodeText(contrib,"name","<unknown>"),
49- XmlUtil.GetSingleNodeText(contrib,"description","")) {}
47+ protected Contribution(Plugin owner, ParamsReader contrib)
48+ : this(owner, contrib,
49+ contrib["name"].InnerTextOr("<unknown>"),
50+ contrib["description"].InnerTextOr("")) {}
5051
51- protected Contribution(Plugin owner, XmlElement contrib, string name, string description)
52+ protected Contribution(Plugin owner, ParamsReader contrib, string name, string description)
5253 {
5354 this.parent = owner;
54- this.baseDir = Path.GetDirectoryName(contrib.BaseURI);
5555 this.name = name;
5656 this.description = description;
5757 //Debug.WriteLine("name:" + name + " ,baseDir:" + baseDir);
@@ -58,13 +58,13 @@
5858 id = GenerateID(contrib);
5959 try
6060 {
61- CtbType = contrib.Attributes["type"].Value;
61+ CtbType = contrib["type"].InnerText;
6262 }
6363 catch
6464 {
6565 string templ = Main.resources["xml.attribute_not_found"].stringValue;
6666 throw new PluginXmlException(contrib, string.Format(
67- templ, contrib.Name, "type", contrib.OwnerDocument.BaseURI));
67+ templ, "contribution", "type", contrib.SourceURI));
6868 }
6969 }
7070
@@ -72,7 +72,6 @@
7272 protected Contribution(Plugin owner, string _type, string short_id, string _name, string _description)
7373 {
7474 this.parent = owner;
75- this.baseDir = parent.dirName;
7675 this.CtbType = _type;
7776 this.id = GenerateID(owner, short_id);
7877 this.name = _name;
@@ -201,8 +200,7 @@
201200 ///
202201 /// This poinst to the plug-in directory.
203202 /// </summary>
204- public string PluginDir { get { return baseDir; } }
205- private string baseDir;
203+ public string PluginDir { get { return parent.dirName; } }
206204
207205 /// <summary>
208206 /// Returns the Plugin object that contains this contribution.
--- NeoFT/framework/framework/plugin/PluginSerializationBinder.cs (revision 105)
+++ NeoFT/framework/framework/plugin/PluginSerializationBinder.cs (revision 106)
@@ -4,6 +4,7 @@
44 using System.Reflection;
55 using System.Runtime.Serialization;
66 using nft.framework;
7+using System.IO;
78
89 namespace nft.framework.plugin
910 {
@@ -47,7 +48,27 @@
4748 {
4849 theInstance.addAssembly(asm);
4950 }
50-
51+
52+ protected static Dictionary<string, Assembly> asmcache = new Dictionary<string, Assembly>();
53+ public static Assembly SafeLoadAssembly(IFileSource f) {
54+ Assembly a = null;
55+ LocalFile lfile = f as LocalFile;
56+ if (lfile != null) {
57+ // load assumig from local strage.
58+ a = Assembly.LoadFrom(lfile.AbsolutePath);
59+ } else if (!asmcache.TryGetValue(f.IdenticalPath, out a)) {
60+ // load from byte stream.
61+ using (Stream stream = f.OpenRead()) {
62+ byte[] dllimage = new byte[stream.Length];
63+ stream.Read(dllimage, 0, dllimage.Length);
64+ stream.Close();
65+ a = Assembly.Load(dllimage);
66+ }
67+ asmcache.Add(f.IdenticalPath, a);
68+ }
69+ return a;
70+ }
71+
5172 protected void addAssembly(Assembly asm)
5273 {
5374 if(!assemblies.ContainsKey(asm.GetName().Name))
@@ -73,6 +94,7 @@
7394 return null;
7495 }
7596
97+
7698 // public override System.Type BindToType(string assemblyName, string typeName) {
7799 // Type t;
78100 //
--- NeoFT/framework/framework/plugin/CtbCustomCtbFactory.cs (revision 105)
+++ NeoFT/framework/framework/plugin/CtbCustomCtbFactory.cs (revision 106)
@@ -13,10 +13,9 @@
1313 /// </summary>
1414 [PrimitiveContribution]
1515 public abstract class CtbCustomCtbFactory : Contribution, IContributionFactory {
16- public CtbCustomCtbFactory(Plugin p, XmlElement e)
16+ public CtbCustomCtbFactory(Plugin p, ParamsReader e)
1717 : base(p, e) {
18- baseType = PluginUtil.loadTypeFromManifest(
19- (XmlElement)XmlUtil.SelectSingleNode(e, "basetype"));
18+ baseType = PluginUtil.loadTypeFromManifest(e["basetype"]);
2019 }
2120
2221 #region IContributionFactory メンバ
@@ -23,7 +22,7 @@
2322 private readonly Type baseType;
2423 public Type OutputType { get { return baseType; } }
2524
26- public Contribution load(Plugin owner, XmlElement e) {
25+ public Contribution load(Plugin owner, ParamsReader e) {
2726 Contribution contrib = Create(owner, e);
2827 Debug.Assert(baseType.IsInstanceOfType(contrib));
2928 return contrib;
@@ -30,7 +29,7 @@
3029 }
3130 #endregion
3231
33- protected abstract Contribution Create(Plugin owner, XmlElement e);
32+ protected abstract Contribution Create(Plugin owner, ParamsReader e);
3433
3534 }
3635 }
--- NeoFT/framework/framework/plugin/PluginManager.cs (revision 105)
+++ NeoFT/framework/framework/plugin/PluginManager.cs (revision 106)
@@ -6,10 +6,11 @@
66 using System.Windows.Forms;
77 using System.Xml;
88 using nft.util;
9+using nft.framework.loader;
910
1011 namespace nft.framework.plugin
1112 {
12- public delegate void ParseEventHandler(Plugin p, XmlElement e);
13+ public delegate void ParseEventHandler(Plugin p, ParamsReader e);
1314 public delegate void InitCompleteEventHandler();
1415
1516 /// <summary>
@@ -83,7 +84,7 @@
8384 }
8485
8586 // called from Plugin on initialization
86- internal void NotifyStartParse(Plugin p, XmlElement e)
87+ internal void NotifyStartParse(Plugin p, ParamsReader e)
8788 {
8889 if( BeforeContributionParse!=null )
8990 BeforeContributionParse(p,e);
@@ -90,61 +91,67 @@
9091 }
9192
9293 #region initialization processes
93- private ArrayList SeekPluginDirectories(ICollection directories,ProgressMonitor monitor)
94+ private ArrayList SeekPluginDirectories(ICollection directories, ProgressMonitor monitor) {
95+ ArrayList pluginSet = new ArrayList();
96+ monitor.Progress(1, 1, "プラグインを検索中");
97+ string[][] subdirs = new string[directories.Count][];
98+ int n = 0;
99+ int count = 0;
100+ // pre-search subdirectories to count total numbers.
101+ foreach (string dir in directories) {
102+ subdirs[n] = Directory.GetDirectories(dir);
103+ count += subdirs[n++].Length;
104+ }
105+ monitor.SetMaximum(2, count);
106+
107+ n = 0;
108+ foreach (string dir in directories) {
109+ ProcessSubDirectories(pluginSet, dir, subdirs[n++], monitor);
110+ }
111+ return pluginSet;
112+ }
113+ private void ProcessSubDirectories(ArrayList pluginSet, string parent, string[] subdirs, ProgressMonitor monitor)
94114 {
95- ArrayList pluginSet = new ArrayList();
115+ foreach( string dir in subdirs )
116+ {
117+ monitor.Progress(2,1,dir);
118+ string path = Path.Combine(parent, dir);
119+ string filepath = Path.Combine(path, Plugin.PluginFileName);
120+ FileInfo info = new FileInfo(filepath);
121+ if (!info.Exists)
122+ continue; // this directory doesn't have the plugin.xml file.
96123
97- monitor.Progress(1,1,"プラグインを検索中");
98-
99- string[][] subdirs = new string[directories.Count][];
100- int n=0;
101- int count=0;
102- foreach( string dir in directories )
103- {
104- subdirs[n] = Directory.GetDirectories( dir );
105- count += subdirs[n++].Length;
106- }
107-
108- // locate plugins
109- monitor.SetMaximum(2,count);
110-
111- foreach( string[] dirarray in subdirs )
112- {
113- foreach( string dir in dirarray )
114- {
115- monitor.Progress(2,1,dir);
116- if (!File.Exists(Path.Combine(dir, Plugin.PluginFileName)))
117- continue; // this directory doesn't have the plugin.xml file.
118-
119- Plugin p = null;
120- try
124+ Plugin p = null;
125+ try
126+ {
127+ p = new Plugin(new Uri(path),info.LastWriteTime);
128+ XmlDocument doc = XmlUtil.LoadFile(filepath);
129+ XmlParamParser parser = new XmlParamParser(doc);
130+ ParamsReader reader = new ParamsReader(path, parser);
131+ pluginSet.Add( p );
132+ p.LoadParams(reader["plug-in"]);
133+ if( pluginMap.Contains(p.ID) )
121134 {
122- p = new Plugin(dir);
123- pluginSet.Add( p );
124- if( pluginMap.Contains(p.ID) )
125- {
126- p._state = InstallationState.FatalError;
127- // loaded more than once
128- // maybe same subdir name in different plugin dirs.
129- throw new Exception( string.Format(
130- "プラグイン「{0}」は{1}と{2}の二箇所からロードされています",
131- p.ID, p.dirName, ((Plugin)pluginMap[p.ID]).dirName) );
132- }
133- pluginMap.Add( p.ID, p );
134- }
135- catch( Exception e )
136- {
137- Debug.WriteLine(e.Message);
138- if(p!=null)
139- p._state = InstallationState.FatalError;
135+ p._state = InstallationState.FatalError;
136+ // loaded more than once
137+ // maybe same subdir name in different plugin dirs.
138+ throw new Exception( string.Format(
139+ "プラグイン「{0}」は{1}と{2}の二箇所からロードされています",
140+ p.ID, p.dirName, ((Plugin)pluginMap[p.ID]).dirName) );
141+ }
142+ pluginMap.Add( p.ID, p );
143+ }
144+ catch( Exception e )
145+ {
146+ Debug.WriteLine(e.Message);
147+ if(p!=null)
148+ p._state = InstallationState.FatalError;
140149
141- string templ = Main.resources["plugin.plugin_load_error"].stringValue;
142- templ+="\n"+e.Message;
143- ReportError(string.Format(templ,Path.GetFileName(dir)),e);
144- }
150+ string templ = Main.resources["plugin.plugin_load_error"].stringValue;
151+ templ+="\n"+e.Message;
152+ ReportError(string.Format(templ,Path.GetFileName(dir)),e);
145153 }
146- }
147- return pluginSet;
154+ }
148155 }
149156
150157 private void SolveDependency(ArrayList pluginSet, ProgressMonitor monitor)
@@ -338,7 +345,7 @@
338345 {
339346 ArrayList list = new ArrayList();
340347 foreach( Plugin p in plugins ) {
341- foreach( Contribution contrib in p.contributions ) {
348+ foreach( Contribution contrib in p.Contributions ) {
342349 if( contributionType.IsInstanceOfType(contrib) )
343350 if( !hideDisabled || contrib.IsAttached )
344351 list.Add(contrib);
@@ -356,7 +363,7 @@
356363 get {
357364 ArrayList list = new ArrayList();
358365 foreach( Plugin p in plugins )
359- foreach( Contribution contrib in p.contributions )
366+ foreach( Contribution contrib in p.Contributions )
360367 list.Add(contrib);
361368
362369 return (Contribution[])list.ToArray(typeof(Contribution));
@@ -367,7 +374,7 @@
367374 get {
368375 ArrayList list = new ArrayList();
369376 foreach (Plugin p in plugins)
370- foreach (Contribution contrib in p.primitives)
377+ foreach (Contribution contrib in p.Primitives)
371378 list.Add(contrib);
372379
373380 return (Contribution[])list.ToArray(typeof(Contribution));
--- NeoFT/framework/framework/plugin/BinaryModule.cs (revision 105)
+++ NeoFT/framework/framework/plugin/BinaryModule.cs (revision 106)
@@ -9,7 +9,7 @@
99 /// </summary>
1010 [PrimitiveContribution]
1111 public class BinaryModule : Contribution{
12- public BinaryModule(Plugin p, XmlElement e)
12+ public BinaryModule(Plugin p, ParamsReader e)
1313 : base(p, e) {
1414 }
1515 }
--- NeoFT/framework/framework/plugin/PluginUtil.cs (revision 105)
+++ NeoFT/framework/framework/plugin/PluginUtil.cs (revision 106)
@@ -24,16 +24,16 @@
2424 /// </summary>
2525 /// <param name="p">owner plugin</param>
2626 /// <param name="contrib">contribution target node</param>
27- public static Contribution createContributionObject(Plugin p, XmlElement elm) {
28- XmlElement el = (XmlElement)XmlUtil.SelectSingleNode(elm, "class");
27+ public static Contribution createContributionObject(Plugin p, ParamsReader elm) {
28+ ParamsReader el = elm["class"];
2929 Type t = loadTypeFromManifest(el);
3030 object[] args = new object[] { p, elm };
3131 return (Contribution)loadObjectFromManifest(elm, args, null);
3232 }
3333
34- public static IContributionFactory createCtbFactory(Plugin p, XmlElement elm) {
35- XmlElement el = (XmlElement)elm.SelectSingleNode("class");
36- if (el == null) // should use default factory.
34+ public static IContributionFactory createCtbFactory(Plugin p, ParamsReader elm) {
35+ ParamsReader el = elm["class"];
36+ if (el.IsNull) // should use default factory.
3737 return new DefaultContributionFactory(p, elm);
3838 Type t = loadTypeFromManifest(el);
3939 object[] args = t.IsSubclassOf(typeof(Contribution)) ?
@@ -51,9 +51,9 @@
5151 /// <param name="args">arguments array for constructor</param>
5252 /// <param name="defaultType">if 'elm' has no "class" element, use as creation type
5353 /// (can e null)</param>
54- public static object loadObjectFromManifest(XmlElement elm, object[] args, Type defaultType) {
55- XmlElement el = elm.SelectSingleNode("class") as XmlElement;
56- Type t = (el != null) ? loadTypeFromManifest(el) : defaultType;
54+ public static object loadObjectFromManifest(ParamsReader elm, object[] args, Type defaultType) {
55+ ParamsReader el = elm["class"];
56+ Type t = (el.IsNull) ? defaultType : loadTypeFromManifest(el);
5757 return CreateInstance(elm, t, args);
5858 }
5959
@@ -64,19 +64,19 @@
6464 /// </summary>
6565 /// <param name="elm">contribution target node</param>
6666 /// <param name="args">arguments array for constructor</param>
67- public static object loadObjectFromManifest(XmlElement elm, object[] args) {
68- XmlElement el = XmlUtil.SelectSingleNode(elm, "class") as XmlElement;
67+ public static object loadObjectFromManifest(ParamsReader elm, object[] args) {
68+ ParamsReader el = elm["class"];
6969 Type t = loadTypeFromManifest(el);
7070 return CreateInstance(elm, t, args);
7171 }
7272
73- private static object CreateInstance(XmlElement elm, Type t, object[] args) {
73+ private static object CreateInstance(ParamsReader elm, Type t, object[] args) {
7474 try {
7575 // give XmlNode as first argument of constructor.
7676 object result = Activator.CreateInstance(t, args);
7777 if (result == null) {
7878 string templ = Main.resources["xml.class_load_error"].stringValue;
79- throw new Exception(string.Format(templ, t.FullName, elm.OwnerDocument.BaseURI));
79+ throw new Exception(string.Format(templ, t.FullName, elm.SourceURI));
8080 }
8181 return result;
8282 } catch (TargetInvocationException e) {
@@ -83,7 +83,7 @@
8383 Debug.WriteLine(e.Message);
8484 Debug.WriteLine(e.StackTrace);
8585 string templ = Main.resources["xml.class_load_error"].stringValue;
86- throw new Exception(string.Format(templ, t.FullName, elm.OwnerDocument.BaseURI), e);
86+ throw new Exception(string.Format(templ, t.FullName, elm.SourceURI), e);
8787 }
8888 }
8989
@@ -91,36 +91,37 @@
9191 /// Load a type from the name attribute and the codebase attribute .
9292 /// </summary>
9393 /// <param name="e">Typically a "class" element</param>
94- public static Type loadTypeFromManifest( XmlElement e ) {
95- string typeName = e.Attributes["name"].Value;
96- Assembly a;
97- if( e.Attributes["codebase"]==null ) {
94+ public static Type loadTypeFromManifest( ParamsReader e ) {
95+ string typeName = e["name"].InnerText;
96+ Assembly a;
97+ ParamsReader cb = e["codebase"];
98+ if( cb.IsNull ) {
9899 // load the class from the FreeTrain.Main.dll
99100 a = Assembly.GetExecutingAssembly();
100101 } else {
101- string s = e.Attributes["codebase"].Value;
102+ string s = cb.InnerText;
102103 // if start with '.', it's abbreviation of nft.XXX.dll
103104 // at the application base directory.
104105 if(s.StartsWith("."))
105106 s = string.Format("{0}NFT{1}.DLL",Directories.AppBaseDir,s);
106107 // load the class from the specified assembly
107- Uri codeBase = XmlUtil.resolve( e, s );
108-
109- if( !codeBase.IsFile )
110- throw new FormatException("指定されたコードベースはファイル名ではありません:"+codeBase);
111-
112- a = Assembly.LoadFrom( codeBase.LocalPath );
108+ IFileSource f = cb.GetFileSource(s);
109+ if( f==null )
110+ throw new FormatException("指定されたコードベースはファイル名ではありません:"+cb.InnerText);
111+ a = PluginSerializationBinder.SafeLoadAssembly(f);
112+
113113 }
114114 PluginSerializationBinder.registerAssembly(a);
115+ //Debug.Assert(typeName != null);
115116 return a.GetType(typeName,true);
116117 }
117118
118- public static Type loadTypeFromManifest(XmlElement e, Type required) {
119+ public static Type loadTypeFromManifest(ParamsReader e, Type required) {
119120 Type t = loadTypeFromManifest(e);
120121 if (required != null) {
121122 if (!required.IsAssignableFrom(t)) {
122123 string templ = Main.resources["xml.class_cast_error"].stringValue;
123- object[] a2 = new object[] { t.FullName, required.Name, e.BaseURI };
124+ object[] a2 = new object[] { t.FullName, required.Name, e.SourceURI };
124125 throw new InvalidCastException(string.Format(templ, a2));
125126 }
126127 }
@@ -127,13 +128,13 @@
127128 return t;
128129 }
129130
130- public static void RegisterCommand( string id, ICommandEntity_Old entity, XmlNode commandNode )
131+ public static void RegisterCommand( string id, ICommandEntity_Old entity, ParamsReader commandNode )
131132 {
132133 Debug.Assert(entity!=null&&id!=null&&commandNode!=null,"Invalid Command is going to regist!");
133- string pid = PluginUtil.GetPruginDirName(commandNode);
134- string bar = XmlUtil.GetAttribute(commandNode,"toolbar","MAIN");
135- string bid = XmlUtil.GetAttribute(commandNode,"button",null);
136- string mpath = XmlUtil.GetAttribute(commandNode,"menupath",null);
134+ string pid = PluginUtil.GetPluginDirName(commandNode);
135+ string bar = commandNode["toolbar"].InnerTextOr("MAIN");
136+ string bid = commandNode["button"].InnerText;
137+ string mpath = commandNode["menupath"].InnerText;
137138 if( bid != null )
138139 Main.mainFrame.SetToolButtonCommand(id,entity,bar,bid);
139140 if( mpath != null )
@@ -140,12 +141,17 @@
140141 Main.mainFrame.SetMenuCommand(id,entity,mpath);
141142 }
142143
143- public static string GetPruginDirName( XmlNode node )
144+ [Obsolete("Not available.",true)]
145+ public static string GetPluginDirName( XmlNode node )
144146 {
145147 return Path.GetFileName(Path.GetDirectoryName(node.OwnerDocument.BaseURI));
146148 }
147149
148- public static string GetPruginFullPath( XmlNode node )
150+ public static string GetPluginDirName(ParamsReader node) {
151+ return Path.GetFileName(node.SourceURI);
152+ }
153+
154+ public static string GetPluginFullPath( XmlNode node )
149155 {
150156 return Path.GetDirectoryName(node.OwnerDocument.BaseURI);
151157 }
--- NeoFT/framework/framework/plugin/Plugin.cs (revision 105)
+++ NeoFT/framework/framework/plugin/Plugin.cs (revision 106)
@@ -14,7 +14,7 @@
1414 public const string PluginFileName = "plugin.xml";
1515 #region IHasNameAndID メンバ
1616
17- private readonly string _id;
17+ private string _id;
1818 // plugin 'id' is equals to the subdir name where "plugin.xml" is placed.
1919 public string ID {
2020 get { return _id; }
@@ -26,16 +26,16 @@
2626
2727 #endregion
2828
29- private readonly string _title;
29+ private string _title;
3030 public string Title { get { return _title; } }
3131
32- private readonly string _author;
32+ private string _author;
3333 public string author { get { return _author; } }
3434
35- private readonly string _homepage;
35+ private string _homepage;
3636 public string homepage { get { return _homepage; } }
3737
38- private readonly DateTime _lastModified;
38+ internal protected DateTime _lastModified; // settled from PluginManager
3939 public DateTime lastModifiedTime { get { return _lastModified; } }
4040
4141 public string getInfoText(string linecode) {
@@ -44,6 +44,11 @@
4444 }
4545
4646 /// <summary>
47+ /// Location uri of this plug-in
48+ /// </summary>
49+ public readonly Uri Uri;
50+
51+ /// <summary>
4752 /// Base directory of this plug-in
4853 /// </summary>
4954 public readonly string dirName;
@@ -51,14 +56,14 @@
5156 /// <summary>
5257 /// All the contributions in this plug-in
5358 /// </summary>
54- public readonly IList contributions = new ArrayList();
59+ public readonly IList Contributions = new ArrayList();
5560
5661 /// <summary>
5762 /// All the contribution definers and binary modules in this plug-in
5863 /// </summary>
59- public readonly IList primitives = new ArrayList();
64+ public readonly IList Primitives = new ArrayList();
6065
61- public int TotalContribCount { get { return contributions.Count + primitives.Count; } }
66+ //public int TotalContribCount { get { return Contributions.Count + Primitives.Count; } }
6267
6368 /// <summary>
6469 /// Contents of plugin.xml
@@ -65,6 +70,12 @@
6570 /// Available only during the initialization phase.
6671 /// </summary>
6772 private XmlDocument doc;
73+
74+ /// <summary>
75+ /// ParamsReader is given from PluginManager and will set null after loading complete.
76+ /// </summary>
77+ internal protected ParamsReader _reader;
78+
6879 private string data_dir = null;
6980
7081 #region IAddable メンバ
@@ -86,7 +97,7 @@
8697
8798 public void Detach() {
8899 Debug.WriteLine("dt" + totalDetachables);
89- foreach (Contribution c in contributions)
100+ foreach (Contribution c in Contributions)
90101 if (c.QueryDetach())
91102 c.Detach();
92103 if (onDetach != null)
@@ -96,7 +107,7 @@
96107
97108 public void Attach() {
98109 Debug.WriteLine("at" + totalDetachables);
99- foreach (Contribution c in contributions)
110+ foreach (Contribution c in Contributions)
100111 c.Attach();
101112 if (onAttach != null)
102113 onAttach(this);
@@ -127,7 +138,9 @@
127138 /// Loads a plug-in from manifest XML "plugin.xml".
128139 /// dirName does NOT contains the file name "plugin.xml".
129140 /// </summary>
141+ [Obsolete]
130142 public Plugin(string dirName) {
143+ this.Uri = new Uri(dirName);
131144 this.dirName = dirName;
132145 _id = Path.GetFileName(dirName);
133146 _lastModified = lastUpdatedDate(dirName);
@@ -140,6 +153,25 @@
140153 }
141154
142155 /// <summary>
156+ /// Loads a plug-in with ParamsReader".
157+ /// directory name of URI is used as identifier.
158+ /// </summary>
159+ /// <param name="path">URI indicates file source path. folder name is used as plugin ID.</param>
160+ public Plugin(Uri path, DateTime lastModified) {
161+ this.Uri = path;
162+ _lastModified = lastModified;
163+ this.dirName = path.LocalPath; //path.AbsolutePath;
164+ _id = Path.GetFileName(path.LocalPath.Replace("/", "\\"));
165+ }
166+
167+ internal protected void LoadParams(ParamsReader reader){
168+ _reader = reader;
169+ _title = reader["title"].InnerText;
170+ _homepage = reader["homepage"].InnerTextOr("N/A");
171+ _author = reader["author"].InnerTextOr("<unknown>");
172+ }
173+
174+ /// <summary>
143175 /// Can be used for Cashed data storage of this plug-in.
144176 /// Each plug-in has it's isolated sub-directory under the DataDir.
145177 /// </summary>
@@ -161,8 +193,8 @@
161193 if (!this.ID.Equals("system"))
162194 a.Add(PluginManager.theInstance.GetPlugin("system"));
163195
164- foreach (XmlElement depend in doc.DocumentElement.SelectNodes("depend")) {
165- string name = depend.Attributes["on"].Value;
196+ foreach (ParamsReader depend in _reader.EnumChildren("depend")) {
197+ string name = depend["on"].InnerText;
166198 Plugin p = PluginManager.theInstance.GetPlugin(name);
167199 if (p == null) {
168200 string templ = Main.resources["plugin.dependency_not_found"].stringValue;
@@ -176,11 +208,13 @@
176208 /// <summary>
177209 /// Loads plugin.xml file from the directory.
178210 /// </summary>
211+ [Obsolete]
179212 private static XmlDocument loadManifest(string dirName) {
180213 string path = Path.Combine(dirName, PluginFileName);
181214 return XmlUtil.LoadFile(path);
182215 }
183216
217+ [Obsolete]
184218 private static DateTime lastUpdatedDate(string dirName) {
185219 string path = Path.Combine(dirName, PluginFileName);
186220 FileInfo info = new FileInfo(path);
@@ -193,23 +227,22 @@
193227 /// Loads class type contributions from this plug-in
194228 /// </summary>
195229 internal void loadBinaries() {
196- XmlElement root = doc.DocumentElement;
197230 // locate contribution factories first,
198231 // because we'll need them to load contributions.
199- foreach (XmlElement contrib in root.SelectNodes("contribution")) {
200- string type = contrib.Attributes["type"].Value;
232+ foreach (ParamsReader contrib in _reader.EnumChildren("contribution")) {
233+ string type = contrib["type"].InnerText;
201234 try {
202235 Contribution cb = null;
203236 // load a contribution factory
204237 if ("factory".Equals(type)) {
205238 PluginManager.theInstance.NotifyStartParse(this, contrib);
206- XmlNode nd = contrib.SelectSingleNode("declare");
239+ ParamsReader nd = contrib["declare"];
207240 string regtype;
208- if (nd != null) {
209- regtype = XmlUtil.GetAttribute(nd, "type");
241+ if (!nd.IsNull) {
242+ regtype = nd["type"].InnerText;
210243 } else {
211244 // use name property for alternative.
212- regtype = XmlUtil.SelectSingleNode(contrib, "name").InnerText;
245+ regtype = contrib["name"].InnerText;
213246 }
214247 object[] args = new object[] { contrib };
215248 // create and register contribution factory
@@ -232,19 +265,16 @@
232265 continue;
233266 }
234267 if (Contribution.isPrimitiveContribution(cb.GetType())) {
235- primitives.Add(cb);
268+ Primitives.Add(cb);
236269 } else {
237- contributions.Add(cb);
270+ Contributions.Add(cb);
238271 }
239- cb.SetOwner(this);
240272 cb.Attach();
241273 cb._state = InstallationState.Ready;
242274 } catch (Exception e) {
243275 _state = InstallationState.FatalError;
244- string templ = Main.resources["plugin.contrib_load_error"].stringValue;
245- string _id = XmlUtil.GetAttribute(contrib, "id", "unknown");
246- string _name = XmlUtil.GetAttribute(contrib, "name", "unknown");
247- throw new Exception(string.Format(templ, root.BaseURI, _name, _id), e);
276+ string msg = MakeContribExceptionMessage(contrib);
277+ throw new Exception(msg, e);
248278 }
249279 }
250280 }
@@ -253,18 +283,17 @@
253283 /// Loads contributions from this plug-in
254284 /// </summary>
255285 internal void loadContributions() {
256- XmlElement root = doc.DocumentElement;
257286 Contribution c = null;
258287 // load contributions
259- foreach (XmlElement contrib in root.SelectNodes("contribution")) {
288+ foreach (ParamsReader contrib in _reader.EnumChildren("contribution")) {
260289 try {
261- string type = contrib.Attributes["type"].Value;
290+ string type = contrib["type"].InnerText;
262291 if ("factory".Equals(type) || "binary".Equals(type)) continue; // ignore
263292
264293 PluginManager.theInstance.NotifyStartParse(this, contrib);
265294 IContributionFactory factory = PluginManager.theInstance.GetContributionFactory(type);
266295 c = factory.load(this, contrib);
267- contributions.Add(c);
296+ Contributions.Add(c);
268297 c.Attach();
269298 detachable |= c.IsDetachable;
270299 if (c.IsDetachable) {
@@ -273,7 +302,6 @@
273302 c.OnDetach += new AttachChangeEvent(this.AttachChangeEventHandler);
274303 }
275304 PluginManager.theInstance.AddContribution(c);
276- c.SetOwner(this);
277305 c._state = InstallationState.Ready;
278306 } catch (Exception e) {
279307 Debug.WriteLine(e.Message);
@@ -284,10 +312,7 @@
284312 }
285313 if (c != null)
286314 c._state = InstallationState.FatalError;
287- string templ = Main.resources["plugin.contrib_load_error"].stringValue;
288- string _id = XmlUtil.GetAttribute(contrib, "id", "unknown");
289- string _name = XmlUtil.GetAttribute(contrib, "name", "unknown");
290- string msg = string.Format(templ, root.BaseURI, _name, _id);
315+ string msg = MakeContribExceptionMessage(contrib);
291316
292317 if(_state != InstallationState.FatalError)
293318 _state = InstallationState.PartialError;
@@ -298,6 +323,12 @@
298323 _state = InstallationState.Ready;
299324 }
300325
326+ private string MakeContribExceptionMessage(ParamsReader pr) {
327+ string templ = Main.resources["plugin.contrib_load_error"].stringValue;
328+ string _id = pr["id"].InnerTextOr("unknown");
329+ string _name = pr["name"].InnerTextOr("unknown");
330+ return string.Format(templ, dirName, _name, _id);
331+ }
301332
302333 /// <summary>
303334 /// Loads a stream from the plug-in directory.
--- NeoFT/framework/framework/plugin/PluginXmlException.cs (revision 105)
+++ NeoFT/framework/framework/plugin/PluginXmlException.cs (revision 106)
@@ -1,5 +1,6 @@
11 using System;
22 using System.Xml;
3+using System.IO;
34
45 namespace nft.framework.plugin
56 {
@@ -8,17 +9,17 @@
89 /// </summary>
910 public class PluginXmlException : Exception
1011 {
11- protected XmlNode node;
12+ protected ParamsReader node;
1213 protected Plugin plugin = null;
1314 protected Contribution contrib = null;
1415
15- public PluginXmlException(XmlNode node, string msg)
16+ public PluginXmlException(ParamsReader node, string msg)
1617 :base(msg)
1718 {
1819 this.node = node;
1920 }
2021
21- public PluginXmlException(Plugin p, XmlNode node, string msg)
22+ public PluginXmlException(Plugin p, ParamsReader node, string msg)
2223 :this(node,msg)
2324 {
2425 this.plugin = p;
@@ -25,7 +26,7 @@
2526 ConfirmPlugin(node);
2627 }
2728
28- public PluginXmlException(Contribution c, XmlNode node, string msg)
29+ public PluginXmlException(Contribution c, ParamsReader node, string msg)
2930 :this(node,msg)
3031 {
3132 this.contrib = c;
@@ -33,11 +34,11 @@
3334 ConfirmPlugin(node);
3435 }
3536
36- private void ConfirmPlugin(XmlNode node)
37+ private void ConfirmPlugin(ParamsReader node)
3738 {
3839 if(plugin==null)
3940 {
40- string pname = PluginUtil.GetPruginDirName(node);
41+ string pname = Path.GetFileName(Path.GetDirectoryName(node.SourceURI)+"");
4142 plugin = Main.plugins.GetPlugin(pname);
4243 }
4344 }
@@ -61,6 +62,6 @@
6162 return msg;
6263 }
6364
64- public XmlNode SourceNode{ get{ return node; } }
65+ public ParamsReader ParamsReader { get { return node; } }
6566 }
6667 }
--- NeoFT/framework/framework/plugin/CustomContributionFactory.cs (revision 105)
+++ NeoFT/framework/framework/plugin/CustomContributionFactory.cs (revision 106)
@@ -15,20 +15,19 @@
1515 this.baseType = basetype;
1616 }
1717
18- public CustomContributionFactory(XmlElement e)
19- : this(PluginUtil.loadTypeFromManifest(
20- (XmlElement)XmlUtil.SelectSingleNode(e, "basetype"))) { }
18+ public CustomContributionFactory(ParamsReader e)
19+ : this(PluginUtil.loadTypeFromManifest(e["basetype"])) { }
2120
2221
2322 private readonly Type baseType;
2423 public Type OutputType { get { return baseType; } }
2524
26- public Contribution load(Plugin owner, XmlElement e) {
25+ public Contribution load(Plugin owner, ParamsReader e) {
2726 Contribution contrib = Cretate(owner, e);
2827 Debug.Assert(baseType.IsInstanceOfType(contrib));
2928 return contrib;
3029 }
3130
32- protected abstract Contribution Cretate(Plugin owner, XmlElement e);
31+ protected abstract Contribution Cretate(Plugin owner, ParamsReader e);
3332 }
3433 }
--- NeoFT/framework/framework/plugin/CtbContributionDefiner.cs (revision 105)
+++ NeoFT/framework/framework/plugin/CtbContributionDefiner.cs (revision 106)
@@ -10,7 +10,7 @@
1010 [PrimitiveContribution]
1111 public class CtbContributionDefiner : Contribution
1212 {
13- public CtbContributionDefiner(Plugin p, XmlElement e)
13+ public CtbContributionDefiner(Plugin p, ParamsReader e)
1414 : base(p, e)
1515 {
1616 //e.SelectSingleNode("implementesion");
--- NeoFT/framework/framework/plugin/DummyContribution.cs (revision 105)
+++ NeoFT/framework/framework/plugin/DummyContribution.cs (revision 106)
@@ -17,7 +17,7 @@
1717 /// Dummy Contribution for Debug
1818 /// </summary>
1919 /// <exception cref="XmlException">If the parsing fails</exception>
20- public DummyContribution(Plugin p, XmlElement e) : base(p, e) { }
20+ public DummyContribution(Plugin p, ParamsReader e) : base(p, e) { }
2121
2222 // TODO: additional parameters, like population and attractiveness.
2323 }
--- NeoFT/framework/framework/plugin/ContributionFactory.cs (revision 105)
+++ NeoFT/framework/framework/plugin/ContributionFactory.cs (revision 106)
@@ -17,7 +17,7 @@
1717 /// In case of an error, this method must throw an exception
1818 /// instead of silently returning null.
1919 /// </summary>
20- Contribution load( Plugin owner, XmlElement e );
20+ Contribution load( Plugin owner, ParamsReader e );
2121
2222 Type OutputType { get; }
2323 }
@@ -24,24 +24,20 @@
2424
2525 public class DefaultContributionFactory : Contribution, IContributionFactory
2626 {
27- internal protected DefaultContributionFactory(Plugin p, XmlElement elm )
27+ internal protected DefaultContributionFactory(Plugin p, ParamsReader elm)
2828 : base(p, elm)
2929 {
30- XmlNode nd = elm.SelectSingleNode("basetype");
31- if (nd == null) {
32- nd = elm.SelectSingleNode("implementation");
33- if (nd == null)
34- {
35- throw new PluginXmlException(p, elm, "<basetype> is required for ContributionFactory.");
36- }
30+ ParamsReader nd = elm["basetype|implementation"];
31+ if (nd.IsNull) {
32+ throw new PluginXmlException(p, elm, "<basetype> is required for ContributionFactory.");
3733 }
38- this.baseType = PluginUtil.loadTypeFromManifest((XmlElement)nd);
34+ this.baseType = PluginUtil.loadTypeFromManifest(nd);
3935 }
4036
4137 private readonly Type baseType;
4238 public Type OutputType { get{ return baseType; } }
4339
44- public Contribution load( Plugin owner, XmlElement e )
40+ public Contribution load(Plugin owner, ParamsReader e)
4541 {
4642 Contribution contrib = (Contribution)Activator.CreateInstance(baseType, new object[] { owner, e });
4743 if( baseType.IsInstanceOfType(contrib) )
--- NeoFT/framework/framework/plugin/PreFormatterContribution.cs (revision 105)
+++ NeoFT/framework/framework/plugin/PreFormatterContribution.cs (revision 106)
@@ -10,7 +10,7 @@
1010 /// </summary>
1111 public class CtbPreFormatter : Contribution
1212 {
13- public CtbPreFormatter(Plugin p, XmlElement contrib)
13+ public CtbPreFormatter(Plugin p, ParamsReader contrib)
1414 : base(p, contrib)
1515 {
1616 //
--- NeoFT/framework/framework/ParamsReader.cs (revision 105)
+++ NeoFT/framework/framework/ParamsReader.cs (revision 106)
@@ -7,13 +7,17 @@
77 {
88 public class ParamsReader
99 {
10+ private string sourceUri;
1011 private IParamsParser[] loader;
12+ protected IDictionary<string, ParamsReader> overwrites = null;
1113
12- public ParamsReader(IParamsParser ploader) {
14+ public ParamsReader(string srcUri, IParamsParser ploader) {
15+ this.sourceUri = srcUri;
1316 Loaders = ploader != null ? new IParamsParser[] { ploader } : null;
1417 }
1518
16- protected ParamsReader(IParamsParser[] ploaders) {
19+ protected ParamsReader(string srcUri, IParamsParser[] ploaders) {
20+ this.sourceUri = srcUri;
1721 Loaders = ploaders;
1822 }
1923
@@ -21,22 +25,49 @@
2125 get { return PrimaryLoader.InnerText; }
2226 }
2327
28+ /// <summary>
29+ /// Returns InnerText if not null. Returns default_val if InnerText is null.
30+ /// </summary>
31+ /// <param name="defalut_val"></param>
32+ /// <returns></returns>
33+ public string InnerTextOr(string defalut_val) {
34+ string ret =PrimaryLoader.InnerText;
35+ return (ret != null) ? ret : defalut_val;
36+ }
37+
38+ /// <summary>
39+ /// Returns child element corresponds to the key.
40+ /// If this reader contains multiple value, this method enumelates for the first element.
41+ /// </summary>
42+ /// <param name="key"></param>
43+ /// <returns></returns>
2444 public ParamsReader this[string key] {
2545 get {
2646 if (key == null || key.Length == 0) {
27- return new ParamsReader(NullParam.TheInstance);
47+ return new ParamsReader(sourceUri, NullParam.TheInstance);
2848 }
2949 String[] keys = key.Split('|');
3050 if (keys.Length == 1) {
3151 IParamsParser[] parr = FindForKey(PrimaryLoader, keys[0]);
32- return new ParamsReader(parr);
52+ return new ParamsReader(sourceUri, parr);
3353 } else {
3454 IParamsParser[] parr = FindForMultiKeys(PrimaryLoader, keys);
35- return new ParamsReader(parr);
55+ return new ParamsReader(sourceUri, parr);
3656 }
3757 }
3858 }
3959
60+ public void OverWrite(string key, string value) {
61+ OverWrite(key, new ParamsReader(sourceUri, new PlainStringParam(value)));
62+ }
63+
64+ public void OverWrite(string key, ParamsReader value) {
65+ if (overwrites == null) {
66+ overwrites = new Dictionary<string, ParamsReader>();
67+ }
68+ overwrites.Add(key, value);
69+ }
70+
4071 public IFileSource GetFileSource(string path) {
4172 IFileSource src = null;
4273 foreach (IParamsParser pp in loader) {
@@ -49,13 +80,15 @@
4980 public ParamsReader this[int index] {
5081 get {
5182 if (index < 0 || index >= loader.Length) {
52- return new ParamsReader(NullParam.TheInstance);
83+ return new ParamsReader(sourceUri, NullParam.TheInstance);
5384 } else {
54- return new ParamsReader(loader[index]);
85+ return new ParamsReader(sourceUri, loader[index]);
5586 }
5687 }
5788 }
5889
90+ public string SourceURI { get { return sourceUri; } }
91+
5992 public bool IsNull {
6093 get { return loader.Length == 0 || PrimaryLoader.IsNull; }
6194 }
@@ -64,25 +97,46 @@
6497 get { return loader.IsMap; }
6598 }
6699 */
100+ /// <summary>
101+ /// True means multiple values. (Result of multiple children for some key)
102+ /// </summary>
67103 public bool IsArray {
68104 get { return loader.Length>1; }
69105 }
70-
106+ /// <summary>
107+ /// Returns count of elements. (Result of multiple children for some key)
108+ /// </summary>
71109 public int Length {
72110 get { return loader.Length; }
73111 }
74112
75-
76- public IEnumerable<ParamsReader> Enum {
77- get {
78- return new ParamsReaderEnumerator(loader);
113+ /// <summary>
114+ /// Enumelate all children
115+ /// </summary>
116+ public IEnumerable<ParamsReader> Each {
117+ get {
118+ return new ParamsArrayEnumerator(sourceUri, loader);
79119 }
80120 }
81121
122+ /// <summary>
123+ /// Enumelate all children witch match specified key.
124+ /// </summary>
125+ /// <param name="key"></param>
126+ /// <returns></returns>
82127 public IEnumerable<ParamsReader> EnumChildren(string key) {
83- return new KeyedParamsReaderEnumerator(loader, key);
128+ return new KeySpecifiedChildParamsEnumerator(sourceUri, loader, key);
84129 }
85130
131+ /// <summary>
132+ /// Enumelate all children with it's key.
133+ /// If this reader contains multiple value, this method enumelates for the first element.
134+ /// </summary>
135+ /// <returns></returns>
136+ public IEnumerable<KeyValuePair<string,ParamsReader>> EnumChildren() {
137+ return new ChildParamsReaderEnumerator(sourceUri, PrimaryLoader);
138+ }
139+
86140 protected IParamsParser PrimaryLoader {
87141 get {
88142 return loader.Length>0 ? loader[0]:NullParam.TheInstance;
@@ -102,8 +156,13 @@
102156 }
103157 }
104158
105- static protected IParamsParser[] FindForKey(IParamsParser p, String key) {
159+ protected IParamsParser[] FindForKey(IParamsParser p, String key) {
106160 List<IParamsParser> arr = new List<IParamsParser>();
161+ ParamsReader ror;
162+ // append overwirted value at first (if exist).
163+ if (overwrites != null && overwrites.TryGetValue(key, out ror)) {
164+ arr.Add(ror.PrimaryLoader);
165+ }
107166 IEnumerator<IParamsParser> en = p.EnumChildren(key);
108167 while (en.MoveNext()) {
109168 arr.Add(en.Current);
@@ -111,8 +170,16 @@
111170 return arr.ToArray();
112171 }
113172
114- static protected IParamsParser[] FindForMultiKeys(IParamsParser p, String[] keys) {
173+ protected IParamsParser[] FindForMultiKeys(IParamsParser p, String[] keys) {
115174 List<IParamsParser> arr = new List<IParamsParser>();
175+ foreach (String k in keys) {
176+ ParamsReader ror;
177+ // append overwirted value at first (if exist).
178+ if (overwrites != null && overwrites.TryGetValue(k, out ror)) {
179+ arr.Add(ror.PrimaryLoader);
180+ break;
181+ }
182+ }
116183 IEnumerator<KeyValuePair<String, IParamsParser>> en = p.EnumChildren();
117184 while (en.MoveNext()) {
118185 foreach (String k in keys) {
@@ -126,11 +193,12 @@
126193 return arr.ToArray();
127194 }
128195
129- internal protected class ParamsReaderEnumerator : IEnumerable<ParamsReader>
196+ internal protected class ParamsArrayEnumerator : IEnumerable<ParamsReader>
130197 {
131198 protected readonly IParamsParser[] array;
132-
133- public ParamsReaderEnumerator(IParamsParser[] arr) {
199+ protected readonly string sourceUri;
200+ public ParamsArrayEnumerator(string srcUri, IParamsParser[] arr) {
201+ this.sourceUri = srcUri;
134202 if (arr == null) arr = new IParamsParser[0];
135203 this.array = arr;
136204 }
@@ -137,7 +205,7 @@
137205
138206 public IEnumerator<ParamsReader> GetEnumerator() {
139207 foreach (IParamsParser pp in array) {
140- yield return new ParamsReader(pp);
208+ yield return new ParamsReader(sourceUri, pp);
141209 }
142210 }
143211
@@ -146,12 +214,14 @@
146214 }
147215 }
148216
149- internal protected class KeyedParamsReaderEnumerator : IEnumerable<ParamsReader>
217+ internal protected class KeySpecifiedChildParamsEnumerator : IEnumerable<ParamsReader>
150218 {
151219 protected readonly IParamsParser[] array;
220+ protected readonly string sourceUri;
152221 protected readonly string key;
153222
154- public KeyedParamsReaderEnumerator(IParamsParser[] arr, string key) {
223+ public KeySpecifiedChildParamsEnumerator(string srcUri, IParamsParser[] arr, string key) {
224+ this.sourceUri = srcUri;
155225 if (arr == null) arr = new IParamsParser[0];
156226 this.array = arr;
157227 this.key = key;
@@ -164,7 +234,7 @@
164234 foreach (IParamsParser pp in array) {
165235 IEnumerator<IParamsParser> en = pp.EnumChildren(key);
166236 while (en.MoveNext()) {
167- yield return new ParamsReader(en.Current);
237+ yield return new ParamsReader(sourceUri, en.Current);
168238 }
169239 }
170240 } else {
@@ -173,7 +243,7 @@
173243 while (en.MoveNext()) {
174244 foreach (String k in keys) {
175245 if (en.Current.Key.Equals(keys)) {
176- yield return new ParamsReader(en.Current.Value);
246+ yield return new ParamsReader(sourceUri, en.Current.Value);
177247 break;
178248 }
179249 }
@@ -186,5 +256,29 @@
186256 return GetEnumerator();
187257 }
188258 }
259+
260+ internal protected class ChildParamsReaderEnumerator : IEnumerable<KeyValuePair<string, ParamsReader>>
261+ {
262+ protected readonly IParamsParser parser;
263+ protected readonly string sourceUri;
264+ public ChildParamsReaderEnumerator(string srcUri, IParamsParser pp) {
265+ this.sourceUri = srcUri;
266+ if (pp == null) pp = NullParam.TheInstance;
267+ this.parser = pp;
268+ }
269+
270+ public IEnumerator<KeyValuePair<string, ParamsReader>> GetEnumerator() {
271+ IEnumerator<KeyValuePair<string, IParamsParser>> en = parser.EnumChildren();
272+ while (en.MoveNext()) {
273+ KeyValuePair<string, IParamsParser> pair = en.Current;
274+ ParamsReader pr = new ParamsReader(sourceUri, pair.Value);
275+ yield return new KeyValuePair<string, ParamsReader>(pair.Key, pr);
276+ }
277+ }
278+
279+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
280+ return GetEnumerator();
281+ }
282+ }
189283 }
190284 }
--- NeoFT/framework/ui/command/CommandUI.cs (revision 105)
+++ NeoFT/framework/ui/command/CommandUI.cs (revision 106)
@@ -14,22 +14,22 @@
1414 public static readonly int IconIndexUnassinged = -1;
1515 protected CommandUI() { }
1616
17- public CommandUI(Contribution owner, XmlElement e) {
18- string cap = XmlUtil.GetSingleNodeText(e, "caption", null);
19- this.capShort = XmlUtil.GetSingleNodeText(e, "short-caption", cap);
20- this.capLong = XmlUtil.GetSingleNodeText(e, "long-caption", cap);
21- this.desc = XmlUtil.GetSingleNodeText(e, "description", null);
22- XmlElement eico = e.SelectSingleNode("icon") as XmlElement;
23- if (eico != null) {
24- string iconpath = XmlUtil.GetSingleNodeText(e, "icon", null);
17+ public CommandUI(Contribution owner, ParamsReader e) {
18+ string cap = e["caption"].InnerText;
19+ this.capShort = e["short-caption"].InnerTextOr(cap);
20+ this.capLong = e["long-caption"].InnerTextOr(cap);
21+ this.desc = e["description"].InnerText;
22+ ParamsReader eico = e["icon"];
23+ if (!eico.IsNull) {
24+ string iconpath = eico.InnerText;
2525 this.icon = PluginImageManager.GetBundledImageRef(owner, iconpath);
26- XmlAttribute xa = eico.Attributes["index"];
27- if (xa != null) {
28- this.iconIdx = int.Parse(xa.Value);
26+ ParamsReader xa = eico["index"];
27+ if (!xa.IsNull) {
28+ this.iconIdx = int.Parse(xa.InnerText);
2929 }
30- }
31- XmlElement ent = e.SelectSingleNode("entity") as XmlElement;
32- if (ent != null) {
30+ }
31+ ParamsReader ent = e["entity"];
32+ if (!ent.IsNull) {
3333 this.entity = LoadEntityFromManifest(ent);
3434 }
3535 }
@@ -183,7 +183,7 @@
183183 }
184184 }
185185
186- protected virtual ICommandEntity LoadEntityFromManifest(XmlElement e) {
186+ protected virtual ICommandEntity LoadEntityFromManifest(ParamsReader e) {
187187 object[] args = new object[] { e };
188188 object ret = PluginUtil.loadObjectFromManifest(e, args);
189189 return (ICommandEntity)ret;
@@ -193,7 +193,7 @@
193193 public class TriggerCommandUI : CommandUI {
194194 protected TriggerCommandUI() { }
195195
196- public TriggerCommandUI(Contribution owner, XmlElement e)
196+ public TriggerCommandUI(Contribution owner, ParamsReader e)
197197 : base(owner, e) {
198198 }
199199
@@ -207,7 +207,7 @@
207207 public class SingleSelFixedListUI : CommandUI {
208208 protected SingleSelFixedListUI() { }
209209
210- public SingleSelFixedListUI(Contribution owner, XmlElement e)
210+ public SingleSelFixedListUI(Contribution owner, ParamsReader e)
211211 : base(owner, e) {
212212 }
213213
--- NeoFT/framework/ui/command/SubformCommand.cs (revision 105)
+++ NeoFT/framework/ui/command/SubformCommand.cs (revision 106)
@@ -32,7 +32,7 @@
3232
3333 readonly CtbSubform innerCtb;
3434
35- public SubformCommand(XmlElement e) {
35+ public SubformCommand(ParamsReader e) {
3636 innerCtb = new CtbSubform(null, e);
3737 }
3838
--- NeoFT/framework/ui/command/CommandManager.cs (revision 105)
+++ NeoFT/framework/ui/command/CommandManager.cs (revision 106)
@@ -64,11 +64,11 @@
6464 protected string before;
6565 protected string after;
6666
67- public CommandPathHint(XmlElement e) {
68- this.ID = XmlUtil.GetAttribute(e, "id");
69- this.Parent = XmlUtil.GetAttribute(e, "parent");
70- this.Before = XmlUtil.GetAttribute(e, "before", null);
71- this.After = XmlUtil.GetAttribute(e, "after", null);
67+ public CommandPathHint(ParamsReader e) {
68+ this.ID = e["id"].InnerText;
69+ this.Parent = e["parent"].InnerText;
70+ this.Before = e["before"].InnerText;
71+ this.After = e["after"].InnerText;
7272 }
7373
7474 public CommandPathHint(string id) {
--- NeoFT/TestLauncher/test/SomeTest.cs (nonexistent)
+++ NeoFT/TestLauncher/test/SomeTest.cs (revision 106)
@@ -0,0 +1,30 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using nft.framework;
6+using System.IO;
7+using System.Diagnostics;
8+
9+namespace nft.test.test
10+{
11+ class SomeTest
12+ {
13+ [TestEntry(new object[]{@"C:\test\testsub"})]
14+ [TestEntry(new object[] { "file://c:/test/testsub" })]
15+ [TestEntry(new object[] { "http://test.com/test/testsub2" })]
16+ static private string Test1(string path) {
17+ string localpath = new Uri(path).LocalPath;
18+ Debug.WriteLine(localpath);
19+ return Path.GetFileName(localpath);
20+ }
21+
22+ [TestEntry(new object[] { @"C:\test\testsub.xml" })]
23+ [TestEntry(new object[] { "file://c:/test/testsub" })]
24+ [TestEntry(new object[] { "http://test.com/test/testsub2.xml" })]
25+ static private string Test2(string path) {
26+ return Path.GetFileName(Path.GetDirectoryName(path) + "");
27+ }
28+
29+ }
30+}
--- NeoFT/TestLauncher/test/ParamsReaderTest.cs (revision 105)
+++ NeoFT/TestLauncher/test/ParamsReaderTest.cs (revision 106)
@@ -23,8 +23,8 @@
2323 [TestEntry]
2424 static private void TestXmlParser(){
2525 XmlParamParser parser = new XmlParamParser(doc);
26- ParamsReader reader = new ParamsReader(parser);
27- ParamsReader r2 = reader["plug-in "];
26+ ParamsReader reader = new ParamsReader(doc.BaseURI, parser);
27+ ParamsReader r2 = reader["plug-in"];
2828 Debug.WriteLine("title = " + r2["title"].InnerText);
2929 foreach (ParamsReader r3 in r2.EnumChildren("contribution")) {
3030 Debug.Write("name = " + r3["name"].InnerText);
--- NeoFT/ui_jp/ui/WinFormManager.cs (revision 105)
+++ NeoFT/ui_jp/ui/WinFormManager.cs (revision 106)
@@ -11,7 +11,7 @@
1111 public class WinFormManager : IFormManager
1212 {
1313
14- public WinFormManager(XmlNode node) {
14+ public WinFormManager(ParamsReader node) {
1515 }
1616
1717 public void Register(string name, Type win_form_class) {
--- NeoFT/ui_jp/ui/system/ErrorMessageBox.cs (revision 105)
+++ NeoFT/ui_jp/ui/system/ErrorMessageBox.cs (revision 106)
@@ -7,6 +7,7 @@
77 using nft.framework;
88 using nft.controls;
99 using System.Text;
10+using System.Diagnostics;
1011
1112 namespace nft.ui.system
1213 {
@@ -224,6 +225,7 @@
224225 }
225226
226227 private void throwButton_Click(object sender, EventArgs e) {
228+ Debug.WriteLine(detail.Text);
227229 throw exception;
228230 }
229231 }
--- NeoFT/ui_jp/ui/system/PluginListDialog.cs (revision 105)
+++ NeoFT/ui_jp/ui/system/PluginListDialog.cs (revision 106)
@@ -323,9 +323,9 @@
323323 {
324324 Application.DoEvents();
325325 Plugin p = (Plugin)item.Tag;
326- foreach (Contribution c in p.primitives)
326+ foreach (Contribution c in p.Primitives)
327327 clist.Items.Add( CreateListItem(c) );
328- foreach( Contribution c in p.contributions )
328+ foreach( Contribution c in p.Contributions )
329329 clist.Items.Add( CreateListItem(c) );
330330 }
331331 }
@@ -336,9 +336,9 @@
336336 if(p!=null)
337337 {
338338 e.Node.Nodes.Clear();
339- foreach (Contribution c in p.primitives)
339+ foreach (Contribution c in p.Primitives)
340340 e.Node.Nodes.Add( CreateTreeItem(c) );
341- foreach( Contribution c in p.contributions )
341+ foreach( Contribution c in p.Contributions )
342342 e.Node.Nodes.Add( CreateTreeItem(c) );
343343 }
344344 }
Show on old repository browser