public void Defaults() { var muxer = new Muxer(); Assert.AreEqual(true, muxer.Initiator); Assert.AreEqual(false, muxer.Receiver); }
private static Command RunVbc(string[] vbcArgs) { //TODO: Need to utilize the .NET Core vbc.exe... // For now, we are using the .NET Framework vbc.exe instead of the .NET Core vbc.exe as we are not yet sure where that is located/available. var vbcEnvExe = Environment.GetEnvironmentVariable("DOTNET_VBC_PATH"); var exec = Environment.GetEnvironmentVariable("DOTNET_VBC_EXEC")?.ToUpper() ?? "COREHOST"; var muxer = new Muxer(); if (vbcEnvExe == null) { Reporter.Error.WriteLine("Env var DOTNET_VBC_PATH is required"); Reporter.Error.WriteLine("DOTNET_VBC_PATH=path/to/vbc.dll"); Reporter.Error.WriteLine("DOTNET_VBC_EXEC if value is COREHOST it's run like 'dotnet '%DOTNET_VBC_PATH%', otherwise just '%DOTNET_VBC_PATH%'"); throw new Exception("cannot locate vbc"); } else { switch (exec) { case "RUN": return(Command.Create(vbcEnvExe, vbcArgs.ToArray())); case "COREHOST": default: var host = muxer.MuxerPath; return(Command.Create(host, new[] { vbcEnvExe }.Concat(vbcArgs).ToArray())); } } }
private CommandSpec CreateNetCoreCommandSpec(ResolverArguments arguments) { Debug.Assert(!string.IsNullOrEmpty(arguments.RuntimeConfigJson), "RuntimeConfigJson is null or empty."); Debug.Assert(!string.IsNullOrEmpty(arguments.DepsJsonFile), "DepsJsonFile is null or empty."); var args = new List <string>(); args.Add("exec"); args.Add("--runtimeconfig"); args.Add(arguments.RuntimeConfigJson); args.Add("--depsfile"); args.Add(arguments.DepsJsonFile); if (!string.IsNullOrEmpty(arguments.NuGetPackageRoot)) { args.Add("--additionalprobingpath"); args.Add(arguments.NuGetPackageRoot); } var commandPath = Path.Combine(NetCoreToolDir, "ef" + FileNameSuffixes.DotNet.DynamicLib); args.Add(commandPath); args.AddRange(arguments.CommandArguments); var muxer = new Muxer(); var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(args.OrEmptyIfNull()); return(new CommandSpec(muxer.MuxerPath, escapedArgs, CommandResolutionStrategy.ProjectToolsPackage)); }
private static Command RunFsc(List <string> fscArgs, string temp) { var fscEnvExe = Environment.GetEnvironmentVariable("DOTNET_FSC_PATH"); var exec = Environment.GetEnvironmentVariable("DOTNET_FSC_EXEC")?.ToUpper() ?? "COREHOST"; var muxer = new Muxer(); if (fscEnvExe != null) { switch (exec) { case "RUN": return(Command.Create(fscEnvExe, fscArgs.ToArray())); case "COREHOST": default: var host = muxer.MuxerPath; return(Command.Create(host, new[] { fscEnvExe }.Concat(fscArgs).ToArray())); } } else { var fscCommandSpec = ResolveFsc(fscArgs, temp)?.Spec; return(Command.Create(fscCommandSpec)); } }
public async Task NewStream_Send() { var channel = new MemoryStream(); var muxer = new Muxer { Channel = channel, Initiator = true }; var nextId = muxer.NextStreamId; var stream = await muxer.CreateStreamAsync("foo"); // Correct stream id is assigned. Assert.AreEqual(nextId, stream.Id); Assert.AreEqual(nextId + 2, muxer.NextStreamId); Assert.AreEqual("foo", stream.Name); // Substreams are managed. Assert.AreEqual(1, muxer.Substreams.Count); Assert.AreSame(stream, muxer.Substreams[stream.Id]); // NewStream message is sent. channel.Position = 0; Assert.AreEqual(stream.Id << 3, channel.ReadVarint32()); Assert.AreEqual(3, channel.ReadVarint32()); var name = new byte[3]; channel.Read(name, 0, 3); Assert.AreEqual("foo", Encoding.UTF8.GetString(name)); Assert.AreEqual(channel.Length, channel.Position); }
public async Task AcquireWrite() { var muxer = new Muxer(); var tasks = new List <Task <string> > { Task.Run(async() => { using (await muxer.AcquireWriteAccessAsync()) { await Task.Delay(100); } return("step 1"); }), Task.Run(async() => { using (await muxer.AcquireWriteAccessAsync()) { await Task.Delay(50); } return("step 2"); }), }; var done = await Task.WhenAll(tasks); Assert.AreEqual("step 1", done[0]); Assert.AreEqual("step 2", done[1]); }
private void ResolveCommand(ref string executable, ref string args) { if (executable.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { var newArgs = ArgumentEscaper.EscapeSingleArg(executable); if (!string.IsNullOrEmpty(args)) { newArgs += " " + args; } args = newArgs; executable = new Muxer().MuxerPath; } else if (executable == "dotnet") { executable = new Muxer().MuxerPath; } else if (!Path.IsPathRooted(executable)) { executable = Env.GetCommandPath(executable) ?? Env.GetCommandPathFromRootPath(_baseDirectory, executable); } }
public int ExecuteTool(string[] args) { var muxer = new Muxer(); var toolDepsFile = Directory.EnumerateFiles(AppContext.BaseDirectory, "*.deps.json").Single(); var toolRuntimeConfig = Directory.EnumerateFiles(AppContext.BaseDirectory, "*.runtimeconfig.json").Single(); var dotnetArgs = new [] { "exec", "--runtimeconfig", toolRuntimeConfig, "--depsfile", toolDepsFile, _toolAssembly.Location }.Concat(args).ToArray(); var arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(dotnetArgs); var process = Process.Start(new ProcessStartInfo() { Arguments = arguments, FileName = muxer.MuxerPath, UseShellExecute = true, WorkingDirectory = Path.GetDirectoryName(_testProjectPath) }); process.WaitForExit(); return(process.ExitCode); }
public async Task CloseStream_Event() { var channel = new MemoryStream(); var muxer1 = new Muxer { Channel = channel, Initiator = true }; await using (await muxer1.CreateStreamAsync("foo")) { await using (await muxer1.CreateStreamAsync("bar")) { // open and close a stream. } } channel.Position = 0; var muxer2 = new Muxer { Channel = channel }; var closeCount = 0; muxer2.SubstreamClosed += (s, e) => { ++closeCount; }; await muxer2.ProcessRequestsAsync(); Assert.AreEqual(2, closeCount); }
protected CommandResult TestExecutable(string outputDir, string executableName, string expectedOutput) { var executablePath = Path.Combine(outputDir, executableName); var args = new List <string>(); if (IsPortable(executablePath)) { args.Add("exec"); args.Add(ArgumentEscaper.EscapeSingleArg(executablePath)); var muxer = new Muxer(); executablePath = muxer.MuxerPath; } var executableCommand = new TestCommand(executablePath); var result = executableCommand.ExecuteWithCapturedOutput(string.Join(" ", args)); if (!string.IsNullOrEmpty(expectedOutput)) { result.Should().HaveStdOut(expectedOutput); } result.Should().NotHaveStdErr(); result.Should().Pass(); return(result); }
public async Task Writing() { var ms = new MemoryStream(); var muxer = new Muxer { Channel = ms }; var stream = new Substream { Muxer = muxer }; var m1 = new byte[1]; stream.AddData(new byte[] { 10 }); Assert.IsTrue(stream.CanRead); Assert.IsTrue(stream.CanWrite); Assert.AreEqual(1, await stream.ReadAsync(m1, 0, 1)); await stream.WriteAsync(m1, 0, 1); stream.WriteByte(11); await stream.FlushAsync(); ms.Position = 0; var header = await Header.ReadAsync(ms); var length = await Varint.ReadVarint32Async(ms); var payload = new byte[length]; ms.Read(payload, 0, length); Assert.AreEqual(stream.Id, header.StreamId); Assert.AreEqual(2, payload.Length); CollectionAssert.AreEqual(new byte[] { 10, 11 }, payload); }
public FullAdder() { foreach (Muxer mux in aMuxers) { _WireInA += mux.InputSelect; } foreach (Muxer mux in bMuxers) { _WireInB += mux.InputSelect; } foreach (Muxer mux in cMuxers) { _WireInCarry += mux.InputSelect; } Muxer m = bMuxers[0]; aMuxers[0].Output += m.AInput; aMuxers[1].Output += m.BInput; _WireInA += m.CInput; m = bMuxers[1]; aMuxers[1].Output += m.AInput; _WireInA += m.BInput; aMuxers[0].Output += m.CInput; m = bMuxers[2]; _WireInA += m.AInput; aMuxers[0].Output += m.BInput; aMuxers[1].Output += m.CInput; m = bMuxers[3]; aMuxers[2].Output += m.AInput; aMuxers[3].Output += m.BInput; m = bMuxers[4]; aMuxers[3].Output += m.AInput; aMuxers[4].Output += m.CInput; m = bMuxers[5]; aMuxers[4].Output += m.BInput; aMuxers[5].Output += m.CInput; m = cMuxers[0]; bMuxers[0].Output += m.AInput; bMuxers[1].Output += m.BInput; bMuxers[2].Output += m.CInput; m.Output += InvokeSumOutput; m = cMuxers[1]; bMuxers[3].Output += m.AInput; bMuxers[4].Output += m.BInput; bMuxers[5].Output += m.CInput; m.Output += InvokeCarryOutput; }
public OutIfPosCircuit(IComponentOutput evalComponent, IComponentOutput outComponent) { Muxer muxer = new Muxer(); outComponent.Output += muxer.CInput; evalComponent.Output += muxer.InputSelect; muxer.Output += (s, t) => Output?.Invoke(this, t); }
public OutIfNotNeuCircuit(TritMatchCircuit3 matchGate, IComponentOutput componentOutput) { Muxer muxer = new Muxer(); componentOutput.Output += muxer.AInput; componentOutput.Output += muxer.CInput; matchGate.Output += muxer.InputSelect; muxer.Output += (s, t) => Output?.Invoke(this, t); }
public CommandSpec Resolve(CommandResolverArguments commandResolverArguments) { if (commandResolverArguments.CommandName == Muxer.MuxerName) { var muxer = new Muxer(); var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart( commandResolverArguments.CommandArguments.OrEmptyIfNull()); return(new CommandSpec(muxer.MuxerPath, escapedArgs)); } return(null); }
/// <summary> /// Redis connect muxer to cluester rediservers /// </summary> public void Connect() { if (_muxer == null) { _muxer = new RedisContext(_context).ConnectionMultiplexer; } if (_database == null) { _database = Muxer.GetDatabase(); } }
public CommandSpec Resolve(CommandResolverArguments commandResolverArguments) { if (commandResolverArguments.CommandName == Muxer.MuxerName) { var muxer = new Muxer(); var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart( commandResolverArguments.CommandArguments.OrEmptyIfNull()); return new CommandSpec(muxer.MuxerPath, escapedArgs, CommandResolutionStrategy.RootedPath); } return null; }
private void LoadMuxers(string muxerType) { var result = RunFFmpeg($"-v quiet -{muxerType}"); foreach (var line in result.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)) { IMuxer muxer = new Muxer(); if (muxer.Fill(line)) { Muxer.Muxers.Add(muxer); } } }
public void InitiatorReceiver() { var muxer = new Muxer { Initiator = true }; Assert.AreEqual(true, muxer.Initiator); Assert.AreEqual(false, muxer.Receiver); Assert.AreEqual(0, muxer.NextStreamId & 1); muxer.Receiver = true; Assert.AreEqual(false, muxer.Initiator); Assert.AreEqual(true, muxer.Receiver); Assert.AreEqual(1, muxer.NextStreamId & 1); }
private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, IEnumerable <string> packageFolders, string runtimeConfigPath) { var host = string.Empty; var arguments = new List <string>(); var muxer = new Muxer(); host = muxer.MuxerPath; if (host == null) { throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer); } arguments.Add("exec"); if (runtimeConfigPath != null) { arguments.Add("--runtimeconfig"); arguments.Add(runtimeConfigPath); } if (depsFilePath != null) { arguments.Add("--depsfile"); arguments.Add(depsFilePath); } foreach (var packageFolder in packageFolders) { arguments.Add("--additionalprobingpath"); arguments.Add(packageFolder); } if (_addAdditionalArguments != null) { _addAdditionalArguments(commandPath, arguments); } arguments.Add(commandPath); arguments.AddRange(commandArguments); return(CreateCommandSpec(host, arguments)); }
/// <summary> /// Establish the connection with the remote node. /// </summary> /// <param name="securityProtocols"></param> /// <param name="cancel"></param> /// <remarks> /// This should be called when the local peer wants a connection with /// the remote peer. /// </remarks> public async Task InitiateAsync( IEnumerable <IEncryptionProtocol> securityProtocols, CancellationToken cancel = default(CancellationToken)) { await EstablishProtocolAsync("/multistream/", cancel); // Find the first security protocol that is also supported by the remote. var exceptions = new List <Exception>(); foreach (var protocol in securityProtocols) { try { await EstablishProtocolAsync(protocol.ToString(), cancel); } catch (Exception e) { exceptions.Add(e); continue; } await protocol.EncryptAsync(this, cancel); break; } if (!SecurityEstablished.Task.IsCompleted) { throw new AggregateException("Could not establish a secure connection.", exceptions); } await EstablishProtocolAsync("/multistream/", cancel); await EstablishProtocolAsync("/mplex/", cancel); var muxer = new Muxer { Channel = Stream, Initiator = true, Connection = this }; muxer.SubstreamCreated += (s, e) => ReadMessages(e, CancellationToken.None); this.MuxerEstablished.SetResult(muxer); var _ = muxer.ProcessRequestsAsync(); }
/// <inheritdoc /> public async Task ProcessMessageAsync(PeerConnection connection, Stream stream, CancellationToken cancel = default(CancellationToken)) { log.Debug("start processing requests from " + connection.RemoteAddress); var muxer = new Muxer { Channel = stream, Connection = connection, Receiver = true }; muxer.SubstreamCreated += (s, e) => connection.ReadMessages(e, CancellationToken.None); // Attach muxer to the connection. It now becomes the message reader. connection.MuxerEstablished.SetResult(muxer); await muxer.ProcessRequestsAsync(); log.Debug("stop processing from " + connection.RemoteAddress); }
public TryteMemory() { for (int x = 0; x < TRIBBLE_SIZE; x++) { for (int y = 0; y < TRIBBLE_SIZE; y++) { TryteRegisterCircuit regComp = new TryteRegisterCircuit(_DataBus, _ReadWriteEnableWire, _XRails[x], _YRails[y]); regComp.BusOutput += (s, t) => BusOutput?.Invoke(this, t); _Addresses[x, y] = regComp; } } int c = 0; for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { for (int k = -1; k < 2; k++) { Muxer muxer = new Muxer(inputStateA: Trit.Neg, inputStateC: Trit.Pos); TritMatchCircuit3 matchGate = new TritMatchCircuit3((Trit)i, (Trit)j, (Trit)k); matchGate.Output += muxer.InputSelect; muxer.Output += _XRails[c].Input; _XRailMatch[c] = matchGate; muxer = new Muxer(inputStateA: Trit.Neg, inputStateC: Trit.Pos); matchGate = new TritMatchCircuit3((Trit)i, (Trit)j, (Trit)k); matchGate.Output += muxer.InputSelect; muxer.Output += _YRails[c].Input; _YRailMatch[c] = matchGate; c++; } } } #if DEBUG ComponentTools.SetComponentNames(this); #endif }
public async Task NewStream_Receive() { var channel = new MemoryStream(); var muxer1 = new Muxer { Channel = channel, Initiator = true }; await muxer1.CreateStreamAsync("foo"); await muxer1.CreateStreamAsync("bar"); channel.Position = 0; var muxer2 = new Muxer { Channel = channel }; var n = 0; muxer2.SubstreamCreated += (s, e) => ++ n; await muxer2.ProcessRequestsAsync(); Assert.AreEqual(2, n); }
public async Task NewStream_AlreadyAssigned() { var channel = new MemoryStream(); var muxer1 = new Muxer { Channel = channel, Initiator = true }; await muxer1.CreateStreamAsync("foo"); var muxer2 = new Muxer { Channel = channel, Initiator = true }; await muxer2.CreateStreamAsync("bar"); channel.Position = 0; var muxer3 = new Muxer { Channel = channel }; await muxer3.ProcessRequestsAsync(new CancellationTokenSource(500).Token); // The channel is closed because of 2 new streams with same id. Assert.IsFalse(channel.CanRead); Assert.IsFalse(channel.CanWrite); }
public ToolEnvironment([NotNull] IFileSystem fileSystem) { if (fileSystem == null) { throw new ArgumentNullException(nameof(fileSystem)); } DotnetPath = new Muxer().MuxerPath; var location = GetType().GetTypeInfo().Assembly.Location; var curDirectory = Path.GetDirectoryName(location); string[] targetDirectory; do { targetDirectory = fileSystem.GetDirectories(Path.Combine("..", Path.Combine("..", curDirectory)), "common").ToArray(); curDirectory = fileSystem.GetParent(curDirectory); }while (curDirectory != null && targetDirectory.Length == 0); if (targetDirectory.Length != 1) { throw new ToolException("Cannot find tools."); } _baseToolsPath = targetDirectory[0]; }
public async Task <IActionResult> GetToken(string rtsp) { var needAdd = false; var muxer = MuxerService.Instance.GetByRtsp(rtsp); if (muxer == null) { muxer = new Muxer(rtsp, _commonOptions.FilePath); needAdd = true; } if (await muxer.Start()) { if (needAdd) { MuxerService.Instance.Add(muxer); } return(Ok(new TokenView { token = muxer.Token })); } muxer.Dispose(); return(BadRequest()); }
private static void AddAdditionalParameters(string commandPath, IList <string> arguments) { if (PrefersCliRuntime(commandPath)) { var runtimeConfigFile = Path.ChangeExtension(commandPath, FileNameSuffixes.RuntimeConfigJson); if (!File.Exists(runtimeConfigFile)) { throw new GracefulException(string.Format(LocalizableStrings.CouldNotFindToolRuntimeConfigFile, nameof(PackagedCommandSpecFactory), Path.GetFileName(commandPath))); } var runtimeConfig = new RuntimeConfig(runtimeConfigFile); var muxer = new Muxer(); Version currentFrameworkSimpleVersion = GetVersionWithoutPrerelease(muxer.SharedFxVersion); Version toolFrameworkSimpleVersion = GetVersionWithoutPrerelease(runtimeConfig.Framework.Version); if (currentFrameworkSimpleVersion.Major != toolFrameworkSimpleVersion.Major) { Reporter.Verbose.WriteLine( string.Format( LocalizableStrings.IgnoringPreferCLIRuntimeFile, nameof(PackagedCommandSpecFactory), runtimeConfig.Framework.Version, muxer.SharedFxVersion)); } else { arguments.Add("--fx-version"); arguments.Add(muxer.SharedFxVersion); } } }
private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable <string> commandArguments, string depsFilePath, string runtimeConfigPath) { var arguments = new List <string>(); var muxer = new Muxer(); var host = muxer.MuxerPath; if (host == null) { throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer); } arguments.Add("exec"); if (runtimeConfigPath != null) { arguments.Add("--runtimeconfig"); arguments.Add(runtimeConfigPath); } if (depsFilePath != null) { arguments.Add("--depsfile"); arguments.Add(depsFilePath); } arguments.Add(commandPath); arguments.AddRange(commandArguments); return(CreateCommandSpec(host, arguments)); }
private CommandSpec CreatePackageCommandSpecUsingMuxer( string commandPath, IEnumerable <string> commandArguments) { var arguments = new List <string>(); var muxer = new Muxer(); var host = muxer.MuxerPath; if (host == null) { throw new Exception(LocalizableStrings.UnableToLocateDotnetMultiplexer); } arguments.Add(commandPath); if (commandArguments != null) { arguments.AddRange(commandArguments); } return(CreateCommandSpec(host, arguments)); }
private int RunExecutable() { // Set up the workspace _workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment()); CalculateDefaultsForNonAssigned(); // Compile to that directory var result = Build.BuildCommand.Run(new[] { $"--framework", $"{_context.TargetFramework}", $"--configuration", Configuration, $"{_context.ProjectFile.ProjectDirectory}" }, _workspace); if (result != 0) { return(result); } List <string> hostArgs = new List <string>(); if (!_context.TargetFramework.IsDesktop() && _context.LockFile != null) { // Add Nuget Packages Probing Paths const string probingPathArg = "--additionalprobingpath"; foreach (var packageFolder in _context.LockFile.PackageFolders) { // DotNetHost doesn't handle additional probing paths with a trailing slash hostArgs.Insert(0, PathUtility.EnsureNoTrailingDirectorySeparator(packageFolder.Path)); hostArgs.Insert(0, probingPathArg); } } // Now launch the output and give it the results var outputPaths = _context.GetOutputPaths(Configuration); var outputName = outputPaths.RuntimeFiles.Executable; if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (_context.TargetFramework.IsDesktop()) { // Run mono if we're running a desktop target on non windows _args.Insert(0, outputName); if (string.Equals(Configuration, "Debug", StringComparison.OrdinalIgnoreCase)) { // If we're compiling for the debug configuration then add the --debug flag // other options may be passed using the MONO_OPTIONS env var _args.Insert(0, "--debug"); } outputName = "mono"; } } ICommand command; if (outputName.EndsWith(FileNameSuffixes.DotNet.DynamicLib, StringComparison.OrdinalIgnoreCase)) { // The executable is a ".dll", we need to call it through dotnet.exe var muxer = new Muxer(); command = _commandFactory.Create(muxer.MuxerPath, Enumerable.Concat( Enumerable.Concat(new string[] { "exec" }, hostArgs), Enumerable.Concat(new string[] { outputName }, _args))); } else { command = _commandFactory.Create(outputName, Enumerable.Concat(hostArgs, _args)); } result = command .Execute() .ExitCode; return(result); }