Esempio n. 1
0
        public void CloseConnection()
        {
            lock (clientLocker)
            {
                if (ClientConnected)
                {
                    try
                    {
                        ClientWriter.WriteLine("-- " + Properties.strings.cya);
                        ClientWriter.Flush();
                    }
                    catch (IOException) { }
                    ConnectedServer.WriteToAllClients("-- " + string.Format(Properties.strings.disconnectedClient,
                                                                            Name + "@" + ClientIep.Address, ClientIep.Port));

                    ClientWriter.Close();
                    ClientReader.Close();
                    ClientStream.Close();
                    ClientSocket.Close();
                    ClientConnected = false;
                    ConnectedServer.connectedClients.Remove(this);
                }
            }
            ConnectedServer.RefreshInfo();
        }
Esempio n. 2
0
        private async Task <Connection> CreateConnection(string action, string argument)
        {
            var pipeName = GetPipeName();

            try
            {
                var stream = new NamedPipeClientStream(pipeName);
                await stream.ConnectAsync();

                var writer = new ClientWriter(stream);
                writer.Write(action);
                writer.Write(argument);

                return(new Connection(stream));
            }
            catch
            {
                try
                {
                    _processInfo?.Process.Kill();
                }
                catch
                {
                    // Inherent race condition here.  Just need to make sure the process is
                    // dead as it can't even handle new connections.
                }

                throw;
            }
        }
Esempio n. 3
0
 internal BackgroundWriter(ClientWriter writer, ImmutableArray <T> data, Action <ClientWriter, T> writeValue, CancellationToken cancellationToken)
 {
     _writer            = writer;
     _writeValue        = writeValue;
     _data              = data;
     _cancellationToken = cancellationToken;
 }
 internal ClientStream(StrongConnect pc, Socket c)
 {
     client      = c;
     wtr         = new ClientWriter(client);
     rdr         = new ClientReader(client);
     rdr.buf.pos = 2;
     rdr.buf.len = 0;
 }
Esempio n. 5
0
 protected static void Go(string assemblyFileName, Stream stream, AppDomainSupport appDomainSupport,
                          Action <XunitFrontController, TestAssemblyConfiguration, ClientWriter> action)
 {
     using (AssemblyHelper.SubscribeResolve())
         using (var xunit = new XunitFrontController(appDomainSupport, assemblyFileName, shadowCopy: false))
             using (var writer = new ClientWriter(stream))
             {
                 var configuration = ConfigReader.Load(assemblyFileName);
                 action(xunit, configuration, writer);
             }
 }
Esempio n. 6
0
        private void DisconnectForced(string reason)
        {
            bool clientWasConnected = Client?.Connected == true;

            ReceivedLines.Clear();
            Client?.Dispose();
            ClientStream?.Dispose();
            ClientReader?.Dispose();
            ClientWriter?.Dispose();

            Client       = null;
            ClientStream = null;
            ClientReader = null;
            ClientWriter = null;

            Connected     = false;
            ReadLoopTask  = null;
            KeepAliveTask = null;

            if (clientWasConnected)
            {
                ConnectionClosed?.Invoke(this, new EventArgs <string>(reason));
            }
        }
Esempio n. 7
0
 internal TestDiscoverySink(ClientWriter writer)
 {
     _writer = writer;
 }
Esempio n. 8
0
 public TestRunSink(ClientWriter writer)
 {
     _writer = writer;
 }
Esempio n. 9
0
        public async Task <GeneratedCodeWorkspace> ExecuteAsync(CodeModel codeModel, Configuration configuration)
        {
            Directory.CreateDirectory(configuration.OutputFolder);
            var project          = GeneratedCodeWorkspace.Create(configuration.OutputFolder, configuration.SharedSourceFolder);
            var sourceInputModel = new SourceInputModel(await project.GetCompilationAsync());

            var context = new BuildContext(codeModel, configuration, sourceInputModel);

            var modelWriter            = new ModelWriter();
            var clientWriter           = new ClientWriter();
            var restClientWriter       = new RestClientWriter();
            var serializeWriter        = new SerializationWriter();
            var headerModelModelWriter = new ResponseHeaderGroupWriter();

            foreach (var model in context.Library.Models)
            {
                var codeWriter = new CodeWriter();
                modelWriter.WriteModel(codeWriter, model);

                var serializerCodeWriter = new CodeWriter();
                serializeWriter.WriteSerialization(serializerCodeWriter, model);

                var name = model.Type.Name;
                project.AddGeneratedFile($"Models/{name}.cs", codeWriter.ToString());
                project.AddGeneratedFile($"Models/{name}.Serialization.cs", serializerCodeWriter.ToString());
            }

            foreach (var client in context.Library.RestClients)
            {
                var restCodeWriter = new CodeWriter();
                restClientWriter.WriteClient(restCodeWriter, client);

                project.AddGeneratedFile($"{client.Type.Name}.cs", restCodeWriter.ToString());
            }

            foreach (ResponseHeaderGroupType responseHeaderModel in context.Library.HeaderModels)
            {
                var headerModelCodeWriter = new CodeWriter();
                headerModelModelWriter.WriteHeaderModel(headerModelCodeWriter, responseHeaderModel);

                project.AddGeneratedFile($"{responseHeaderModel.Type.Name}.cs", headerModelCodeWriter.ToString());
            }

            foreach (var client in context.Library.Clients)
            {
                var codeWriter = new CodeWriter();
                clientWriter.WriteClient(codeWriter, client, context.Configuration);

                project.AddGeneratedFile($"{client.Type.Name}.cs", codeWriter.ToString());
            }

            foreach (var operation in context.Library.LongRunningOperations)
            {
                var codeWriter = new CodeWriter();
                LongRunningOperationWriter.Write(codeWriter, operation);

                project.AddGeneratedFile($"{operation.Type.Name}.cs", codeWriter.ToString());
            }

            if (context.Configuration.AzureArm)
            {
                var codeWriter = new CodeWriter();
                ManagementClientWriter.WriteClientOptions(codeWriter, context);
                project.AddGeneratedFile($"{context.Configuration.LibraryName}ManagementClientOptions.cs", codeWriter.ToString());

                var clientCodeWriter = new CodeWriter();
                ManagementClientWriter.WriteAggregateClient(clientCodeWriter, context);
                project.AddGeneratedFile($"{context.Configuration.LibraryName}ManagementClient.cs", clientCodeWriter.ToString());
            }

            return(project);
        }
Esempio n. 10
0
        private void ClientListening()
        {
            string message;

            lock (clientLocker)
            {
                if (ClientConnected)
                {
                    try
                    {
                        ClientWriter.WriteLine("-- " + Properties.strings.motd + ": " + ConnectedServer.WelcomeMessage);
                        ClientWriter.Flush();
                        ClientWriter.Write("-- " + Properties.strings.enterNickname + ": ");
                        ClientWriter.Flush();
                    }
                    catch (IOException) { }
                }
            }
            try
            {
                do
                {
                    string name = ClientReader.ReadLine();
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        lock (clientLocker)
                        {
                            if (ClientConnected)
                            {
                                ClientWriter.Write("-- " + Properties.strings.enterNickname + ": ");
                                ClientWriter.Flush();
                            }
                        }
                    }
                    else
                    {
                        Name = name;
                    }
                } while (string.IsNullOrWhiteSpace(name));
            }
            catch (IOException) { }

            ConnectedServer.RefreshInfo();

            ConnectedServer.WriteToAllClients("-- " + string.Format(Properties.strings.connectedWithClient,
                                                                    Name + "@" + ClientIep.Address, ClientIep.Port));

            lock (clientLocker)
            {
                if (ClientConnected)
                {
                    try
                    {
                        ClientWriter.WriteLine("-- " + Properties.strings.commands);
                        ClientWriter.Flush();
                    }
                    catch (IOException) { }
                }
            }

            while (ClientConnected)
            {
                try
                {
                    message = ClientReader.ReadLine();
                    if (message != null)
                    {
                        //Handles available commands
                        if (!string.IsNullOrWhiteSpace(message))
                        {
                            if (message[0] == '#')
                            {
                                if (message == Properties.strings.exit)
                                {
                                    lock (clientLocker)
                                        if (ClientConnected)
                                        {
                                            CloseConnection();
                                        }
                                }
                                else if (message == Properties.strings.list)
                                {
                                    lock (clientLocker)
                                        if (ClientConnected)
                                        {
                                            ConnectedServer.List(this);
                                        }
                                }
                                else if (message == Properties.strings.cmd)
                                {
                                    lock (clientLocker)
                                    {
                                        if (ClientConnected)
                                        {
                                            ClientWriter.WriteLine("-- " + Properties.strings.availableCommands + ": ");
                                            ClientWriter.Flush();
                                            ClientWriter.WriteLine("\t-- " + Properties.strings.cmd + ": " + Properties.strings.cmdInfo);
                                            ClientWriter.Flush();
                                            ClientWriter.WriteLine("\t-- " + Properties.strings.exit + ": " + Properties.strings.exitInfo);
                                            ClientWriter.Flush();
                                            ClientWriter.WriteLine("\t-- " + Properties.strings.list + ": " + Properties.strings.listInfo);
                                            ClientWriter.Flush();
                                        }
                                    }
                                }
                                else
                                {
                                    lock (clientLocker)
                                    {
                                        if (ClientConnected)
                                        {
                                            ClientWriter.WriteLine("-- " + Properties.strings.unknownCmd);
                                            ClientWriter.Flush();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                ConnectedServer.WriteToAllClients("|| " + Name + "@" + ClientIep.Address + " >> " + message);
                            }
                        }
                        else
                        {
                            lock (clientLocker)
                            {
                                if (ClientConnected)
                                {
                                    ClientWriter.WriteLine("-- " + Properties.strings.enterMessage);
                                    ClientWriter.Flush();
                                }
                            }
                        }
                    }
                    else
                    {
                        CloseConnection();
                    }
                }
                catch (IOException)
                {
                    break;
                }
            }

            CloseConnection();
        }