<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Lime.Protocol;
using Lime.Protocol.Serialization;
using Lime.Protocol.Server;
using Lime.Transport.Tcp;
using Lime.Protocol.Network;
using Lime.Protocol.Security;
using Lime.Protocol.Serialization.Newtonsoft;
using Lime.Transport.WebSocket;

namespace Lime.Sample.Server
{
    class Program
    {
        static IDictionary<Node, IServerChannel> _nodeChannelsDictionary = new Dictionary<Node, IServerChannel>();
        static Node _serverNode = Node.Parse("server@domain.com/default");

        static void Main(string[] args)
        {
            MainAsync(args).Wait();
        }

        static async Task MainAsync(string[] args)
        {
            Console.Write("Enter the listener URI (Press ENTER for default): ");

            var inputListenerUri = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(inputListenerUri))
            {
                inputListenerUri = "net.tcp://localhost:55321";
            }

            Console.WriteLine("Starting the server...");

            // Create and start a listener
            var listenerUri = new Uri(inputListenerUri);
            var transportListener = GetTransportListenerForUri(listenerUri);

            // Starts listening
            try
            {
                await transportListener.StartAsync();
                var cts = new CancellationTokenSource();
                var listenerTask = ListenAsync(transportListener, cts.Token);

                Console.WriteLine("Server started. Press ENTER to stop.");
                Console.ReadLine();
                cts.Cancel();

                await listenerTask;
                await transportListener.StopAsync();

                Console.WriteLine("Server stopped. Press any key to exit.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Server failed with message '{ex.Message}'. Press any key to exit.");
            }

            
            Console.Read();
        }

        static ITransportListener GetTransportListenerForUri(Uri uri)
        {            
            var serializer = new JsonNetSerializer(); 

            switch (uri.Scheme)
            {
                case "net.tcp":
                    X509Certificate2 serverCertificate = null;  // You should provide a certificate for TLS
                    return new TcpTransportListener(
                        uri,
                        serverCertificate,
                        serializer);
                case "ws":
                case "wss":
                    return new WebSocketTransportListener(
                        uri,
                        new X509CertificateInfo("263d0ce222ea752f0a8ea850c5c8abffa0d785e2", StoreName.My), 
                        serializer);                    

                default:
                    throw new NotSupportedException($"Unsupported URI scheme '{uri.Scheme}'");<commit_msg>Removed certificate thumbprint from the server sample<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Lime.Protocol;
using Lime.Protocol.Serialization;
using Lime.Protocol.Server;
using Lime.Transport.Tcp;
using Lime.Protocol.Network;
using Lime.Protocol.Security;
using Lime.Protocol.Serialization.Newtonsoft;
using Lime.Transport.WebSocket;

namespace Lime.Sample.Server
{
    class Program
    {
        static IDictionary<Node, IServerChannel> _nodeChannelsDictionary = new Dictionary<Node, IServerChannel>();
        static Node _serverNode = Node.Parse("server@domain.com/default");

        static void Main(string[] args)
        {
            MainAsync(args).Wait();
        }

        static async Task MainAsync(string[] args)
        {
            Console.Write("Enter the listener URI (Press ENTER for default): ");

            var inputListenerUri = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(inputListenerUri))
            {
                inputListenerUri = "net.tcp://localhost:55321";
            }

            Console.WriteLine("Starting the server...");

            // Create and start a listener
            var listenerUri = new Uri(inputListenerUri);
            var transportListener = GetTransportListenerForUri(listenerUri);

            // Starts listening
            try
            {
                await transportListener.StartAsync();
                var cts = new CancellationTokenSource();
                var listenerTask = ListenAsync(transportListener, cts.Token);

                Console.WriteLine("Server started. Press ENTER to stop.");
                Console.ReadLine();
                cts.Cancel();

                await listenerTask;
                await transportListener.StopAsync();

                Console.WriteLine("Server stopped. Press any key to exit.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Server failed with message '{ex.Message}'. Press any key to exit.");
            }

            
            Console.Read();
        }

        static ITransportListener GetTransportListenerForUri(Uri uri)
        {            
            var serializer = new JsonNetSerializer(); 

            switch (uri.Scheme)
            {
                case "net.tcp":
                    X509Certificate2 serverCertificate = null;  // You should provide a certificate for TLS
                    return new TcpTransportListener(
                        uri,
                        serverCertificate,
                        serializer);
                case "ws":
                case "wss":
                    return new WebSocketTransportListener(
                        uri,
                        null, 
                        serializer);                    

                default:
                    throw new NotSupportedException($"Unsupported URI scheme '{uri.Scheme}'");
{'fraction_non_alphanumeric': 0.08223107569721115, 'fraction_numerical': 0.007808764940239044, 'mean_word_length': 1.7406113537117904, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4718835', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1413, 'n_words': 363}