public UiResult ReadData() { var rval = new UiResult(); var readAllText = File.ReadAllText(_file); var strings = readAllText.Split("\r\n".ToCharArray()); var val = Program.InstancesBuilder.Resolve <IStringParser>().Parse(strings.FirstOrDefault() ?? ""); if (val == null) { throw new InvalidCastException(); } rval.First = val.Value; rval.Operation = strings.ElementAtOrDefault(1) ?? ""; if (!Program.InstancesBuilder.Resolve <IEnumerable <IEngine> >().Any(i => string.Compare(i.Operation, rval.Operation, StringComparison.OrdinalIgnoreCase) == 0)) { throw new InvalidOperationException(); } val = Program.InstancesBuilder.Resolve <IStringParser>().Parse(strings.ElementAtOrDefault(2) ?? ""); if (val == null) { throw new InvalidCastException(); } rval.Second = val.Value; return(rval); }
public virtual void Close(UiResult result = null) { if (result != null) { _uiResultInternal = result; } UIManager.instance.CloseUi(this, _uiResultInternal); _ChangeUiState(UiState.None); }
public UiResult ReadData() { var rval = new UiResult { Operation = "+" }; var actionsArray = new[] { new { Text = "First argument: ", ErrorMessage = "Invalid value [{0}]", Parser = (Func <string, bool>)(str => { var val = Program.InstancesBuilder.Resolve <IStringParser>().Parse(str); if (val != null) { rval.First = val.Value; return(true); } return(false); }) }, new { Text = "Operation: ", ErrorMessage = "Invalid operation [{0}]", Parser = (Func <string, bool>)(str => { if (Program.InstancesBuilder.Resolve <IEnumerable <IEngine> >().Any(i => string.Compare(i.Operation, str, StringComparison.OrdinalIgnoreCase) == 0)) { rval.Operation = str; return(true); } return(false); }) }, new { Text = "Second argument: ", ErrorMessage = "Invalid value [{0}]", Parser = (Func <string, bool>)(str => { var val = Program.InstancesBuilder.Resolve <IStringParser>().Parse(str); if (val != null) { rval.Second = val.Value; return(true); } return(false); }) } }; foreach (var i in actionsArray) { while (true) { Console.WriteLine(i.Text); var str = Console.ReadLine(); if (i.Parser(str)) { break; } Console.WriteLine(i.ErrorMessage, str); } } return(rval); }
public void CloseUi(UiCtrlBase uiCtrlBase, UiResult result = null) { UiCtrl uiCtrl = (UiCtrl)uiCtrlBase as UiCtrl; if (uiCtrl == null) { return; } if (uiCtrl._uiState == UiState.WillDestroy) { return; } if (_currUi == uiCtrl) { _currUi = null; } UiCtrl popup_ui = GetUi(uiPopupList, uiCtrl.uiId); if (popup_ui != null) { uiPopupList.Remove(popup_ui); } uiCtrl._Deactivate(); uiCtrl._OnWillDestroy(); Delegate resultCbD = uiCtrl._resultCbD; if (uiCtrl._resultCbD != null) { if (result == null) { result = uiCtrl.uiResult; result.btId = ButtonId.Cancel; } else { if (result.GetType() != uiCtrl.GetResultType()) { Debug.Assert(false, @"ResultType must be '" + uiCtrl.GetResultType() + @"' not '" + result.GetType() + @"'."); } } result.uiCtrl = uiCtrl; } if (uiCtrl._resultCbD != null) { if (result == null) { result = uiCtrl.uiResult; result.btId = ButtonId.Cancel; } else { if (result.GetType() != uiCtrl.GetResultType()) { Debug.Assert(false, @"ResultType must be '" + uiCtrl.GetResultType() + @"' not '" + result.GetType() + @"'."); } } result.uiCtrl = uiCtrl; } if (resultCbD != null) { resultCbD.DynamicInvoke(new object[] { result }); } }
void Awake() { ins = this; }