Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var res1 = EnvironmentTools.AddPath(Compiler.cscEnv);

            Console.WriteLine(res1);
            string code = "using System; " +
                          "class App                            " +
                          "{                                    " +
                          "    static void Main(string[] args)  " +
                          "    {                                " +
                          "        Console.WriteLine(\"成功:02\");" +
                          "        Console.ReadKey();             " +
                          "    }                                  " +
                          "}                                      ";


            string fname = "code.cs";

            File.WriteAllText(fname, code);

            Windows.ExecuteCommand("csc -out:demo.exe code.cs");

            ProcessStartInfo p = new ProcessStartInfo();

            p.FileName = "demo.exe";
            Process.Start(p);
            Console.ReadKey();
        }
Exemplo n.º 2
0
    public string GetProfilerPath()
    {
        if (_profilerFileLocation != null)
        {
            return(_profilerFileLocation);
        }

        string extension = EnvironmentTools.GetOS() switch
        {
            "win" => "dll",
            "linux" => "so",
            "osx" => "dylib",
            _ => throw new PlatformNotSupportedException()
        };

        string fileName     = $"OpenTelemetry.AutoInstrumentation.Native.{extension}";
        string nukeOutput   = GetNukeBuildOutput();
        string profilerPath = EnvironmentTools.IsWindows()
            ? Path.Combine(nukeOutput, $"win-{EnvironmentTools.GetPlatform().ToLower()}", fileName)
            : Path.Combine(nukeOutput, fileName);

        if (File.Exists(profilerPath))
        {
            _profilerFileLocation = profilerPath;
            _output?.WriteLine($"Found profiler at {_profilerFileLocation}.");
            return(_profilerFileLocation);
        }

        throw new Exception($"Unable to find profiler at: {profilerPath}");
    }
        public async Task OutOfProcess()
        {
            EnsureWindowsAndX64();

            var buildPs1 = Path.Combine(EnvironmentTools.GetSolutionDirectory(), "tracer", "build.ps1");

            try
            {
                // GacFixture is not compatible with .NET Core, use the Nuke target instead
                Process.Start("powershell", $"{buildPs1} GacAdd --framework net461").WaitForExit();

                using var iisFixture = await StartIis(IisAppType.AspNetCoreOutOfProcess);

                using var console = ConsoleHelper.Redirect();

                var result = await CheckIisCommand.ExecuteAsync(
                    new CheckIisSettings { SiteName = "sample" },
                    iisFixture.IisExpress.ConfigFile,
                    iisFixture.IisExpress.Process.Id,
                    MockRegistryService());

                result.Should().Be(0);

                console.Output.Should().Contain(Resources.OutOfProcess);
                console.Output.Should().NotContain(Resources.AspNetCoreProcessNotFound);
                console.Output.Should().Contain(Resources.IisNoIssue);
            }
            finally
            {
                Process.Start("powershell", $"{buildPs1} GacRemove --framework net461").WaitForExit();
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            if (JobShouldRun(Versions, args))
            {
                Console.WriteLine("--------------- Versions Job Started ---------------");
                SetAllVersions.Run();
                Console.WriteLine("--------------- Versions Job Complete ---------------");
            }

            var solutionDir = EnvironmentTools.GetSolutionDirectory();

            if (JobShouldRun(Integrations, args))
            {
                Console.WriteLine("--------------- Integrations Job Started ---------------");
                GenerateIntegrationDefinitions.Run(solutionDir);
                Console.WriteLine("--------------- Integrations Job Complete ---------------");
            }

            if (JobShouldRun(Msi, args))
            {
                Environment.SetEnvironmentVariable("SOLUTION_DIR", solutionDir);
                var publishBatch = Path.Combine(solutionDir, "tools", "PrepareRelease", "publish-all.bat");
                ExecuteCommand(publishBatch);

                Console.WriteLine("--------------- MSI Job Started ---------------");
                SyncMsiContent.Run();
                Console.WriteLine("--------------- MSI Job Complete ---------------");
            }
        }
Exemplo n.º 5
0
    public string GetTestApplicationExecutionSource()
    {
        string executor;

        if (_testApplicationDirectory.Contains("aspnet"))
        {
            executor = $"C:\\Program Files{(Environment.Is64BitProcess ? string.Empty : " (x86)")}\\IIS Express\\iisexpress.exe";
        }
        else if (IsCoreClr())
        {
            executor = EnvironmentTools.IsWindows() ? "dotnet.exe" : "dotnet";
        }
        else
        {
            var appFileName = $"{FullTestApplicationName}.exe";
            executor = Path.Combine(GetTestApplicationApplicationOutputDirectory(), appFileName);

            if (!File.Exists(executor))
            {
                throw new Exception($"Unable to find executing assembly at {executor}");
            }
        }

        return(executor);
    }
Exemplo n.º 6
0
        /// <summary>
        /// Execute this process synchronously and return information about the media file
        /// </summary>
        /// <returns>A MediaInfo object with all of the media file's information</returns>
        /// <remarks>This method is synchronous and will only return once the process is finished</remarks>
        public MediaInfo Execute()
        {
            if (_alreadyExecuted)
            {
                throw new InvalidOperationException("Cannot execute process more than once");
            }

            _alreadyExecuted = true;
            _process.StartInfo.UseShellExecute        = false;
            _process.StartInfo.FileName               = EnvironmentTools.CalculateProcessName(MEDIAINFO_PROCESS);
            _process.StartInfo.Arguments              = string.Format("--output=XML \"{0}\"", _pathToVideoFile);
            _process.StartInfo.RedirectStandardInput  = true;
            _process.StartInfo.RedirectStandardOutput = true;
            _process.StartInfo.RedirectStandardError  = true;
            _process.StartInfo.ErrorDialog            = false;

            bool   processStarted  = _process.Start();
            string mediaInfoOutput = _process.StandardOutput.ReadToEnd();

            if (processStarted == false)
            {
                throw new InvalidOperationException("Could not start process");
            }

            _process.WaitForExit();
            if (_process.ExitCode != 0)
            {
                throw new InvalidOperationException("The MediaInfo process did not execute properly");
            }

            return(_serializer.Deserialize(mediaInfoOutput) as MediaInfo);
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                throw new ArgumentException($@"You must specify at least one job name from [""{Versions}"", ""{Integrations}, ""{Msi}""].");
            }

            var solutionDir = EnvironmentTools.GetSolutionDirectory();

            if (JobShouldRun(Integrations, args))
            {
                Console.WriteLine("--------------- Integrations Job Started ---------------");
                GenerateIntegrationDefinitions.Run(solutionDir);
                Console.WriteLine("--------------- Integrations Job Complete ---------------");
            }

            if (JobShouldRun(Versions, args))
            {
                Console.WriteLine("--------------- Versions Job Started ---------------");
                SetAllVersions.Run();
                Console.WriteLine("--------------- Versions Job Complete ---------------");
            }

            if (JobShouldRun(Msi, args))
            {
                Environment.SetEnvironmentVariable("SOLUTION_DIR", solutionDir);
                var publishBatch = Path.Combine(solutionDir, "tools", "PrepareRelease", "publish-all.bat");
                ExecuteCommand(publishBatch);

                Console.WriteLine("--------------- MSI Job Started ---------------");
                SyncMsiContent.Run();
                Console.WriteLine("--------------- MSI Job Complete ---------------");
            }
        }
Exemplo n.º 8
0
        public void CreatePlayer()
        {
            int x = 0;
            int z = 0;

            GetFreeCoordinates(out x, out z);
            Instantiate(EnvironmentTools.GetPlayer(), new Vector3(x, -0.5f, z), Quaternion.identity);
            Matrix[x, z] = 1;
        }
Exemplo n.º 9
0
 private void ShowExplosion(Vector3 direction, float explosionLength)
 {
     for (int i = 1; i <= explosionLength; i++)
     {
         var        position = new Vector3(transform.position.x + direction.x * i, transform.position.y, transform.position.z + direction.z * i);
         GameObject gameobj  = Instantiate(EnvironmentTools.GetExplosion(), position, Quaternion.identity);
         Destroy(gameobj, lifespan);
     }
 }
Exemplo n.º 10
0
 public void GenerateGround()
 {
     for (int x = 0; x < width; x++)
     {
         for (int z = 0; z < length; z++)
         {
             Instantiate(EnvironmentTools.GetGround(), new Vector3(x, -0.5f, z), Quaternion.identity);
         }
     }
 }
Exemplo n.º 11
0
        public void NoExceptions()
        {
            if (EnvironmentTools.IsWindows())
            {
                Output.WriteLine("Ignored for Windows");
                return;
            }

            CheckForSmoke(shouldDeserializeTraces: false);
        }
Exemplo n.º 12
0
    public string GetTestApplicationProjectDirectory()
    {
        var solutionDirectory = EnvironmentTools.GetSolutionDirectory();
        var projectDir        = Path.Combine(
            solutionDirectory,
            _testApplicationDirectory,
            $"{FullTestApplicationName}");

        return(projectDir);
    }
Exemplo n.º 13
0
 public void RandomGenerateBreakWalls()
 {
     for (int k = 0; k < breakWallNumber; k++)
     {
         int x;
         int z;
         GetFreeCoordinates(out x, out z);
         Instantiate(EnvironmentTools.GetBreakWall(), new Vector3(x, 0, z), Quaternion.identity);
         Matrix[x, z] = 2;
     }
 }
Exemplo n.º 14
0
        protected TestHelper(EnvironmentHelper environmentHelper, ITestOutputHelper output)
        {
            EnvironmentHelper = environmentHelper;
            Output            = output;

            Output.WriteLine($"Platform: {EnvironmentTools.GetPlatform()}");
            Output.WriteLine($"Configuration: {EnvironmentTools.GetBuildConfiguration()}");
            Output.WriteLine($"TargetFramework: {EnvironmentHelper.GetTargetFramework()}");
            Output.WriteLine($".NET Core: {EnvironmentHelper.IsCoreClr()}");
            Output.WriteLine($"Profiler DLL: {EnvironmentHelper.GetProfilerPath()}");
        }
Exemplo n.º 15
0
 public void CreateSmartEnemy(int number)
 {
     for (int k = 0; k < number; k++)
     {
         int x;
         int z;
         base.GetFreeCoordinates(out x, out z);
         Instantiate(EnvironmentTools.GetSmartEnemy(), new Vector3(x, -0.5f, z), Quaternion.identity);
         Matrix[x, z] = 1;
     }
 }
Exemplo n.º 16
0
        private static void CopyIntegrationsJson()
        {
            var sourceFile      = Path.Combine(EnvironmentTools.GetSolutionDirectory(), "integrations.json");
            var destinationPath = Path.Combine(_tracerHomeDirectory, "integrations.json");

            if (File.Exists(destinationPath))
            {
                File.Delete(destinationPath);
            }

            File.Copy(sourceFile, destinationPath);
        }
Exemplo n.º 17
0
        protected TestHelper(EnvironmentHelper environmentHelper, ITestOutputHelper output)
        {
            EnvironmentHelper = environmentHelper;
            SampleAppName     = EnvironmentHelper.SampleName;
            Output            = output;

            PathToSample = EnvironmentHelper.GetSampleApplicationOutputDirectory();
            Output.WriteLine($"Platform: {EnvironmentTools.GetPlatform()}");
            Output.WriteLine($"Configuration: {EnvironmentTools.GetBuildConfiguration()}");
            Output.WriteLine($"TargetFramework: {EnvironmentHelper.GetTargetFramework()}");
            Output.WriteLine($".NET Core: {EnvironmentHelper.IsCoreClr()}");
            Output.WriteLine($"Application: {GetSampleApplicationPath()}");
            Output.WriteLine($"Profiler DLL: {EnvironmentHelper.GetProfilerPath()}");
        }
Exemplo n.º 18
0
        public async Task TestSecurity()
        {
            var enableSecurity = true;

            // use the same rule file that's embbed but load it via an env var, to verify there's not bugs in that code path
            var externalRulesFile =
                Path.Combine(EnvironmentTools.GetSolutionDirectory(), "tracer/src/Datadog.Trace/AppSec/Waf/rule-set.json");

            var agent = await RunOnSelfHosted(enableSecurity, externalRulesFile);

            var settings = VerifyHelper.GetSpanVerifierSettings();

            await TestBlockedRequestWithVerifyAsync(agent, DefaultAttackUrl, 5, 1, settings);
        }
Exemplo n.º 19
0
 public void GenerateConcreteWalls()
 {
     for (int x = 0; x < width; x++)
     {
         for (int z = 0; z < length; z++)
         {
             if (IsBorder(x, z) || IsEvenCell(x, z))
             {
                 Instantiate(EnvironmentTools.GetConcreteWall(), new Vector3(x, 0, z), Quaternion.identity);
                 Matrix[x, z] = 1;
             }
         }
     }
 }
Exemplo n.º 20
0
 public void GenerateBreakWalls()
 {
     for (int x = 2; x < width - 2; x++)
     {
         for (int z = 2; z < length - 2; z++)
         {
             if (!IsBorder(x, z) && IsOddCell(x, z))
             {
                 Instantiate(EnvironmentTools.GetBreakWall(), new Vector3(x, 0, z), Quaternion.identity);
                 Matrix[x, z] = 2;
             }
         }
     }
 }
Exemplo n.º 21
0
    public static string GetNukeBuildOutput()
    {
        string nukeOutputPath = Path.Combine(
            EnvironmentTools.GetSolutionDirectory(),
            "bin",
            "tracer-home");

        if (Directory.Exists(nukeOutputPath))
        {
            _nukeOutputLocation = nukeOutputPath;

            return(_nukeOutputLocation);
        }

        throw new Exception($"Unable to find Nuke output at: {nukeOutputPath}. Ensure Nuke has run first.");
    }
        private static string GetRunnerToolTargetFolder()
        {
            var folder = Environment.GetEnvironmentVariable("ToolInstallDirectory");

            if (string.IsNullOrEmpty(folder))
            {
                folder = Path.Combine(
                    EnvironmentTools.GetSolutionDirectory(),
                    "tracer",
                    "bin",
                    "runnerTool",
                    "installed");
            }

            return(folder);
        }
Exemplo n.º 23
0
        private static void SynchronizeVersion(string path, Func <string, string> transform)
        {
            var solutionDirectory = EnvironmentTools.GetSolutionDirectory();
            var fullPath          = Path.Combine(solutionDirectory, path);

            Console.WriteLine($"Updating version instances for {path}");

            if (!File.Exists(fullPath))
            {
                throw new Exception($"File not found to version: {path}");
            }

            var fileContent    = File.ReadAllText(fullPath);
            var newFileContent = transform(fileContent);

            File.WriteAllText(fullPath, newFileContent, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
        }
Exemplo n.º 24
0
 private void PutBomb()
 {
     GameObject[] go = GameObject.FindGameObjectsWithTag("Bomb");
     if (go.Length <= bombLimit)
     {
         Vector3 bombposition = new Vector3(Mathf.RoundToInt(transform.position.x), 0, Mathf.RoundToInt(transform.position.z));
         if (wallPass == true)
         {
             Collider[] hitColliders = Physics.OverlapSphere(bombposition, 0.1f);
             if (hitColliders.Length > 1)
             {
                 return;
             }
         }
         Instantiate(EnvironmentTools.GetBomb(), bombposition, Quaternion.identity);
     }
 }
Exemplo n.º 25
0
    private async Task <TestcontainersContainer> LaunchMongoContainerAsync(int port)
    {
        var waitOS = EnvironmentTools.IsWindows()
            ? Wait.ForWindowsContainer()
            : Wait.ForUnixContainer();

        var mongoContainersBuilder = new TestcontainersBuilder <TestcontainersContainer>()
                                     .WithImage(MongoDbImage)
                                     .WithName($"mongo-db-{port}")
                                     .WithPortBinding(port, MongoDbPort)
                                     .WithWaitStrategy(waitOS.UntilPortIsAvailable(MongoDbPort));

        var container = mongoContainersBuilder.Build();
        await container.StartAsync();

        return(container);
    }
Exemplo n.º 26
0
        public static void Save(string benchmarkName, DateTime date)
        {
            var solutionDirectory = EnvironmentTools.GetSolutionDirectory();

            var fileFriendlyDate   = date.ToString("yyyy-dd-mm_HH-mm-ss");
            var benchmarkDirectory = Path.Combine(solutionDirectory, "performance", "benchmarks");

            if (!Directory.Exists(benchmarkDirectory))
            {
                Directory.CreateDirectory(benchmarkDirectory);
            }

            var resultsPath = Path.Combine(benchmarkDirectory, benchmarkName);

            if (!Directory.Exists(resultsPath))
            {
                Directory.CreateDirectory(resultsPath);
            }

            var persistedDirectoryName = $"{benchmarkName}_{fileFriendlyDate}_{EnvironmentTools.GetTracerVersion()}_{EnvironmentTools.GetBuildConfiguration()}";

            if (EnvironmentTools.IsConfiguredToProfile(typeof(Program)))
            {
                persistedDirectoryName += "_Profiled";
            }
            else
            {
                persistedDirectoryName += "_NonProfiled";
            }

            var currentDirectory = Environment.CurrentDirectory;

            var resultDirectory = Path.Combine(currentDirectory, _benchmarkResultFolder);

            if (!Directory.Exists(resultDirectory))
            {
                throw new Exception("Can't find the benchmarks to save");
            }

            var ultimateDirectory = Path.Combine(resultsPath, persistedDirectoryName);

            Directory.Move(resultDirectory, ultimateDirectory);
        }
Exemplo n.º 27
0
        private void GetRandomPowerUp(int number, int x, int z)
        {
            switch (number)
            {
            case 0:
                Instantiate(EnvironmentTools.GetBombUp(), new Vector3(x, 0, z), Quaternion.identity);
                break;

            case 1:
                Instantiate(EnvironmentTools.GetFlameUp(), new Vector3(x, 0, z), Quaternion.identity);
                break;

            case 2:
                Instantiate(EnvironmentTools.GetSpeedUp(), new Vector3(x, 0, z), Quaternion.identity);
                break;

            case 3:
                Instantiate(EnvironmentTools.GetWallPass(), new Vector3(x, 0, z), Quaternion.identity);
                break;
            }
        }
Exemplo n.º 28
0
        public async Task Http_Headers_Contain_ContainerId()
        {
            string expectedContainedId = ContainerMetadata.GetContainerId();
            string actualContainerId   = null;
            var    agentPort           = TcpPortProvider.GetOpenPort();

            using (var agent = new MockTracerAgent(agentPort))
            {
                agent.RequestReceived += (sender, args) =>
                {
                    actualContainerId = args.Value.Request.Headers[AgentHttpHeaderNames.ContainerId];
                };

                var settings = new TracerSettings
                {
                    Exporter = new ExporterSettings()
                    {
                        AgentUri = new Uri($"http://localhost:{agent.Port}"),
                    }
                };
                var tracer = new Tracer(settings, agentWriter: null, sampler: null, scopeManager: null, statsd: null);

                using (var scope = tracer.StartActive("operationName"))
                {
                    scope.Span.ResourceName = "resourceName";
                }

                await tracer.FlushAsync();

                var spans = agent.WaitForSpans(1);
                Assert.Equal(1, spans.Count);
                Assert.Equal(expectedContainedId, actualContainerId);

                if (EnvironmentTools.IsWindows())
                {
                    // we don't extract the containerId on Windows (yet?)
                    Assert.Null(actualContainerId);
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// 尝试编译
        /// </summary>
        /// <param name="outName"></param>
        /// <param name="key"></param>
        /// <param name="csFile"></param>
        public static void TryComplire(string outName, string key = crcKey, string csFile = csFileName)
        {
            var    data   = File.ReadAllBytes(csFile);//加密了的数据
            string csname = "code.depub.decode";

            using (var rc4 = new RC4(Encoding.UTF8.GetBytes(key)))
            {
                string cedetail = rc4.Decrypt(data);
                File.WriteAllText(csname, cedetail);

                if (EnvironmentTools.AddPath(cscEnv) == false)
                {
                    throw new Exception("系统不知错,错误 -05");
                }

                string batcmd = string.Format(@"csc -out:{0} {1} -win32icon:icon.ico -resource:{2} -resource:{3} -resource:{4} -resource:{5}"
                                              , outName, csname, "DCARE.exe", "HinxCor.CompressionDot45.dll", "ICSharpCode.SharpZipLib.dll", "data.mhx");
                Windows.ExecuteCommand(batcmd);
                File.Delete(csname);
                File.Delete("data.mhx");
            }
        }
Exemplo n.º 30
0
    public string GetTestApplicationApplicationOutputDirectory(string packageVersion = "", string framework = "")
    {
        var targetFramework = string.IsNullOrEmpty(framework) ? GetTargetFramework() : framework;
        var binDir          = Path.Combine(
            GetTestApplicationProjectDirectory(),
            "bin");

        if (_testApplicationDirectory.Contains("aspnet"))
        {
            return(Path.Combine(
                       binDir,
                       EnvironmentTools.GetBuildConfiguration(),
                       "app.publish"));
        }

        return(Path.Combine(
                   binDir,
                   packageVersion,
                   EnvironmentTools.GetPlatform().ToLowerInvariant(),
                   EnvironmentTools.GetBuildConfiguration(),
                   targetFramework));
    }