load Plugin/Contributions through ParamsReader.
@@ -172,20 +172,11 @@ | ||
172 | 172 | GraphicsDeviceService graphicsDeviceService; |
173 | 173 | ServiceContainer services; |
174 | 174 | |
175 | - public XnaGraphicManager(XmlNode node) | |
175 | + public XnaGraphicManager(ParamsReader node) | |
176 | 176 | { |
177 | 177 | 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)"); | |
189 | 180 | Initialize(atr_name, atr_desc); |
190 | 181 | ConfigureService.OnSystemInfoRequested += new AdditonalSystemInfoHandler(ConfigureService_OnSystemInfoRequested); |
191 | 182 | } |
@@ -22,12 +22,18 @@ | ||
22 | 22 | /// </summary> |
23 | 23 | public class CtbImageResouceFactory : CtbCustomCtbFactory |
24 | 24 | { |
25 | - public CtbImageResouceFactory(Plugin p, XmlElement contrib) | |
25 | + public CtbImageResouceFactory(Plugin p, ParamsReader contrib) | |
26 | 26 | : base(p, contrib) { |
27 | 27 | } |
28 | 28 | |
29 | - protected override Contribution Create(Plugin owner, XmlElement e) | |
29 | + protected override Contribution Create(Plugin owner, ParamsReader e) | |
30 | 30 | { |
31 | + ParamsReader src = e["src"]; | |
32 | + if(!src.IsNull){ | |
33 | + e.OverWrite("name","Image:"+src.InnerText); | |
34 | + } else { | |
35 | + e.OverWrite("name","<unknown>"); | |
36 | + } | |
31 | 37 | return new CtbImageResource(owner, e); |
32 | 38 | } |
33 | 39 |
@@ -20,14 +20,13 @@ | ||
20 | 20 | protected bool auto_color_key; |
21 | 21 | protected string src_text; |
22 | 22 | |
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) | |
25 | 24 | { |
26 | 25 | reffer = null; |
27 | - XmlNode nd = contrib.SelectSingleNode("src"); | |
26 | + ParamsReader nd = contrib["src"]; | |
28 | 27 | 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; | |
31 | 30 | if (auto_color_key) |
32 | 31 | { |
33 | 32 | colorkey = Color.Transparent; |
@@ -34,7 +33,7 @@ | ||
34 | 33 | } |
35 | 34 | else |
36 | 35 | { |
37 | - colorkey = StringParseUtil.CreateColor(attext); | |
36 | + colorkey = StringParseUtil.CreateColor(ckey.InnerText); | |
38 | 37 | } |
39 | 38 | |
40 | 39 | } |
@@ -19,12 +19,12 @@ | ||
19 | 19 | public readonly Color BaseColor; |
20 | 20 | protected HeightCutPlaneImgSet imgSet; |
21 | 21 | |
22 | - public CtbHeightCutPlaneTexture(Plugin p, CtbHeightCutPlaneTextureFactory factory, XmlElement ctb) | |
22 | + public CtbHeightCutPlaneTexture(Plugin p, CtbHeightCutPlaneTextureFactory factory, ParamsReader ctb) | |
23 | 23 | : base(p, ctb) { |
24 | 24 | if (HeightCutPlaneImgSet.textureFactory == null) { |
25 | 25 | HeightCutPlaneImgSet.textureFactory = factory; |
26 | 26 | } |
27 | - string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null); | |
27 | + string text = ctb["basecolor"].InnerText; | |
28 | 28 | BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text)); |
29 | 29 | CreateAndRegister(BaseColor, out imgSet); |
30 | 30 | } |
@@ -99,12 +99,12 @@ | ||
99 | 99 | public readonly Color BaseColor; |
100 | 100 | protected HeightCutSlopeImgSet imgSet; |
101 | 101 | |
102 | - public CtbHeightCutSlopeTexture(Plugin p, CtbHeightCutSlopeTextureFactory factory, XmlElement ctb) | |
102 | + public CtbHeightCutSlopeTexture(Plugin p, CtbHeightCutSlopeTextureFactory factory, ParamsReader ctb) | |
103 | 103 | : base(p, ctb) { |
104 | 104 | if (HeightCutSlopeImgSet.textureFactory == null) { |
105 | 105 | HeightCutSlopeImgSet.textureFactory = factory; |
106 | 106 | } |
107 | - string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null); | |
107 | + string text = ctb["basecolor"].InnerText; | |
108 | 108 | BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text)); |
109 | 109 | CreateAndRegister(BaseColor, out imgSet); |
110 | 110 | } |
@@ -34,7 +34,7 @@ | ||
34 | 34 | // Template set of Ground Images. Used for like a clipping mask. |
35 | 35 | protected PlainGroundImgSet imageSet; |
36 | 36 | |
37 | - public CtbGroundTextureFactory(Plugin p, XmlElement contrib) | |
37 | + public CtbGroundTextureFactory(Plugin p, ParamsReader contrib) | |
38 | 38 | : base(p, contrib) { |
39 | 39 | imageSet = new PlainGroundImgSet(DataDirectory); |
40 | 40 | } |
@@ -50,7 +50,7 @@ | ||
50 | 50 | imageSet.PrepareCache(); |
51 | 51 | } |
52 | 52 | |
53 | - protected override Contribution Create(Plugin owner, XmlElement e) | |
53 | + protected override Contribution Create(Plugin owner, ParamsReader e) | |
54 | 54 | { |
55 | 55 | //TODO:将来テクスチャ画像対応の地形テクスチャも… |
56 | 56 | return new CtbSimpleGroundTexture(owner, this, e); |
@@ -19,9 +19,9 @@ | ||
19 | 19 | public readonly Color BaseColor; |
20 | 20 | protected SimpleGroundPlateSet plateSet; |
21 | 21 | |
22 | - public CtbSimpleGroundTexture(Plugin p, CtbGroundTextureFactory factory, XmlElement ctb) | |
22 | + public CtbSimpleGroundTexture(Plugin p, CtbGroundTextureFactory factory, ParamsReader ctb) | |
23 | 23 | : base(p, ctb) { |
24 | - string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null); | |
24 | + string text = ctb["basecolor"].InnerText; | |
25 | 25 | BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text)); |
26 | 26 | CreateAndRegister(this, BaseColor, out plateSet); |
27 | 27 | } |
@@ -33,7 +33,7 @@ | ||
33 | 33 | // Template set of Cliff Images. Used for like a clipping mask. |
34 | 34 | protected PlainCliffImgSet imageSet; |
35 | 35 | |
36 | - public CtbCliffTextureFactory(Plugin p, XmlElement contrib) | |
36 | + public CtbCliffTextureFactory(Plugin p, ParamsReader contrib) | |
37 | 37 | : base(p, contrib) { |
38 | 38 | imageSet = new PlainCliffImgSet(DataDirectory); |
39 | 39 | } |
@@ -54,7 +54,7 @@ | ||
54 | 54 | textureCache = new Dictionary<Int32, ITextureOld>(num); |
55 | 55 | } |
56 | 56 | |
57 | - protected override Contribution Create(Plugin owner, XmlElement e) | |
57 | + protected override Contribution Create(Plugin owner, ParamsReader e) | |
58 | 58 | { |
59 | 59 | //TODO:将来テクスチャ画像対応の地形テクスチャも… |
60 | 60 | return new CtbSimpleCliffTexture(owner, this, e); |
@@ -26,12 +26,12 @@ | ||
26 | 26 | //public static ITexture GetSilhouetteTexture(Scaler scl, short id) { |
27 | 27 | // return theInstance.GetTexture(scl, id); |
28 | 28 | //} |
29 | - | |
30 | - public CtbHeightCutPlaneTextureFactory(Plugin p, XmlElement contrib) | |
29 | + | |
30 | + public CtbHeightCutPlaneTextureFactory(Plugin p, ParamsReader contrib) | |
31 | 31 | : base(p, contrib) { |
32 | 32 | } |
33 | 33 | |
34 | - protected override Contribution Create(Plugin owner, XmlElement e) | |
34 | + protected override Contribution Create(Plugin owner, ParamsReader e) | |
35 | 35 | { |
36 | 36 | //TODO:将来テクスチャ画像対応の地形テクスチャも… |
37 | 37 | return new CtbHeightCutPlaneTexture(owner, this, e); |
@@ -39,11 +39,11 @@ | ||
39 | 39 | } |
40 | 40 | |
41 | 41 | public class CtbHeightCutSlopeTextureFactory : CtbCustomCtbFactory { |
42 | - public CtbHeightCutSlopeTextureFactory(Plugin p, XmlElement contrib) | |
42 | + public CtbHeightCutSlopeTextureFactory(Plugin p, ParamsReader contrib) | |
43 | 43 | : base(p, contrib) { |
44 | 44 | } |
45 | 45 | |
46 | - protected override Contribution Create(Plugin owner, XmlElement e) { | |
46 | + protected override Contribution Create(Plugin owner, ParamsReader e) { | |
47 | 47 | //TODO:将来テクスチャ画像対応の地形テクスチャも… |
48 | 48 | return new CtbHeightCutSlopeTexture(owner, this, e); |
49 | 49 | } |
@@ -19,9 +19,9 @@ | ||
19 | 19 | public readonly Color BaseColor; |
20 | 20 | protected SimpleCliffPlateSet plateSet; |
21 | 21 | |
22 | - public CtbSimpleCliffTexture(Plugin p, CtbCliffTextureFactory factory, XmlElement ctb) | |
22 | + public CtbSimpleCliffTexture(Plugin p, CtbCliffTextureFactory factory, ParamsReader ctb) | |
23 | 23 | : base(p, ctb) { |
24 | - string text = XmlUtil.GetSingleNodeText(ctb, "basecolor", null); | |
24 | + string text = ctb["basecolor"].InnerText; | |
25 | 25 | BaseColor = ColorUtil.To12BitColor(StringParseUtil.CreateColor(text)); |
26 | 26 | CreateAndRegister(this, BaseColor, out plateSet); |
27 | 27 | } |
@@ -13,6 +13,7 @@ | ||
13 | 13 | using System.Runtime.InteropServices; |
14 | 14 | using System.Diagnostics; |
15 | 15 | using nft.framework.plugin; |
16 | +using nft.framework; | |
16 | 17 | |
17 | 18 | namespace nft.contributions.game { |
18 | 19 | public class CtbImageImportTerrainGenerator : CtbTerrainGenerator, ITerrainGenerator |
@@ -24,7 +25,7 @@ | ||
24 | 25 | public const string KEY_COLOR_CHANNEL = "UseColorChannel"; |
25 | 26 | public const string KEY_SEA_LEVEL_HEIGHT = "SeaLevelHeight"; |
26 | 27 | |
27 | - public CtbImageImportTerrainGenerator(Plugin p, XmlElement contrib) : base(p, contrib) { } | |
28 | + public CtbImageImportTerrainGenerator(Plugin p, ParamsReader contrib) : base(p, contrib) { } | |
28 | 29 | public override ITerrainGenerator Generator { get { return this; } } |
29 | 30 | |
30 | 31 | #region ITerrainGenerator メンバ |
@@ -19,7 +19,7 @@ | ||
19 | 19 | /// </summary> |
20 | 20 | public abstract class CtbTerrainGenerator : CtbMapGenerator, ITerrainGenerator |
21 | 21 | { |
22 | - public CtbTerrainGenerator(Plugin p, XmlElement contrib) : base(p, contrib) { } | |
22 | + public CtbTerrainGenerator(Plugin p, ParamsReader contrib) : base(p, contrib) { } | |
23 | 23 | public abstract ITerrainGenerator Generator { get; } |
24 | 24 | public static Array ListEnabled() |
25 | 25 | { |
@@ -38,7 +38,7 @@ | ||
38 | 38 | public const string KEY_MAX_HEIGHT = "MaxHeight"; |
39 | 39 | public const string KEY_GROUND_LEVEL = "GroundLevel"; |
40 | 40 | |
41 | - public CtbFlatTerrainGenerator(Plugin p, XmlElement contrib) : base(p, contrib) { } | |
41 | + public CtbFlatTerrainGenerator(Plugin p, ParamsReader contrib) : base(p, contrib) { } | |
42 | 42 | public override ITerrainGenerator Generator { get { return this; } } |
43 | 43 | |
44 | 44 | #region ITerrainGenerator メンバ |
@@ -17,7 +17,7 @@ | ||
17 | 17 | /// </summary> |
18 | 18 | public abstract class CtbWorldDivider : CtbMapGenerator, IWorldDivider |
19 | 19 | { |
20 | - public CtbWorldDivider(Plugin p, XmlElement contrib) : base(p, contrib) { } | |
20 | + public CtbWorldDivider(Plugin p, ParamsReader contrib) : base(p, contrib) { } | |
21 | 21 | public abstract IWorldDivider Divider { get; } |
22 | 22 | public static Array ListEnabled() |
23 | 23 | { |
@@ -33,7 +33,7 @@ | ||
33 | 33 | |
34 | 34 | public class CtbSimpleDivider : CtbWorldDivider |
35 | 35 | { |
36 | - public CtbSimpleDivider(Plugin p, XmlElement contrib) : base(p, contrib) { } | |
36 | + public CtbSimpleDivider(Plugin p, ParamsReader contrib) : base(p, contrib) { } | |
37 | 37 | public override IWorldDivider Divider { get { return this; } } |
38 | 38 | |
39 | 39 | #region IWorldDivider メンバ |
@@ -4,10 +4,11 @@ | ||
4 | 4 | using nft.framework.plugin; |
5 | 5 | using System.Xml; |
6 | 6 | using System.Diagnostics; |
7 | +using nft.framework; | |
7 | 8 | |
8 | 9 | namespace nft.debug { |
9 | 10 | class TestBinaryModule :BinaryModule { |
10 | - public TestBinaryModule(Plugin p, XmlElement e) | |
11 | + public TestBinaryModule(Plugin p, ParamsReader e) | |
11 | 12 | : base(p, e) { |
12 | 13 | Debug.WriteLine("TestBinaryModule Constructed"); |
13 | 14 | } |
@@ -53,11 +53,11 @@ | ||
53 | 53 | protected Type typeSetupUI = null; |
54 | 54 | protected IMapGeneSetupPanel pnlSetupUI; |
55 | 55 | |
56 | - public CtbMapGenerator(Plugin p, XmlElement contrib) | |
56 | + public CtbMapGenerator(Plugin p, ParamsReader contrib) | |
57 | 57 | : 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); | |
61 | 61 | if (typeof(IMapGeneSetupPanel).IsAssignableFrom(t)) { |
62 | 62 | typeSetupUI = t; |
63 | 63 | } else { |
@@ -22,13 +22,13 @@ | ||
22 | 22 | /// |
23 | 23 | /// This contribution can add several items at once. |
24 | 24 | /// </summary> |
25 | - public CtbMenuItem(Plugin p, XmlElement e) | |
25 | + public CtbMenuItem(Plugin p, ParamsReader e) | |
26 | 26 | : base(p, e) |
27 | 27 | { |
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 | |
30 | 30 | CommandPathHint hint = new CommandPathHint(parent); |
31 | - XmlNode entries = XmlUtil.SelectSingleNode(e,"entries"); | |
31 | + ParamsReader entries = e["entries"]; | |
32 | 32 | if ("ROOT".Equals(hint.Parent)) |
33 | 33 | hint.Parent = ""; |
34 | 34 | location = hint.Parent; |
@@ -35,31 +35,28 @@ | ||
35 | 35 | parseNode(entries, hint); |
36 | 36 | } |
37 | 37 | |
38 | - protected void parseNode(XmlNode node, CommandPathHint hint) | |
38 | + protected void parseNode(ParamsReader node, CommandPathHint hint) | |
39 | 39 | { |
40 | - foreach( XmlNode cn in node.ChildNodes ) | |
40 | + foreach (ParamsReader cn in node.EnumChildren("item")) | |
41 | 41 | { |
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) | |
43 | 47 | { |
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); | |
55 | 52 | } |
56 | 53 | } |
57 | 54 | |
58 | 55 | } |
59 | 56 | |
60 | - protected CommandUI parseItem(XmlNode item) | |
57 | + protected CommandUI parseItem(ParamsReader item) | |
61 | 58 | { |
62 | - string _cap = XmlUtil.GetAttribute(item, "caption", "").Trim(); | |
59 | + string _cap = item["caption"].InnerTextOr("").Trim(); | |
63 | 60 | TriggerCommandUI cui = new TriggerCommandUI(_cap, item.InnerText, null); |
64 | 61 | return cui; |
65 | 62 | } |
@@ -23,14 +23,14 @@ | ||
23 | 23 | /// |
24 | 24 | /// This contribution can add several items at once. |
25 | 25 | /// </summary> |
26 | - public CtbCommandUIGroup(Plugin p, XmlElement e) | |
26 | + public CtbCommandUIGroup(Plugin p, ParamsReader e) | |
27 | 27 | : base(p, e) |
28 | 28 | { |
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); | |
34 | 34 | ImageRef imgref = PluginImageManager.GetBundledImageRef(this, iconpath); |
35 | 35 | } |
36 | 36 |
@@ -21,24 +21,23 @@ | ||
21 | 21 | /// |
22 | 22 | /// This contribution can add several items at once. |
23 | 23 | /// </summary> |
24 | - public CtbToolButton(Plugin p, XmlElement e) | |
24 | + public CtbToolButton(Plugin p, ParamsReader e) | |
25 | 25 | : base(p, e) { |
26 | - XmlElement bar = (XmlElement)XmlUtil.SelectSingleNode(e, "bar"); | |
26 | + ParamsReader bar = e["bar"]; | |
27 | 27 | parseNode(bar); |
28 | 28 | } |
29 | 29 | |
30 | - protected void parseNode(XmlElement ebar) | |
30 | + protected void parseNode(ParamsReader ebar) | |
31 | 31 | { |
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 | |
35 | 35 | CommandPathHint hint = new CommandPathHint(ebar); |
36 | - foreach (XmlNode cn in ebar.ChildNodes) | |
36 | + foreach (ParamsReader cn in ebar.EnumChildren("button")) | |
37 | 37 | { |
38 | - if(!cn.Name.Equals("button")) continue; | |
39 | 38 | //ButtonCreationInfo info = parseButton(cn); |
40 | 39 | //Main.mainFrame.AddToolButton(info,barname,after,before); |
41 | - hint.ID = XmlUtil.GetAttribute(cn, "bid", "").Trim(); | |
40 | + hint.ID = cn["bid"].InnerTextOr("").Trim(); | |
42 | 41 | CommandUI cui = parseButton(cn); |
43 | 42 | CommandManager.TheInstance.RegisterCommand(this, cui, null, hint); |
44 | 43 |
@@ -46,14 +45,14 @@ | ||
46 | 45 | |
47 | 46 | } |
48 | 47 | |
49 | - protected CommandUI parseButton(XmlNode item) | |
48 | + protected CommandUI parseButton(ParamsReader item) | |
50 | 49 | { |
51 | - string _img = XmlUtil.GetAttribute(item,"image").Trim(); | |
50 | + string _img = item["image"].InnerText.Trim(); | |
52 | 51 | ImageRef iref = PluginImageManager.GetBundledImageRef(this, _img); |
53 | - string _cap = XmlUtil.GetAttribute(item, "caption", "").Trim(); | |
52 | + string _cap = item["caption"].InnerTextOr("").Trim(); | |
54 | 53 | 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) { | |
57 | 56 | cui.IconIndex = int.Parse(aidx.InnerText); |
58 | 57 | } |
59 | 58 | return cui; |
@@ -22,20 +22,21 @@ | ||
22 | 22 | protected readonly string methodName; |
23 | 23 | private string path; |
24 | 24 | |
25 | - public CtbCommandEntity(Plugin p, XmlElement contrib ) : base(p, contrib) | |
25 | + public CtbCommandEntity(Plugin p, ParamsReader contrib) | |
26 | + : base(p, contrib) | |
26 | 27 | { |
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); | |
30 | 31 | |
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"); | |
34 | 35 | |
35 | - if( mn!=null ) | |
36 | + if(!mn.IsNull) | |
36 | 37 | { |
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"))) | |
39 | 40 | methodType = MethodType.Static; |
40 | 41 | else |
41 | 42 | methodType = MethodType.Instance; |
@@ -43,7 +44,7 @@ | ||
43 | 44 | if( methodName == null ) |
44 | 45 | { |
45 | 46 | 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)); | |
47 | 48 | } |
48 | 49 | } |
49 | 50 | else |
@@ -53,7 +54,7 @@ | ||
53 | 54 | PluginUtil.RegisterCommand( id, entity, cmd ); |
54 | 55 | } |
55 | 56 | |
56 | - protected virtual ICommandEntity_Old CreateEntity( XmlElement contrib ) | |
57 | + protected virtual ICommandEntity_Old CreateEntity( ParamsReader contrib ) | |
57 | 58 | { |
58 | 59 | if( commandType.Equals("ModalForm")) |
59 | 60 | return new ModalFormCommand(targetType); |
@@ -24,16 +24,16 @@ | ||
24 | 24 | /// |
25 | 25 | /// This contribution can add several items at once. |
26 | 26 | /// </summary> |
27 | - public CtbCommandUI(Plugin p, XmlElement e) | |
27 | + public CtbCommandUI(Plugin p, ParamsReader e) | |
28 | 28 | : base(p, e) |
29 | 29 | { |
30 | 30 | object[] args = new object[] { this, e }; |
31 | 31 | 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"]; | |
35 | 35 | ConfirmIDAttribute(ndMenu); |
36 | - XmlElement ndTool = (XmlElement)ndSetup.SelectSingleNode("tool-item"); | |
36 | + ParamsReader ndTool = ndSetup["tool-item"]; | |
37 | 37 | ConfirmIDAttribute(ndTool); |
38 | 38 | CommandPathHint hint = new CommandPathHint(ndMenu); |
39 | 39 | CommandPathHint hint2 = new CommandPathHint(ndTool); |
@@ -41,10 +41,9 @@ | ||
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
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); | |
48 | 47 | } |
49 | 48 | } |
50 | 49 | } |
@@ -57,10 +57,10 @@ | ||
57 | 57 | /// </summary> |
58 | 58 | protected readonly Type windowType; |
59 | 59 | |
60 | - public CtbSubform(Plugin p, XmlElement e) | |
60 | + public CtbSubform(Plugin p, ParamsReader e) | |
61 | 61 | : base(p, e) { |
62 | 62 | options = LoadOptions(e); |
63 | - windowType = PluginUtil.loadTypeFromManifest((XmlElement)XmlUtil.SelectSingleNode(e,"class")); | |
63 | + windowType = PluginUtil.loadTypeFromManifest(e["class"]); | |
64 | 64 | if (IsSingleton) { |
65 | 65 | contentMap = new Dictionary<string, SubformHolder>(1); |
66 | 66 | } else { |
@@ -68,8 +68,8 @@ | ||
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
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(); | |
73 | 73 | String[] sarr = optstr.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); |
74 | 74 | |
75 | 75 | return new List<string>(sarr); |
@@ -111,7 +111,6 @@ | ||
111 | 111 | protected virtual Image CreateImage() { |
112 | 112 | //return Image.FromFile(((LocalFile)source).AbsolutePath); |
113 | 113 | Stream s = source.OpenRead(); |
114 | - Encoder enc = Encoder.Version; | |
115 | 114 | Image img = Bitmap.FromStream(s); |
116 | 115 | s.Close(); |
117 | 116 | s.Dispose(); |
@@ -180,14 +179,16 @@ | ||
180 | 179 | /// <param name="filename"></param> |
181 | 180 | /// <returns></returns> |
182 | 181 | 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; | |
184 | 184 | ImageRef refObj = null; |
185 | - if (!pathlist.TryGetValue(path, out refObj)) { | |
186 | - FileInfo info = new FileInfo(path); | |
185 | + if (!pathlist.TryGetValue(keypath, out refObj)) { | |
187 | 186 | if (info.Exists) { |
188 | 187 | IFileSource src = new LocalFile(info.FullName); |
189 | 188 | 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); | |
191 | 192 | } |
192 | 193 | } |
193 | 194 | return refObj; |
@@ -7,6 +7,7 @@ | ||
7 | 7 | using nft.framework.plugin; |
8 | 8 | using nft.util; |
9 | 9 | using System.IO; |
10 | +using nft.framework.loader; | |
10 | 11 | |
11 | 12 | namespace nft.framework |
12 | 13 | { |
@@ -21,8 +22,9 @@ | ||
21 | 22 | |
22 | 23 | static public void Initialize(){ |
23 | 24 | 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")) { | |
26 | 28 | try{ |
27 | 29 | GlobalModuleEntry gm = loadModule(cn); |
28 | 30 | if(gm!=null){ |
@@ -41,11 +43,11 @@ | ||
41 | 43 | /// The "codeBase" attribute and the "name" attribute of |
42 | 44 | /// a class element are used to determine the class to be loaded. |
43 | 45 | /// </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"]; | |
46 | 48 | 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(""); | |
49 | 51 | |
50 | 52 | GlobalModuleEntry entry = new GlobalModuleEntry(null, null, name, desc); |
51 | 53 | object result = null; |
@@ -56,11 +58,11 @@ | ||
56 | 58 | Debug.WriteLine(e.Message); |
57 | 59 | Debug.WriteLine(e.StackTrace); |
58 | 60 | 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); | |
60 | 62 | } |
61 | 63 | if(!(result is IGlobalModule)){ |
62 | 64 | 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 }; | |
64 | 66 | throw new InvalidCastException(string.Format(templ,args)); |
65 | 67 | } |
66 | 68 | entry.ModuleInstance = (IGlobalModule)result; |
@@ -20,14 +20,13 @@ | ||
20 | 20 | /// <summary> |
21 | 21 | /// Constructor for the use in plugin.xml |
22 | 22 | /// </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"])){} | |
26 | 25 | |
27 | 26 | private readonly Type concreteType; |
28 | 27 | public Type OutputType { get{ return concreteType; } } |
29 | 28 | |
30 | - public Contribution load( Plugin owner, XmlElement e ) { | |
29 | + public Contribution load(Plugin owner, ParamsReader e) { | |
31 | 30 | return (Contribution)Activator.CreateInstance(concreteType,new object[]{owner, e}); |
32 | 31 | } |
33 | 32 | } |
@@ -20,15 +20,14 @@ | ||
20 | 20 | this.baseType = baseType; |
21 | 21 | } |
22 | 22 | |
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"])) {} | |
26 | 25 | |
27 | 26 | |
28 | 27 | private readonly Type baseType; |
29 | 28 | public Type OutputType { get{ return baseType; } } |
30 | 29 | |
31 | - public Contribution load( Plugin owner, XmlElement e ) | |
30 | + public Contribution load(Plugin owner, ParamsReader e) | |
32 | 31 | { |
33 | 32 | Contribution contrib = PluginUtil.createContributionObject(owner, e) as Contribution; |
34 | 33 | if( baseType.IsInstanceOfType(contrib) ) |
@@ -24,17 +24,17 @@ | ||
24 | 24 | // Contribution ID will be used as a part of filepath. |
25 | 25 | // {Plugin_id}\{Contribution_short_id} |
26 | 26 | static public readonly string PID_Sepalator = "\\"; |
27 | - static string GenerateID( XmlElement contrib ) | |
27 | + static string GenerateID( ParamsReader contrib ) | |
28 | 28 | { |
29 | - string short_id = XmlUtil.GetAttribute( contrib, "id", null); | |
29 | + string short_id = contrib["id"].InnerText; | |
30 | 30 | if( short_id == null ) |
31 | 31 | { |
32 | 32 | string templ = Main.resources["xml.attribute_not_found"].stringValue; |
33 | 33 | throw new PluginXmlException(contrib,string.Format( |
34 | - templ,contrib.Name,"name",contrib.OwnerDocument.BaseURI)); | |
34 | + templ,"contribution","name",contrib.SourceURI)); | |
35 | 35 | } |
36 | 36 | |
37 | - string pname = PluginUtil.GetPruginDirName(contrib); | |
37 | + string pname = PluginUtil.GetPluginDirName(contrib); | |
38 | 38 | return pname + PID_Sepalator + short_id; |
39 | 39 | } |
40 | 40 | static string GenerateID(Plugin owner, string short_id) |
@@ -44,14 +44,14 @@ | ||
44 | 44 | } |
45 | 45 | #endregion |
46 | 46 | |
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("")) {} | |
50 | 51 | |
51 | - protected Contribution(Plugin owner, XmlElement contrib, string name, string description) | |
52 | + protected Contribution(Plugin owner, ParamsReader contrib, string name, string description) | |
52 | 53 | { |
53 | 54 | this.parent = owner; |
54 | - this.baseDir = Path.GetDirectoryName(contrib.BaseURI); | |
55 | 55 | this.name = name; |
56 | 56 | this.description = description; |
57 | 57 | //Debug.WriteLine("name:" + name + " ,baseDir:" + baseDir); |
@@ -58,13 +58,13 @@ | ||
58 | 58 | id = GenerateID(contrib); |
59 | 59 | try |
60 | 60 | { |
61 | - CtbType = contrib.Attributes["type"].Value; | |
61 | + CtbType = contrib["type"].InnerText; | |
62 | 62 | } |
63 | 63 | catch |
64 | 64 | { |
65 | 65 | string templ = Main.resources["xml.attribute_not_found"].stringValue; |
66 | 66 | throw new PluginXmlException(contrib, string.Format( |
67 | - templ, contrib.Name, "type", contrib.OwnerDocument.BaseURI)); | |
67 | + templ, "contribution", "type", contrib.SourceURI)); | |
68 | 68 | } |
69 | 69 | } |
70 | 70 |
@@ -72,7 +72,6 @@ | ||
72 | 72 | protected Contribution(Plugin owner, string _type, string short_id, string _name, string _description) |
73 | 73 | { |
74 | 74 | this.parent = owner; |
75 | - this.baseDir = parent.dirName; | |
76 | 75 | this.CtbType = _type; |
77 | 76 | this.id = GenerateID(owner, short_id); |
78 | 77 | this.name = _name; |
@@ -201,8 +200,7 @@ | ||
201 | 200 | /// |
202 | 201 | /// This poinst to the plug-in directory. |
203 | 202 | /// </summary> |
204 | - public string PluginDir { get { return baseDir; } } | |
205 | - private string baseDir; | |
203 | + public string PluginDir { get { return parent.dirName; } } | |
206 | 204 | |
207 | 205 | /// <summary> |
208 | 206 | /// Returns the Plugin object that contains this contribution. |
@@ -4,6 +4,7 @@ | ||
4 | 4 | using System.Reflection; |
5 | 5 | using System.Runtime.Serialization; |
6 | 6 | using nft.framework; |
7 | +using System.IO; | |
7 | 8 | |
8 | 9 | namespace nft.framework.plugin |
9 | 10 | { |
@@ -47,7 +48,27 @@ | ||
47 | 48 | { |
48 | 49 | theInstance.addAssembly(asm); |
49 | 50 | } |
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 | + | |
51 | 72 | protected void addAssembly(Assembly asm) |
52 | 73 | { |
53 | 74 | if(!assemblies.ContainsKey(asm.GetName().Name)) |
@@ -73,6 +94,7 @@ | ||
73 | 94 | return null; |
74 | 95 | } |
75 | 96 | |
97 | + | |
76 | 98 | // public override System.Type BindToType(string assemblyName, string typeName) { |
77 | 99 | // Type t; |
78 | 100 | // |
@@ -13,10 +13,9 @@ | ||
13 | 13 | /// </summary> |
14 | 14 | [PrimitiveContribution] |
15 | 15 | public abstract class CtbCustomCtbFactory : Contribution, IContributionFactory { |
16 | - public CtbCustomCtbFactory(Plugin p, XmlElement e) | |
16 | + public CtbCustomCtbFactory(Plugin p, ParamsReader e) | |
17 | 17 | : base(p, e) { |
18 | - baseType = PluginUtil.loadTypeFromManifest( | |
19 | - (XmlElement)XmlUtil.SelectSingleNode(e, "basetype")); | |
18 | + baseType = PluginUtil.loadTypeFromManifest(e["basetype"]); | |
20 | 19 | } |
21 | 20 | |
22 | 21 | #region IContributionFactory メンバ |
@@ -23,7 +22,7 @@ | ||
23 | 22 | private readonly Type baseType; |
24 | 23 | public Type OutputType { get { return baseType; } } |
25 | 24 | |
26 | - public Contribution load(Plugin owner, XmlElement e) { | |
25 | + public Contribution load(Plugin owner, ParamsReader e) { | |
27 | 26 | Contribution contrib = Create(owner, e); |
28 | 27 | Debug.Assert(baseType.IsInstanceOfType(contrib)); |
29 | 28 | return contrib; |
@@ -30,7 +29,7 @@ | ||
30 | 29 | } |
31 | 30 | #endregion |
32 | 31 | |
33 | - protected abstract Contribution Create(Plugin owner, XmlElement e); | |
32 | + protected abstract Contribution Create(Plugin owner, ParamsReader e); | |
34 | 33 | |
35 | 34 | } |
36 | 35 | } |
@@ -6,10 +6,11 @@ | ||
6 | 6 | using System.Windows.Forms; |
7 | 7 | using System.Xml; |
8 | 8 | using nft.util; |
9 | +using nft.framework.loader; | |
9 | 10 | |
10 | 11 | namespace nft.framework.plugin |
11 | 12 | { |
12 | - public delegate void ParseEventHandler(Plugin p, XmlElement e); | |
13 | + public delegate void ParseEventHandler(Plugin p, ParamsReader e); | |
13 | 14 | public delegate void InitCompleteEventHandler(); |
14 | 15 | |
15 | 16 | /// <summary> |
@@ -83,7 +84,7 @@ | ||
83 | 84 | } |
84 | 85 | |
85 | 86 | // called from Plugin on initialization |
86 | - internal void NotifyStartParse(Plugin p, XmlElement e) | |
87 | + internal void NotifyStartParse(Plugin p, ParamsReader e) | |
87 | 88 | { |
88 | 89 | if( BeforeContributionParse!=null ) |
89 | 90 | BeforeContributionParse(p,e); |
@@ -90,61 +91,67 @@ | ||
90 | 91 | } |
91 | 92 | |
92 | 93 | #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) | |
94 | 114 | { |
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. | |
96 | 123 | |
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) ) | |
121 | 134 | { |
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; | |
140 | 149 | |
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); | |
145 | 153 | } |
146 | - } | |
147 | - return pluginSet; | |
154 | + } | |
148 | 155 | } |
149 | 156 | |
150 | 157 | private void SolveDependency(ArrayList pluginSet, ProgressMonitor monitor) |
@@ -338,7 +345,7 @@ | ||
338 | 345 | { |
339 | 346 | ArrayList list = new ArrayList(); |
340 | 347 | foreach( Plugin p in plugins ) { |
341 | - foreach( Contribution contrib in p.contributions ) { | |
348 | + foreach( Contribution contrib in p.Contributions ) { | |
342 | 349 | if( contributionType.IsInstanceOfType(contrib) ) |
343 | 350 | if( !hideDisabled || contrib.IsAttached ) |
344 | 351 | list.Add(contrib); |
@@ -356,7 +363,7 @@ | ||
356 | 363 | get { |
357 | 364 | ArrayList list = new ArrayList(); |
358 | 365 | foreach( Plugin p in plugins ) |
359 | - foreach( Contribution contrib in p.contributions ) | |
366 | + foreach( Contribution contrib in p.Contributions ) | |
360 | 367 | list.Add(contrib); |
361 | 368 | |
362 | 369 | return (Contribution[])list.ToArray(typeof(Contribution)); |
@@ -367,7 +374,7 @@ | ||
367 | 374 | get { |
368 | 375 | ArrayList list = new ArrayList(); |
369 | 376 | foreach (Plugin p in plugins) |
370 | - foreach (Contribution contrib in p.primitives) | |
377 | + foreach (Contribution contrib in p.Primitives) | |
371 | 378 | list.Add(contrib); |
372 | 379 | |
373 | 380 | return (Contribution[])list.ToArray(typeof(Contribution)); |
@@ -9,7 +9,7 @@ | ||
9 | 9 | /// </summary> |
10 | 10 | [PrimitiveContribution] |
11 | 11 | public class BinaryModule : Contribution{ |
12 | - public BinaryModule(Plugin p, XmlElement e) | |
12 | + public BinaryModule(Plugin p, ParamsReader e) | |
13 | 13 | : base(p, e) { |
14 | 14 | } |
15 | 15 | } |
@@ -24,16 +24,16 @@ | ||
24 | 24 | /// </summary> |
25 | 25 | /// <param name="p">owner plugin</param> |
26 | 26 | /// <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"]; | |
29 | 29 | Type t = loadTypeFromManifest(el); |
30 | 30 | object[] args = new object[] { p, elm }; |
31 | 31 | return (Contribution)loadObjectFromManifest(elm, args, null); |
32 | 32 | } |
33 | 33 | |
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. | |
37 | 37 | return new DefaultContributionFactory(p, elm); |
38 | 38 | Type t = loadTypeFromManifest(el); |
39 | 39 | object[] args = t.IsSubclassOf(typeof(Contribution)) ? |
@@ -51,9 +51,9 @@ | ||
51 | 51 | /// <param name="args">arguments array for constructor</param> |
52 | 52 | /// <param name="defaultType">if 'elm' has no "class" element, use as creation type |
53 | 53 | /// (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); | |
57 | 57 | return CreateInstance(elm, t, args); |
58 | 58 | } |
59 | 59 |
@@ -64,19 +64,19 @@ | ||
64 | 64 | /// </summary> |
65 | 65 | /// <param name="elm">contribution target node</param> |
66 | 66 | /// <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"]; | |
69 | 69 | Type t = loadTypeFromManifest(el); |
70 | 70 | return CreateInstance(elm, t, args); |
71 | 71 | } |
72 | 72 | |
73 | - private static object CreateInstance(XmlElement elm, Type t, object[] args) { | |
73 | + private static object CreateInstance(ParamsReader elm, Type t, object[] args) { | |
74 | 74 | try { |
75 | 75 | // give XmlNode as first argument of constructor. |
76 | 76 | object result = Activator.CreateInstance(t, args); |
77 | 77 | if (result == null) { |
78 | 78 | 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)); | |
80 | 80 | } |
81 | 81 | return result; |
82 | 82 | } catch (TargetInvocationException e) { |
@@ -83,7 +83,7 @@ | ||
83 | 83 | Debug.WriteLine(e.Message); |
84 | 84 | Debug.WriteLine(e.StackTrace); |
85 | 85 | 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); | |
87 | 87 | } |
88 | 88 | } |
89 | 89 |
@@ -91,36 +91,37 @@ | ||
91 | 91 | /// Load a type from the name attribute and the codebase attribute . |
92 | 92 | /// </summary> |
93 | 93 | /// <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 ) { | |
98 | 99 | // load the class from the FreeTrain.Main.dll |
99 | 100 | a = Assembly.GetExecutingAssembly(); |
100 | 101 | } else { |
101 | - string s = e.Attributes["codebase"].Value; | |
102 | + string s = cb.InnerText; | |
102 | 103 | // if start with '.', it's abbreviation of nft.XXX.dll |
103 | 104 | // at the application base directory. |
104 | 105 | if(s.StartsWith(".")) |
105 | 106 | s = string.Format("{0}NFT{1}.DLL",Directories.AppBaseDir,s); |
106 | 107 | // 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 | + | |
113 | 113 | } |
114 | 114 | PluginSerializationBinder.registerAssembly(a); |
115 | + //Debug.Assert(typeName != null); | |
115 | 116 | return a.GetType(typeName,true); |
116 | 117 | } |
117 | 118 | |
118 | - public static Type loadTypeFromManifest(XmlElement e, Type required) { | |
119 | + public static Type loadTypeFromManifest(ParamsReader e, Type required) { | |
119 | 120 | Type t = loadTypeFromManifest(e); |
120 | 121 | if (required != null) { |
121 | 122 | if (!required.IsAssignableFrom(t)) { |
122 | 123 | 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 }; | |
124 | 125 | throw new InvalidCastException(string.Format(templ, a2)); |
125 | 126 | } |
126 | 127 | } |
@@ -127,13 +128,13 @@ | ||
127 | 128 | return t; |
128 | 129 | } |
129 | 130 | |
130 | - public static void RegisterCommand( string id, ICommandEntity_Old entity, XmlNode commandNode ) | |
131 | + public static void RegisterCommand( string id, ICommandEntity_Old entity, ParamsReader commandNode ) | |
131 | 132 | { |
132 | 133 | 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; | |
137 | 138 | if( bid != null ) |
138 | 139 | Main.mainFrame.SetToolButtonCommand(id,entity,bar,bid); |
139 | 140 | if( mpath != null ) |
@@ -140,12 +141,17 @@ | ||
140 | 141 | Main.mainFrame.SetMenuCommand(id,entity,mpath); |
141 | 142 | } |
142 | 143 | |
143 | - public static string GetPruginDirName( XmlNode node ) | |
144 | + [Obsolete("Not available.",true)] | |
145 | + public static string GetPluginDirName( XmlNode node ) | |
144 | 146 | { |
145 | 147 | return Path.GetFileName(Path.GetDirectoryName(node.OwnerDocument.BaseURI)); |
146 | 148 | } |
147 | 149 | |
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 ) | |
149 | 155 | { |
150 | 156 | return Path.GetDirectoryName(node.OwnerDocument.BaseURI); |
151 | 157 | } |
@@ -14,7 +14,7 @@ | ||
14 | 14 | public const string PluginFileName = "plugin.xml"; |
15 | 15 | #region IHasNameAndID メンバ |
16 | 16 | |
17 | - private readonly string _id; | |
17 | + private string _id; | |
18 | 18 | // plugin 'id' is equals to the subdir name where "plugin.xml" is placed. |
19 | 19 | public string ID { |
20 | 20 | get { return _id; } |
@@ -26,16 +26,16 @@ | ||
26 | 26 | |
27 | 27 | #endregion |
28 | 28 | |
29 | - private readonly string _title; | |
29 | + private string _title; | |
30 | 30 | public string Title { get { return _title; } } |
31 | 31 | |
32 | - private readonly string _author; | |
32 | + private string _author; | |
33 | 33 | public string author { get { return _author; } } |
34 | 34 | |
35 | - private readonly string _homepage; | |
35 | + private string _homepage; | |
36 | 36 | public string homepage { get { return _homepage; } } |
37 | 37 | |
38 | - private readonly DateTime _lastModified; | |
38 | + internal protected DateTime _lastModified; // settled from PluginManager | |
39 | 39 | public DateTime lastModifiedTime { get { return _lastModified; } } |
40 | 40 | |
41 | 41 | public string getInfoText(string linecode) { |
@@ -44,6 +44,11 @@ | ||
44 | 44 | } |
45 | 45 | |
46 | 46 | /// <summary> |
47 | + /// Location uri of this plug-in | |
48 | + /// </summary> | |
49 | + public readonly Uri Uri; | |
50 | + | |
51 | + /// <summary> | |
47 | 52 | /// Base directory of this plug-in |
48 | 53 | /// </summary> |
49 | 54 | public readonly string dirName; |
@@ -51,14 +56,14 @@ | ||
51 | 56 | /// <summary> |
52 | 57 | /// All the contributions in this plug-in |
53 | 58 | /// </summary> |
54 | - public readonly IList contributions = new ArrayList(); | |
59 | + public readonly IList Contributions = new ArrayList(); | |
55 | 60 | |
56 | 61 | /// <summary> |
57 | 62 | /// All the contribution definers and binary modules in this plug-in |
58 | 63 | /// </summary> |
59 | - public readonly IList primitives = new ArrayList(); | |
64 | + public readonly IList Primitives = new ArrayList(); | |
60 | 65 | |
61 | - public int TotalContribCount { get { return contributions.Count + primitives.Count; } } | |
66 | + //public int TotalContribCount { get { return Contributions.Count + Primitives.Count; } } | |
62 | 67 | |
63 | 68 | /// <summary> |
64 | 69 | /// Contents of plugin.xml |
@@ -65,6 +70,12 @@ | ||
65 | 70 | /// Available only during the initialization phase. |
66 | 71 | /// </summary> |
67 | 72 | 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 | + | |
68 | 79 | private string data_dir = null; |
69 | 80 | |
70 | 81 | #region IAddable メンバ |
@@ -86,7 +97,7 @@ | ||
86 | 97 | |
87 | 98 | public void Detach() { |
88 | 99 | Debug.WriteLine("dt" + totalDetachables); |
89 | - foreach (Contribution c in contributions) | |
100 | + foreach (Contribution c in Contributions) | |
90 | 101 | if (c.QueryDetach()) |
91 | 102 | c.Detach(); |
92 | 103 | if (onDetach != null) |
@@ -96,7 +107,7 @@ | ||
96 | 107 | |
97 | 108 | public void Attach() { |
98 | 109 | Debug.WriteLine("at" + totalDetachables); |
99 | - foreach (Contribution c in contributions) | |
110 | + foreach (Contribution c in Contributions) | |
100 | 111 | c.Attach(); |
101 | 112 | if (onAttach != null) |
102 | 113 | onAttach(this); |
@@ -127,7 +138,9 @@ | ||
127 | 138 | /// Loads a plug-in from manifest XML "plugin.xml". |
128 | 139 | /// dirName does NOT contains the file name "plugin.xml". |
129 | 140 | /// </summary> |
141 | + [Obsolete] | |
130 | 142 | public Plugin(string dirName) { |
143 | + this.Uri = new Uri(dirName); | |
131 | 144 | this.dirName = dirName; |
132 | 145 | _id = Path.GetFileName(dirName); |
133 | 146 | _lastModified = lastUpdatedDate(dirName); |
@@ -140,6 +153,25 @@ | ||
140 | 153 | } |
141 | 154 | |
142 | 155 | /// <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> | |
143 | 175 | /// Can be used for Cashed data storage of this plug-in. |
144 | 176 | /// Each plug-in has it's isolated sub-directory under the DataDir. |
145 | 177 | /// </summary> |
@@ -161,8 +193,8 @@ | ||
161 | 193 | if (!this.ID.Equals("system")) |
162 | 194 | a.Add(PluginManager.theInstance.GetPlugin("system")); |
163 | 195 | |
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; | |
166 | 198 | Plugin p = PluginManager.theInstance.GetPlugin(name); |
167 | 199 | if (p == null) { |
168 | 200 | string templ = Main.resources["plugin.dependency_not_found"].stringValue; |
@@ -176,11 +208,13 @@ | ||
176 | 208 | /// <summary> |
177 | 209 | /// Loads plugin.xml file from the directory. |
178 | 210 | /// </summary> |
211 | + [Obsolete] | |
179 | 212 | private static XmlDocument loadManifest(string dirName) { |
180 | 213 | string path = Path.Combine(dirName, PluginFileName); |
181 | 214 | return XmlUtil.LoadFile(path); |
182 | 215 | } |
183 | 216 | |
217 | + [Obsolete] | |
184 | 218 | private static DateTime lastUpdatedDate(string dirName) { |
185 | 219 | string path = Path.Combine(dirName, PluginFileName); |
186 | 220 | FileInfo info = new FileInfo(path); |
@@ -193,23 +227,22 @@ | ||
193 | 227 | /// Loads class type contributions from this plug-in |
194 | 228 | /// </summary> |
195 | 229 | internal void loadBinaries() { |
196 | - XmlElement root = doc.DocumentElement; | |
197 | 230 | // locate contribution factories first, |
198 | 231 | // 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; | |
201 | 234 | try { |
202 | 235 | Contribution cb = null; |
203 | 236 | // load a contribution factory |
204 | 237 | if ("factory".Equals(type)) { |
205 | 238 | PluginManager.theInstance.NotifyStartParse(this, contrib); |
206 | - XmlNode nd = contrib.SelectSingleNode("declare"); | |
239 | + ParamsReader nd = contrib["declare"]; | |
207 | 240 | string regtype; |
208 | - if (nd != null) { | |
209 | - regtype = XmlUtil.GetAttribute(nd, "type"); | |
241 | + if (!nd.IsNull) { | |
242 | + regtype = nd["type"].InnerText; | |
210 | 243 | } else { |
211 | 244 | // use name property for alternative. |
212 | - regtype = XmlUtil.SelectSingleNode(contrib, "name").InnerText; | |
245 | + regtype = contrib["name"].InnerText; | |
213 | 246 | } |
214 | 247 | object[] args = new object[] { contrib }; |
215 | 248 | // create and register contribution factory |
@@ -232,19 +265,16 @@ | ||
232 | 265 | continue; |
233 | 266 | } |
234 | 267 | if (Contribution.isPrimitiveContribution(cb.GetType())) { |
235 | - primitives.Add(cb); | |
268 | + Primitives.Add(cb); | |
236 | 269 | } else { |
237 | - contributions.Add(cb); | |
270 | + Contributions.Add(cb); | |
238 | 271 | } |
239 | - cb.SetOwner(this); | |
240 | 272 | cb.Attach(); |
241 | 273 | cb._state = InstallationState.Ready; |
242 | 274 | } catch (Exception e) { |
243 | 275 | _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); | |
248 | 278 | } |
249 | 279 | } |
250 | 280 | } |
@@ -253,18 +283,17 @@ | ||
253 | 283 | /// Loads contributions from this plug-in |
254 | 284 | /// </summary> |
255 | 285 | internal void loadContributions() { |
256 | - XmlElement root = doc.DocumentElement; | |
257 | 286 | Contribution c = null; |
258 | 287 | // load contributions |
259 | - foreach (XmlElement contrib in root.SelectNodes("contribution")) { | |
288 | + foreach (ParamsReader contrib in _reader.EnumChildren("contribution")) { | |
260 | 289 | try { |
261 | - string type = contrib.Attributes["type"].Value; | |
290 | + string type = contrib["type"].InnerText; | |
262 | 291 | if ("factory".Equals(type) || "binary".Equals(type)) continue; // ignore |
263 | 292 | |
264 | 293 | PluginManager.theInstance.NotifyStartParse(this, contrib); |
265 | 294 | IContributionFactory factory = PluginManager.theInstance.GetContributionFactory(type); |
266 | 295 | c = factory.load(this, contrib); |
267 | - contributions.Add(c); | |
296 | + Contributions.Add(c); | |
268 | 297 | c.Attach(); |
269 | 298 | detachable |= c.IsDetachable; |
270 | 299 | if (c.IsDetachable) { |
@@ -273,7 +302,6 @@ | ||
273 | 302 | c.OnDetach += new AttachChangeEvent(this.AttachChangeEventHandler); |
274 | 303 | } |
275 | 304 | PluginManager.theInstance.AddContribution(c); |
276 | - c.SetOwner(this); | |
277 | 305 | c._state = InstallationState.Ready; |
278 | 306 | } catch (Exception e) { |
279 | 307 | Debug.WriteLine(e.Message); |
@@ -284,10 +312,7 @@ | ||
284 | 312 | } |
285 | 313 | if (c != null) |
286 | 314 | 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); | |
291 | 316 | |
292 | 317 | if(_state != InstallationState.FatalError) |
293 | 318 | _state = InstallationState.PartialError; |
@@ -298,6 +323,12 @@ | ||
298 | 323 | _state = InstallationState.Ready; |
299 | 324 | } |
300 | 325 | |
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 | + } | |
301 | 332 | |
302 | 333 | /// <summary> |
303 | 334 | /// Loads a stream from the plug-in directory. |
@@ -1,5 +1,6 @@ | ||
1 | 1 | using System; |
2 | 2 | using System.Xml; |
3 | +using System.IO; | |
3 | 4 | |
4 | 5 | namespace nft.framework.plugin |
5 | 6 | { |
@@ -8,17 +9,17 @@ | ||
8 | 9 | /// </summary> |
9 | 10 | public class PluginXmlException : Exception |
10 | 11 | { |
11 | - protected XmlNode node; | |
12 | + protected ParamsReader node; | |
12 | 13 | protected Plugin plugin = null; |
13 | 14 | protected Contribution contrib = null; |
14 | 15 | |
15 | - public PluginXmlException(XmlNode node, string msg) | |
16 | + public PluginXmlException(ParamsReader node, string msg) | |
16 | 17 | :base(msg) |
17 | 18 | { |
18 | 19 | this.node = node; |
19 | 20 | } |
20 | 21 | |
21 | - public PluginXmlException(Plugin p, XmlNode node, string msg) | |
22 | + public PluginXmlException(Plugin p, ParamsReader node, string msg) | |
22 | 23 | :this(node,msg) |
23 | 24 | { |
24 | 25 | this.plugin = p; |
@@ -25,7 +26,7 @@ | ||
25 | 26 | ConfirmPlugin(node); |
26 | 27 | } |
27 | 28 | |
28 | - public PluginXmlException(Contribution c, XmlNode node, string msg) | |
29 | + public PluginXmlException(Contribution c, ParamsReader node, string msg) | |
29 | 30 | :this(node,msg) |
30 | 31 | { |
31 | 32 | this.contrib = c; |
@@ -33,11 +34,11 @@ | ||
33 | 34 | ConfirmPlugin(node); |
34 | 35 | } |
35 | 36 | |
36 | - private void ConfirmPlugin(XmlNode node) | |
37 | + private void ConfirmPlugin(ParamsReader node) | |
37 | 38 | { |
38 | 39 | if(plugin==null) |
39 | 40 | { |
40 | - string pname = PluginUtil.GetPruginDirName(node); | |
41 | + string pname = Path.GetFileName(Path.GetDirectoryName(node.SourceURI)+""); | |
41 | 42 | plugin = Main.plugins.GetPlugin(pname); |
42 | 43 | } |
43 | 44 | } |
@@ -61,6 +62,6 @@ | ||
61 | 62 | return msg; |
62 | 63 | } |
63 | 64 | |
64 | - public XmlNode SourceNode{ get{ return node; } } | |
65 | + public ParamsReader ParamsReader { get { return node; } } | |
65 | 66 | } |
66 | 67 | } |
@@ -15,20 +15,19 @@ | ||
15 | 15 | this.baseType = basetype; |
16 | 16 | } |
17 | 17 | |
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"])) { } | |
21 | 20 | |
22 | 21 | |
23 | 22 | private readonly Type baseType; |
24 | 23 | public Type OutputType { get { return baseType; } } |
25 | 24 | |
26 | - public Contribution load(Plugin owner, XmlElement e) { | |
25 | + public Contribution load(Plugin owner, ParamsReader e) { | |
27 | 26 | Contribution contrib = Cretate(owner, e); |
28 | 27 | Debug.Assert(baseType.IsInstanceOfType(contrib)); |
29 | 28 | return contrib; |
30 | 29 | } |
31 | 30 | |
32 | - protected abstract Contribution Cretate(Plugin owner, XmlElement e); | |
31 | + protected abstract Contribution Cretate(Plugin owner, ParamsReader e); | |
33 | 32 | } |
34 | 33 | } |
@@ -10,7 +10,7 @@ | ||
10 | 10 | [PrimitiveContribution] |
11 | 11 | public class CtbContributionDefiner : Contribution |
12 | 12 | { |
13 | - public CtbContributionDefiner(Plugin p, XmlElement e) | |
13 | + public CtbContributionDefiner(Plugin p, ParamsReader e) | |
14 | 14 | : base(p, e) |
15 | 15 | { |
16 | 16 | //e.SelectSingleNode("implementesion"); |
@@ -17,7 +17,7 @@ | ||
17 | 17 | /// Dummy Contribution for Debug |
18 | 18 | /// </summary> |
19 | 19 | /// <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) { } | |
21 | 21 | |
22 | 22 | // TODO: additional parameters, like population and attractiveness. |
23 | 23 | } |
@@ -17,7 +17,7 @@ | ||
17 | 17 | /// In case of an error, this method must throw an exception |
18 | 18 | /// instead of silently returning null. |
19 | 19 | /// </summary> |
20 | - Contribution load( Plugin owner, XmlElement e ); | |
20 | + Contribution load( Plugin owner, ParamsReader e ); | |
21 | 21 | |
22 | 22 | Type OutputType { get; } |
23 | 23 | } |
@@ -24,24 +24,20 @@ | ||
24 | 24 | |
25 | 25 | public class DefaultContributionFactory : Contribution, IContributionFactory |
26 | 26 | { |
27 | - internal protected DefaultContributionFactory(Plugin p, XmlElement elm ) | |
27 | + internal protected DefaultContributionFactory(Plugin p, ParamsReader elm) | |
28 | 28 | : base(p, elm) |
29 | 29 | { |
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."); | |
37 | 33 | } |
38 | - this.baseType = PluginUtil.loadTypeFromManifest((XmlElement)nd); | |
34 | + this.baseType = PluginUtil.loadTypeFromManifest(nd); | |
39 | 35 | } |
40 | 36 | |
41 | 37 | private readonly Type baseType; |
42 | 38 | public Type OutputType { get{ return baseType; } } |
43 | 39 | |
44 | - public Contribution load( Plugin owner, XmlElement e ) | |
40 | + public Contribution load(Plugin owner, ParamsReader e) | |
45 | 41 | { |
46 | 42 | Contribution contrib = (Contribution)Activator.CreateInstance(baseType, new object[] { owner, e }); |
47 | 43 | if( baseType.IsInstanceOfType(contrib) ) |
@@ -10,7 +10,7 @@ | ||
10 | 10 | /// </summary> |
11 | 11 | public class CtbPreFormatter : Contribution |
12 | 12 | { |
13 | - public CtbPreFormatter(Plugin p, XmlElement contrib) | |
13 | + public CtbPreFormatter(Plugin p, ParamsReader contrib) | |
14 | 14 | : base(p, contrib) |
15 | 15 | { |
16 | 16 | // |
@@ -7,13 +7,17 @@ | ||
7 | 7 | { |
8 | 8 | public class ParamsReader |
9 | 9 | { |
10 | + private string sourceUri; | |
10 | 11 | private IParamsParser[] loader; |
12 | + protected IDictionary<string, ParamsReader> overwrites = null; | |
11 | 13 | |
12 | - public ParamsReader(IParamsParser ploader) { | |
14 | + public ParamsReader(string srcUri, IParamsParser ploader) { | |
15 | + this.sourceUri = srcUri; | |
13 | 16 | Loaders = ploader != null ? new IParamsParser[] { ploader } : null; |
14 | 17 | } |
15 | 18 | |
16 | - protected ParamsReader(IParamsParser[] ploaders) { | |
19 | + protected ParamsReader(string srcUri, IParamsParser[] ploaders) { | |
20 | + this.sourceUri = srcUri; | |
17 | 21 | Loaders = ploaders; |
18 | 22 | } |
19 | 23 |
@@ -21,22 +25,49 @@ | ||
21 | 25 | get { return PrimaryLoader.InnerText; } |
22 | 26 | } |
23 | 27 | |
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> | |
24 | 44 | public ParamsReader this[string key] { |
25 | 45 | get { |
26 | 46 | if (key == null || key.Length == 0) { |
27 | - return new ParamsReader(NullParam.TheInstance); | |
47 | + return new ParamsReader(sourceUri, NullParam.TheInstance); | |
28 | 48 | } |
29 | 49 | String[] keys = key.Split('|'); |
30 | 50 | if (keys.Length == 1) { |
31 | 51 | IParamsParser[] parr = FindForKey(PrimaryLoader, keys[0]); |
32 | - return new ParamsReader(parr); | |
52 | + return new ParamsReader(sourceUri, parr); | |
33 | 53 | } else { |
34 | 54 | IParamsParser[] parr = FindForMultiKeys(PrimaryLoader, keys); |
35 | - return new ParamsReader(parr); | |
55 | + return new ParamsReader(sourceUri, parr); | |
36 | 56 | } |
37 | 57 | } |
38 | 58 | } |
39 | 59 | |
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 | + | |
40 | 71 | public IFileSource GetFileSource(string path) { |
41 | 72 | IFileSource src = null; |
42 | 73 | foreach (IParamsParser pp in loader) { |
@@ -49,13 +80,15 @@ | ||
49 | 80 | public ParamsReader this[int index] { |
50 | 81 | get { |
51 | 82 | if (index < 0 || index >= loader.Length) { |
52 | - return new ParamsReader(NullParam.TheInstance); | |
83 | + return new ParamsReader(sourceUri, NullParam.TheInstance); | |
53 | 84 | } else { |
54 | - return new ParamsReader(loader[index]); | |
85 | + return new ParamsReader(sourceUri, loader[index]); | |
55 | 86 | } |
56 | 87 | } |
57 | 88 | } |
58 | 89 | |
90 | + public string SourceURI { get { return sourceUri; } } | |
91 | + | |
59 | 92 | public bool IsNull { |
60 | 93 | get { return loader.Length == 0 || PrimaryLoader.IsNull; } |
61 | 94 | } |
@@ -64,25 +97,46 @@ | ||
64 | 97 | get { return loader.IsMap; } |
65 | 98 | } |
66 | 99 | */ |
100 | + /// <summary> | |
101 | + /// True means multiple values. (Result of multiple children for some key) | |
102 | + /// </summary> | |
67 | 103 | public bool IsArray { |
68 | 104 | get { return loader.Length>1; } |
69 | 105 | } |
70 | - | |
106 | + /// <summary> | |
107 | + /// Returns count of elements. (Result of multiple children for some key) | |
108 | + /// </summary> | |
71 | 109 | public int Length { |
72 | 110 | get { return loader.Length; } |
73 | 111 | } |
74 | 112 | |
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); | |
79 | 119 | } |
80 | 120 | } |
81 | 121 | |
122 | + /// <summary> | |
123 | + /// Enumelate all children witch match specified key. | |
124 | + /// </summary> | |
125 | + /// <param name="key"></param> | |
126 | + /// <returns></returns> | |
82 | 127 | public IEnumerable<ParamsReader> EnumChildren(string key) { |
83 | - return new KeyedParamsReaderEnumerator(loader, key); | |
128 | + return new KeySpecifiedChildParamsEnumerator(sourceUri, loader, key); | |
84 | 129 | } |
85 | 130 | |
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 | + | |
86 | 140 | protected IParamsParser PrimaryLoader { |
87 | 141 | get { |
88 | 142 | return loader.Length>0 ? loader[0]:NullParam.TheInstance; |
@@ -102,8 +156,13 @@ | ||
102 | 156 | } |
103 | 157 | } |
104 | 158 | |
105 | - static protected IParamsParser[] FindForKey(IParamsParser p, String key) { | |
159 | + protected IParamsParser[] FindForKey(IParamsParser p, String key) { | |
106 | 160 | 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 | + } | |
107 | 166 | IEnumerator<IParamsParser> en = p.EnumChildren(key); |
108 | 167 | while (en.MoveNext()) { |
109 | 168 | arr.Add(en.Current); |
@@ -111,8 +170,16 @@ | ||
111 | 170 | return arr.ToArray(); |
112 | 171 | } |
113 | 172 | |
114 | - static protected IParamsParser[] FindForMultiKeys(IParamsParser p, String[] keys) { | |
173 | + protected IParamsParser[] FindForMultiKeys(IParamsParser p, String[] keys) { | |
115 | 174 | 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 | + } | |
116 | 183 | IEnumerator<KeyValuePair<String, IParamsParser>> en = p.EnumChildren(); |
117 | 184 | while (en.MoveNext()) { |
118 | 185 | foreach (String k in keys) { |
@@ -126,11 +193,12 @@ | ||
126 | 193 | return arr.ToArray(); |
127 | 194 | } |
128 | 195 | |
129 | - internal protected class ParamsReaderEnumerator : IEnumerable<ParamsReader> | |
196 | + internal protected class ParamsArrayEnumerator : IEnumerable<ParamsReader> | |
130 | 197 | { |
131 | 198 | 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; | |
134 | 202 | if (arr == null) arr = new IParamsParser[0]; |
135 | 203 | this.array = arr; |
136 | 204 | } |
@@ -137,7 +205,7 @@ | ||
137 | 205 | |
138 | 206 | public IEnumerator<ParamsReader> GetEnumerator() { |
139 | 207 | foreach (IParamsParser pp in array) { |
140 | - yield return new ParamsReader(pp); | |
208 | + yield return new ParamsReader(sourceUri, pp); | |
141 | 209 | } |
142 | 210 | } |
143 | 211 |
@@ -146,12 +214,14 @@ | ||
146 | 214 | } |
147 | 215 | } |
148 | 216 | |
149 | - internal protected class KeyedParamsReaderEnumerator : IEnumerable<ParamsReader> | |
217 | + internal protected class KeySpecifiedChildParamsEnumerator : IEnumerable<ParamsReader> | |
150 | 218 | { |
151 | 219 | protected readonly IParamsParser[] array; |
220 | + protected readonly string sourceUri; | |
152 | 221 | protected readonly string key; |
153 | 222 | |
154 | - public KeyedParamsReaderEnumerator(IParamsParser[] arr, string key) { | |
223 | + public KeySpecifiedChildParamsEnumerator(string srcUri, IParamsParser[] arr, string key) { | |
224 | + this.sourceUri = srcUri; | |
155 | 225 | if (arr == null) arr = new IParamsParser[0]; |
156 | 226 | this.array = arr; |
157 | 227 | this.key = key; |
@@ -164,7 +234,7 @@ | ||
164 | 234 | foreach (IParamsParser pp in array) { |
165 | 235 | IEnumerator<IParamsParser> en = pp.EnumChildren(key); |
166 | 236 | while (en.MoveNext()) { |
167 | - yield return new ParamsReader(en.Current); | |
237 | + yield return new ParamsReader(sourceUri, en.Current); | |
168 | 238 | } |
169 | 239 | } |
170 | 240 | } else { |
@@ -173,7 +243,7 @@ | ||
173 | 243 | while (en.MoveNext()) { |
174 | 244 | foreach (String k in keys) { |
175 | 245 | if (en.Current.Key.Equals(keys)) { |
176 | - yield return new ParamsReader(en.Current.Value); | |
246 | + yield return new ParamsReader(sourceUri, en.Current.Value); | |
177 | 247 | break; |
178 | 248 | } |
179 | 249 | } |
@@ -186,5 +256,29 @@ | ||
186 | 256 | return GetEnumerator(); |
187 | 257 | } |
188 | 258 | } |
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 | + } | |
189 | 283 | } |
190 | 284 | } |
@@ -14,22 +14,22 @@ | ||
14 | 14 | public static readonly int IconIndexUnassinged = -1; |
15 | 15 | protected CommandUI() { } |
16 | 16 | |
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; | |
25 | 25 | 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); | |
29 | 29 | } |
30 | - } | |
31 | - XmlElement ent = e.SelectSingleNode("entity") as XmlElement; | |
32 | - if (ent != null) { | |
30 | + } | |
31 | + ParamsReader ent = e["entity"]; | |
32 | + if (!ent.IsNull) { | |
33 | 33 | this.entity = LoadEntityFromManifest(ent); |
34 | 34 | } |
35 | 35 | } |
@@ -183,7 +183,7 @@ | ||
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - protected virtual ICommandEntity LoadEntityFromManifest(XmlElement e) { | |
186 | + protected virtual ICommandEntity LoadEntityFromManifest(ParamsReader e) { | |
187 | 187 | object[] args = new object[] { e }; |
188 | 188 | object ret = PluginUtil.loadObjectFromManifest(e, args); |
189 | 189 | return (ICommandEntity)ret; |
@@ -193,7 +193,7 @@ | ||
193 | 193 | public class TriggerCommandUI : CommandUI { |
194 | 194 | protected TriggerCommandUI() { } |
195 | 195 | |
196 | - public TriggerCommandUI(Contribution owner, XmlElement e) | |
196 | + public TriggerCommandUI(Contribution owner, ParamsReader e) | |
197 | 197 | : base(owner, e) { |
198 | 198 | } |
199 | 199 |
@@ -207,7 +207,7 @@ | ||
207 | 207 | public class SingleSelFixedListUI : CommandUI { |
208 | 208 | protected SingleSelFixedListUI() { } |
209 | 209 | |
210 | - public SingleSelFixedListUI(Contribution owner, XmlElement e) | |
210 | + public SingleSelFixedListUI(Contribution owner, ParamsReader e) | |
211 | 211 | : base(owner, e) { |
212 | 212 | } |
213 | 213 |
@@ -32,7 +32,7 @@ | ||
32 | 32 | |
33 | 33 | readonly CtbSubform innerCtb; |
34 | 34 | |
35 | - public SubformCommand(XmlElement e) { | |
35 | + public SubformCommand(ParamsReader e) { | |
36 | 36 | innerCtb = new CtbSubform(null, e); |
37 | 37 | } |
38 | 38 |
@@ -64,11 +64,11 @@ | ||
64 | 64 | protected string before; |
65 | 65 | protected string after; |
66 | 66 | |
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; | |
72 | 72 | } |
73 | 73 | |
74 | 74 | public CommandPathHint(string id) { |
@@ -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 | +} |
@@ -23,8 +23,8 @@ | ||
23 | 23 | [TestEntry] |
24 | 24 | static private void TestXmlParser(){ |
25 | 25 | 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"]; | |
28 | 28 | Debug.WriteLine("title = " + r2["title"].InnerText); |
29 | 29 | foreach (ParamsReader r3 in r2.EnumChildren("contribution")) { |
30 | 30 | Debug.Write("name = " + r3["name"].InnerText); |
@@ -11,7 +11,7 @@ | ||
11 | 11 | public class WinFormManager : IFormManager |
12 | 12 | { |
13 | 13 | |
14 | - public WinFormManager(XmlNode node) { | |
14 | + public WinFormManager(ParamsReader node) { | |
15 | 15 | } |
16 | 16 | |
17 | 17 | public void Register(string name, Type win_form_class) { |
@@ -7,6 +7,7 @@ | ||
7 | 7 | using nft.framework; |
8 | 8 | using nft.controls; |
9 | 9 | using System.Text; |
10 | +using System.Diagnostics; | |
10 | 11 | |
11 | 12 | namespace nft.ui.system |
12 | 13 | { |
@@ -224,6 +225,7 @@ | ||
224 | 225 | } |
225 | 226 | |
226 | 227 | private void throwButton_Click(object sender, EventArgs e) { |
228 | + Debug.WriteLine(detail.Text); | |
227 | 229 | throw exception; |
228 | 230 | } |
229 | 231 | } |
@@ -323,9 +323,9 @@ | ||
323 | 323 | { |
324 | 324 | Application.DoEvents(); |
325 | 325 | Plugin p = (Plugin)item.Tag; |
326 | - foreach (Contribution c in p.primitives) | |
326 | + foreach (Contribution c in p.Primitives) | |
327 | 327 | clist.Items.Add( CreateListItem(c) ); |
328 | - foreach( Contribution c in p.contributions ) | |
328 | + foreach( Contribution c in p.Contributions ) | |
329 | 329 | clist.Items.Add( CreateListItem(c) ); |
330 | 330 | } |
331 | 331 | } |
@@ -336,9 +336,9 @@ | ||
336 | 336 | if(p!=null) |
337 | 337 | { |
338 | 338 | e.Node.Nodes.Clear(); |
339 | - foreach (Contribution c in p.primitives) | |
339 | + foreach (Contribution c in p.Primitives) | |
340 | 340 | e.Node.Nodes.Add( CreateTreeItem(c) ); |
341 | - foreach( Contribution c in p.contributions ) | |
341 | + foreach( Contribution c in p.Contributions ) | |
342 | 342 | e.Node.Nodes.Add( CreateTreeItem(c) ); |
343 | 343 | } |
344 | 344 | } |