Exemple #1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     host = new ServiceHost(typeof(Services));
     localhost.Content = GetIp.GetLocalIP();
     try
     {
         host.Open();
     }
     catch (Exception)
     {
         throw;
     }
     #region Remote Spy
     Action <Message> action = message =>
     {
         string s1 = null;
         string s2 = null;
         if (message.Sender == p1)
         {
             s1 = "我自己";
         }
         else
         {
             s1 = message.Sender.Name.ToString();
         }
         if (message.Receiver == null)
         {
             s2 = "对大家群聊说:";
         }
         else
         {
             s2 = string.Format("对{0}私聊说:", message.Receiver.Name);
         }
         this.listening_box.Items.Add(s1 + s2 + message.Word);
     };
     var anotherToken = Services.hub.Subscribe(action);
     #endregion
     #region Add
     Action <string> add = operate =>
     {
         //异步委托处理
         Dispatcher.BeginInvoke(new Action(delegate
         {
             online_users.Items.Clear();
             foreach (var l in Services.People)
             {
                 this.online_users.Items.Add(l.Name);
                 l.CallBackmessage.Onlineuser(Services.People);
             }
         }));
     };
     var Token1 = Services.hubadd.Subscribe(add);
 }
Exemple #2
0
 void Start()
 {
     Instance = this;
 }
Exemple #3
0
        public static int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name        = "ConsoleApp",
                Description = "An required assignment",
            };

            app.HelpOption(inherited: true);

            //Number 1
            /*------------------------------------------------------------------------*/
            app.Command("uppercase", setCmd =>
            {
                var word = setCmd.Argument("key", "Name of the config").IsRequired();
                setCmd.OnExecute(() =>
                {
                    Console.WriteLine(StringTransform.Uppercase(word.Value));
                });
            });

            app.Command("lowercase", setCmd =>
            {
                setCmd.Description = "Set config value";
                var word           = setCmd.Argument("key", "Name of the config").IsRequired();
                setCmd.OnExecute(() =>
                {
                    Console.WriteLine(StringTransform.Lowercase(word.Value));
                });
            });

            app.Command("capitalize", setCmd =>
            {
                setCmd.Description = "Set config value";
                var word           = setCmd.Argument("key", "Name of the config").IsRequired();
                setCmd.OnExecute(() =>
                {
                    Console.WriteLine(StringTransform.Capitalize(word.Value));
                });
            });

            //Number 2
            /*------------------------------------------------------------------------*/


            app.Command("add", cmd =>
            {
                var files = cmd.Argument("numbers", "numbers to count", multipleValues: true);
                cmd.OnExecute(() =>
                {
                    var result = Arithmetic.DoArithmetic(files.Values, "add");

                    Console.WriteLine(result);
                });
            });

            app.Command("substract", cmd =>
            {
                var files = cmd.Argument("numbers", "numbers to count", multipleValues: true);
                cmd.OnExecute(() =>
                {
                    var result = Arithmetic.DoArithmetic(files.Values, "substract");

                    Console.WriteLine(result);
                });
            });

            app.Command("multiply", cmd =>
            {
                var files = cmd.Argument("numbers", "numbers to count", multipleValues: true);
                cmd.OnExecute(() =>
                {
                    var result = Arithmetic.DoArithmetic(files.Values, "multiply");

                    Console.WriteLine(result);
                });
            });

            app.Command("divide", cmd =>
            {
                var files = cmd.Argument("numbers", "numbers to count", multipleValues: true);
                cmd.OnExecute(() =>
                {
                    var result = Arithmetic.DoArithmetic(files.Values, "divide");

                    Console.WriteLine(result);
                });
            });

            //Number 3
            /*------------------------------------------------------------------------*/

            app.Command("palindrome", setCmd =>
            {
                setCmd.Description = "Set c onfig value";
                var word           = setCmd.Argument("key", "Name of the config").IsRequired();
                setCmd.OnExecute(() =>
                {
                    var result = Palindrome.IsPalindrome(word.Value);
                    if (result == true)
                    {
                        Console.WriteLine("Is Palindrome? Yes");
                    }
                    else
                    {
                        Console.WriteLine("Is Palindrome? No");
                    }
                });
            });

            //Number 4
            /*------------------------------------------------------------------------*/

            app.Command("obfuscator", setCmd =>
            {
                setCmd.Description = "Set c onfig value";
                var word           = setCmd.Argument("key", "Name of the config").IsRequired();
                setCmd.OnExecute(() =>
                {
                    Console.WriteLine(Obfuscator.Obfuscate(word.Value));
                });
            });

            app.OnExecute(() =>
            {
                Console.WriteLine("Specify a subcommand");
                app.ShowHelp();
                return(1);
            });

            //Number 5
            /*------------------------------------------------------------------------*/


            app.Command("random", cmd =>
            {
                var length                = cmd.Option("--length", "setting random length", CommandOptionType.SingleOrNoValue);
                var letters               = cmd.Option("--letters", "setting letters availability", CommandOptionType.SingleOrNoValue);
                var numbers               = cmd.Option("--numbers", "setting numbers availability", CommandOptionType.SingleOrNoValue);
                var lowercase             = cmd.Option("--lowercase", "setting lowercase", CommandOptionType.NoValue);
                RandomGenerator generator = new RandomGenerator();
                cmd.OnExecute(() =>
                {
                    int num = Convert.ToInt32(length.Value());
                    string result;
                    if (!length.HasValue())
                    {
                        num = 32;
                    }

                    if (!letters.HasValue() || numbers.HasValue())
                    {
                        result = generator.GenerateNum(num);
                    }
                    else if (letters.HasValue() || !numbers.HasValue())
                    {
                        result = generator.GenerateLet(num);
                    }
                    else
                    {
                        result = generator.GenerateAll(num);
                    }

                    if (lowercase.HasValue())
                    {
                        result = result.ToLower();
                    }

                    Console.WriteLine(result);
                });
            });

            //Number 6
            /*------------------------------------------------------------------------*/

            app.Command("ip", cmd =>
            {
                cmd.OnExecute(() =>
                {
                    Console.WriteLine(GetIp.GetLocalIPAddress());
                });
            });

            //Number 7
            /*------------------------------------------------------------------------*/

            app.Command("ip-external", cmd =>
            {
                cmd.OnExecute(() =>
                {
                    Console.WriteLine(GetIp.GetPublicIp());
                });
            });

            //Number 8
            /*------------------------------------------------------------------------*/

            app.Command("screenshot", cmd =>
            {
                var link   = cmd.Argument("link", "link to be screenshot").IsRequired();
                var format = cmd.Option("--format", "the format", CommandOptionType.SingleOrNoValue);
                var output = cmd.Option("--output", "the output", CommandOptionType.SingleOrNoValue);
                cmd.OnExecute(() =>
                {
                    if (format.HasValue() && output.HasValue())
                    {
                        Screenshot.GetScreenshot(link.Value, format.Value(), output.Value());
                    }
                    else if (format.HasValue())
                    {
                        Screenshot.GetScreenshot(link.Value, format.Value());
                    }
                    else if (output.HasValue())
                    {
                        Screenshot.GetScreenshot(link.Value, default, output.Value());