<commit_before>﻿/*
 * Copyright 2015 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * 
 * Product  : Rapid SCADA
 * Module   : SCADA-Server Console Application for Mono .NET framework
 * Summary  : The main entry point for the application
 * 
 * Author   : <NAME>
 * Created  : 2015
 * Modified : 2015
 */

using Scada.Server.Svc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Scada.Server.Mono
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            // запуск службы
            Console.WriteLine("Starting SCADA-Server");
            Manager manager = new Manager();
            manager.StartService();

            Console.WriteLine("SCADA-Server is started");
            Console.WriteLine("Press 'x' to stop SCADA-Server");

            // остановка службы при нажатии 'x'
            while (Console.ReadKey(true).KeyChar != 'x') { }
            manager.StopService();
            Console.WriteLine("SCADA-Server is stopped");
        }
    }
}<commit_msg>Receive stop command from file<commit_after>﻿/*
 * Copyright 2015 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * 
 * Product  : Rapid SCADA
 * Module   : SCADA-Server Console Application for Mono .NET framework
 * Summary  : The main entry point for the application
 * 
 * Author   : <NAME>
 * Created  : 2015
 * Modified : 2015
 */

using Scada.Server.Svc;
using System;
using System.IO;
using System.Threading;

namespace Scada.Server.Mono
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    class Program
    {
        /// <summary>
        /// Задержка потока для экономии ресурсов, мс
        /// </summary>
        private const int ThreadDelay = 200;

        /// <summary>
        /// Механизм для получения команды остановки сервиса из файла
        /// </summary>
        private class StopListener
        {
            /// <summary>
            /// Имя файла остановки сервиса
            /// </summary>
            private string stopFileName;
            /// <summary>
            /// Обнаружен файл остановки сервиса
            /// </summary>
            public volatile bool StopFileFound;

            /// <summary>
            /// Конструктор
            /// </summary>
            public StopListener(string stopFileName)
            {
                StopFileFound = false;
                this.stopFileName = stopFileName;
                Thread thread = new Thread(new ThreadStart(WaitForStopFile));
                thread.Priority = ThreadPriority.BelowNormal;
                thread.Start();
            }

            /// <summary>
            /// Ожидать появления файла остановки сервиса
            /// </summary>
            private void WaitForStopFile()
            {
                while (!StopFileFound)
                {
                    if (File.Exists(stopFileName))
                        StopFileFound = true;
                    else
                        Thread.Sleep(ThreadDelay);
                }
            }

            /// <summary>
            /// Удалить файл остановки сервиса
            /// </summary>
            public void DeleteStopFile()
            {
                try
                {
                    File.Delete(stopFileName);
                }
                catch { }
            }
        }


        /// <summary>
        /// Основной цикл работы программы
        /// </summary>
        static void Main(string[] args)
        {
            // запуск службы
            Console.WriteLine("Starting SCADA-Server");
            Manager manager = new Manager();
            manager.StartService();

            Console.WriteLine("SCADA-Server is started");
            Console.WriteLine("Press 'x' or create 'serverstop' file to stop SCADA-Server");

            // остановка службы при нажатии 'x' или обнаружении файла остановки
            StopListener stopListener = 
                new StopListener(string.Format("..{0}Cmd{0}serverstop", Path.DirectorySeparatorChar));
            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.X || stopListener.StopFileFound))
                Thread.Sleep(ThreadDelay);
            manager.StopService();
            stopListener.DeleteStopFile();
            Console.WriteLine("SCADA-Server is stopped");
        }
    }
}
{'fraction_non_alphanumeric': 0.09681528662420383, 'fraction_numerical': 0.0067333939945404915, 'mean_word_length': 1.7827848101265822, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7573688', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1421, 'n_words': 444}