Ejemplo n.º 1
0
        /// <summary>
        /// The entry point to the program.
        /// <param name="args">The arguments to this program.</param>
        /// </summary>
        public static void Main(string[] args)
        {
            // Check the pre-conditions:
            if(args.Length < 3)
            {
                Console.WriteLine("Please provide as argument:");
                Console.WriteLine("... (1) the ICCC password");
                Console.WriteLine("... (2) your Ocean server's IP address and port e.g. 127.0.0.1:50000");
                Console.WriteLine("... (3) the port where this instance of the program should use e.g. 51000");
                return;
            }

            // Register the own listener:
            var tmpMessage = new ICCCMyListenerCommand(); Registrar.INSTANCE.addLocalListener(tmpMessage.getChannel(), tmpMessage.getCommand(), ICCCMyListenerReceiver.myListenerReceiver);

            // Run the interactive shell:
            Task.Run(function: input);

            // Get the current version of the program:
            var versionAttribute = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).FirstOrDefault() as AssemblyFileVersionAttribute;

            // Finally, start the ICCC server. Thus, this call will block forever:
            ICCCSetup.INSTANCE.startAndBlock("Example005", versionAttribute.Version, args[0], new string[] { args[1] }, "127.0.0.1:" + args[2]);
        }
Ejemplo n.º 2
0
        static Task<bool> input()
        {
            printHelp();
            while(true)
            {
                Console.WriteLine("Type help to see all commands!");
                var line = Console.ReadLine(); Console.WriteLine();

                if(line.StartsWith("log="))
                {
                    var messageText = line.Replace("log=", string.Empty);
                    ICCCLog.INSTANCE.logShort("Interactive Ocean Console", LogCategory.APP, LogLevel.INFO, LogMessageName.USER, messageText);
                    Console.WriteLine("Was send to the logging system");
                }

                if(line == "help")
                {
                    printHelp();
                }

                if(line == "send")
                {
                    // Build the message:
                    var message = new ICCCMyListenerCommand();

                    // Bring in some payload i.e. data:
                    message.Factor2Use = 0.48645;
                    message.MyInput2Process = new string[] { "Hello", "World!" };

                    // Send the message:
                    var answer = ICCCConnection.INSTANCE.send2Any(message, ICCCKind.KindALL) as ICCCMyListenerCommandAnswer;

                    // Print the result:
                    if(answer == null)
                    {
                        Console.WriteLine("No answer was present!");
                    }
                    else
                    {
                        Console.WriteLine("The answer is: successful={0}; clusterName={1}", answer.ProcessSuccessful, answer.DestinationClusterName);
                    }
                }

                if(line == "exit")
                {
                    ICCCSetup.INSTANCE.shutdown();
                }

                if(line == "cls")
                {
                    Console.Clear();
                }

                if(line == "ping")
                {
                    var answers = ICCCConnection.INSTANCE.send2All(new ICCCPing(), ICCCKind.KindALL);
                    foreach(var a in answers)
                    {
                        var obj = a as ICCCDefaultAnswer;
                        if(obj != null)
                            Console.WriteLine("ping!");
                    }
                }

                if(line == "version")
                {
                    var answers = ICCCConnection.INSTANCE.send2All(new ICCCGetVersion(), ICCCKind.KindALL);
                    foreach(var a in answers)
                    {
                        var obj = a as ICCCGetVersionAnswer;
                        if(obj != null)
                        {
                            Console.WriteLine("Version: name='{0}', kind={1}, version='{2}'", obj.Name, obj.Kind, obj.Version);
                        }
                    }
                }

                if(line == "NumGen")
                {
                    var answer = ICCCConnection.INSTANCE.send2Any(new ICCCNumGenNext(), ICCCKind.KindOcean);
                    var obj = answer as ICCCNumGenNextAnswer;
                    if(obj != null)
                    {
                        Console.WriteLine("Your next unique number={0}", obj.Number);
                    }
                }
            }

            return Task.FromResult<bool>(true);
        }