void SyncComplete(object sender, ISyncEventArgs e) { ControlsContext.Current.ActionHandlerLocker.Release(); var common = (ICommonData)_context.ValueStack.Values["common"]; common.SyncIsOK = e.Ok; DbContext.Current.Database.SyncComplete(e.Ok); if (_handler != null) { _context.InvokeOnMainThread(() => { _handler.ExecuteCallback(_scriptEngine.Visitor, _state, null); _state = null; _handler = null; }); } if (!e.Ok) { LastError = e.Exception.Message; _context.HandleException(e.Exception); } }
public async void Create(object address, string text, string subject, object attachments , IJsExecutable handler, object state) { string[] destinations = ObjectToStringArray(address); var paths = new List <string>(); // ReSharper disable once LoopCanBeConvertedToQuery foreach (var item in ObjectToStringArray(attachments)) { if (!string.IsNullOrWhiteSpace(item)) { try { paths.Add(IOContext.Current.TranslateLocalPath(item)); } catch (NonFatalException) { } } } await _applicationContext.EmailProvider.OpenEmailManager(destinations, subject, text, paths.ToArray()); if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, state, new Args <object>(null)); } }
public async void Ask(object message , IJsExecutable positiveHandler, object positiveValue, IJsExecutable negativeHandler, object negativeValue) { ControlsContext.Current.ActionHandlerLocker.Acquire(); try { string msg = ObjToString(message); var yes = new DialogButton(D.YES); var no = new DialogButton(D.NO); bool positive = await _context.DialogProvider.Ask(msg, yes, no); IJsExecutable handler = positive ? positiveHandler : negativeHandler; object value = positive ? positiveValue : negativeValue; if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args <Result>(positive ? Result.Yes : Result.No)); } } finally { ControlsContext.Current.ActionHandlerLocker.Release(); } }
public async void Alert(object message, IJsExecutable handler, object value, object positiveText, object negativeText, object neutralText) { ControlsContext.Current.ActionHandlerLocker.Acquire(); try { string msg = ObjToString(message); var positiveButtonText = ObjToString(positiveText); var positive = new DialogButton(positiveButtonText); DialogButton negative = null; if (negativeText != null) negative = new DialogButton(_context.Dal.TranslateString(negativeText.ToString())); DialogButton neutral = null; if (neutralText != null) neutral = new DialogButton(_context.Dal.TranslateString(neutralText.ToString())); int number = await _context.DialogProvider.Alert(msg, positive, negative, neutral); if (handler != null) handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args<int>(number)); } finally { ControlsContext.Current.ActionHandlerLocker.Release(); } }
public async void Post(string query, string data, IJsExecutable callback, object state) { using (var req = CreateRequest()) { try { var content = new StringContent(data); var r = await req.PostAsync(query, content); if (callback != null) { string result = await r.Content.ReadAsStringAsync(); callback.ExecuteCallback(_scriptEngine.Visitor, state, new WebRequestArgs(result)); } } catch (WebException e) { HandleException(callback, state, e); } catch (TaskCanceledException e) { HandleException(callback, state, new WebException("", WebExceptionStatus.Timeout)); } } }
public async void Alert(object message, IJsExecutable handler, object value, object positiveText, object negativeText, object neutralText) { ControlsContext.Current.ActionHandlerLocker.Acquire(); try { string msg = ObjToString(message); var positiveButtonText = ObjToString(positiveText); var positive = new DialogButton(positiveButtonText); DialogButton negative = null; if (negativeText != null) { negative = new DialogButton(_context.Dal.TranslateString(negativeText.ToString())); } DialogButton neutral = null; if (neutralText != null) { neutral = new DialogButton(_context.Dal.TranslateString(neutralText.ToString())); } int number = await _context.DialogProvider.Alert(msg, positive, negative, neutral); if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args <int>(number)); } } finally { ControlsContext.Current.ActionHandlerLocker.Release(); } }
private async void AnyDateTimeDialog(DateTimeDialog func, object caption, DateTime current , IJsExecutable positiveHandler, object positiveValue, IJsExecutable negativeHandler, object negativeValue) { ControlsContext.Current.ActionHandlerLocker.Acquire(); try { string capt = ObjToString(caption); var ok = new DialogButton(D.OK); var cancel = new DialogButton(D.CANCEL); IDialogAnswer <DateTime> answer = await func(capt, current, ok, cancel); IJsExecutable handler = answer.Positive ? positiveHandler : negativeHandler; object value = answer.Positive ? positiveValue : negativeValue; if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args <DateTime>(answer.Result)); } } finally { ControlsContext.Current.ActionHandlerLocker.Release(); } }
// ReSharper disable once MemberCanBePrivate.Global public async void Feedback(string title, string text, IJsExecutable handler, object value) { bool result = await LogManager.Reporter.Send(title, text, ReportType.Feedback); if (handler != null) { _context.InvokeOnMainThread( () => handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args <bool>(result))); } }
public void Scan(IJsExecutable handler, object value) { Action<object> callback = result => { if (handler != null) // todo: change api to universal format handler.ExecuteCallback(_scriptEngine.Visitor, result, value); }; _context.ScanBarcode(callback); }
public void Scan(IJsExecutable handler, object value) { Action <object> callback = result => { if (handler != null) { // todo: change api to universal format handler.ExecuteCallback(_scriptEngine.Visitor, result, value); } }; _context.ScanBarcode(callback); }
private void HandleException(IJsExecutable callback, object state, WebException e) { var error = new WebError(e); if (callback != null) { callback.ExecuteCallback(_scriptEngine.Visitor, state, new WebRequestArgs(error)); } else { LogManager.Logger.Error(error.Message, false); } }
public void Copy(string destinationPath, IJsExecutable callback, object state) { string path = IOContext.Current.TranslateLocalPath( destinationPath); Action<bool> handler; if (callback != null) handler = result => callback.ExecuteCallback(_scriptEngine.Visitor, state, new CallbackArgs(result)); else handler = result => { }; _context.GalleryProvider.Copy(path, Size, handler); }
public async void ShowTime(string caption, DateTime current, IJsExecutable handler, object value) { caption = _context.Dal.TranslateString(caption); var ok = new DialogButton(D.OK); var cancel = new DialogButton(D.CANCEL); IDialogAnswer <DateTime> answer = await _context.DialogProvider.Time(caption, current, ok, cancel); if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, answer.Result, value); } }
public async void Question(string message, IJsExecutable handler, object value) { message = _context.Dal.TranslateString(message); var yes = new DialogButton(D.YES); var no = new DialogButton(D.NO); bool positive = await _context.DialogProvider.Ask(message, yes, no); if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, positive ? Result.Yes : Result.No, value); } }
public async void Select(string caption, object items, IJsExecutable handler, object value) { KeyValuePair <object, string>[] rows = PrepareSelection(items); caption = _context.Dal.TranslateString(caption); var ok = new DialogButton(D.OK); var cancel = new DialogButton(D.CANCEL); IDialogAnswer <object> answer = await _context.DialogProvider.Choose(caption, rows, 0, ok, cancel); if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, answer.Result, value); } }
public void Copy(string destinationPath, IJsExecutable callback, object state) { string path = IOContext.Current.TranslateLocalPath(destinationPath); Action <bool> handler; if (callback != null) { handler = result => callback.ExecuteCallback(_scriptEngine.Visitor, state, new CallbackArgs(result)); } else { handler = result => { } }; _context.GalleryProvider.Copy(path, Size, handler); }
public void MakeSnapshot(string path, int size, IJsExecutable callback, object state) { string p = IOContext.Current.TranslateLocalPath(path); Action <bool> handler; if (callback != null) { handler = result => callback.ExecuteCallback(_scriptEngine.Visitor, state, new CallbackArgs(result)); } else { handler = res => { } }; _context.CameraProvider.MakeSnapshot(p, size, handler); }
public async void Message(object message, IJsExecutable handler, object value) { ControlsContext.Current.ActionHandlerLocker.Acquire(); try { string msg = ObjToString(message); var close = new DialogButton(D.CLOSE); await _context.DialogProvider.Message(msg, close); if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args <object>(null)); } } finally { ControlsContext.Current.ActionHandlerLocker.Release(); } }
public async void Create(object address, string text, string subject, object attachments , IJsExecutable handler, object state) { string[] destinations = ObjectToStringArray(address); var paths = new List<string>(); // ReSharper disable once LoopCanBeConvertedToQuery foreach (var item in ObjectToStringArray(attachments)) if (!string.IsNullOrWhiteSpace(item)) try { paths.Add(IOContext.Current.TranslateLocalPath(item)); } catch (NonFatalException) { } await _applicationContext.EmailProvider.OpenEmailManager(destinations, subject, text, paths.ToArray()); if (handler != null) handler.ExecuteCallback(_scriptEngine.Visitor, state, new Args<object>(null)); }
private async void InvokeAsync(Action callback, IJsExecutable handler, object state) { ControlsContext.Current.ActionHandlerLocker.Acquire(); _lastException = null; try { await Task.Run(callback); SuccessSync = true; } catch (Exception e) { _lastException = e; SuccessSync = false; } finally { LastSyncTime = DateTime.Now; WriteFsLog(); ControlsContext.Current.ActionHandlerLocker.Release(); if (handler != null) { _io.InvokeOnMainThread(() => { var args = new EventArgs { State = state, Result = _lastException == null }; handler.ExecuteCallback(_scriptEngine.Visitor, args, null); handler = null; state = null; }); } } }
public async void Get(string query, IJsExecutable callback, object state) { using (var req = CreateRequest()) { try { var result = await req.GetStringAsync(query); if (callback != null) { callback.ExecuteCallback(_scriptEngine.Visitor, state, new WebRequestArgs(result)); } } catch (WebException e) { HandleException(callback, state, e); } catch (TaskCanceledException e) { HandleException(callback, state, new WebException("", WebExceptionStatus.Timeout)); } } }
public async void Choose(object caption, object items, object startKey , IJsExecutable positiveHandler, object positiveValue, IJsExecutable negativeHandler, object negativeValue) { ControlsContext.Current.ActionHandlerLocker.Acquire(); try { KeyValuePair <object, string>[] rows = PrepareSelection(items); int index = 0; for (int i = 0; i < rows.Length; i++) { if (rows[i].Key.Equals(startKey)) { index = i; break; } } string capt = ObjToString(caption); var ok = new DialogButton(D.OK); var cancel = new DialogButton(D.CANCEL); IDialogAnswer <object> answer = await _context.DialogProvider.Choose(capt, rows, index, ok, cancel); IJsExecutable handler = answer.Positive ? positiveHandler : negativeHandler; object value = answer.Positive ? positiveValue : negativeValue; if (handler != null) { handler.ExecuteCallback(_scriptEngine.Visitor, value, new KeyValueArgs <object, string>(answer.Result, rows)); } } finally { ControlsContext.Current.ActionHandlerLocker.Release(); } }
public async void Question(string message, IJsExecutable handler, object value) { message = _context.Dal.TranslateString(message); var yes = new DialogButton(D.YES); var no = new DialogButton(D.NO); bool positive = await _context.DialogProvider.Ask(message, yes, no); if (handler != null) handler.ExecuteCallback(_scriptEngine.Visitor, positive ? Result.Yes : Result.No, value); }
public async void Select(string caption, object items, IJsExecutable handler, object value) { KeyValuePair<object, string>[] rows = PrepareSelection(items); caption = _context.Dal.TranslateString(caption); var ok = new DialogButton(D.OK); var cancel = new DialogButton(D.CANCEL); IDialogAnswer<object> answer = await _context.DialogProvider.Choose(caption, rows, 0, ok, cancel); if (handler != null) handler.ExecuteCallback(_scriptEngine.Visitor, answer.Result, value); }
public void MakeSnapshot(string path, int size, IJsExecutable callback, object state) { string p = IOContext.Current.TranslateLocalPath(path); Action<bool> handler; if (callback != null) handler = result => callback.ExecuteCallback(_scriptEngine.Visitor, state, new CallbackArgs(result)); else handler = res => { }; _context.CameraProvider.MakeSnapshot(p, size, handler); }
public async void ShowTime(string caption, DateTime current, IJsExecutable handler, object value) { caption = _context.Dal.TranslateString(caption); var ok = new DialogButton(D.OK); var cancel = new DialogButton(D.CANCEL); IDialogAnswer<DateTime> answer = await _context.DialogProvider.Time(caption, current, ok, cancel); if (handler != null) handler.ExecuteCallback(_scriptEngine.Visitor, answer.Result, value); }
// ReSharper disable once MemberCanBePrivate.Global public async void Feedback(string title, string text, IJsExecutable handler, object value) { bool result = await LogManager.Reporter.Send(title, text, ReportType.Feedback); if (handler != null) _context.InvokeOnMainThread( () => handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args<bool>(result))); }
public async void Message(object message, IJsExecutable handler, object value) { ControlsContext.Current.ActionHandlerLocker.Acquire(); try { string msg = ObjToString(message); var close = new DialogButton(D.CLOSE); await _context.DialogProvider.Message(msg, close); if (handler != null) handler.ExecuteCallback(_scriptEngine.Visitor, value, new Args<object>(null)); } finally { ControlsContext.Current.ActionHandlerLocker.Release(); } }
private async void InvokeAsync(Action callback, IJsExecutable handler, object state) { ControlsContext.Current.ActionHandlerLocker.Acquire(); _lastException = null; try { await Task.Run(callback); SuccessSync = true; } catch (Exception e) { _lastException = e; SuccessSync = false; } finally { LastSyncTime = DateTime.Now; WriteFsLog(); ControlsContext.Current.ActionHandlerLocker.Release(); if (handler != null) _io.InvokeOnMainThread(() => { var args = new EventArgs { State = state, Result = _lastException == null }; handler.ExecuteCallback(_scriptEngine.Visitor, args, null); handler = null; state = null; }); } }