コード例 #1
0
ファイル: KastBox.cs プロジェクト: natepisarski/kast
 /// <summary>
 /// Creates a new KastBox, with the name as the process's name
 /// </summary>
 /// <param name="name">The name of the process that this Box will manage</param>
 public KastBox(string name, KastConfiguration masterConfig)
 {
     ProcessName = name;
     MasterConfig = masterConfig;
     ProcessArguments = new List<string> ();
     Defaults ();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Initialize the Program given an IP Adress and a port.
        /// </summary>
        /// <param name="address">The address to listen to</param>
        /// <param name="port">The port to listen to</param>
        public Program(KastConfiguration master, Logger logger)
        {
            MainServitor = new Servitor (IPAddress.Parse(master.Get("server_address")),
                int.Parse(master.Get("server_port")));
            Log = logger;
            MasterConfig = master;
            Relay = new KastRelay (master, logger);

            // Tick delay is read in seconds
            TickDelay = (int) double.Parse(master.Get("settings_tick_delay"))*(1000);
        }
コード例 #3
0
ファイル: KastHook.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Makes a KastHook using an existing Box and a string target.
        /// </summary>
        /// <param name="box">Box.</param>
        /// <param name="target">Target.</param>
        /// <param name="option">The option to use</param> 
        public KastHook(KastBox box, string target, KastHookOption option, KastConfiguration masterConfig)
        {
            Box = box;
            Target = target;
            Option = option;

            Name = "";

            MasterConfig = masterConfig;
            Log = new Logger (masterConfig.Get("log"));
        }
コード例 #4
0
ファイル: KastRelay.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Create an empty KastRelay
        /// </summary>
        public KastRelay(KastConfiguration masterConfig, Logger log)
        {
            ActiveBoxes = new List<KastBox>();
            Feeds = new List<KastFeed> ();
            Hooks = new List<KastHook> ();
            Components = new List<KastComponent> ();

            MasterConfig = masterConfig;
            Log = log;

            Builder = new KastBuilder (MasterConfig, Log);
        }
コード例 #5
0
ファイル: KastFeed.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Create a new KastFeed from a source, destination, and configuration
        /// </summary>
        /// <param name="source">The source box</param>
        /// <param name="destination">The destination box</param>
        /// <param name="config">The configuratin</param>
        public KastFeed(KastComponent source, KastComponent destination, KastConfiguration config)
        {
            Source = source;
            Destination = destination;

            try {
                Option = BuildKastFeedOption(config.Get("option"));
                Name = config.Get("name");
            }catch(Exception e){
                Defaults ();
            }
        }
コード例 #6
0
ファイル: KastHook.cs プロジェクト: natepisarski/kast
 /// <summary>
 /// Build a KastHook using a KastConfiguration
 /// </summary>
 /// <param name="box">The box to capture.</param> 
 /// <param name="target">The string that will make this hook fire</param>
 /// <param name="config">Configuration assets, such as name and option.</param>
 public KastHook(KastComponent box, string target, KastConfiguration config, KastConfiguration masterConfig)
 {
     Box = box;
     Target = target;
     MasterConfig = masterConfig;
     Log = new Logger (masterConfig.Get("log"));
     try {
         Option = this.BuildKastHookOption(config.Get("option"));
         Name = config.Get("name");
     }catch(Exception e){
         Defaults ();
     }
 }
コード例 #7
0
ファイル: KastBox.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Build the Box using a process name and configuration
        /// </summary>
        /// <param name="procName">The name of the process</param>
        /// <param name="kc">The KastConfiguration for this Box. Accepts: args, name</param>
        public KastBox(string procName, KastConfiguration kc, KastConfiguration masterConfig, Logger log)
        {
            ProcessName = procName;
            MasterConfig = masterConfig;
            Buffer = new List<string> ();
            ProcessArguments = new List<string> ();
            Log = log;
            try{
                if(kc.Has("args"))
                    ProcessArguments = Sections.EscapeSplit(kc.Get("args"), ',');

                Name = kc.Get("name");
            }catch(Exception e){
                Defaults ();
            }
        }
コード例 #8
0
ファイル: KastRelay.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Places two named components in a feed.
        /// </summary>
        /// <param name="name1">The component with this name to match</param>
        /// <param name="name2">The component with this name to match</param>
        /// <param name="config">The configuration to use for this Feed.</param>
        public void BindComponents(string name1, string name2, KastConfiguration config)
        {
            KastComponent item1 = GetComponentByName (name1);
            KastComponent item2 = GetComponentByName (name2);

            // Weed out all possible sources of error.
            if (item1 == null || item2 == null || (!(item1 is KastBox)) || (!(item2 is KastBox)))
                return;

            var newFeed = new KastFeed (item1 as KastBox,
                              item2 as KastBox,
                              config);

            Feeds.Add (newFeed);
            Components.Add (newFeed);
        }
コード例 #9
0
ファイル: KastBuilder.cs プロジェクト: natepisarski/kast
        /// <summary>
        ///  Build the box itself
        /// </summary>
        /// <param name="source">Source lines given by the command line.</param>
        public KastComponent BuildBox(string[] source)
        {
            source = Sections.ParseSections (Sections.RepairString (source), '+');

            if(!VerifyBox(source))
                throw new Exception(MasterConfig.Get("message_misshapen_box"));

            // program arg1 arg2...
            string[] programString = source [1].Split (' ');
            var config = new KastConfiguration (KastConfiguration.BuildAssets (source [2]));
            return new KastBox(programString[0], config, MasterConfig, Log);
        }
コード例 #10
0
ファイル: KastBuilder.cs プロジェクト: natepisarski/kast
 /// <summary>
 /// Initializes a KastBuilder with a configuration and a log
 /// </summary>
 /// <param name="masterConfig">The master configuration</param>
 /// <param name="log">Log.</param>
 public KastBuilder(KastConfiguration masterConfig, Logger log)
 {
     MasterConfig = masterConfig;
     Log = log;
 }
コード例 #11
0
ファイル: KastBuilder.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Build the Hook itself
        /// </summary>
        /// <param name="source">Source lines given by the command line.</param>
        public KastComponent BuildHook(string[] source)
        {
            source = Sections.ParseSections (Sections.RepairString (source), '|');

            if (!VerifyHook (source))
                throw new Exception (MasterConfig.Get("message_misshapen_hook"));

            var configuration = new KastConfiguration (KastConfiguration.BuildAssets (source [3]));

            KastComponent hook;

            // This Hook is a future!
            hook = (source [1] [0].Equals ('@')) ?
                BuildFuture (source [1]) :
                BuildBox (source [1].Split (' '));

            return new KastHook(
                hook,
                source [2],
                configuration,
                MasterConfig
            );
        }
コード例 #12
0
ファイル: KastBuilder.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Create a new Feed given a list of arguments
        /// </summary>
        /// <param name="source">Source lines given by the command line.</param>
        public KastComponent BuildFeed(string[] source)
        {
            // Get the sections in the format [feed, source, destination, assets]
            source = Sections.ParseSections (Sections.RepairString(source), '|');

            if (!VerifyFeed (source))
                throw new Exception (MasterConfig.Get("message_misshapen_feed"));

            var configuration = new KastConfiguration (KastConfiguration.BuildAssets(source [3]));

            KastComponent sourceComp;
            KastComponent destinationComp;

            sourceComp =  (source [1] [0].Equals ('@')) ?
                BuildFuture (source [1]) :
                BuildBox (source [1].Split (' '));

            destinationComp = (source [2] [0].Equals ('@')) ?
                BuildFuture (source [2]) :
                BuildBox (source [2].Split (' '));

            return new KastFeed (sourceComp, destinationComp, configuration);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Either creates a server in this thread, or sends data to a running server.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            //*
            Console.WriteLine ();

            // Help the user if they need it
            if (args.Length == 0 || args [0].Equals ("help")){
                if (args.Length > 1)
                    Console.WriteLine (Help (args [1]));
                else
                    Console.WriteLine (Help ());
                return;
            }

            // If it's not asking for help, server, or client, just exit.
            if (!(args [0].Equals ("server") || args [0].Equals ("client"))) {
                Console.WriteLine ("Unrecognized command. Exiting kast. Use \"kast help\" for help.");
                Environment.Exit (0);
            }

            var masterConfig = new KastConfiguration ();

            // Is there a command line flag specifying the configuration?
            if (args.Length > 1 && args [1].Equals ("file"))
                masterConfig.Load (args [2]);
            else
                masterConfig = new KastConfiguration(KastConfiguration.DefaultConfiguration ());

            var logger = new Logger (masterConfig.Get("server_log"));

            if(args[0].Equals("server")){
                var server = new Server.Program (masterConfig, logger);
                server.Start ();
            } else {
                // Send everything but "client" and "file" if it exists
                var client = new Client.Program (masterConfig, logger);
                client.main(Transformations.Subsequence (args, (args[1].Equals("file")?3:1), args.Length).AsArray());
            }
            //*/
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: natepisarski/kast
        /// <summary>
        /// Until the project is mature, I will be using this to test the program
        /// </summary>
        public static void Test()
        {
            //*
            KastConfiguration master = new KastConfiguration ();
            master = new KastConfiguration(KastConfiguration.DefaultConfiguration ());

            Logger log = new Logger (master.Get("server_log"));

            Kast.Server.Program server = new Kast.Server.Program (master, log);
            Kast.Client.Program client = new Kast.Client.Program (master, log);

            // The server is running now
            new Thread (new ThreadStart (server.Start)).Start ();

            client.SendData ("box gshfdkgj sdgfjk");

            Console.WriteLine ("Successful test");
            //*/
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: natepisarski/kast
 /// <summary>
 /// Initializes a new instance of the Program, with the masterConfig
 /// configuration
 /// </summary>
 /// <param name="masterConfig">The configuration to use for the client</param>
 /// <param name="log">The logger to write to</param>
 public Program(KastConfiguration masterConfig, Logger log)
 {
     MasterConfig = masterConfig;
     Log = log;
 }
コード例 #16
0
ファイル: Program.cs プロジェクト: natepisarski/kast
 /// <summary>
 /// Create a new Server, listening to the
 /// default port of 4206.
 /// <param name="master">The master configuration to use</param>
 /// </summary>
 public Program(KastConfiguration master)
 {
     MainServitor = new Servitor();
     Relay = new KastRelay(master, new Logger(master.Get("log")));
     TickDelay = 1000;
 }