private static async Task <int> CommitDocumentsAsync(CommitDocumentsOptions options) { if (options.DocumentType == DocumentType.Sandbox && string.IsNullOrEmpty(options.Sandbox)) { throw new ArgumentException("Sandbox must be specified when committing sandbox documents."); } if (options.DocumentType == DocumentType.Account) { options.Sandbox = null; } IEnumerable <string> files = Glob(options.Files); int fileCount = files.Count(); if (fileCount == 0) { Console.Error.WriteLine("There are no files selected to commit."); return(-1); } Console.WriteLine($"Committing {fileCount} file(s) to Xbox Live."); string eTag = options.ETag ?? GetETag(files, options.Sandbox); if (options.Force) { eTag = null; } Task <ConfigResponse <ValidationResponse> > documentsTask; if (options.DocumentType == DocumentType.Sandbox) { Console.WriteLine("Committing sandbox documents."); documentsTask = ConfigurationManager.CommitSandboxDocumentsAsync(files, options.Scid, options.Sandbox, eTag, options.ValidateOnly, options.Message); } else { Console.WriteLine("Committing account documents."); if (options.AccountId == Guid.Empty) { DevAccount user = ToolAuthentication.LoadLastSignedInUser(); options.AccountId = new Guid(user.AccountId); } documentsTask = ConfigurationManager.CommitAccountDocumentsAsync(files, options.AccountId, eTag, options.ValidateOnly, options.Message); } ConfigResponse <ValidationResponse> result = await documentsTask; SaveETag(result.Result.ETag, Path.GetDirectoryName(files.First()), options.Sandbox); Console.WriteLine($"Can Commit: {result.Result.CanCommit}"); Console.WriteLine($"Committed: {result.Result.Committed}"); PrintValidationInfo(result.Result.ValidationInfo); return(0); }
/// <inheritdoc /> protected override void BeginProcessing() { DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (this.RequiresAuthorization) { if (account == null) { throw new Exception("Didn't find dev signin info, please use \"Connect-DevAccount\" to initiate."); } if (account.AccountSource != DevAccountSource.WindowsDevCenter) { throw new Exception("You must sign in with a valid Windows Dev Center account."); } } PropertyInfo accountIdProperty = this.GetType().GetProperty("AccountId"); if (accountIdProperty != null && account != null) { Guid accountIdPropertyValue = (Guid)accountIdProperty.GetValue(this); if (accountIdPropertyValue == Guid.Empty) { accountIdProperty.SetValue(this, new Guid(account.AccountId)); } } }
public override void Initialize(LayoutElementsContainer layout) { DevAccount devAccount = ToolAuthentication.LoadLastSignedInUser(); layout.Header("Account"); if (devAccount != null) { layout.Label("Username: "******"Id: " + devAccount.Id); layout.Label("Type: " + devAccount.AccountType); } else { layout.Label("Not logged in"); } layout.Header("Sandbox"); var sb = layout.TextBox(); var setSb = layout.Button("Set Sandbox"); setSb.Button.Clicked += () => SandboxHelper.SetSandbox(sb.Text); var retail = layout.Button("Switch to retail"); setSb.Button.Clicked += () => SandboxHelper.SetSandbox("RETAIL"); }
private async void SingInout_Click(object sender, EventArgs e) { try { this.btnSingInout.Enabled = false; if (this.signedInuser != null) { ToolAuthentication.SignOut(); this.signedInuser = null; } else { DevAccountSource accountSource = DevAccountSource.WindowsDevCenter; this.signedInuser = await ToolAuthentication.SignInAsync(accountSource, null); } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error"); } finally { this.UpdateAccountPanel(); this.btnSingInout.Enabled = true; } }
private static void DisplayDevAccount(DevAccount devAccount, string indent) { Console.WriteLine($"{indent}ID : {devAccount.Id}"); Console.WriteLine($"{indent}Publisher ID : {devAccount.AccountId}"); Console.WriteLine($"{indent}AccountType : {devAccount.AccountType}"); Console.WriteLine($"{indent}AccountMoniker : {devAccount.AccountMoniker}"); Console.WriteLine($"{indent}AccountSource : {devAccount.AccountSource}"); }
private static async Task <int> Main(string[] args) { Options options = null; try { // Only assign the option and verb here, as the commandlineParser doesn't support async callback yet. ParserResult <Options> result = Parser.Default.ParseArguments <Options>(args) .WithParsed(parsedOptions => { options = parsedOptions; }); if (options == null) { Console.Error.WriteLine("Parsing parameters error."); return(-1); } DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account == null) { Console.Error.WriteLine("Didn't found dev sign in info, please use \"XblDevAccount.exe signin\" to initiate."); return(-1); } Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}"); return(await OnDownload(options)); } catch (HttpRequestException ex) { Console.WriteLine($"Error: XblConnectedStorage failed."); if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized))) { Console.WriteLine( $"Unable to authorize the account with XboxLive service with scid : {options?.ServiceConfigurationId} and sandbox : {options?.Sandbox}, please contact your administrator."); } else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden))) { Console.WriteLine( "Your account doesn't have access to perform the operation, please contact your administrator."); } else { Console.WriteLine(ex.Message); } return(-1); } catch (Exception ex) { Console.Error.WriteLine("Error: unexpected error found."); Console.Error.WriteLine(ex.Message); return(-1); } }
/// <inheritdoc/> protected override void Process() { if (!Enum.TryParse(this.AccountSource, out AccountSourceOption source)) { throw new ArgumentException("Invalid account source. Must be either 'WindowsDevCenter'.", nameof(this.AccountSource)); } DevAccount devAccount = ToolAuthentication.SignInAsync((DevAccountSource)source, this.UserName).Result; this.WriteObject($"Developer account {devAccount.Name} has successfully signed in."); this.WriteObject(devAccount); }
/// <inheritdoc/> protected override void Process() { DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account != null) { this.WriteObject($"Developer account {account.Name} from {account.AccountSource} is currently signed in."); this.WriteObject(account); } else { this.WriteObject($"No signed in account found."); } }
private static int OnSignOut() { DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account != null) { ToolAuthentication.SignOut(); Console.WriteLine($"Developer account {account.Name} from {account.AccountSource} has successfully signed out."); return(0); } else { Console.WriteLine($"No signed in account found."); return(-1); } }
private static int OnShow() { DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account != null) { Console.WriteLine($"Developer account {account.Name} from {account.AccountSource} is currently signed in."); DisplayDevAccount(account, "\t"); return(0); } else { Console.WriteLine($"No signed in account found."); return(-1); } }
private void UpdateAccountPanel() { this.signedInuser = ToolAuthentication.LoadLastSignedInUser(); if (this.signedInuser != null) { this.btnSingInout.Text = "Sign Out"; this.cmbAccountSource.Enabled = false; this.labelUserName.Text = this.signedInuser.Name; this.btnQuery.Enabled = true; } else { this.btnSingInout.Text = "Sign In"; this.cmbAccountSource.Enabled = true; this.labelUserName.Text = string.Empty; this.btnQuery.Enabled = false; } }
protected override void ProcessRecord() { try { DevAccountSource accountType = DevAccountSource.UniversalDeveloperCenter; if (AccountSource.Equals("XboxDeveloperPortal", StringComparison.OrdinalIgnoreCase) || AccountSource.Equals("XDP", StringComparison.OrdinalIgnoreCase)) { accountType = DevAccountSource.XboxDeveloperPortal; } DevAccount account = Microsoft.Xbox.Services.Tool.Auth.SignIn(accountType, UserName).Result; WriteObject(account); } catch (AggregateException e) { var innerEx = e.InnerException; WriteError(new ErrorRecord(innerEx, "Set-XBLDevUdcAccount failed", ErrorCategory.SecurityError, null)); } }
private static async Task <int> OnReset(ResetOptions options) { string xuid = string.Empty; if (options == null) { Console.WriteLine("Unknown parameter error"); return(-1); } if (!string.IsNullOrEmpty(options.TestAccount)) { TestAccount testAccount = await ToolAuthentication.SignInTestAccountAsync(options.TestAccount, options.Sandbox); if (testAccount == null) { Console.Error.WriteLine($"Failed to log in to test account {options.TestAccount}."); return(-1); } xuid = testAccount.Xuid; Console.WriteLine($"Using Test account {options.TestAccount} ({testAccount.Gamertag}) with xuid {xuid}"); } else if (!string.IsNullOrEmpty(options.XboxUserId)) { DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account == null) { Console.Error.WriteLine("Resetting by XUID requires a signed in Partner Center account. Please use \"XblDevAccount.exe signin\" to log in."); return(-1); } xuid = options.XboxUserId; Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}"); } Console.WriteLine($"Resetting data for player with XUID {xuid} for SCID {options.ServiceConfigurationId} in sandbox {options.Sandbox}"); try { UserResetResult result = await PlayerReset.ResetPlayerDataAsync( options.ServiceConfigurationId, options.Sandbox, xuid); switch (result.OverallResult) { case ResetOverallResult.Succeeded: Console.WriteLine("Player data has been reset successfully."); return(0); case ResetOverallResult.CompletedError: Console.WriteLine("An error occurred while resetting player data:"); if (!string.IsNullOrEmpty(result.HttpErrorMessage)) { Console.WriteLine($"\t{result.HttpErrorMessage}"); } PrintProviderDetails(result.ProviderStatus); return(-1); case ResetOverallResult.Timeout: Console.WriteLine("Player data reset has timed out:"); PrintProviderDetails(result.ProviderStatus); return(-1); default: Console.WriteLine("An unknown error occurred while resetting player data."); return(-1); } } catch (HttpRequestException ex) { Console.WriteLine("Error: player data reset failed"); if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized))) { Console.WriteLine( $"Unable to authorize the account with Xbox Live and scid : {options.ServiceConfigurationId} and sandbox : {options.Sandbox}, please contact your administrator."); } else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden))) { Console.WriteLine( "Your account doesn't have access to perform the operation, please contact your administrator."); } else { Console.WriteLine(ex.Message); } return(-1); } }
private static async Task <int> GetDocumentsAsync(GetDocumentsOptions options) { if (options.DocumentType == DocumentType.Sandbox && string.IsNullOrEmpty(options.Sandbox)) { throw new ArgumentException("Sandbox must be specified when obtaining sandbox documents."); } if (options.DocumentType == DocumentType.Sandbox && options.Scid == Guid.Empty) { throw new ArgumentException("SCID must be specified when obtaining sandbox documents."); } if (options.DocumentType == DocumentType.Account) { options.Sandbox = null; } EnsureDirectory(options.Destination); Task <DocumentsResponse> documentsTask; if (options.DocumentType == DocumentType.Sandbox) { Console.WriteLine("Obtaining sandbox documents."); documentsTask = ConfigurationManager.GetSandboxDocumentsAsync(options.Scid, options.Sandbox); } else { Console.WriteLine("Obtaining account documents."); if (options.AccountId == Guid.Empty) { DevAccount user = ToolAuthentication.LoadLastSignedInUser(); options.AccountId = new Guid(user.AccountId); } documentsTask = ConfigurationManager.GetAccountDocumentsAsync(options.AccountId); } using (DocumentsResponse documents = await documentsTask) { Console.WriteLine($"ETag: {documents.ETag}"); Console.WriteLine($"Version: {documents.Version}"); Console.WriteLine("Files: "); foreach (ConfigFileStream file in documents.Documents) { string path = Path.Combine(options.Destination, file.Name); using (FileStream fileStream = File.Create(path)) { await file.Stream.CopyToAsync(fileStream); } Console.WriteLine($" - {file.Name}"); } SaveETag(documents.ETag, options.Destination, options.Sandbox); Console.WriteLine($"Saved {documents.Documents.Count()} files to {options.Destination}."); } return(0); }
private static async Task <int> Main(string[] args) { int exitCode = 0; string invokedVerb = string.Empty; BaseOptions baseOptions = null; try { // Only assign the option and verb here, as the commandlineParser doesn't support async callback yet. var result = Parser.Default.ParseArguments <QuotaOptions, BlobMetadataOptions, DeleteOptions, DownloadOptions, UploadOptions>(args) .WithParsed(options => { var verbAttribute = Attribute.GetCustomAttribute(options.GetType(), typeof(VerbAttribute)) as VerbAttribute; invokedVerb = verbAttribute?.Name; baseOptions = options as BaseOptions; }) .WithNotParsed(err => exitCode = -1); DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account == null) { Console.Error.WriteLine("Didn't found dev sign in info, please use \"XblDevAccount.exe signin\" to initiate."); return(-1); } Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}"); if (invokedVerb == "quota" && baseOptions is QuotaOptions quotaOptions) { exitCode = await OnGetQuota(quotaOptions); } else if (invokedVerb == "list" && baseOptions is BlobMetadataOptions blobMetadataOptions) { exitCode = await OnGetBlobMetadata(blobMetadataOptions); } else if (invokedVerb == "delete" && baseOptions is DeleteOptions deleteOptions) { exitCode = await OnDelete(deleteOptions); } else if (invokedVerb == "download" && baseOptions is DownloadOptions downloadOptions) { exitCode = await OnDownload(downloadOptions); } else if (invokedVerb == "upload" && baseOptions is UploadOptions uploadOptions) { exitCode = await OnUpload(uploadOptions); } else { Console.Error.WriteLine("Parsing parameters error."); exitCode = -1; } } catch (HttpRequestException ex) { Console.WriteLine($"Error: GlobalStorage {invokedVerb} failed."); if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized))) { Console.WriteLine( $"Unable to authorize the account with XboxLive service with scid : {baseOptions?.ServiceConfigurationId} and sandbox : {baseOptions?.Sandbox}, please contact your administrator."); } else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden))) { Console.WriteLine( "Your account doesn't have access to perform the operation, please contact your administrator."); } else { Console.WriteLine(ex.Message); } return(-1); } catch (Exception ex) { Console.Error.WriteLine("Error: unexpected error found."); Console.Error.WriteLine(ex.Message); exitCode = -1; } return(exitCode); }
private static async Task <int> OnReset(ResetOptions options) { if (options == null) { Console.WriteLine("Unknown parameter error"); return(-1); } DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account == null) { Console.Error.WriteLine("Didn't found dev sign in info, please use \"XblDevAccount.exe signin\" to initiate."); return(-1); } Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}"); Console.WriteLine($"Resetting player {options.XboxUserId} data for scid {options.ServiceConfigurationId}, sandbox {options.Sandbox}"); try { UserResetResult result = await PlayerReset.ResetPlayerDataAsync( options.ServiceConfigurationId, options.Sandbox, options.XboxUserId); switch (result.OverallResult) { case ResetOverallResult.Succeeded: Console.WriteLine("Resetting has completed successfully."); return(0); case ResetOverallResult.CompletedError: Console.WriteLine("Resetting has completed with some error:"); if (!string.IsNullOrEmpty(result.HttpErrorMessage)) { Console.WriteLine($"\t{result.HttpErrorMessage}"); } PrintProviderDetails(result.ProviderStatus); return(-1); case ResetOverallResult.Timeout: Console.WriteLine("Resetting has timed out:"); PrintProviderDetails(result.ProviderStatus); return(-1); default: Console.WriteLine("has completed with unknown error"); return(-1); } } catch (HttpRequestException ex) { Console.WriteLine("Error: player data reset failed"); if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized))) { Console.WriteLine( $"Unable to authorize the account with XboxLive service with scid : {options.ServiceConfigurationId} and sandbox : {options.Sandbox}, please contact your administrator."); } else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden))) { Console.WriteLine( "Your account doesn't have access to perform the operation, please contact your administrator."); } else { Console.WriteLine(ex.Message); } return(-1); } }
private static async Task <int> Main(string[] args) { VirtualTerminal.Enable(); int exitCode = 0; DevAccount account = ToolAuthentication.LoadLastSignedInUser(); if (account == null) { Console.Error.WriteLine("Didn't find dev signin info, please use \"XblDevAccount.exe signin\" to initiate."); return(-1); } if (account.AccountSource != DevAccountSource.WindowsDevCenter) { Console.Error.WriteLine("You must sign in with a valid Windows Dev Center account."); } string invokedVerb = null; object opts = null; Console.WriteLine($"Using Dev account {account.Name} from {account.AccountSource}"); try { // Find all of the subclasses which inherit from BaseOptions. Type[] argumentTypes = typeof(Program).GetNestedTypes(BindingFlags.NonPublic).Where(c => c.IsSubclassOf(typeof(BaseOptions))).ToArray(); // Only assign the option and verb here, as the commandlineParser doesn't support async callback yet. Parser.Default.ParseArguments(args, argumentTypes) .WithParsed(options => { VerbAttribute verbAttribute = Attribute.GetCustomAttribute(options.GetType(), typeof(VerbAttribute)) as VerbAttribute; invokedVerb = verbAttribute?.Name; opts = options; }) .WithNotParsed(err => exitCode = -1); if (opts != null) { // Find property called AccountId. If it not set, then set it to the logged in user's account Id. PropertyInfo accountIdProperty = opts.GetType().GetProperty("AccountId"); if (accountIdProperty != null) { Guid accountIdPropertyValue = (Guid)accountIdProperty.GetValue(opts); if (accountIdPropertyValue == Guid.Empty) { accountIdProperty.SetValue(opts, new Guid(account.AccountId)); } } // Find the method which takes this class as an argument. MethodInfo method = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Where(c => c.GetParameters().FirstOrDefault()?.ParameterType == opts.GetType()).FirstOrDefault(); if (method == null) { // This should never happen, but just in case... throw new InvalidOperationException($"Method with parameter {opts.GetType()} not found."); } Task <int> methodResult = (Task <int>)method.Invoke(null, new object[] { opts }); exitCode = await methodResult; } } catch (HttpRequestException ex) { Console.Error.WriteLine($"Error: XblConfig {invokedVerb} failed."); if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Unauthorized))) { Console.Error.WriteLine( $"Unable to authorize the account with the XboxLive service, please contact your administrator."); } else if (ex.Message.Contains(Convert.ToString((int)HttpStatusCode.Forbidden))) { Console.Error.WriteLine( "Your account doesn't have access to perform the operation, please contact your administrator."); } else { Console.WriteLine(ex.Message); } exitCode = -1; } catch (Exception ex) { Console.Error.WriteLine("Error: unexpected error found."); Console.Error.WriteLine(ex.Message); exitCode = -1; } if (System.Diagnostics.Debugger.IsAttached) { Console.Read(); } return(exitCode); }