private void OnExtendedSearch(object sender, ExtendedSearchEventArgs e) { Execute.BeginInvoke(() => { try { var provider = (ISearchProvider)sender; provider.ExtendedSearchCompleted -= OnExtendedSearch; if (e.Success) { _details = e.TorrentDetails; _searchDetailsController.TableView.ReloadData(); } else { MessageBox.Show(e.ErrorMessage, "Error"); } _busyIndicator.IsBusy = false; } catch (Exception exc) { Console.WriteLine(exc); } }); }
private void OnSearchCompleted(object sender, SearchEventArgs e) { Execute.BeginInvoke(() => { if (e.Success) { _torrents = e.Urls; if (_tableView != null) { _tableView.ReloadData(); } } _busyIndicator.IsBusy = false; }); }
private void SendToServer(Action action) { Execute.Background(() => { try { action(); _server.StartPolling(); } catch (Exception exc) { Execute.BeginInvoke(() => MessageBox.Show(exc.Message, "Error")); } }); }
/// <summary> /// Execute each function on each segment of the stream /// </summary> /// <param name="stream"></param> /// <param name="actions">Actions to applies</param> /// <param name="bufferLength">Size of buffer to get a segment of stream</param> /// <param name="callback">Call back funtion</param> /// <returns>Handler to async operation</returns> public static IAsyncResult BeginExecute(this Stream stream, IEnumerable <Action <byte[], int> > actions, int bufferLength = 1024, AsyncCallback callback = null) { Execute <byte[]> execute = x => { var buff = new byte[bufferLength]; while (stream.Position < stream.Length) { int readers = stream.Read(buff, (int)stream.Position, bufferLength); foreach (var action in x) { action(buff, readers); } } }; return(execute.BeginInvoke(actions, callback, execute)); }
protected virtual void Initialize() { var container = TinyIoCContainer.Current; _server = container.Resolve <Server>(); _hub = container.Resolve <ITinyMessengerHub>(); _hub.Subscribe <TorrentDetailsMessage>(m => { _torrent = m.Torrent; _torrentDetailsController.TableView.ReloadData(); _torrentDetailsController.TableView.SetContentOffset(PointF.Empty, false); _navigationController.PushViewController(_torrentDetailsController, true); }); _hub.Subscribe <TorrentChangedMessage>(m => Execute.BeginInvoke(() => { if (_torrent != null && _torrent.ID == m.Torrent.ID) { if (m.Removed) { _navigationController.PopViewControllerAnimated(true); } else { _torrent = m.Torrent; _torrentDetailsController.TableView.ReloadData(); } } })); for (int i = 0; i < _cells.Length; i++) { _cells[i] = new UITableViewCell(UITableViewCellStyle.Value1, string.Empty) { SelectionStyle = UITableViewCellSelectionStyle.None, }; } }
private void InvokeCommand(string commandName, InvokeCommandMessage message) { ICommand command = commands[commandName]; if (command.Async) { var worker = new Execute(command.Execute); var callback = new AsyncCallback(CommandCompletedCallback); AsyncOperation async = AsyncOperationManager.CreateOperation(message); log.DebugFormat("Starting asynchronous exeucution of \"{0}\"", message.Command); worker.BeginInvoke(message.IrcEventArgs, callback, async); } else { IEnumerable<string> response = commands[commandName].Execute(message.IrcEventArgs); log.DebugFormat("Synchronous execution of \"{0}\" complete. Sending response...", message.Command); if (response != null && response.Any()) SendIrcResponse(message, response); } }
protected virtual void Initialize() { var container = TinyIoCContainer.Current; //Messenger _hub = container.Resolve <ITinyMessengerHub>(); _hub.Subscribe <ApplicationMessage>(m => { if (m.Content == ApplicationMessageType.Loaded || m.Content == ApplicationMessageType.Foregrounded) { // if (!string.IsNullOrEmpty(_settings.Url) && ++_settings.NumberOfRuns == 3) // { // MessageBox.Ask("Would you consider donating a mere $.99?", "Enjoy the App?", yes => // { // if (yes) // { // _hub.Publish(new DonateMessage(this)); // } // else // { // Refresh(); // } // }); // } // else { Refresh(); } } }); _hub.Subscribe <AddTorrentMessage>(m => { try { _server.AddUrl(m.Url.Url); } catch (Exception exc) { Execute.BeginInvoke(() => MessageBox.Show(exc.Message, "Error")); } }); _settings = container.Resolve <Settings>(); //Server _server = container.Resolve <Server>(); _server.TorrentsChanged += (sender, e) => Execute.BeginInvoke(() => { if (_tableView != null) { _tableView.ReloadData(); } }); _server.TorrentsError += (sender, e) => Execute.BeginInvoke(() => { MessageBox.Show("Could not get list of torrents: " + Environment.NewLine + e.Exception.Message + Environment.NewLine + "Press refresh to try again.", "Error"); }); _server.TorrentChanged += (sender, e) => _hub.Publish(new TorrentChangedMessage(this, false, e.Torrent)); _server.TorrentRemoved += (sender, e) => _hub.Publish(new TorrentChangedMessage(this, true, e.Torrent)); }