<commit_before>﻿/*
 * Copyright 2013 
 * Licensed under the MIT license: <http://www.opensource.org/licenses/mit-license.php>
 */

/*
 * Includes a reference to the Json.NET library <http://json.codeplex.com>, used under 
 * MIT license. See <http://www.opensource.org/licenses/mit-license.php>  for license details. 
 * Json.NET is copyright 2007 <NAME>
 */

/* 
 * Includes the Alchemy Websockets Library 
 * <http://www.olivinelabs.com/index.php/projects/71-alchemy-websockets>, 
 * used under LGPL license. See <http://www.gnu.org/licenses/> for license details. 
 * Alchemy Websockets is copyright 2011 Olivine Labs.
 */

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Alchemy;
using Alchemy.Classes;
using Newtonsoft.Json;
using System.Net;
using System.Threading.Tasks;
using System.Timers;
using Trinity.UnitTest;

namespace Afinity
{
    /// <summary>
    /// This menu functions is used to give access to some function by sending commands through the websocket.
    /// Originally, the ConSol offered full control over C# (you could send a real C# command, and it would get executed)
    /// Now that ProteoProfile has been designed to run server side, remote code execution has been removed.
    /// Only functions listed here will be executed, to prevent security flaws. Anything added here is automatically available
    /// from the command line interface. 
    /// TODO Remove ToString and other "object" class methods from the options listed by the ls command.
    /// </summary>
    public class MenuFunctions
    {
        public string YeastSampleTest(UserContext context)
        {
            YeastSample.Launch();
            return "Yeast sample test executed!";
        }

        public string SettePeptideSampleTest(UserContext context)
        {
            SettePeptideSample.Launch();
            return "Sette Peptide sample executed";
        }

        public string MhcSampleTest(UserContext context)
        {
            MhcSample.Launch();
            return "Mhc sample test executed";
        }

        public string ls(UserContext context)
        {
            string output = "";
            Type thisType = this.GetType();
            System.Reflection.MethodInfo[] theMethods = thisType.GetMethods();
            foreach (System.Reflection.MethodInfo method in theMethods)
            {
                output += ", " + method.Name;
            }
            return output.Substring(2);
        }
    }

    /// <summary>
    /// Main class with websocket initialisation. Also creates a ConSole object to handle log files generation and 
    /// </summary>
    class TrinityMain
    {
        /// <summary>
        /// Store the list of online users. Wish I had a ConcurrentList. 
        /// </summary>
        protected static ConcurrentDictionary<UserContext, string> OnlineUsers = new ConcurrentDictionary<UserContext, string>();
                
        /// <summary>
        /// Console wrapper with integrated log files and command compiler (through reflection)
        /// </summary>
        public static ConSol Sol;
        
        /// <summary>
        /// Console wrapper with integrated log files and command compiler (through reflection)
        /// </summary>
        public static MenuFunctions Instance = new MenuFunctions();

        /// <summary>
        /// Initialize the application and start the Alchemy Websockets server
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Start SOL

            //Console <controller>
            Sol = new ConSol();// = new vsConSOLe(new UpdateMethod(UpdateMethodHandler));                        
            string command = "";

            //RawStatsUnitTest.Run();

            //Tests.Run();
            //Tests.DrownCatPeptidesWithAllProteins();
            //Tests.LysineConservation();
            //NoEnzymeDigestUnitTest.Run();
            //Instance.MhcSampleTest(null); 
            Instance.YeastSampleTest(null);
            //Tests.LysineConservation();
            //Tests.MascotCompare();


            // Initialize the server on port 81, accept any IPs, and bind events.
            var aServer = new WebSocketServer(81, IPAddress.Any)
            {
                OnReceive = OnReceive,
                OnSend = OnSend,
                OnConnected = OnConnect,
                OnDisconnect = OnDisconnect,
                TimeOut = new TimeSpan(150, 0, 0)
            };

            aServer.Start();

            Sol.WriteLine("Welcome to ConSOLe : the command line, server-side interface of Trinity!");
            Sol.WriteLine("Type in the commands you wish to be executed");

            do
            {/*
                if (!string.IsNullOrEmpty(command))<commit_msg>Renamed a unit test function<commit_after>﻿/*
 * Copyright 2013 
 * Licensed under the MIT license: <http://www.opensource.org/licenses/mit-license.php>
 */

/*
 * Includes a reference to the Json.NET library <http://json.codeplex.com>, used under 
 * MIT license. See <http://www.opensource.org/licenses/mit-license.php>  for license details. 
 * Json.NET is copyright 2007 <NAME>
 */

/* 
 * Includes the Alchemy Websockets Library 
 * <http://www.olivinelabs.com/index.php/projects/71-alchemy-websockets>, 
 * used under LGPL license. See <http://www.gnu.org/licenses/> for license details. 
 * Alchemy Websockets is copyright 2011 Olivine Labs.
 */

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Alchemy;
using Alchemy.Classes;
using Newtonsoft.Json;
using System.Net;
using System.Threading.Tasks;
using System.Timers;
using Trinity.UnitTest;

namespace Afinity
{
    /// <summary>
    /// This menu functions is used to give access to some function by sending commands through the websocket.
    /// Originally, the ConSol offered full control over C# (you could send a real C# command, and it would get executed)
    /// Now that ProteoProfile has been designed to run server side, remote code execution has been removed.
    /// Only functions listed here will be executed, to prevent security flaws. Anything added here is automatically available
    /// from the command line interface. 
    /// TODO Remove ToString and other "object" class methods from the options listed by the ls command.
    /// </summary>
    public class MenuFunctions
    {
        public string YeastSampleTest(UserContext context)
        {
            YeastSample.Launch();
            return "Yeast sample test executed!";
        }

        public string SettePeptideSampleTest(UserContext context)
        {
            SettePeptideSample.Launch();
            return "Sette Peptide sample executed";
        }

        public string MhcSampleTest(UserContext context)
        {
            MhcSample.Launch();
            return "Mhc sample test executed";
        }

        public string ls(UserContext context)
        {
            string output = "";
            Type thisType = this.GetType();
            System.Reflection.MethodInfo[] theMethods = thisType.GetMethods();
            foreach (System.Reflection.MethodInfo method in theMethods)
            {
                output += ", " + method.Name;
            }
            return output.Substring(2);
        }
    }

    /// <summary>
    /// Main class with websocket initialisation. Also creates a ConSole object to handle log files generation and 
    /// </summary>
    class TrinityMain
    {
        /// <summary>
        /// Store the list of online users. Wish I had a ConcurrentList. 
        /// </summary>
        protected static ConcurrentDictionary<UserContext, string> OnlineUsers = new ConcurrentDictionary<UserContext, string>();
                
        /// <summary>
        /// Console wrapper with integrated log files and command compiler (through reflection)
        /// </summary>
        public static ConSol Sol;
        
        /// <summary>
        /// Console wrapper with integrated log files and command compiler (through reflection)
        /// </summary>
        public static MenuFunctions Instance = new MenuFunctions();

        /// <summary>
        /// Initialize the application and start the Alchemy Websockets server
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Start SOL

            //Console <controller>
            Sol = new ConSol();// = new vsConSOLe(new UpdateMethod(UpdateMethodHandler));                        
            string command = "";

            //RawStatsUnitTest.Run();

            //Tests.Run();
            NBSample.Launch();
            //Tests.YangLiuPeptidesWithAllProteins();
            //Tests.LysineConservation();
            //NoEnzymeDigestUnitTest.Run();
            //Instance.MhcSampleTest(null); 
            //Instance.YeastSampleTest(null);
            //Tests.LysineConservation();
            //Tests.MascotCompare();


            // Initialize the server on port 81, accept any IPs, and bind events.
            var aServer = new WebSocketServer(81, IPAddress.Any)
            {
                OnReceive = OnReceive,
                OnSend = OnSend,
                OnConnected = OnConnect,
                OnDisconnect = OnDisconnect,
                TimeOut = new TimeSpan(150, 0, 0)
            };

            aServer.Start();

            Sol.WriteLine("Welcome to ConSOLe : the command line, server-side interface of Trinity!");
            Sol.WriteLine("Type in the commands you wish to be executed");

            do
            {/*
                if (!string.IsNullOrEmpty(command))
{'fraction_non_alphanumeric': 0.09727506426735219, 'fraction_numerical': 0.00493573264781491, 'mean_word_length': 2.027077497665733, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, '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': '2669707', 'n_tokens_mistral': 2529, 'n_tokens_neox': 2363, 'n_words': 788}