Beispiel #1
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool ChangeTrack(string fromTrack, string toTrack)
        {
            if (_serviceThread != null)
            {
                return(false);
            }
            UpdateStatus(string.Empty);
            if (string.Compare(fromTrack, toTrack, StringComparison.OrdinalIgnoreCase) == 0)
            {
                UpdateStatus("Both tracks identical");
                return(false);
            }
            _cts           = new CancellationTokenSource();
            _serviceThread = new Thread(async() =>
            {
                UpdateStatus(string.Empty);
                StringBuilder sb = new StringBuilder();
                try
                {
                    UserCredential credential = await GetCredatials();
                    using (AndroidPublisherService service = new AndroidPublisherService(GetInitializer(credential)))
                    {
                        EditsResource edits = service.Edits;
                        EditsResource.InsertRequest editRequest = edits.Insert(null, PackageName);
                        AppEdit appEdit     = await editRequest.ExecuteAsync(_cts.Token);
                        Track trackResponse = await edits.Tracks.Get(PackageName, appEdit.Id, fromTrack).ExecuteAsync(_cts.Token);
                        sb.AppendLine($"From track: {fromTrack}");
                        if (trackResponse.VersionCodes.Count != 1 || !trackResponse.VersionCodes[0].HasValue)
                        {
                            sb.AppendLine($"Invalid version count: {trackResponse.VersionCodes.Count}");
                            UpdateStatus(sb.ToString());
                            throw new Exception("Invalid version count");
                        }
                        int currentVersion = trackResponse.VersionCodes[0].Value;
                        sb.AppendLine($"Version: {currentVersion}");
                        UpdateStatus(sb.ToString());

                        Track assignTrack = new Track {
                            VersionCodes = new List <int?> {
                                currentVersion
                            }
                        };
                        await edits.Tracks.Update(assignTrack, PackageName, appEdit.Id, toTrack).ExecuteAsync();
                        sb.AppendLine($"Assigned to track: {toTrack}");
                        UpdateStatus(sb.ToString());

                        Track unassignTrack = new Track {
                            VersionCodes = new List <int?>()
                        };
                        await edits.Tracks.Update(unassignTrack, PackageName, appEdit.Id, fromTrack).ExecuteAsync();
                        sb.AppendLine($"Unassigned from track: {fromTrack}");
                        UpdateStatus(sb.ToString());

                        ApkListingsListResponse listingsResponse = await edits.Apklistings.List(PackageName, appEdit.Id, currentVersion).ExecuteAsync(_cts.Token);
                        if (listingsResponse.Listings != null)
                        {
                            foreach (ApkListing listing in listingsResponse.Listings)
                            {
                                if (listing.RecentChanges != null)
                                {
                                    await edits.Apklistings.Update(listing, PackageName, appEdit.Id, currentVersion, listing.Language).ExecuteAsync(_cts.Token);
                                    sb.AppendLine($"Changes for language {listing.Language} updated");
                                    UpdateStatus(sb.ToString());
                                }
                            }
                        }

                        EditsResource.CommitRequest commitRequest = edits.Commit(PackageName, appEdit.Id);
                        AppEdit appEditCommit = await commitRequest.ExecuteAsync(_cts.Token);
                        sb.AppendLine($"App edit committed: {appEditCommit.Id}");
                        UpdateStatus(sb.ToString());
                    }
                }
                catch (Exception e)
                {
                    sb.AppendLine($"Exception: {e.Message}");
                }
                finally
                {
                    _serviceThread = null;
                    _cts.Dispose();
                    UpdateStatus(sb.ToString());
                }
            });
            _serviceThread.Start();

            return(true);
        }
Beispiel #2
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool ListTracks()
        {
            if (_serviceThread != null)
            {
                return(false);
            }
            UpdateStatus(string.Empty);
            _cts           = new CancellationTokenSource();
            _serviceThread = new Thread(async() =>
            {
                UpdateStatus(string.Empty);
                StringBuilder sb = new StringBuilder();
                try
                {
                    UserCredential credential = await GetCredatials();
                    using (AndroidPublisherService service = new AndroidPublisherService(GetInitializer(credential)))
                    {
                        EditsResource edits = service.Edits;
                        EditsResource.InsertRequest editRequest = edits.Insert(null, PackageName);
                        AppEdit appEdit = await editRequest.ExecuteAsync(_cts.Token);
                        foreach (string track in TracksAll)
                        {
                            if (sb.Length > 0)
                            {
                                sb.AppendLine();
                            }
                            sb.AppendLine($"Track: {track}");
                            try
                            {
                                Track trackResponse = await edits.Tracks.Get(PackageName, appEdit.Id, track).ExecuteAsync(_cts.Token);
                                foreach (int?version in trackResponse.VersionCodes)
                                {
                                    if (version != null)
                                    {
                                        sb.AppendLine($"Version: {version.Value}");
                                        await PrintExpansion(sb, edits, appEdit, version.Value);
                                        try
                                        {
                                            Testers testers = await edits.Testers.Get(PackageName, appEdit.Id, track).ExecuteAsync(_cts.Token);
                                            sb.AppendLine("Test active");
                                            if (testers.GoogleGroups != null)
                                            {
                                                foreach (string group in testers.GoogleGroups)
                                                {
                                                    sb.AppendLine($"Tester group: {group}");
                                                }
                                            }
                                            if (testers.GooglePlusCommunities != null)
                                            {
                                                foreach (string community in testers.GooglePlusCommunities)
                                                {
                                                    sb.AppendLine($"Tester community: {community}");
                                                }
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            // ignored
                                        }

                                        try
                                        {
                                            ApkListingsListResponse listingsResponse = await edits.Apklistings.List(PackageName, appEdit.Id, version.Value).ExecuteAsync(_cts.Token);
                                            if (listingsResponse.Listings != null)
                                            {
                                                foreach (ApkListing listing in listingsResponse.Listings)
                                                {
                                                    string changes = listing.RecentChanges ?? string.Empty;
                                                    changes        = changes.Replace("\n", "\\n");
                                                    sb.AppendLine($"Changes ({listing.Language}): {changes}");
                                                }
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            // ignored
                                        }
                                    }
                                    else
                                    {
                                        sb.AppendLine("No version");
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                sb.AppendLine("No data");
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    sb.AppendLine($"Exception: {e.Message}");
                }
                finally
                {
                    _serviceThread = null;
                    _cts.Dispose();
                    UpdateStatus(sb.ToString());
                }
            });
            _serviceThread.Start();

            return(true);
        }