Ejemplo n.º 1
0
        public Config(bool daemon = false)
        {
            Daemon    = daemon;
            Root      = ExecutableTools.Relative(@"Root");
            WebRoot   = PathTools.Combine(Root, "Web");
            WebIP     = "127.0.0.1";
            WebPort   = 12334;
            ShellRoot = PathTools.Combine(Root, "Test_{0}", TimeTools.Compact(DateTime.Now));
            ShellIP   = "127.0.0.1";
            ShellPort = 12333;

            Directory.CreateDirectory(WebRoot);
            Directory.CreateDirectory(ShellRoot);

            var writers = new WriteLineCollection();

            writers.Add(new StdoutWriteLine());
            var logfile = PathTools.Combine(Root, "log.txt");

            log = new StreamWriter(logfile, true);
            writers.Add(new TextWriterWriteLine(log));
            Timed        = new TimedWriter(writers);
            Logger.TRACE = Timed;
            writers.WriteLine(string.Empty); //separating line
            writers.WriteLine("");
            Logger.Trace("-----------------------------------------------------------------------------");
            Logger.Trace("Test case {0} starting...", TestContext.CurrentContext.Test.FullName);
            //System.InvalidOperationException : This property has already been set and cannot be modified.
            //Thread.CurrentThread.Name = "NUnit";
        }
Ejemplo n.º 2
0
        public Simple()
        {
            var writers = new WriteLineCollection();

            writers.Add(new StdoutWriteLine());
            var logfile = ExecutableTools.Relative("log.txt");

            log = new StreamWriter(logfile, true);
            writers.Add(new TextWriterWriteLine(log));
            Logger.TRACE = new TimedWriter(writers);
            writers.WriteLine(string.Empty); //separating line
            writers.WriteLine("");
            Logger.Trace("-----------------------------------------------------------------------------");
            Logger.Trace("Test case {0} starting...", TestContext.CurrentContext.Test.FullName);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            ProgramTools.Setup();

            var config = new Config();

            config.IP      = "0.0.0.0";
            config.Port    = 22333;
            config.Delay   = 5000;
            config.Timeout = 5000;
            config.Root    = ExecutableTools.Relative("Root");

            //args will always log to stderr because daemon flag not loaded yet
            ExecutableTools.LogArgs(new StderrWriteLine(), args, (arg) =>
            {
                ConfigTools.SetProperty(config, arg);
            });

            AssertTools.NotEmpty(config.Root, "Missing Root path");
            AssertTools.NotEmpty(config.IP, "Missing IP");
            AssertTools.Ip(config.IP, "Invalid IP");

            var pid     = Process.GetCurrentProcess().Id;
            var writers = new WriteLineCollection();

            if (!config.Daemon)
            {
                writers.Add(new StderrWriteLine());
                Logger.TRACE = new TimedWriter(writers);
            }

            Logger.Trace("Root {0}", config.Root);

            var dbpath    = Path.Combine(config.Root, "SharpDaemon.LiteDb");
            var logpath   = Path.Combine(config.Root, "SharpDaemon.Log.txt");
            var eppath    = Path.Combine(config.Root, "SharpDaemon.Endpoint.txt");
            var downloads = Path.Combine(config.Root, "Downloads");

            Directory.CreateDirectory(downloads); //creates root as well

            //acts like mutex for the workspace
            var log = new StreamWriter(logpath, true);

            writers.Add(new TextWriterWriteLine(log));

            ExecutableTools.LogArgs(new TextWriterWriteLine(log), args);

            var instance = new Instance(new Instance.Args
            {
                DbPath       = dbpath,
                RestartDelay = config.Delay,
                Downloads    = downloads,
                EndPoint     = new IPEndPoint(IPAddress.Parse(config.IP), config.Port),
            });

            Stdio.SetStatus("Listening on {0}", instance.EndPoint);

            using (var disposer = new Disposer())
            {
                //wrap to add to disposable count
                disposer.Push(new Disposable.Wrapper(log));
                disposer.Push(instance);
                disposer.Push(() => Disposing(config.Timeout));

                if (config.Daemon)
                {
                    Logger.Trace("Stdin loop...");
                    var line = Stdio.ReadLine();
                    while (line != null)
                    {
                        Logger.Trace("> {0}", line);
                        if ("exit!" == line)
                        {
                            break;
                        }
                        line = Stdio.ReadLine();
                    }
                    Logger.Trace("Stdin closed");
                }
                else
                {
                    Logger.Trace("Stdin loop...");
                    var shell  = instance.CreateShell();
                    var stream = new ShellStream(new StdoutWriteLine(), new ConsoleReadLine());
                    //disposer.Push(stream); //stdin.readline wont return even after close/dispose call
                    var line = stream.ReadLine();
                    while (line != null)
                    {
                        if ("exit!" == line)
                        {
                            break;
                        }
                        Shell.ParseAndExecute(shell, stream, line);
                        line = stream.ReadLine();
                    }
                    Logger.Trace("Stdin closed");
                }
            }

            Environment.Exit(0);
        }