Example #1
0
        // in main method: ReflectionTest2.TestStart(new string[] {"/help", "/out"});
        public static void TestStart(string[] args)
        {
            foreach (var i in args)
            {
                Console.Write(i + ";");
            }
            Console.WriteLine();

            string errorMessage;

            CommandLineInfo commandLine = new CommandLineInfo();

            if (!CommandLineInfoHandler.TryParse(args, commandLine, out errorMessage))
            {
                Console.WriteLine(errorMessage);
                DisplayHelp();
            }

            if (commandLine.Help)
            {
                DisplayHelp();
            }
            else
            {
                if (commandLine.Priority != ProcessPriorityClass.Normal)
                {
                    Console.WriteLine(@"this is commandLine.Priority: {commandLine.Priority}");
                }
            }
        }
        public static void Main(string[] args)
        {
            string errorMessage;
            CommandLineInfo commandLine = new CommandLineInfo();
            if(!CommandLineHandler.TryParse(
                args, commandLine, out errorMessage))
            {
                Console.WriteLine(errorMessage);
                DisplayHelp();
            }

            if(commandLine.Help)
            {
                DisplayHelp();
            }
            else
            {
                if(commandLine.Priority !=
                    ProcessPriorityClass.Normal)
                {
                    // Change thread priority
                }

            }
            // ...
        }
        public static void ChapterMain(string[] args)
        {
            string          errorMessage;
            CommandLineInfo commandLine = new CommandLineInfo();

            if (!CommandLineHandler.TryParse(
                    args, commandLine, out errorMessage))
            {
                Console.WriteLine(errorMessage);
                DisplayHelp();
            }

            if (commandLine.Help)
            {
                DisplayHelp();
            }
            else
            {
                if (commandLine.Priority !=
                    ProcessPriorityClass.Normal)
                {
                    // Change thread priority
                }
            }
            // ...
        }
        public void TestParseCommandLine12()
        {
            var cli = CommandLineInfo.ParseCommandLine(new[] { "-cw:ssid", "hello", "-cw:pwd", "world" });

            Assert.IsNotNull(cli);

            Assert.IsTrue(cli.Action == CommandLineAction.ConnectWifi && cli.WifiSSID == "hello" && cli.WifiPassword == "world");
        }
        public void TestParseCommandLine13()
        {
            var cli = CommandLineInfo.ParseCommandLine(new[] { "-cw:ssid", "hello", "-cw:pwd", "" });

            Assert.IsNotNull(cli);

            Assert.IsTrue(cli.Action == CommandLineAction.ConnectWifi && cli.WifiSSID == "hello" &&
                          string.IsNullOrWhiteSpace(cli.WifiPassword));
        }
Example #6
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine(Usage);
                return;
            }

            var commandLineInfo = new CommandLineInfo(args);

            if (!commandLineInfo.Initialize())
            {
                return;
            }

            var streamWriter = new StreamWriter(commandLineInfo.Output);
            var jsonWriter   = new JsonTextWriter(streamWriter);

            Stopwatch watch = new Stopwatch();

            watch.Start();

            foreach (var file in commandLineInfo.Inputs)
            {
                Console.WriteLine("Input: " + file);
            }

            Console.WriteLine("Output: " + commandLineInfo.Output);

            bool success = ConvertToJson(jsonWriter, commandLineInfo.Inputs, Console.WriteLine);

            jsonWriter.Close();
            streamWriter.Close();

            if (!success)
            {
                Console.WriteLine("Error encountered.");
            }
            else
            {
                Console.WriteLine("Finished processing in " + watch.ElapsedMilliseconds + " milliseconds");
            }
        }
        static void FSCall(CommandLineInfo commandLine)
        {
            Console.WriteLine($"Running [{commandLine.FileName} {commandLine.Arguments}]");

            try
            {
                var psi = new ProcessStartInfo()
                {
                    FileName  = commandLine.FileName,
                    Arguments = commandLine.Arguments,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                };

                var process = new Process()
                {
                    StartInfo = psi
                };

                process.Start();

                string result = process.StandardOutput.ReadToEnd();
                string errors = process.StandardError.ReadToEnd();

                process.WaitForExit();

                Console.WriteLine($"Completed with {process.ExitCode}");
                Console.WriteLine($"Stdout: {result}");
                Console.WriteLine($"Stderror {errors}");

                if (process.ExitCode != 0)
                {
                    throw new Exception(errors);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Exception running {commandLine.FileName} {commandLine.Arguments}", ex);
            }
        }
    private void Start()
    {
        GameManager.instance.PlayerData.netID = (uint)Random.Range(0, 1000);
        ipAddress.text = "35.246.2.9";

#if UNITY_SERVER
        ipAddress.text = "127.0.0.1";
#endif
        portNumber.text = "15937";


        for (int i = 0; i < ToggledButtons.Length; ++i)
        {
            Button btn = ToggledButtons[i].GetComponent <Button>();
            if (btn != null)
            {
                _uiButtons.Add(btn);
            }
        }

        if (!useTCP)
        {
            // Do any firewall opening requests on the operating system
            NetWorker.PingForFirewall(ushort.Parse(portNumber.text));
        }

        if (useMainThreadManagerForRPCs)
        {
            Rpc.MainThreadRunner = MainThreadManager.Instance;
        }

#if UNITY_SERVER
        _targetScene = CommandLineInfo.GetTargetScene();
        Debug.Log($"Target Scene Index: {_targetScene}");

        Host();
#endif
    }
        public static void Main(string[] args)
        {
            CommandLineInfo commandLine = new CommandLineInfo();

            if (!CommandLineHandler.TryParse(
                    args, commandLine, out string?errorMessage))
            {
                Console.WriteLine(errorMessage);
                DisplayHelp();
            }
            else if (commandLine.Help || string.IsNullOrWhiteSpace(commandLine.Out))
            {
                DisplayHelp();
            }
            else
            {
                if (commandLine.Priority !=
                    ProcessPriorityClass.Normal)
                {
                    // Change thread priority
                }
                Console.WriteLine(
                    @$ "Running {
                        Path.GetFileName(Environment.GetCommandLineArgs()[0])} /Out:{
Example #10
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine(Usage);
                return;
            }

            var commandLineInfo = new CommandLineInfo(args);
            if (!commandLineInfo.Initialize())
            {
                return;
            }

            var streamWriter = new StreamWriter(commandLineInfo.Output);
            var jsonWriter = new JsonTextWriter(streamWriter);

            Stopwatch watch = new Stopwatch();
            watch.Start();

            foreach (var file in commandLineInfo.Inputs)
            {
                Console.WriteLine("Input: " + file);
            }

            Console.WriteLine("Output: " + commandLineInfo.Output);

            bool success = ConvertToJson(jsonWriter, commandLineInfo.Inputs, Console.WriteLine);

            jsonWriter.Close();
            streamWriter.Close();

            if (!success)
            {
                Console.WriteLine("Error encountered.");
            }
            else
            {
                Console.WriteLine("Finished processing in " + watch.ElapsedMilliseconds + " milliseconds");
            }
        }
Example #11
0
        public void TestParseCommandLine11()
        {
            var cli = CommandLineInfo.ParseCommandLine(new[] { "-cw:ssid", "hello" });

            Assert.IsNull(cli); // needs a '-cw:pwd' and password, too
        }
Example #12
0
        public void TestParseCommandLine10()
        {
            var cli = CommandLineInfo.ParseCommandLine(new[] { "-dw:ssid", "dummy" });

            Assert.IsTrue(cli.Action == CommandLineAction.DisconnectWifi && cli.WifiSSID == "dummy");
        }
Example #13
0
        public void TestParseCommandLine2()
        {
            var cli = CommandLineInfo.ParseCommandLine(new[] { "-ea" });

            Assert.IsTrue(cli.Action == CommandLineAction.EnableAllAdapters);
        }
Example #14
0
        static unsafe void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine(Usage);
                return;
            }

            var commandLineInfo = new CommandLineInfo(args);
            if (!commandLineInfo.Initialize())
            {
                return;
            }

            var fileName = commandLineInfo.Output;

            if (File.Exists(fileName))
            {
                Console.WriteLine(fileName + " already exists, please delete the file and try again, or change the output filename");
                return;
            }

            sqlite3* db;
            int error;
            if ((error = NativeMethods.sqlite3_open16(fileName, out db)) != 0)
            {
                Console.WriteLine("sqlite3_open16 failed with error code: " + error);
            }

            var sqlWriter = new EtwSQLiteWriter(db);
            var deserializer = new Deserializer<EtwSQLiteWriter>(sqlWriter);

            Stopwatch watch = new Stopwatch();
            watch.Start();

            var inputs = commandLineInfo.Inputs;

            int count = inputs.Count;

            var fileSessions = new EVENT_TRACE_LOGFILEW[inputs.Count];
            var handles = new ulong[count];

            DateTime minStartTime = DateTime.MaxValue;
            DateTime maxEndTime = DateTime.MinValue;

            for (int i = 0; i < count; ++i)
            {
                fileSessions[i] = new EVENT_TRACE_LOGFILEW
                {
                    LogFileName = inputs[i],
                    EventRecordCallback = deserializer.Deserialize,
                    BufferCallback = deserializer.BufferCallback,
                    LogFileMode = Etw.PROCESS_TRACE_MODE_EVENT_RECORD | Etw.PROCESS_TRACE_MODE_RAW_TIMESTAMP
                };

                handles[i] = Etw.OpenTrace(ref fileSessions[i]);
                minStartTime = MinDate(minStartTime, DateTime.FromFileTime(fileSessions[i].LogfileHeader.StartTime));
                maxEndTime = MaxDate(maxEndTime, DateTime.FromFileTime(fileSessions[i].LogfileHeader.StartTime));
            }

            sqlite3_stmt* createTableStmt;
            char* tail;

            var columnNames = @"(LogFileName TEXT, LoggerName TEXT, StartTime TEXT, EndTime TEXT, BootTime Text, EventsLost INTEGER, CpuSpeedInMHz DOUBLE, PerfFreq DOUBLE, NumberOfProcessors INTEGER, PointerSize INTEGER, BufferSize INTEGER, BuffersRead INTEGER, BuffersLost INTEGER, BuffersWritten INTEGER, LogFileMode INTEGER, MaximumFileSize INTEGER, ReservedFlags INTEGER, INTEGER TimerResolution, INTEGER CurrentTime, INTEGER Filled, INTEGER IsKernelTrace)";

            var createSql = @"CREATE TABLE EventInfo " + columnNames;
            NativeMethods.sqlite3_prepare(db, createSql, createSql.Length, out createTableStmt, out tail);

            NativeMethods.sqlite3_step(createTableStmt);
            NativeMethods.sqlite3_finalize(createTableStmt);

            sqlite3_stmt* eventStmt;

            string eventInfoTableSql =
                @"INSERT INTO EventInfo " + columnNames + " VALUES (" +
                "@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21) ";
            NativeMethods.sqlite3_prepare(db, eventInfoTableSql, eventInfoTableSql.Length, out eventStmt, out tail);

            NativeMethods.sqlite3_step(eventStmt);
            NativeMethods.sqlite3_finalize(eventStmt);

            for (int i = 0; i < handles.Length; ++i)
            {
                unchecked
                {
                    if (handles[i] == (ulong)(~0))
                    {
                        switch (Marshal.GetLastWin32Error())
                        {
                        case 0x57:
                            Console.WriteLine("Error: For file: " + inputs[i] + " Windows returned 0x57 -- The Logfile parameter is NULL.");
                            return;
                        case 0xA1:
                            Console.WriteLine("Error: For file: " + inputs[i] + " Windows returned 0xA1 -- The specified path is invalid.");
                            return;
                        case 0x5:
                            Console.WriteLine("Error: For file: " + inputs[i] + " Windows returned 0x5 -- Access is denied.");
                            return;
                        default:
                            Console.WriteLine("Error: For file: " + inputs[i] + " Windows returned an unknown error.");
                            return;
                        }
                    }
                }

                var currentSession = fileSessions[i];

                var logFileName = currentSession.LogFileName ?? string.Empty;
                NativeMethods.sqlite3_bind_text(eventStmt, 1, logFileName, logFileName.Length, NativeMethods.Transient);

                var loggerName = currentSession.LoggerName ?? string.Empty;
                NativeMethods.sqlite3_bind_text(eventStmt, 2, loggerName, loggerName.Length, NativeMethods.Transient);

                var startDateStr = DateTime.FromFileTime(currentSession.LogfileHeader.StartTime).ToString(@"yyyy\-MM\-dd HH\:mm\:ss.FFFFFFF");
                NativeMethods.sqlite3_bind_text(eventStmt, 3, startDateStr, startDateStr.Length, NativeMethods.Transient);

                var endDateStr = DateTime.FromFileTime(currentSession.LogfileHeader.EndTime).ToString(@"yyyy\-MM\-dd HH\:mm\:ss.FFFFFFF");
                NativeMethods.sqlite3_bind_text(eventStmt, 4, endDateStr, endDateStr.Length, NativeMethods.Transient);

                var bootDateStr = DateTime.FromFileTime(currentSession.LogfileHeader.BootTime).ToString(@"yyyy\-MM\-dd HH\:mm\:ss.FFFFFFF");
                NativeMethods.sqlite3_bind_text(eventStmt, 5, bootDateStr, bootDateStr.Length, NativeMethods.Transient);

                NativeMethods.sqlite3_bind_int64(eventStmt, 6, currentSession.LogfileHeader.EventsLost);

                NativeMethods.sqlite3_bind_int64(eventStmt, 7, currentSession.LogfileHeader.CpuSpeedInMHz);
                NativeMethods.sqlite3_bind_int64(eventStmt, 8, currentSession.LogfileHeader.PerfFreq);
                NativeMethods.sqlite3_bind_int64(eventStmt, 9, currentSession.LogfileHeader.NumberOfProcessors);

                NativeMethods.sqlite3_bind_int64(eventStmt, 10, currentSession.LogfileHeader.PointerSize);

                NativeMethods.sqlite3_bind_int64(eventStmt, 11, currentSession.BufferSize);
                NativeMethods.sqlite3_bind_int64(eventStmt, 12, currentSession.BuffersRead);
                NativeMethods.sqlite3_bind_int64(eventStmt, 13, currentSession.LogfileHeader.BuffersLost);
                NativeMethods.sqlite3_bind_int64(eventStmt, 14, currentSession.LogfileHeader.BuffersWritten);

                NativeMethods.sqlite3_bind_int64(eventStmt, 15, currentSession.LogfileHeader.LogFileMode);
                NativeMethods.sqlite3_bind_int64(eventStmt, 16, currentSession.LogfileHeader.MaximumFileSize);

                NativeMethods.sqlite3_bind_int64(eventStmt, 17, currentSession.LogfileHeader.ReservedFlags);
                NativeMethods.sqlite3_bind_int64(eventStmt, 18, currentSession.LogfileHeader.TimerResolution);

                NativeMethods.sqlite3_bind_int64(eventStmt, 19, currentSession.CurrentTime);
                NativeMethods.sqlite3_bind_int64(eventStmt, 20, currentSession.Filled);
                NativeMethods.sqlite3_bind_int64(eventStmt, 21, currentSession.IsKernelTrace);

                NativeMethods.sqlite3_step(eventStmt);
                NativeMethods.sqlite3_reset(eventStmt);
            }

            NativeMethods.sqlite3_finalize(eventStmt);

            NativeMethods.sqlite3_exec(db, "BEGIN TRANSACTION;", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            Etw.ProcessTrace(handles, (uint)handles.Length, IntPtr.Zero, IntPtr.Zero);
            sqlWriter.Dispose();

            NativeMethods.sqlite3_exec(db, "END TRANSACTION;", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            NativeMethods.sqlite3_close(db);

            watch.Stop();

            Console.WriteLine("Processing Time: " + watch.ElapsedMilliseconds + " milliseconds");

            GC.KeepAlive(fileSessions);
        }