Beispiel #1
0
        private async Task ProcessMessageCallback(CallbackData data)
        {
            if (data.Event == "message")
            {
                var messageText = ((TextMessage)data.Message).Text;

                if (messageText.ToLower() == "start")
                {
                    data.Message.TrackingData = ViberBotTrackingData.Empty();
                    await MenuAction.Execute(data);

                    return;
                }
                if (messageText.ToLower() == "cancel" || data.Message.TrackingData == null)
                {
                    data.Message.TrackingData = ViberBotTrackingData.Empty();
                    await DefaultAction.Execute(data);

                    return;
                }
                if (messageText.ToLower() == "help")
                {
                    data.Message.TrackingData = ViberBotTrackingData.Empty();
                    await HelpAction.Execute(data);

                    return;
                }
                try
                {
                    var trackingData = JsonConvert.DeserializeObject <ViberBotTrackingData>(data.Message.TrackingData);

                    if (messageText.Contains("Action"))
                    {
                        trackingData.NextAction = messageText;
                    }

                    if (trackingData != null && !string.IsNullOrEmpty(trackingData.NextAction))
                    {
                        Type magicType = Type.GetType($"ViberBot.Client.Actions.{trackingData.NextAction}");
                        if (magicType != null)
                        {
                            MethodInfo magicMethod = magicType.GetMethod("Execute");
                            magicMethod.Invoke(null, new object[] { data });
                        }
                    }
                    else
                    {
                        await DefaultAction.Execute(data);
                    }
                }
                catch
                {
                    await SendTextMessage(data.Sender.Id, BotError.SomethingWentWrong);
                }
            }
        }
Beispiel #2
0
        private static void AddRemoveHelp(HelpAction action)
        {
            string shellName       = ExtensionInformation.Shell.Name;
            string shellVersion    = ExtensionInformation.Shell.Version;
            string helpPackagePath = ExtensionInformation.GetContentLocation("MSHelp");

            if (helpPackagePath == null)
            {
                Logging.Log(Logging.Severity.Error, "Could not get help package content location");
                return;
            }

            string helpManagerArguments = string.Format(@"/catalogName {0}{1} /locale en-us", shellName, shellVersion.Replace(".", ""));

            switch (action)
            {
            case HelpAction.INSTALL_HELP:
                helpManagerArguments += string.Format(@" /operation install /sourceuri ""{0}""", helpPackagePath);
                break;

            case HelpAction.UNINSTALL_HELP:
                helpManagerArguments += string.Format(@" /operation uninstall /sourceuri ""{0}""", helpPackagePath);
                break;

            default:
                throw new NotImplementedException();
            }

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.UseShellExecute = true;
            startInfo.FileName        = GetHelpManagerPath();
            startInfo.Arguments       = helpManagerArguments;
            startInfo.Verb            = "runas";

            try
            {
                Logging.Log(Logging.Severity.Information, "Help install action {0} started with Help manager arguments: {1}", action, startInfo.Arguments);
                Process p = Process.Start(startInfo);
                p.Exited += (s, e) => { Logging.Log(Logging.Severity.Information, "Help install action {0} exited with code {1}", action, p.ExitCode); };

                if ((p != null) && (action == HelpAction.UNINSTALL_HELP))
                {
                    p.WaitForExit();
                }
            }
            catch (Exception e)
            {
                Logging.Log(Logging.Severity.Error, "Could not execute help install action {0}: {1}", action, e.Message);
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Ball on Chair!");

            // Wire up dependencies
            var ledgerService = new JsonBackedLedgerService(SystemClock.Instance, PersistenceDirectory);
            var playerService = new JsonBackedPlayerService(PersistenceDirectory);
            var roundService  = new JsonBackedRoundService(playerService, ledgerService, SystemClock.Instance, PersistenceDirectory);

            // Link Actions
            var exit = new ExitContainer();
            var autocompleteActions = new List <CliActionBase>
            {
                new AddPlayerAction(playerService),
                new RemovePlayerFromRoundAction(playerService, roundService, ledgerService),
                new CashOutPlayerAction(playerService, ledgerService),
                new CreditPlayerAction(playerService, ledgerService),
                new ViewPlayerAction(playerService, ledgerService, roundService),
                new RenamePlayerAction(playerService),
                new ListRoundsAction(roundService),
                new ViewRoundAction(roundService, playerService),
                new ListPlayersAction(playerService, ledgerService),
                new ListPositivePlayersAction(playerService, ledgerService),
                new ExitAction(exit),
                new StartRoundAction(roundService),
                new AddPlayerToRoundAction(playerService, roundService, ledgerService),
                new ListEntrantsRoundAction(roundService, playerService),
                new WinRoundAction(playerService, roundService)
            };

            var helpAction = new HelpAction(autocompleteActions);

            autocompleteActions.Add(helpAction);

            var rootCompletionContainer = new AutoCompletingCliActionsContainer(autocompleteActions);
            var rootCompletionProvider  = new TabCompletionProvider(rootCompletionContainer);

            // Run it
            var root = new RootAction(rootCompletionProvider, exit);

            root.Execute();
        }
Beispiel #4
0
        public static void DoHelpAction(HelpAction action)
        {
            switch (action)
            {
            case HelpAction.INSTALL_HELP:
                ShowHelpInstallMessage();
                AddRemoveHelp(HelpAction.INSTALL_HELP);
                break;

            case HelpAction.UNINSTALL_HELP:
                AddRemoveHelp(HelpAction.UNINSTALL_HELP);
                break;

            case HelpAction.REINSTALL_HELP:
                AddRemoveHelp(HelpAction.UNINSTALL_HELP);
                ShowHelpInstallMessage();
                AddRemoveHelp(HelpAction.INSTALL_HELP);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #5
0
 private void extButtonDrawnHelp_Click(object sender, EventArgs e)
 {
     HelpAction?.Invoke(panelStrip.PointToScreen(new Point(extButtonDrawnHelp.Left, extButtonDrawnHelp.Bottom)));
 }
Beispiel #6
0
        private static IEnumerable <IAction> EnumerateActions(Context context)
        {
            var pack     = context.Pack;
            var options  = context.Options;
            var settings = context.Settings;

            if (HelpAction.IsHelpAction(options))
            {
                yield return(new HelpAction());
            }
            else if (options.ChainOn)
            {
                var actions  = options.ChainValue.Split(' ');
                var iterator = actions.Cast <string>().GetEnumerator();
                while (iterator.MoveNext())
                {
                    var action = iterator.Current;
                    switch (action)
                    {
                    case "init":
                        yield return(new InitAction());

                        break;

                    case "install":
                        yield return(new InstallAction());

                        break;

                    case "upgrade":
                        yield return(new UpgradeAction());

                        break;

                    case "pack":
                        yield return(new PackAction());

                        break;

                    case "deploy":
                        yield return(new DeployAction());

                        break;

                    case "serve":
                        //yield return new ServeAction();
                        break;

                    case "index":
                        yield return(new IndexAction());

                        break;

                    case "authorize":
                        yield return(new AuthorizeAction());

                        break;

                    case "search":
                        while (iterator.MoveNext())
                        {
                            options.FilterValue.Add(iterator.Current);
                        }
                        options.FilterOn = options.FilterValue.Any();
                        yield return(new SearchAction());

                        break;

                    default:
                        throw new PackDmException("Ação não implementada: " + action);
                    }
                }
            }
        }