FreeTrainの進化系を目指す
例外処理の改善と条件付リソース(オーバーライド)の基本インターフェース
| @@ -0,0 +1,34 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.framework.drawing; | |
| 5 | +using nft.framework; | |
| 6 | + | |
| 7 | +namespace nft.core.view | |
| 8 | +{ | |
| 9 | + /// <summary> | |
| 10 | + /// Categorize type of conditions by its watch parameter and time cycle. | |
| 11 | + /// Array of same type conditions can be combined and optimized as Hashmap by ConditionResourceFactory | |
| 12 | + /// </summary> | |
| 13 | + public enum ConditionTypes { Unknown, TimeOfDay, Daily, Weekly, Monthly, Yearly, Weather, Scale } | |
| 14 | + | |
| 15 | + public interface ISceneParams | |
| 16 | + { | |
| 17 | + DateTime Datetime { get; } | |
| 18 | + Object Weather { get; } | |
| 19 | + ZoomScale ZoomScale { get; } | |
| 20 | + } | |
| 21 | + | |
| 22 | + public interface IConditionFactory | |
| 23 | + { | |
| 24 | + ISceneCondition CreateCondition(ParamsReader reader); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public interface ISceneCondition | |
| 28 | + { | |
| 29 | + string ConditionName { get; } | |
| 30 | + ConditionTypes ConditionType { get; } | |
| 31 | + bool IsMatch(ISceneParams p); | |
| 32 | + } | |
| 33 | + | |
| 34 | +} |
| @@ -0,0 +1,85 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | + | |
| 5 | +namespace nft.core.view | |
| 6 | +{ | |
| 7 | + public class ConditionedResource<T> | |
| 8 | + { | |
| 9 | + internal protected T Default; | |
| 10 | + | |
| 11 | + public ConditionedResource(T _default) { | |
| 12 | + this.Default = _default; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public T this[ISceneParams p] { | |
| 16 | + get { | |
| 17 | + T result = this.Default; | |
| 18 | + Choose(p, ref result); | |
| 19 | + return result; | |
| 20 | + } | |
| 21 | + } | |
| 22 | + | |
| 23 | + internal protected virtual bool Choose(ISceneParams p, ref T res){ | |
| 24 | + res = Default; | |
| 25 | + return true; | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + internal class SingleConditionResouce<T> : ConditionedResource<T> | |
| 30 | + { | |
| 31 | + protected readonly ISceneCondition Condition; | |
| 32 | + internal SingleConditionResouce(ISceneCondition cond, T val) :base(val){ | |
| 33 | + this.Condition = cond; | |
| 34 | + } | |
| 35 | + | |
| 36 | + internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 37 | + if (Condition.IsMatch(p)) { | |
| 38 | + res = Default; | |
| 39 | + return true; | |
| 40 | + } else { | |
| 41 | + return false; | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + internal class NestedConditionsResouceRoot<T> : ConditionedResource<T> | |
| 47 | + { | |
| 48 | + internal protected readonly List<ConditionedResource<T>> children; | |
| 49 | + internal NestedConditionsResouceRoot(T val) | |
| 50 | + : base(val) { | |
| 51 | + this.children = new List<ConditionedResource<T>>(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 55 | + foreach (ConditionedResource<T> cc in children) { | |
| 56 | + if (cc.Choose(p, ref res)) { | |
| 57 | + return true; | |
| 58 | + } | |
| 59 | + } | |
| 60 | + res = Default; | |
| 61 | + return true; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void AddChild(ConditionedResource<T> child) { | |
| 65 | + children.Add(child); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + internal class NestedConditionsResouce<T> : NestedConditionsResouceRoot<T> | |
| 70 | + { | |
| 71 | + internal protected readonly ISceneCondition Condition; | |
| 72 | + internal NestedConditionsResouce(ISceneCondition cond, T val) | |
| 73 | + : base(val) { | |
| 74 | + this.Condition = cond; | |
| 75 | + } | |
| 76 | + | |
| 77 | + internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 78 | + if (Condition.IsMatch(p)) { | |
| 79 | + return base.Choose(p, ref res); | |
| 80 | + } else { | |
| 81 | + return false; | |
| 82 | + } | |
| 83 | + } | |
| 84 | + } | |
| 85 | +} |
| @@ -0,0 +1,71 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.framework.drawing; | |
| 5 | +using nft.framework; | |
| 6 | +using nft.framework.plugin; | |
| 7 | + | |
| 8 | +namespace nft.core.view | |
| 9 | +{ | |
| 10 | + public delegate T ResourceParser<T>(ParamsReader reader); | |
| 11 | + | |
| 12 | + public class ConditionedResourceFactory | |
| 13 | + { | |
| 14 | + static private readonly string VALUE_NODE = "default|value"; | |
| 15 | + static private readonly string CONDITION_NODE = "condition"; | |
| 16 | + static private readonly string CONDITION_TYPE_ATTR = "when"; | |
| 17 | + | |
| 18 | + static private Dictionary<string, IConditionFactory> factories = new Dictionary<string, IConditionFactory>(); | |
| 19 | + | |
| 20 | + public static void RegisterConditionFactory(string name, IConditionFactory fct){ | |
| 21 | + factories.Add(name, fct); | |
| 22 | + } | |
| 23 | + | |
| 24 | + public static ConditionedResource<T> LoadAsConditiondResources<T>(ParamsReader resource, ResourceParser<T> callback){ | |
| 25 | + ParamsReader dnode = resource[VALUE_NODE]; | |
| 26 | + T _default = callback(dnode.IsNull ? resource : dnode); | |
| 27 | + ParamsReader conds = resource[CONDITION_NODE]; | |
| 28 | + if (conds.IsNull) { | |
| 29 | + return new ConditionedResource<T>(_default); | |
| 30 | + } else { | |
| 31 | + NestedConditionsResouceRoot<T> ret = new NestedConditionsResouceRoot<T>(_default); | |
| 32 | + foreach (ParamsReader child in conds.Each) { | |
| 33 | + ConditionedResource<T> temp = LoadChildConditions(resource, callback); | |
| 34 | + ret.AddChild(temp); | |
| 35 | + } | |
| 36 | + return AdaptOptimization<T>(ret); | |
| 37 | + } | |
| 38 | + } | |
| 39 | + | |
| 40 | + #region private functions | |
| 41 | + private static ConditionedResource<T> LoadChildConditions<T>(ParamsReader resource, ResourceParser<T> callback){ | |
| 42 | + ISceneCondition sc = GetConditionFor(resource); | |
| 43 | + ParamsReader dnode = resource[VALUE_NODE]; | |
| 44 | + T _default = callback(dnode.IsNull ? resource : dnode); | |
| 45 | + ParamsReader conds = resource[CONDITION_NODE]; | |
| 46 | + if (conds.IsNull) { | |
| 47 | + return new SingleConditionResouce<T>(sc,_default); | |
| 48 | + } else { | |
| 49 | + NestedConditionsResouce<T> ret = new NestedConditionsResouce<T>(sc, _default); | |
| 50 | + foreach (ParamsReader child in conds.Each) { | |
| 51 | + ConditionedResource<T> temp = LoadChildConditions(resource, callback); | |
| 52 | + ret.AddChild(temp); | |
| 53 | + } | |
| 54 | + return AdaptOptimization<T>(ret); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + private static ConditionedResource<T> AdaptOptimization<T>(NestedConditionsResouceRoot<T> orig) { | |
| 59 | + return orig; | |
| 60 | + } | |
| 61 | + | |
| 62 | + private static ISceneCondition GetConditionFor(ParamsReader reader) { | |
| 63 | + ParamsReader pr2 = reader[CONDITION_TYPE_ATTR]; | |
| 64 | + if (pr2.IsNull) throw new PluginXmlException(reader, ""); | |
| 65 | + string attr = pr2.InnerText; | |
| 66 | + | |
| 67 | + return null; | |
| 68 | + } | |
| 69 | + #endregion | |
| 70 | + } | |
| 71 | +} |
| @@ -68,6 +68,9 @@ | ||
| 68 | 68 | <property name="type_indexed_grayscale" type="string" readonly="true">{1}色グレー</property> |
| 69 | 69 | <property name="type_grayscale" type="string" readonly="true">{0}bit グレー</property> |
| 70 | 70 | </properties> |
| 71 | + <properties name="ui_util"> | |
| 72 | + <property name="confirm_exit_message" type="string" readonly="true">NeoFTを終了してよろしいですか?</property> | |
| 73 | + </properties> | |
| 71 | 74 | <properties name="mainframe"> |
| 72 | 75 | <property name="long_title" type="string" readonly="true">Neo Free Train</property> |
| 73 | 76 | <property name="short_title" type="string" readonly="true">NeoFT</property> |
| @@ -81,7 +81,8 @@ | ||
| 81 | 81 | catch(Exception e) |
| 82 | 82 | { |
| 83 | 83 | string templ = Main.resources["directories.errormsg_on_dir_creation"].stringValue; |
| 84 | - UIUtil.ShowException(string.Format(templ,path),e,UIInformLevel.normal); | |
| 84 | + if(UIUtil.ShowException(string.Format(templ,path),e,UIInformLevel.normal)) | |
| 85 | + throw; | |
| 85 | 86 | } |
| 86 | 87 | return defaultPath; |
| 87 | 88 | } |
| @@ -33,7 +33,8 @@ | ||
| 33 | 33 | } |
| 34 | 34 | }catch(Exception e){ |
| 35 | 35 | string txt = Main.resources["global_modules.load_error"].stringValue; |
| 36 | - UIUtil.ShowException(txt,e,UIInformLevel.severe); | |
| 36 | + if(UIUtil.ShowException(txt,e,UIInformLevel.severe)) | |
| 37 | + throw; | |
| 37 | 38 | } |
| 38 | 39 | } |
| 39 | 40 | } |
| @@ -145,7 +145,8 @@ | ||
| 145 | 145 | |
| 146 | 146 | string templ = Main.resources["plugin.plugin_load_error"].stringValue; |
| 147 | 147 | templ+="\n"+e.Message; |
| 148 | - ReportError(string.Format(templ,Path.GetFileName(dir)),e); | |
| 148 | + if(ReportError(string.Format(templ,Path.GetFileName(dir)),e)) | |
| 149 | + throw; | |
| 149 | 150 | } |
| 150 | 151 | } |
| 151 | 152 | } |
| @@ -193,7 +194,8 @@ | ||
| 193 | 194 | } |
| 194 | 195 | catch( Exception e ) |
| 195 | 196 | { |
| 196 | - ReportError(e.Message,e); | |
| 197 | + if(ReportError(e.Message,e)) | |
| 198 | + throw; | |
| 197 | 199 | } |
| 198 | 200 | // Add 'p' to order-list and remove from remaining-list |
| 199 | 201 | pluginSet.Remove(p); |
| @@ -217,7 +219,8 @@ | ||
| 217 | 219 | } |
| 218 | 220 | catch( Exception e ) |
| 219 | 221 | { |
| 220 | - ReportError(e.Message,e); | |
| 222 | + if(ReportError(e.Message,e)) | |
| 223 | + throw; | |
| 221 | 224 | } |
| 222 | 225 | } |
| 223 | 226 |
| @@ -232,7 +235,8 @@ | ||
| 232 | 235 | catch( Exception e ) |
| 233 | 236 | { |
| 234 | 237 | p._state = InstallationState.FatalError; |
| 235 | - ReportError(e.Message,e); | |
| 238 | + if(ReportError(e.Message,e)) | |
| 239 | + throw; | |
| 236 | 240 | } |
| 237 | 241 | } |
| 238 | 242 | } |
| @@ -261,7 +265,8 @@ | ||
| 261 | 265 | } catch (Exception e) { |
| 262 | 266 | contrib._state = InstallationState.FatalError; |
| 263 | 267 | string templ = Main.resources["plugin.contrib_init_error"].stringValue; |
| 264 | - ReportError(string.Format(templ, contrib.Parent.ID, "contrib.name", contrib.ID), e); | |
| 268 | + if(ReportError(string.Format(templ, contrib.Parent.ID, "contrib.name", contrib.ID), e)) | |
| 269 | + throw; | |
| 265 | 270 | } |
| 266 | 271 | } |
| 267 | 272 | foreach (Contribution contrib in nonPrimitives) |
| @@ -281,7 +286,8 @@ | ||
| 281 | 286 | { |
| 282 | 287 | contrib._state = InstallationState.FatalError; |
| 283 | 288 | string templ = Main.resources["plugin.contrib_init_error"].stringValue; |
| 284 | - ReportError(string.Format(templ,contrib.Parent.ID,"contrib.name",contrib.ID),e); | |
| 289 | + if(ReportError(string.Format(templ,contrib.Parent.ID,"contrib.name",contrib.ID),e)) | |
| 290 | + throw; | |
| 285 | 291 | } |
| 286 | 292 | } |
| 287 | 293 | foreach (Contribution contrib in handlers.Keys) { |
| @@ -294,7 +300,8 @@ | ||
| 294 | 300 | } catch (Exception e) { |
| 295 | 301 | contrib._state = InstallationState.FatalError; |
| 296 | 302 | string templ = Main.resources["plugin.contrib_init_error"].stringValue; |
| 297 | - ReportError(string.Format(templ, contrib.Parent.ID, "contrib.name", contrib.ID), e); | |
| 303 | + if(ReportError(string.Format(templ, contrib.Parent.ID, "contrib.name", contrib.ID), e)) | |
| 304 | + throw; | |
| 298 | 305 | } |
| 299 | 306 | } |
| 300 | 307 | } |
| @@ -309,18 +316,24 @@ | ||
| 309 | 316 | } |
| 310 | 317 | } |
| 311 | 318 | |
| 312 | - internal void ReportError(string msg, Exception e) | |
| 319 | + /// <summary> | |
| 320 | + /// Show Plugin Error Form. Should throw again when true returns. | |
| 321 | + /// </summary> | |
| 322 | + /// <param name="msg"></param> | |
| 323 | + /// <param name="e"></param> | |
| 324 | + /// <returns></returns> | |
| 325 | + internal bool ReportError(string msg, Exception e) | |
| 313 | 326 | { |
| 314 | 327 | errCount++; |
| 315 | 328 | if (errCount < SkipTooMenyErrorsCount) { |
| 316 | - UIUtil.ShowException(msg, e, UIInformLevel.minor); | |
| 317 | - return; | |
| 329 | + return UIUtil.ShowException(msg, e, UIInformLevel.minor); | |
| 318 | 330 | } else { |
| 319 | 331 | if (errCount == SkipTooMenyErrorsCount) { |
| 320 | 332 | string templ = Main.resources["plugin.too_many_errors"].stringValue; |
| 321 | - UIUtil.ShowException(templ, new Exception(templ,e), UIInformLevel.minor); | |
| 333 | + Exception ex = new Exception(templ,e); | |
| 334 | + UIUtil.ShowException(templ, ex, UIInformLevel.minor); | |
| 322 | 335 | } |
| 323 | - return; // skip too many | |
| 336 | + return false; // skip too many | |
| 324 | 337 | } |
| 325 | 338 | } |
| 326 | 339 | #endregion |
| @@ -440,7 +453,8 @@ | ||
| 440 | 453 | string msg = MakeContribExceptionMessage(p, ctb_reader); |
| 441 | 454 | if (p._state != InstallationState.FatalError) |
| 442 | 455 | p._state = InstallationState.PartialError; |
| 443 | - ReportError(msg, e); | |
| 456 | + if(ReportError(msg, e)) | |
| 457 | + throw; | |
| 444 | 458 | } |
| 445 | 459 | } |
| 446 | 460 | if (p._state != InstallationState.FatalError && errors == count) { |
| @@ -23,41 +23,43 @@ | ||
| 23 | 23 | :this(node,msg) |
| 24 | 24 | { |
| 25 | 25 | this.plugin = p; |
| 26 | - ConfirmPlugin(node); | |
| 27 | 26 | } |
| 28 | 27 | |
| 29 | 28 | public PluginXmlException(Contribution c, ParamsReader node, string msg) |
| 30 | 29 | :this(node,msg) |
| 31 | 30 | { |
| 32 | - this.contrib = c; | |
| 33 | - this.plugin = c.Parent; | |
| 34 | - ConfirmPlugin(node); | |
| 31 | + AttachContribution(c); | |
| 35 | 32 | } |
| 36 | 33 | |
| 37 | - private void ConfirmPlugin(ParamsReader node) | |
| 34 | + public void AttachContribution(Contribution c){ | |
| 35 | + this.contrib = c; | |
| 36 | + this.plugin = c.Parent; | |
| 37 | + } | |
| 38 | + | |
| 39 | + private bool ConfirmPlugin() | |
| 38 | 40 | { |
| 39 | - if(plugin==null) | |
| 40 | - { | |
| 41 | - string pname = Path.GetFileName(Path.GetDirectoryName(node.SourceURI)+""); | |
| 42 | - plugin = PluginManager.theInstance.GetPlugin(pname); | |
| 43 | - } | |
| 41 | + if (plugin != null) return true; | |
| 42 | + | |
| 43 | + string pname = Path.GetFileName(Path.GetDirectoryName(node.SourceURI)+""); | |
| 44 | + plugin = PluginManager.theInstance.GetPlugin(pname); | |
| 45 | + return plugin != null; | |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | 48 | public string getDetailedMessage(string linecode) |
| 47 | 49 | { |
| 48 | 50 | string msg = base.Message; |
| 49 | - if(plugin==null) | |
| 51 | + if (!ConfirmPlugin()) | |
| 50 | 52 | { |
| 51 | - msg+=string.Format("Plug-In:{0}","N/A"); | |
| 53 | + msg+=string.Format(" Plug-In:{0}","N/A"); | |
| 52 | 54 | return msg; |
| 53 | 55 | } |
| 54 | - msg+=string.Format("Plug-In:{0}{1}",plugin.ID,linecode); | |
| 55 | - msg+=string.Format("Title:{0}{1}",plugin.Title,linecode); | |
| 56 | - msg+=string.Format("Author:{0}",plugin.author); | |
| 56 | + msg+=string.Format(" Plug-In:{0}{1}",plugin.ID,linecode); | |
| 57 | + msg+=string.Format(" Title:{0}{1}",plugin.Title,linecode); | |
| 58 | + msg+=string.Format(" Author:{0}",plugin.author); | |
| 57 | 59 | if(contrib!=null) |
| 58 | 60 | { |
| 59 | - msg+=string.Format("{0}Contrib-ID:{1}",linecode,contrib.ID); | |
| 60 | - msg+=string.Format("{0}Name:{1}",linecode,contrib.Name); | |
| 61 | + msg+=string.Format(" {0}Contrib-ID:{1}",linecode,contrib.ID); | |
| 62 | + msg+=string.Format(" {0}Name:{1}",linecode,contrib.Name); | |
| 61 | 63 | } |
| 62 | 64 | return msg; |
| 63 | 65 | } |
| @@ -50,7 +50,8 @@ | ||
| 50 | 50 | { |
| 51 | 51 | Debug.WriteLine(e); |
| 52 | 52 | string templ = Main.resources["webloader.other_exception"].stringValue; |
| 53 | - UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal); | |
| 53 | + if(UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal)) | |
| 54 | + throw; | |
| 54 | 55 | } |
| 55 | 56 | return null; |
| 56 | 57 | } |
| @@ -77,7 +78,8 @@ | ||
| 77 | 78 | { |
| 78 | 79 | Debug.WriteLine(e); |
| 79 | 80 | string templ = Main.resources["webloader.other_exception"].stringValue; |
| 80 | - UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal); | |
| 81 | + if(UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal)) | |
| 82 | + throw; | |
| 81 | 83 | } |
| 82 | 84 | |
| 83 | 85 | } |
| @@ -103,7 +105,8 @@ | ||
| 103 | 105 | { |
| 104 | 106 | Debug.WriteLine(e); |
| 105 | 107 | string templ = Main.resources["webloader.other_exception"].stringValue; |
| 106 | - UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal); | |
| 108 | + if(UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal)) | |
| 109 | + throw; | |
| 107 | 110 | } |
| 108 | 111 | finally |
| 109 | 112 | { |
| @@ -140,7 +143,8 @@ | ||
| 140 | 143 | { |
| 141 | 144 | Debug.WriteLine(e); |
| 142 | 145 | string templ = Main.resources["webloader.other_exception"].stringValue; |
| 143 | - UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal); | |
| 146 | + if(UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal)) | |
| 147 | + throw; | |
| 144 | 148 | } |
| 145 | 149 | } |
| 146 | 150 |
| @@ -183,7 +187,8 @@ | ||
| 183 | 187 | { |
| 184 | 188 | Debug.WriteLine(e); |
| 185 | 189 | string templ = Main.resources["webloader.other_exception"].stringValue; |
| 186 | - UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal); | |
| 190 | + if(UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal)) | |
| 191 | + throw; | |
| 187 | 192 | } |
| 188 | 193 | } |
| 189 | 194 |
| @@ -231,7 +236,8 @@ | ||
| 231 | 236 | Debug.WriteLine(e); |
| 232 | 237 | Release(); |
| 233 | 238 | string templ = Main.resources["webloader.other_exception"].stringValue; |
| 234 | - UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal); | |
| 239 | + if(UIUtil.ShowException(string.Format(templ,url),e,UIInformLevel.normal)) | |
| 240 | + throw; | |
| 235 | 241 | } |
| 236 | 242 | } |
| 237 | 243 |
| @@ -43,9 +43,9 @@ | ||
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public void ShowException(string text,Exception e,UIInformLevel level) | |
| 46 | + public bool ShowException(string text,Exception e,UIInformLevel level) | |
| 47 | 47 | { |
| 48 | - UIUtil.ShowErrorMessageBox(null, text, e); | |
| 48 | + return UIUtil.ShowErrorMessageBox(null, text, e); | |
| 49 | 49 | } |
| 50 | 50 | public void ShowMessage(string text,UIMessageType type,UIInformLevel level) |
| 51 | 51 | { |
| @@ -114,7 +114,8 @@ | ||
| 114 | 114 | { |
| 115 | 115 | string templ = Main.resources["command.exception@execute"].stringValue; |
| 116 | 116 | string msg = string.Format(templ,new string[]{ID}); |
| 117 | - UIUtil.ShowException(msg,e,UIInformLevel.normal); | |
| 117 | + if(UIUtil.ShowException(msg,e,UIInformLevel.normal)) | |
| 118 | + throw; | |
| 118 | 119 | } |
| 119 | 120 | } |
| 120 | 121 | } |
| @@ -85,9 +85,18 @@ | ||
| 85 | 85 | { |
| 86 | 86 | return handler.ShowQueryMessage(text,UIQueryType.ok_cancel,UIMessageType.question,UIInformLevel.normal); |
| 87 | 87 | } |
| 88 | - static public void ShowException(string text,Exception caused,UIInformLevel level) | |
| 88 | + | |
| 89 | + /// <summary> | |
| 90 | + /// Show Exception Detail Form. Should throw again when true returns. | |
| 91 | + /// ex. if(UIUtil.ShowException(text,caused,level)) throw; | |
| 92 | + /// </summary> | |
| 93 | + /// <param name="text"></param> | |
| 94 | + /// <param name="caused"></param> | |
| 95 | + /// <param name="level"></param> | |
| 96 | + /// <returns>Should throw again if true returns</returns> | |
| 97 | + static public bool ShowException(string text,Exception caused,UIInformLevel level) | |
| 89 | 98 | { |
| 90 | - handler.ShowException(text,caused,level); | |
| 99 | + return handler.ShowException(text,caused,level); | |
| 91 | 100 | } |
| 92 | 101 | |
| 93 | 102 | static public void SetHandler(IMessageUIHandler new_handler) |
| @@ -106,11 +115,11 @@ | ||
| 106 | 115 | { |
| 107 | 116 | Debug.WriteLine(text); |
| 108 | 117 | } |
| 109 | - public void ShowException(string text,Exception caused,UIInformLevel level) | |
| 118 | + public bool ShowException(string text,Exception caused,UIInformLevel level) | |
| 110 | 119 | { |
| 111 | - ShowErrorMessageBox(null,text,caused); | |
| 112 | - Debug.WriteLine(text); | |
| 113 | - Debug.WriteLine(caused.StackTrace); | |
| 120 | + Debug.WriteLine(text); | |
| 121 | + Debug.WriteLine(caused.StackTrace); | |
| 122 | + return ShowErrorMessageBox(null, text, caused); | |
| 114 | 123 | } |
| 115 | 124 | public bool ShowQueryMessage(string text,UIQueryType query,UIMessageType type,UIInformLevel level) |
| 116 | 125 | { |
| @@ -121,25 +130,27 @@ | ||
| 121 | 130 | } |
| 122 | 131 | } |
| 123 | 132 | |
| 124 | - public static void ShowErrorMessageBox(IWin32Window owner, string msg, Exception e ) | |
| 133 | + public static bool ShowErrorMessageBox(IWin32Window owner, string msg, Exception e ) | |
| 125 | 134 | { |
| 126 | 135 | Assembly asm = Assembly.LoadFrom(Directories.AppBaseDir+"NFT.UI.DLL"); |
| 127 | 136 | Type t = asm.GetType("nft.ui.system.ErrorMessageBox"); |
| 128 | 137 | BindingFlags flags = BindingFlags.Public|BindingFlags.Static|BindingFlags.InvokeMethod; |
| 129 | - object ret = t.InvokeMember("Show",flags ,null,null,new object[]{owner,msg,e}); | |
| 130 | - if ((bool)ret && Main.mainFrame!=null) { | |
| 131 | - DialogResult r2 = MessageBox.Show(null, "Are you sure to QUIT?", "NeoFT", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); | |
| 138 | + DialogResult ret = (DialogResult)t.InvokeMember("Show", flags, null, null, new object[] { owner, msg, e }); | |
| 139 | + if (DialogResult.Abort==ret && Main.mainFrame!=null) { | |
| 140 | + string msg2 = Main.resources["ui_util.confirm_exit_message"].stringValue; | |
| 141 | + DialogResult r2 = MessageBox.Show(null, msg2, "NeoFT", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); | |
| 132 | 142 | if (r2 == DialogResult.Yes) { |
| 133 | - Environment.Exit(-2); | |
| 143 | + Environment.Exit(0); | |
| 134 | 144 | } |
| 135 | 145 | } |
| 146 | + return DialogResult.Retry == ret; | |
| 136 | 147 | } |
| 137 | 148 | } |
| 138 | 149 | |
| 139 | 150 | public interface IMessageUIHandler |
| 140 | 151 | { |
| 141 | - void ShowMessage(string text,UIMessageType type,UIInformLevel level); | |
| 142 | - void ShowException(string text,Exception caused,UIInformLevel level); | |
| 152 | + void ShowMessage(string text,UIMessageType type,UIInformLevel level); | |
| 153 | + bool ShowException(string text,Exception caused,UIInformLevel level); | |
| 143 | 154 | bool ShowQueryMessage(string text,UIQueryType query,UIMessageType type,UIInformLevel level); |
| 144 | 155 | void Release(); |
| 145 | 156 | } |