示例#1
0
        public async Task MainAsync(string[] args)
        {
            // TODO: remove this
#if DEBUG
            if (args == null || args.Length == 0)
            {
                Write("[Debug] Enter Command: ");
                args = new[] { ReadLine() };
            }
#endif

            var config = new Configuration();
            config.AddJsonFile("config.json");
            config.AddEnvironmentVariables();

            // check args
            if (args == null ||
                args.Length == 0 ||
                args[0].ToLowerInvariant() == "h" ||
                args[0].ToLowerInvariant() == "help")
            {
                // write help
                var commands =
                    Environment.NewLine + Environment.NewLine +
                    "Xbox Live Enviroment Api - Build " + "alpha 0001" +
                    Environment.NewLine + Environment.NewLine +
                    "USAGE: xbl <command> [options]" +
                    Environment.NewLine + Environment.NewLine +

                    "  xbl login				description_1"+ Environment.NewLine +
                    "  xbl refresh				description_2"+ Environment.NewLine +
                    "  xbl help					description_3"+ Environment.NewLine;

                WriteLine(commands);

#if DEBUG
                ReadLine();
#endif

                return;
            }

            var validInput = false;
            switch (args[0].ToLowerInvariant())
            {
            case "login":
                string windowsLiveAuthenticationServer = null;
                if (!config.TryGet("windows_live_authentication_server", out windowsLiveAuthenticationServer))
                {
                    windowsLiveAuthenticationServer = "http://xdc-wl-auth-api.herokuapp.com/windowslive/authentication/create";
                }
                await Login(windowsLiveAuthenticationServer);

                validInput = true;
                break;

            case "refresh":
                if (!ValidateAuth())
                {
                    return;
                }
                await RefreshTokens(true);

                validInput = true;
                break;

            case "summary":
                if (!ValidateAuth())
                {
                    return;
                }
                await RefreshTokens();

                var settings = GetSettings();

                var xuid = args.Length > 1 ? args[1] : settings.XboxUserId.ToString();
                await Xuid.Summary(settings.Token, settings.UserHeaderSession, xuid);

                validInput = true;
                break;
            }

            if (!validInput)
            {
                WriteLine("No valid command specified - type `xbl help` for a list of options");
            }

#if DEBUG
            ReadLine();
#endif
        }