private static IEnumerable <string> GetGeneratedFilesPaths(string targetDirectoryPath, TestsGeneratorRestrictions restrictions, IEnumerable <string> filePaths) { List <ConsumerResult <string> > generatedFilePaths = new List <ConsumerResult <string> >(); try { var fileSourceCodeProvider = new FileSourceCodeProvider(filePaths); var fileConsumer = new FileConsumer(targetDirectoryPath); var testsGenerator = new TestsGenerator(restrictions); generatedFilePaths = testsGenerator.Generate(fileSourceCodeProvider, fileConsumer).ToList(); } catch (AggregateException aggregateException) { Console.WriteLine(ErrorPromt); foreach (Exception exception in aggregateException.InnerExceptions) { Console.WriteLine(exception.Message); } } catch (ArgumentOutOfRangeException argOutOfRangeException) { Console.WriteLine(ErrorPromt); Console.WriteLine(argOutOfRangeException.Message); } return(generatedFilePaths.Select(x => x.Result).Cast <string>()); }
private async void PersistsAsSerialized(ISerializer serializer, string extension) { var consumer = new FileConsumer <StringEvent>(serializer, _fixture.Folder, extension); var @event = new StringEvent("Test!"); await consumer.HandleAsync(@event); var file = OneFileSaved(extension); FileContainsTheEvent(file, serializer, @event); }
private static void PersistsAsSerialized(Serializer serializer, string extension) { var consumer = new FileConsumer <StringEvent>(serializer, "Events", extension); var @event = new StringEvent("Test!"); consumer.Handle(@event); var file = OneFileSaved(extension); FileContainsTheEvent(file, serializer, @event); }
static void Main(string[] args) { if (args.Length <= 0) { Console.WriteLine("usage: ./VeracityTest <input file path> <time to run (ms)> <delay between producer writes (ms)>"); Console.ReadLine(); return; } FileInfo inputFile = new FileInfo(args[0]); if (!inputFile.Exists) { Console.WriteLine($"File {inputFile.FullName} doesn't exist!"); Console.ReadLine(); return; } Console.WriteLine("control+c to quit early"); int runLength = 10000; int delay = 500; if (args.Length > 1 && int.TryParse(args[1], out int val)) { runLength = val; } if (args.Length > 2 && int.TryParse(args[2], out int val2)) { delay = val2; } IDataQueue dataQueue = new DataQueue(); IProducer producer = new FileProducer(dataQueue, inputFile); IConsumer consoleConsumer = new ConsoleConsumer(dataQueue); IConsumer fileConsumer = new FileConsumer(dataQueue, new FileInfo(@".\output.txt")); dataQueue.RegisterListener(ConsumerType.CONSOLE, consoleConsumer); dataQueue.RegisterListener(ConsumerType.FILE, fileConsumer); producer.StartProducer(delay); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); while (stopWatch.ElapsedMilliseconds < runLength) { Thread.Sleep(500); } stopWatch.Stop(); producer.StopProducer(); }
public void SetUp() { _fullPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var fileSourceCodeProvider = new FileSourceCodeProvider(new List <string> { _fullPath + @"\TracerUse.csnotcompilable" }); var fileConsumer = new FileConsumer(_fullPath + @"\GeneratedTests\"); _testsGenerator = new TestsGenerator(); _testsGenerator.Generate(fileSourceCodeProvider, fileConsumer); string generatedTestText = File.ReadAllText(_fullPath + @"\GeneratedTests\TracerUseTests.cs"); SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(generatedTestText); _testCompilationUnit = syntaxTree.GetCompilationUnitRoot(); }
public override async Task <CommandResult> ExecuteAsync(CancellationToken cancel) { Console.WriteLine($"Connecting to {Hostname}..."); try { using (Client = await SmartGlassClient.ConnectAsync(Hostname)) { var broadcastChannel = Client.BroadcastChannel; // TODO: Wait for BroadcastMessages here... var result = await broadcastChannel.StartGamestreamAsync(); Console.WriteLine($"Connecting to Nano, TCP: {result.TcpPort}, UDP: {result.UdpPort}"); var nano = new NanoClient(Hostname, result.TcpPort, result.UdpPort, new Guid()); await nano.Initialize(); FileConsumer consumer = new FileConsumer("nanostream"); nano.AddConsumer(consumer); await nano.StartStream(); var loop = new Loop(typeof(SessionCommandType)); loop.Execute(); Console.WriteLine($"Disconnected"); } return(CommandResult.Success); } catch (Exception e) { Console.WriteLine($"Failed to connect: {e}"); } finally { Client = null; } return(CommandResult.RuntimeFailure); }
/// <summary> /// Saves broadcasted stream. /// </summary> /// <param name="name"></param> /// <param name="isAppend"></param> public void SaveAs(string name, bool isAppend) { if (log.IsDebugEnabled) { log.Debug("SaveAs - name: " + name + " append: " + isAppend); } // Get stream scope IStreamCapableConnection connection = this.Connection; if (connection == null) { // TODO: throw other exception here? throw new IOException("Stream is no longer connected"); } IScope scope = connection.Scope; // Get stream filename generator IStreamFilenameGenerator generator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; // Generate filename string filename = generator.GenerateFilename(scope, name, ".flv", GenerationType.RECORD); // Get file for that filename FileInfo file; if (generator.ResolvesToAbsolutePath) { file = new FileInfo(filename); } else { file = scope.Context.GetResource(filename).File; } // If append mode is on... if (!isAppend) { if (file.Exists) { // Per livedoc of FCS/FMS: // When "live" or "record" is used, // any previously recorded stream with the same stream URI is deleted. file.Delete(); } } else { if (!file.Exists) { // Per livedoc of FCS/FMS: // If a recorded stream at the same URI does not already exist, // "append" creates the stream as though "record" was passed. isAppend = false; } } //Requery file = new FileInfo(file.FullName); if (!file.Exists) { // Make sure the destination directory exists string directory = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } if (!file.Exists) { using (FileStream fs = file.Create()) { } } if (log.IsDebugEnabled) { log.Debug("Recording file: " + file.FullName); } _recordingFile = new FileConsumer(scope, file); #if !(NET_1_1) Dictionary <string, object> parameterMap = new Dictionary <string, object>(); #else Hashtable parameterMap = new Hashtable(); #endif if (isAppend) { parameterMap.Add("mode", "append"); } else { parameterMap.Add("mode", "record"); } _recordPipe.Subscribe(_recordingFile, parameterMap); _recording = true; _recordingFilename = filename; }
public override async Task <CommandResult> ExecuteAsync(CancellationToken cancel) { if (TokenFilePath != null) { using (FileStream fs = File.Open(TokenFilePath, FileMode.Open)) { AuthService = await AuthenticationService.LoadFromJsonFileStream(fs); await AuthService.AuthenticateAsync(); } await AuthService.DumpToJsonFileAsync(TokenFilePath); } Console.WriteLine($"Connecting to {Hostname}..."); GamestreamSession session = null; SmartGlassClient Client = null; try { Client = await SmartGlassClient.ConnectAsync(Hostname, AuthService == null?null : AuthService.XToken.UserInformation.Userhash, AuthService == null?null : AuthService.XToken.Jwt); } catch (SmartGlassException e) { Console.WriteLine($"Failed to connect: {e.Message}"); return(CommandResult.RuntimeFailure); } catch (TimeoutException) { Console.WriteLine($"Timeout while connecting"); return(CommandResult.RuntimeFailure); } var broadcastChannel = Client.BroadcastChannel; var config = GamestreamConfiguration.GetStandardConfig(); try { session = await broadcastChannel.StartGamestreamAsync(config); } catch (Exception e) { Console.WriteLine($"Failed to send StartGamestream: {e.Message}"); return(CommandResult.RuntimeFailure); } Console.WriteLine($"Connecting to Nano, TCP: {session.TcpPort}, UDP: {session.UdpPort}"); var nano = new NanoClient(Hostname, session); try { Console.WriteLine($"Running protocol init..."); await nano.InitializeProtocolAsync(); await nano.OpenInputChannelAsync(1280, 720); await nano.OpenChatAudioChannelAsync( new Nano.Packets.AudioFormat(1, 24000, AudioCodec.Opus)); Console.WriteLine("Adding FileConsumer"); FileConsumer consumer = new FileConsumer("nanostream"); nano.AddConsumer(consumer); Console.WriteLine("Initializing AV stream (handshaking)..."); await nano.InitializeStreamAsync(nano.AudioFormats[0], nano.VideoFormats[0]); Console.WriteLine("Starting stream..."); await nano.StartStreamAsync(); } catch (Exception e) { Console.WriteLine($"Failed to initialize gamestream: {e}"); return(CommandResult.RuntimeFailure); } Console.WriteLine("Stream is running"); var loop = new Loop(typeof(SessionCommandType)); loop.Execute(); return(CommandResult.Success); }
/// <summary> /// Saves the broadcast stream as a file. /// </summary> /// <param name="name">The path of the file relative to the scope.</param> /// <param name="isAppend">Whether to append to the end of file.</param> public void SaveAs(string name, bool isAppend) { try { IScope scope = this.Scope; IStreamFilenameGenerator generator = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; string filename = generator.GenerateFilename(scope, name, ".flv", GenerationType.RECORD); // Get file for that filename FileInfo file; if (generator.ResolvesToAbsolutePath) { file = new FileInfo(filename); } else { file = scope.Context.GetResource(filename).File; } if (!isAppend) { if (file.Exists) { // Per livedoc of FCS/FMS: // When "live" or "record" is used, // any previously recorded stream with the same stream URI is deleted. file.Delete(); } } else { if (!file.Exists) { // Per livedoc of FCS/FMS: // If a recorded stream at the same URI does not already exist, // "append" creates the stream as though "record" was passed. isAppend = false; } } if (!file.Exists) { // Make sure the destination directory exists string directory = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } if (!file.Exists) { using (FileStream fs = file.Create()) { } } FileConsumer fc = new FileConsumer(scope, file); #if !(NET_1_1) Dictionary <string, object> parameterMap = new Dictionary <string, object>(); #else Hashtable parameterMap = new Hashtable(); #endif if (isAppend) { parameterMap.Add("mode", "append"); } else { parameterMap.Add("mode", "record"); } if (null == _recordPipe) { _recordPipe = new InMemoryPushPushPipe(); } _recordPipe.Subscribe(fc, parameterMap); _recordingFilename = filename; } catch (IOException ex) { log.Error("Save as exception", ex); } }
public void SaveAs(string name, bool isAppend) { FileInfo file; if (log.get_IsDebugEnabled()) { log.Debug(string.Concat(new object[] { "SaveAs - name: ", name, " append: ", isAppend })); } IStreamCapableConnection connection = base.Connection; if (connection == null) { throw new IOException("Stream is no longer connected"); } IScope scope = connection.Scope; IStreamFilenameGenerator scopeService = ScopeUtils.GetScopeService(scope, typeof(IStreamFilenameGenerator)) as IStreamFilenameGenerator; string fileName = scopeService.GenerateFilename(scope, name, ".flv", GenerationType.RECORD); if (scopeService.ResolvesToAbsolutePath) { file = new FileInfo(fileName); } else { file = scope.Context.GetResource(fileName).File; } if (!isAppend) { if (file.Exists) { file.Delete(); } } else if (!file.Exists) { isAppend = false; } file = new FileInfo(file.FullName); if (!file.Exists) { string directoryName = Path.GetDirectoryName(file.FullName); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } } if (!file.Exists) { using (file.Create()) { } } if (log.get_IsDebugEnabled()) { log.Debug("Recording file: " + file.FullName); } this._recordingFile = new FileConsumer(scope, file); Dictionary <string, object> parameterMap = new Dictionary <string, object>(); if (isAppend) { parameterMap.Add("mode", "append"); } else { parameterMap.Add("mode", "record"); } this._recordPipe.Subscribe(this._recordingFile, parameterMap); this._recording = true; this._recordingFilename = fileName; }