Exemple #1
0
 public override void OnDestroy()
 {
     this.Info($"In OnDestroy()...");
     _nodeController?.RaiseNodeShutdownRequested();
     _nodeController = null;
     _helper.RemoveNotification();
     if (_tryRestart)
     {
         var broadcastIntent = new Intent(this, typeof(RestartOnDestroyReceiver));
         SendBroadcast(broadcastIntent);
     }
     _handler.RemoveCallbacks(_runnable);
     _handler.Dispose();
     _handler = null;
     base.OnDestroy();
 }
Exemple #2
0
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            this.Info($"In OnStartCommand(), Action: {intent.Action}...");
            switch (intent.Action)
            {
            case ActionStartNodeService:
                var notification = _helper.CreateNotification("Starting Service and node...");
                StartForeground(NodeServiceNotificationId, notification);
                this.Info($"Called StartForeground...");
                if (_nodeController == null)
                {
                    this.Info($"NodeControllerFactory was null, creating it...");
                    _nodeController              = new NodeController();
                    _nodeController.NodeCrashed += OnNodeCrashed;
                    _nodeController.StartFullNode(intent.GetStringArrayListExtra("startParameters").ToArray());
                    this.Info($"NodeControllerFactory.StartFullNode() has returned...");
                    _helper.UpdateNotification("Started service and node.", new[] { _helper.CreateAction(ActionStopNodeService, "Stop Node") });
                }
                else
                {
                    this.Info($"NodeControllerFactory was not null (already running)...");
                    _helper.UpdateNotification("Node was already running.");
                }
                break;

            case ActionStopNodeService:
                _handler?.RemoveCallbacks(_runnable);
                if (_nodeController != null)
                {
                    this.Info($"Calling NodeControllerFactory.RaiseNodeShutdownRequested()...");
                    _nodeController.RaiseNodeShutdownRequested();
                    _helper.UpdateNotification("Stopping Node.");
                }
                else
                {
                    this.Info($"NodeControllerFactory was null (already stopped)...");
                    _helper.UpdateNotification("Node was already stopped.");
                }
                this.Info(_tag, $"Calling StopForeground(true), StopSelf()...");
                _tryRestart = false;
                StopForeground(true);
                StopSelf();
                break;
            }

            return(StartCommandResult.Sticky);
        }
Exemple #3
0
        void Update()
        {
            // TODO: move the linebuffer into the service,
            // so that we can use the default activity mode. A new instance can then also Bind to the current generation of the service. Then, the reference to the bound service will not become invalid.
            try
            {
                this.Info("Fetching log...");
                NodeController controller = _nodeServiceConnection.NodeControllerFactory.Value;
                if (controller != null)
                {
                    var log = controller.GetLog();
                    if (!string.IsNullOrEmpty(log))
                    {
                        var oldText  = _logView.Text;
                        var oldLines = CountLines(oldText);
                        if (oldLines > 200)
                        {
                            var shorter = DeleteLines(oldText, 100);
                            var newText = shorter + log;
                            _logView.Text = newText;
                            this.Info("Truncated log...");
                        }
                        else
                        {
                            _logView.Text = oldText + log;
                        }

                        _scrollView.FullScroll(FocusSearchDirection.Down);
                    }
                }
            }
            catch (Exception e)
            {
                this.Info($"Error in Update(): {e.Message}");
            }
            finally
            {
                _nodeServiceConnection = null;
                //GC.Collect(0);
            }
        }