Exemple #1
0
        static void Main(string[] args)
        {
            var bootstrapper = new Bootstrapper();
            bootstrapper.Bootstrap();

            var sluzba = bootstrapper.Get<IRegistr>();

            bool spustKonzoli = false;
            var argsParser = new Dictionary<string, Argument>(StringComparer.OrdinalIgnoreCase)
            {
                {"console", new Argument("console", val => spustKonzoli = true)}
            };

            foreach (string param in args)
            {
                var parts = Argument.Parse(param);
                if (argsParser.ContainsKey(parts[0]))
                    argsParser[parts[0]].SetValue(parts[1]);
            }

            var spoustec = new SpoustecSluzby(sluzba);
            if (spustKonzoli)
            {
                spoustec.Start();
                Log.ZapisRadek("Press <Enter> to stop the service.");
                Console.ReadLine();
                spoustec.Stop();
            }
            else
            {
                string logPath = string.Format("{0}\\{1}-log.txt",
                                               AppDomain.CurrentDomain.BaseDirectory,
                                               DateTime.Today.ToString("yyyy-MM-dd"));
                using (var logFile = File.Open(logPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    Log.NastavVystup(new StreamWriter(logFile));
                    var windows = new WindowsSluzba(spoustec);
                    ServiceBase.Run(windows);
                    logFile.Flush();
                }
            }
        }
Exemple #2
0
 public WindowsSluzba(SpoustecSluzby spoustec)
 {
     _spoustec = spoustec;
 }