Esempio n. 1
0
        private void CommandWindow(CommandModel cmd)
        {
            if (cmd.Parameter == "close")
            {
                f_ChatViewManager.CurrentChat.Close();
                return;
            }
            else if (cmd.Parameter == "list")
            {
                var thisChatView = f_MainWindow.ChatViewManager.GetChat(cmd.Chat);

                for (int i = 0;; ++i)
                {
                    ChatView availableChatView = f_MainWindow.ChatViewManager.GetChat(i);
                    if (availableChatView == null)
                    {
                        break;
                    }

                    var builder = new MessageBuilder();
                    builder.AppendEventPrefix();
                    builder.AppendFormat("{0} - {1}", i + 1, availableChatView.Name ?? "");
                    thisChatView.AddMessage(builder.ToMessage());
                }
                return;
            }

            int window;

            if (!Int32.TryParse(cmd.Parameter, out window))
            {
                return;
            }
            ChatView chat = f_ChatViewManager.GetChat(window - 1);

            if (chat == null)
            {
                return;
            }
            f_ChatViewManager.CurrentChat = chat;
        }
Esempio n. 2
0
        public void CommandBenchmarkMessageBuilder(CommandModel cmd)
        {
            Trace.Call(cmd);

            var count         = 1000;
            var showHelp      = false;
            var appendMessage = false;
            var appendText    = false;
            var appendEvent   = false;
            var appendFormat  = false;
            var toMessage     = false;

            try {
                var opts = new NDesk.Options.OptionSet()
                {
                    { "c|count=", v => count = Int32.Parse(v) },
                    { "m|append-message", v => appendMessage = true },
                    { "t|append-text", v => appendText = true },
                    { "e|append-event", v => appendEvent = true },
                    { "f|append-format", v => appendFormat = true },
                    { "T|to-message", v => toMessage = true },
                };
                opts.Add("h|?|help", x => {
                    showHelp   = true;
                    var writer = new StringWriter();
                    opts.WriteOptionDescriptions(writer);
                    AddMessageToFrontend(
                        cmd,
                        CreateMessageBuilder().
                        AppendHeader("{0} usage", cmd.Command).
                        AppendText("\n").
                        AppendText("Parameters:\n").
                        AppendText(writer.ToString()).
                        ToMessage()
                        );
                    return;
                });
                opts.Parse(cmd.Parameter.Split(' '));
                if (showHelp)
                {
                    return;
                }
            } catch (Exception ex) {
                AddMessageToFrontend(
                    cmd,
                    CreateMessageBuilder().
                    AppendErrorText("Invalid parameter: {0}", ex.Message).
                    ToMessage()
                    );
                return;
            }

            DateTime start, stop;

            start = DateTime.UtcNow;
            MessageBuilder builder;

            for (var i = 0; i < count; i++)
            {
                builder = new MessageBuilder();
                if (appendMessage)
                {
                    builder.AppendMessage("This is message with a link to https://www.smuxi.org/.");
                }
                if (appendText)
                {
                    builder.AppendText("This is message with just text.");
                }
                if (appendEvent)
                {
                    builder.AppendEventPrefix();
                }
                if (appendFormat)
                {
                    builder.AppendFormat("{0} [{1}] has joined {2}",
                                         "meebey3",
                                         "[email protected]",
                                         "#smuxi-devel");
                }
                if (toMessage)
                {
                    var msg = builder.ToMessage();
                }
            }
            stop = DateTime.UtcNow;

            builder = new MessageBuilder();
            builder.AppendText("MessageBuilder().");
            if (appendMessage)
            {
                builder.AppendText("AppendMessage().");
            }
            if (appendText)
            {
                builder.AppendText("AppendText().");
            }
            if (appendEvent)
            {
                builder.AppendText("AppendEventPrefix().");
            }
            if (appendFormat)
            {
                builder.AppendText("AppendFormat().");
            }
            if (toMessage)
            {
                builder.AppendText("ToMessage()");
            }
            builder.AppendText(
                " count: {1} took: {2:0} ms avg: {3:0.00} ms",
                cmd.Data,
                count,
                (stop - start).TotalMilliseconds,
                (stop - start).TotalMilliseconds / count
                );
            AddMessageToFrontend(cmd, builder.ToMessage());
        }