示例#1
0
 internal ShutdownEventArgs([NotNull] ShutdownParams shutdownParams)
 {
     if (shutdownParams == null)
     {
         throw new ArgumentNullException("shutdownParams");
     }
     ShutdownParams = shutdownParams;
 }
示例#2
0
        static void RaiseShutdownEndedEvent(ShutdownParams shutdownParams)
        {
            var h = ShutdownEnded;

            if (h != null)
            {
                h(null, new ShutdownEventArgs(shutdownParams));
            }
        }
        async Task <Unit> IRequestHandler <ShutdownParams, Unit> .Handle(ShutdownParams request, CancellationToken token)
        {
            await Task.Yield(); // Ensure shutdown handler runs asynchronously.

            _shutdownRequested = true;

            try
            {
                _shutdownSubject.OnNext(_shutdownRequested);
            }
            finally
            {
                _shutdownSubject.OnCompleted();
            }
            return(Unit.Value);
        }
示例#4
0
        /// <summary>
        /// Call this method to initiate DynamoModel shutdown sequence.
        /// See the definition of ShutdownParams structure for more details.
        /// </summary>
        /// <param name="shutdownParams">A set of parameters that control the 
        /// way in which shutdown sequence is to be performed. See ShutdownParams
        /// for more details.</param>
        /// <returns>Returns true if the shutdown sequence is started, or false 
        /// otherwise (i.e. when user chooses not to proceed with shutting down 
        /// Dynamo).</returns>
        /// 
        public bool PerformShutdownSequence(ShutdownParams shutdownParams)
        {
            if (shutdownSequenceInitiated)
            {
                // There was a prior call to shutdown. This could happen for example
                // when user presses 'ALT + F4' to close the DynamoView, the 'Exit' 
                // handler calls this method to close Dynamo, which in turn closes 
                // the DynamoView ('OnRequestClose' below). When DynamoView closes,
                // its "Window.Closing" event fires and "DynamoView.WindowClosing" 
                // gets called before 'PerformShutdownSequence' is called again.
                // 
                return true;
            }

            if (!AskUserToSaveWorkspacesOrCancel(shutdownParams.AllowCancellation))
                return false;

            // 'shutdownSequenceInitiated' is marked as true here indicating 
            // that the shutdown may not be stopped.
            shutdownSequenceInitiated = true;

            // Request the View layer to close its window (see 
            // ShutdownParams.CloseDynamoView member for details).
            if (shutdownParams.CloseDynamoView)
                OnRequestClose(this, EventArgs.Empty);

            BackgroundPreviewViewModel.Dispose();

            model.ShutDown(shutdownParams.ShutdownHost);
            if (shutdownParams.ShutdownHost)
            {
                model.UpdateManager.HostApplicationBeginQuit();
            }

            UsageReportingManager.DestroyInstance();

            return true;
        }
示例#5
0
        void engine_SpeechRecognized(object sender, System.Speech.Recognition.SpeechRecognizedEventArgs e)
        {
            System.Speech.Synthesis.SpeechSynthesizer         reader = new System.Speech.Synthesis.SpeechSynthesizer();
            System.Speech.Recognition.SpeechRecognitionEngine engine = new System.Speech.Recognition.SpeechRecognitionEngine();
            try
            {
                engine = new System.Speech.Recognition.SpeechRecognitionEngine();
                String message = "";
                String results = e.Result.Text;
                if (!listening)
                {
                    return;
                }
                switch (results)
                {
                case "help":
                    reader.Speak("The available commands are restart, shutdown, status report, and players.");
                    Logger.Log(LogType.ConsoleOutput, "The available commands are restart, shutdown, status report, and a players.");
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "restart":
                    reader.Speak("The server is now restarting.");
                    ShutdownParams param = new ShutdownParams(ShutdownReason.Restarting, TimeSpan.FromSeconds(5), true, true, "Restarting", Player.Console);
                    Server.Shutdown(param, true);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "shutdown":
                    reader.Speak("The server is now shutting down.");
                    Shutdown(ShutdownReason.ShuttingDown, true);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "status report":
                    reader.Speak("Server has been up for " + Math.Round(DateTime.UtcNow.Subtract(Server.StartTime).TotalHours, 1, MidpointRounding.AwayFromZero) + " hours.");
                    Player.Console.ParseMessage("/sinfo", true, false);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                case "players":
                    foreach (Player p in Server.Players)
                    {
                        message += p.Name;
                    }
                    reader.Speak(message);
                    Player.Console.ParseMessage("/players", true, false);
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;

                default:
                    bVoice.ForeColor = System.Drawing.Color.Black;
                    results          = "";
                    engine.RecognizeAsyncStop();
                    engine.Dispose();
                    listening = false;
                    break;
                }
            }
            catch (Exception)
            {
                //Audio Device is either missing or damaged, actual Exception is System.Speech.Internal.Synthesis.AudioException
                engine.RecognizeAsyncStop();
                engine.Dispose();
                return;
            }
        }
示例#6
0
        public virtual async Task <Unit> Handle(ShutdownParams request, CancellationToken cancellationToken)
        {
            await Handle(cancellationToken);

            return(Unit.Value);
        }
示例#7
0
 internal ShutdownEventArgs( ShutdownParams shutdownParams ) {
     ShutdownParams = shutdownParams;
 }
示例#8
0
 void engine_SpeechRecognized(object sender, System.Speech.Recognition.SpeechRecognizedEventArgs e)
 {
     System.Speech.Synthesis.SpeechSynthesizer reader = new System.Speech.Synthesis.SpeechSynthesizer();
     System.Speech.Recognition.SpeechRecognitionEngine engine = new System.Speech.Recognition.SpeechRecognitionEngine();
     try
     {
         engine = new System.Speech.Recognition.SpeechRecognitionEngine();
         String message = "";
         String results = e.Result.Text;
         if (!listening)
         {
             return;
         }
         switch (results)
         {
             case "help":
                 reader.Speak("The available commands are restart, shutdown, status report, and players.");
                 Logger.Log(LogType.ConsoleOutput, "The available commands are restart, shutdown, status report, and a players.");
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "restart":
                 reader.Speak("The server is now restarting.");
                 ShutdownParams param = new ShutdownParams(ShutdownReason.Restarting, TimeSpan.FromSeconds(5), true, true, "Restarting", Player.Console);
                 Server.Shutdown(param, true);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "shutdown":
                 reader.Speak("The server is now shutting down.");
                 Shutdown(ShutdownReason.ShuttingDown, true);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "status report":
                 reader.Speak("Server has been up for " + Math.Round(DateTime.UtcNow.Subtract(Server.StartTime).TotalHours, 1, MidpointRounding.AwayFromZero) + " hours.");
                 Player.Console.ParseMessage("/sinfo", true, false);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             case "players":
                 foreach (Player p in Server.Players)
                 {
                     message += p.Name;
                 }
                 reader.Speak(message);
                 Player.Console.ParseMessage("/players", true, false);
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
             default:
                 bVoice.ForeColor = System.Drawing.Color.Black;
                 results = "";
                 engine.RecognizeAsyncStop();
                 engine.Dispose();
                 listening = false;
                 break;
         }
     }
     catch(Exception)
     {
         //Audio Device is either missing or damaged, actual Exception is System.Speech.Internal.Synthesis.AudioException
         engine.RecognizeAsyncStop();
         engine.Dispose();
         return;
     }
 }
示例#9
0
 internal ShutdownEventArgs([NotNull] ShutdownParams shutdownParams)
 {
     ShutdownParams = shutdownParams ?? throw new ArgumentNullException("shutdownParams");
 }
示例#10
0
 internal ShutdownEventArgs(ShutdownParams shutdownParams)
 {
     ShutdownParams = shutdownParams;
 }