private void SetLeases()
        {
            _clientSponsor?.Close();
            _clientSponsor = new ClientSponsor(TimeSpan.MaxValue);
            _clientSponsor.Register((MarshalByRefObject)_missionPlannerInterfaces.CurrentState);
            //_clientSponsor.Register((MarshalByRefObject) _missionPlannerInterfaces.FlightComms);
            _clientSponsor.Register((MarshalByRefObject)_missionPlannerInterfaces.MissionPlanner);

            var lease = (ILease)_clientSponsor.InitializeLifetimeService();

            _clientSponsor.Renewal(lease);
        }
예제 #2
0
        /// <summary>
        /// Indicates to the EngineProxy that it is no longer needed.
        /// Called by TaskEngine when the task using the EngineProxy is done.
        /// </summary>
        internal void MarkAsInActive()
        {
            activeProxy = false;

            // Since the task has a pointer to this class it may store it in a static field. Null out
            // internal data so the leak of this object doesn't lead to a major memory leak.
            loggingServices   = null;
            parentModule      = null;
            buildEventContext = null;

            // Clear out the sponsor (who is responsible for keeping the EngineProxy remoting lease alive until the task is done)
            // this will be null if the engineproxy was never sent accross an appdomain boundry.
            if (sponsor != null)
            {
                ILease lease = (ILease)RemotingServices.GetLifetimeService(this);

                if (lease != null)
                {
                    lease.Unregister(sponsor);
                }

                sponsor.Close();
                sponsor = null;
            }
        }
예제 #3
0
        /// <summary>
        /// Indicates to the TaskHost that it is no longer needed.
        /// Called by TaskBuilder when the task using the EngineProxy is done.
        /// </summary>
        internal void MarkAsInactive()
        {
            lock (_callbackMonitor)
            {
                VerifyActiveProxy();
                _activeProxy = false;

                // Since the task has a pointer to this class it may store it in a static field. Null out
                // internal data so the leak of this object doesn't lead to a major memory leak.
                _host         = null;
                _requestEntry = null;

                // Don't bother clearing the tiny task location
                _taskLoggingContext    = null;
                _targetBuilderCallback = null;

                // Clear out the sponsor (who is responsible for keeping the EngineProxy remoting lease alive until the task is done)
                // this will be null if the engine proxy was never sent across an AppDomain boundary.
                if (_sponsor != null)
                {
                    ILease lease = (ILease)RemotingServices.GetLifetimeService(this);

                    if (lease != null)
                    {
                        lease.Unregister(_sponsor);
                    }

                    _sponsor.Close();
                    _sponsor = null;
                }
            }
        }
예제 #4
0
        static void Main()
        {
            // Register a channel.
            TcpChannel myChannel = new TcpChannel();

            ChannelServices.RegisterChannel(myChannel);
            RemotingConfiguration.RegisterActivatedClientType(
                typeof(HelloService), "tcp://localhost:8085/");

            // Get the remote object.
            HelloService myService = new HelloService();

            // Get a sponsor for renewal of time.
            ClientSponsor mySponsor = new ClientSponsor();

            // Register the service with sponsor.
            mySponsor.Register(myService);

            // Set renewaltime.
            mySponsor.RenewalTime = TimeSpan.FromMinutes(2);

            // Renew the lease.
            ILease   myLease = (ILease)mySponsor.InitializeLifetimeService();
            TimeSpan myTime  = mySponsor.Renewal(myLease);

            Console.WriteLine("Renewed time in minutes is " + myTime.Minutes.ToString());

            // Call the remote method.
            Console.WriteLine(myService.HelloMethod("World"));

            // Unregister the channel.
            mySponsor.Unregister(myService);
            mySponsor.Close();
        }
예제 #5
0
        public void BuildDocument()
        {
            var sponsor = new ClientSponsor();

            if (_listener != null)
            {
                Logger.LogLevelThreshold = _logLevel;
                Logger.RegisterListener(_listener);
                sponsor.Register(_listener);
            }
            try
            {
                try
                {
                    BuildDocument(_config, _manager, _baseDirectory, _outputDirectory, _pluginDirectory);
                }
                catch (Exception e) when(e is DocfxException || e is DocumentException)
                {
                    throw new DocfxException(e.Message);
                }
                catch (Exception e)
                {
                    throw new DocfxException(e.ToString());
                }
            }
            finally
            {
                sponsor.Close();
            }
        }
예제 #6
0
        public void BuildDocument()
        {
            var sponsor = new ClientSponsor();

            if (_listener != null)
            {
                Logger.LogLevelThreshold = _logLevel;
                Logger.RegisterListener(_listener);
                sponsor.Register(_listener);
            }
            try
            {
                try
                {
                    BuildDocument(_config, _manager, _baseDirectory, _outputDirectory, _pluginDirectory);
                }
                catch (Exception e)
                {
                    // For non-serializable exception, wrap it and throw docfx exception instead
                    throw new DocfxException(e.ToString());
                }
            }
            finally
            {
                sponsor.Close();
            }
        }
예제 #7
0
        public virtual void Dispose()
        {
            if (Sponsor != null) {
                if (Agent != null) {
                    //...
                    Sponsor.Unregister(Agent);
                }

                Sponsor.Close();
                Sponsor = null;
            }

            if (!isUnloaded) Unload(false).GetAwaiter().GetResult();
        }
예제 #8
0
        public static async Task Run(Action <RemoteTaskCompletionSource, ISponsor> action, CancellationToken token)
        {
            var sponsor = new ClientSponsor();

            try {
                var taskHandle = new RemoteTaskCompletionSource(token);
                sponsor.Register(taskHandle);

                action(taskHandle, sponsor);
                await taskHandle.Task;
            }
            finally {
                sponsor.Close();
            }
        }
예제 #9
0
        public void BuildDocument()
        {
            var sponsor = new ClientSponsor();

            EnvironmentContext.SetBaseDirectory(_baseDirectory);
            EnvironmentContext.SetGitFeaturesDisabled(_disableGitFeatures);
            EnvironmentContext.SetVersion(_version);
            if (_listener != null)
            {
                Logger.LogLevelThreshold = _logLevel;
                Logger.RegisterListener(_listener);
                sponsor.Register(_listener);
            }
            try
            {
                try
                {
                    BuildDocument(_config, _manager, _baseDirectory, _outputDirectory, _pluginDirectory, _templateDirectory);
                }
                catch (AggregateException agg) when(agg.InnerException is DocfxException)
                {
                    throw new DocfxException(agg.InnerException.Message);
                }
                catch (AggregateException agg) when(agg.InnerException is DocumentException)
                {
                    throw new DocumentException(agg.InnerException.Message);
                }
                catch (DocfxException e)
                {
                    throw new DocfxException(e.Message);
                }
                catch (DocumentException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    throw new DocfxException(e.ToString());
                }
            }
            finally
            {
                sponsor.Close();
            }
        }
예제 #10
0
        public void Stop()
        {
            lock (_lock)
            {
                if (serverManager != null)
                {
                    try
                    {
                        clientSponsor.Unregister(serverManager as MarshalByRefObject);
                        Logging.Log.Info("Closing client sponsor");
                        clientSponsor.Close();
                        Logging.Log.Info("Stopping server manager");
                        serverManager.Stop();
                        Logging.Log.Info("Unloading AssemblyLoader from server app domain");
                        AssemblyLoader.Unload(serverDomain);
                    }
                    catch (Exception ex)
                    {
                        Logging.Log.Warn("Error during shutdown", ex);
                        throw;
                    }
                }
                else
                {
                    Logging.Log.Error("Tried unloading an already unloaded server manager.");
                }

                clientSponsor = null;
                serverManager = null;

                if (serverDomain != null)
                {
                    Logging.Log.Info("Unloading server app domain");
                    AppDomain.Unload(serverDomain);
                }
                else
                {
                    Logging.Log.Warn("Server app domain already vanished.");
                }

                serverDomain = null;
            }
        }
예제 #11
0
        /// <summary>
        /// Indicates to the TaskHost that it is no longer needed.
        /// Called by TaskBuilder when the task using the EngineProxy is done.
        /// </summary>
        internal void MarkAsInactive()
        {
            VerifyActiveProxy();
            _activeProxy = false;

            _loggingContext  = null;
            _elementLocation = null;

            // Clear out the sponsor (who is responsible for keeping the EngineProxy remoting lease alive until the task is done)
            // this will be null if the engineproxy was never sent across an appdomain boundry.
            if (_sponsor != null)
            {
                ILease lease = (ILease)RemotingServices.GetLifetimeService(this);

                lease?.Unregister(_sponsor);

                _sponsor.Close();
                _sponsor = null;
            }
        }
예제 #12
0
 public virtual void Dispose()
 {
     Tasks?.Dispose();
     MessageClient?.Dispose();
     sponsor?.Close();
 }