Example #1
0
        private async UniTask UploadArtifact(AndroidPublisherService androidPublisherService,
                                             IAndroidDistributionSettings configs, AppEdit appEdit)
        {
            var isAppBundle = configs.IsAppBundle;
            var uploader    = isAppBundle
                ? new AndroidAppBundlerUploader()
                : new AndroidApkUploader() as IAndroidArtifactUploader;

            Debug.Log($"{nameof(PlayStorePublisher)} : Upload to store With {uploader.GetType().Name}");

            // Upload new apk to developer console
            var upload = uploader.Upload(configs, androidPublisherService, appEdit);

            upload.UploadAsync();

            var uploadProgress = upload.GetProgress();

            while (uploadProgress == null || (uploadProgress.Status != UploadStatus.Completed && uploadProgress.Status != UploadStatus.Failed))
            {
                uploadProgress = upload.GetProgress();
                if (uploadProgress != null)
                {
                    OnUploadProgressChanged(uploadProgress);
                }

                Thread.Sleep(UploadAwaitTimeout);
            }

            switch (uploadProgress)
            {
            case { Status: UploadStatus.Completed } :
Example #2
0
        private async Task PrintExpansion(StringBuilder sb, EditsResource edits, AppEdit appEdit, int version)
        {
            try
            {
                ExpansionFile expansionResponse = await edits.Expansionfiles.Get(PackageName, appEdit.Id, version, EditsResource.ExpansionfilesResource.GetRequest.ExpansionFileTypeEnum.Main).ExecuteAsync(_cts.Token);

                if (expansionResponse.ReferencesVersion != null)
                {
                    sb.AppendLine($"Expansion ref ver: {expansionResponse.ReferencesVersion.Value}");
                    ExpansionFile expansionRefResponse = await edits.Expansionfiles.Get(PackageName, appEdit.Id, expansionResponse.ReferencesVersion.Value, EditsResource.ExpansionfilesResource.GetRequest.ExpansionFileTypeEnum.Main).ExecuteAsync(_cts.Token);

                    if (expansionRefResponse.FileSize != null && expansionRefResponse.FileSize.Value > 0)
                    {
                        sb.AppendLine($"Expansion size: {expansionRefResponse.FileSize.Value}");
                    }
                }
                else if ((expansionResponse.FileSize != null && expansionResponse.FileSize.Value > 0))
                {
                    sb.AppendLine($"Expansion size: {expansionResponse.FileSize.Value}");
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
Example #3
0
        private static Track LoadTrackBranch(AndroidPublisherService androidPublisherService, BundleSettings configs,
                                             AppEdit edit)
        {
            var track = androidPublisherService.Edits.Tracks.Get(configs.PackageName, edit.Id, configs.TrackBranch)
                        .Execute();

            Console.WriteLine($"Load TrackBranch:{track.TrackValue}");
            return(track);
        }
Example #4
0
        private static void CommitChangesToGooglePlay(AndroidPublisherService androidPublisherService,
                                                      BundleSettings configs,
                                                      AppEdit edit)
        {
            var commitRequest = androidPublisherService.Edits.Commit(configs.PackageName, edit.Id);
            var appEdit       = commitRequest.Execute();

            Console.WriteLine("App edit with id " + appEdit.Id + " has been comitted");
        }
Example #5
0
        private async Task <string> GetEditId(string packageName, string timeout = "60")
        {
            AppEdit edit = await this.Service.Edits.Insert(new AppEdit()
            {
                ExpiryTimeSeconds = timeout
            }, packageName).ExecuteAsync();

            return(edit.Id);
        }
        public static Track LoadTrackBranch(
            this AndroidPublisherService androidPublisherService,
            IAndroidDistributionSettings configs,
            AppEdit edit)
        {
            var track = androidPublisherService.Edits.Tracks.Get(configs.PackageName, edit.Id, configs.TrackBranch)
                        .Execute();

            Debug.Log($"Load TrackBranch:{track.TrackValue}");
            return(track);
        }
Example #7
0
        private static EditsResource.BundlesResource.UploadMediaUpload UploadAabFile(BundleSettings configs,
                                                                                     AndroidPublisherService androidPublisherService,
                                                                                     AppEdit edit)
        {
            Console.WriteLine("Upload started for aab: " + Path.GetFileName(configs.ApkPath));
            var upload = androidPublisherService.Edits.Bundles.Upload(
                configs.PackageName,
                edit.Id,
                new FileStream(configs.ApkPath, FileMode.Open),
                "application/octet-stream"
                );

            return(upload);
        }
Example #8
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool ListApks()
        {
            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);
                        ApksListResponse apksResponse = await edits.Apks.List(PackageName, appEdit.Id).ExecuteAsync(_cts.Token);

                        sb.AppendLine("Apks:");
                        foreach (Apk apk in apksResponse.Apks)
                        {
                            if (apk.VersionCode != null)
                            {
                                sb.AppendLine($"Version: {apk.VersionCode.Value}, SHA1: {apk.Binary.Sha1}");
                                await PrintExpansion(sb, edits, appEdit, apk.VersionCode.Value);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    sb.AppendLine($"Exception: {e.Message}");
                }
                finally
                {
                    _serviceThread = null;
                    _cts.Dispose();
                    UpdateStatus(sb.ToString());
                }
            });
            _serviceThread.Start();

            return(true);
        }
Example #9
0
        public ResumableUpload Upload(
            IAndroidDistributionSettings configs,
            AndroidPublisherService androidPublisherService,
            AppEdit edit)
        {
            Debug.Log("Upload started for : " + Path.GetFileName(configs.ArtifactPath));
            var upload = androidPublisherService.Edits.Apks.Upload(
                configs.PackageName,
                edit.Id,
                new FileStream(configs.ArtifactPath, FileMode.Open),
                "application/vnd.android.package-archive"
                );

            upload.ResponseReceived += x => OnUploadResponce(x, androidPublisherService, configs, edit);
            return(upload);
        }
Example #10
0
        void InitEditService()
        {
            Logger.WrightLog("Init start...");
            JObject cr = null;

            try
            {
                cr = (JObject)JsonConvert.DeserializeObject(File.ReadAllText(jsonKeyFilePath));
            }
            catch (FileNotFoundException IOex)
            {
                Logger.WrightLog("Init: json file not found exception: " + IOex.Message);
            }
            catch (Exception ex)
            {
                Logger.WrightLog("Init: exception: " + ex.Message);
            }


            var xCred = new ServiceAccountCredential(new ServiceAccountCredential.Initializer((string)cr.GetValue(ServiceAccountCred.EMAIL))
            {
                Scopes = new[] { AndroidPublisherService.Scope.Androidpublisher }
            }.FromPrivateKey((string)cr.GetValue(ServiceAccountCred.KEY)));

            var service = new AndroidPublisherService(new BaseClientService.Initializer
            {
                HttpClientInitializer = xCred,
                ApplicationName       = applicationName
            });

            _edits = service.Edits;
            AppEdit appEdit = _edits.Insert(null, packageName).Execute();

            if (appEdit != null)
            {
                Logger.WrightLog("Init: service created");
                _editsId = appEdit.Id;
            }
            else
            {
                Logger.WrightLog("Init: service FAILED");
            }
        }
        public async Task TestGetReleaseVersion()
        {
            var scopes = new string[] { AndroidPublisherService.Scope.Androidpublisher }; // view and manage your Google Analytics data
                                                                                          // Download p12 file service account key from https://console.developers.google.com
            var keyFilePath = @"c:\file.p12";
            // found https://console.developers.google.com
            var serviceAccountEmail = "your-service-account-key";

            // Load the Key file
            var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
            var credential  = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                Scopes = scopes
            }.FromCertificate(certificate)
                );

            var service = new AndroidPublisherService(
                new BaseClientService.Initializer {
                HttpClientInitializer = credential, ApplicationName = "test app"
            }
                );

            var edits = service.Edits;
            // Create a new edit to make changes.
            var packageName = "com.company.app-name";
            var appEdit     = new AppEdit();
            var editRequest = edits.Insert(appEdit, packageName);

            appEdit = await editRequest.ExecuteAsync();

            // Run the request.
            Console.WriteLine("Executing a list request...");
            var response = edits.Apks.List(packageName, appEdit.Id).Execute();

            // Display the results.
            var latestApk = response.Apks.OrderByDescending(x => x.VersionCode).First();

            Console.WriteLine($"latestVersion {latestApk.VersionCode}");
        }
Example #12
0
        private void UploadObbFiles(AndroidPublisherService service, AppEdit edit, Apk apk,
                                    IAndroidDistributionSettings configs, string[] obbs)
        {
            foreach (var obbPath in obbs)
            {
                var upload = service.Edits.Expansionfiles.Upload(
                    configs.PackageName,
                    edit.Id,
                    apk.VersionCode.Value,
                    EditsResource.ExpansionfilesResource.UploadMediaUpload.ExpansionFileTypeEnum.Main,
                    new FileStream(obbPath, FileMode.Open),
                    "application/octet-stream"
                    );
                Debug.Log($"Starting Uploading Obb:{obbPath}");
                upload.ResponseReceived += response =>
                {
                    if (response == null)
                    {
                        throw new Exception("Failed Upload " + obbPath);
                    }
                    else
                    {
                        Debug.Log("Success Upload " + obbPath);
                    }
                };
                var result = upload.Upload();
                if (result.Exception != null)
                {
                    throw new Exception("Error: " + result.Exception.Message);
                }

                if (result.Status != UploadStatus.Completed)
                {
                    throw new Exception("Obb not uploaded");
                }
                Debug.Log($"Finish Uploading Obb:{obbPath}");
            }
        }
        public void OnUploadResponce(Bundle bundle, AndroidPublisherService androidPublisherService, IAndroidDistributionSettings configs, AppEdit edit)
        {
            if (bundle == null)
            {
                return;
            }

            var track = androidPublisherService.LoadTrackBranch(configs, edit);

            track.UpdateTrackInformation(bundle.VersionCode, configs);

            var updatedTrack = androidPublisherService.Edits.Tracks
                               .Update(track, configs.PackageName, edit.Id, track.TrackValue).Execute();

            Debug.Log("Track " + updatedTrack.TrackValue + " has been updated.");
        }
Example #14
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool UploadApk(string apkFileName, string expansionFileName, string track, List <UpdateInfo> apkChanges)
        {
            if (_serviceThread != null)
            {
                return(false);
            }

            if (!File.Exists(apkFileName))
            {
                UpdateStatus("Apk file not existing");
                return(false);
            }

            if (!string.IsNullOrEmpty(expansionFileName) && !File.Exists(expansionFileName))
            {
                UpdateStatus("Expansion file not existing");
                return(false);
            }

            UpdateStatus(string.Empty);
            _cts           = new CancellationTokenSource();
            _serviceThread = new Thread(async() =>
            {
                UpdateStatus(string.Empty);
                StringBuilder sb = new StringBuilder();
                try
                {
                    if (apkChanges != null)
                    {
                        sb.Append("Changes info for languages: ");
                        foreach (UpdateInfo updateInfo in apkChanges)
                        {
                            sb.Append($"{updateInfo.Language} ");
                        }
                        sb.AppendLine();
                        UpdateStatus(sb.ToString());
                    }

                    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);

                        bool reuseExpansion         = false;
                        ExpansionInfo expansionInfo = await GetNewestExpansionFile(edits, appEdit);
                        if (expansionInfo != null)
                        {
                            sb.AppendLine($"Latest expansion: apk version={expansionInfo.ApkVersion}, expansion version={expansionInfo.ExpansionVersion}, size={expansionInfo.FileSize}");
                            if (!string.IsNullOrEmpty(expansionFileName))
                            {
                                FileInfo fileInfo = new FileInfo(expansionFileName);
                                if (fileInfo.Exists && fileInfo.Length == expansionInfo.FileSize)
                                {
                                    sb.AppendLine("Size unchanged, reusing old expansion file");
                                    reuseExpansion = true;
                                }
                            }
                        }

                        Apk apkUploaded = null;
                        using (FileStream apkStream = new FileStream(apkFileName, FileMode.Open, FileAccess.Read))
                        {
                            long fileLength = (apkStream.Length > 0) ? apkStream.Length : 1;
                            EditsResource.ApksResource.UploadMediaUpload upload = edits.Apks.Upload(PackageName, appEdit.Id, apkStream, "application/vnd.android.package-archive");
                            upload.ChunkSize        = ResumableUpload.MinimumChunkSize;
                            upload.ProgressChanged += progress =>
                            {
                                UpdateStatus(sb.ToString() + $"Apk progress: {100 * progress.BytesSent / fileLength}%");
                            };
                            upload.ResponseReceived += apk =>
                            {
                                apkUploaded = apk;
                            };
                            IUploadProgress uploadProgress = await upload.UploadAsync(_cts.Token);
                            sb.AppendLine($"Upload status: {uploadProgress.Status.ToString()}");
                            UpdateStatus(sb.ToString());
                            if (uploadProgress.Exception != null)
                            {
                                throw uploadProgress.Exception;
                            }
                        }

                        int?versionCode = apkUploaded?.VersionCode;
                        if (!versionCode.HasValue)
                        {
                            throw new Exception("No apk version code");
                        }
                        sb.AppendLine($"Version code uploaded: {versionCode.Value}");
                        UpdateStatus(sb.ToString());

                        if (!string.IsNullOrEmpty(expansionFileName) && !reuseExpansion)
                        {
                            using (FileStream expansionStream = new FileStream(expansionFileName, FileMode.Open, FileAccess.Read))
                            {
                                long fileLength = (expansionStream.Length > 0) ? expansionStream.Length : 1;
                                EditsResource.ExpansionfilesResource.UploadMediaUpload upload = edits.Expansionfiles.Upload(PackageName, appEdit.Id, versionCode.Value,
                                                                                                                            EditsResource.ExpansionfilesResource.UploadMediaUpload.ExpansionFileTypeEnum.Main, expansionStream, "application/octet-stream");
                                upload.ChunkSize        = ResumableUpload.MinimumChunkSize;
                                upload.ProgressChanged += progress =>
                                {
                                    UpdateStatus(sb.ToString() + $"Expansion progress: {100 * progress.BytesSent / fileLength}%");
                                };
                                IUploadProgress uploadProgress = await upload.UploadAsync(_cts.Token);
                                sb.AppendLine($"Upload status: {uploadProgress.Status.ToString()}");
                                UpdateStatus(sb.ToString());
                                if (uploadProgress.Exception != null)
                                {
                                    throw uploadProgress.Exception;
                                }
                            }
                        }
                        else
                        {
                            if (expansionInfo != null)
                            {
                                ExpansionFile expansionRef = new ExpansionFile {
                                    ReferencesVersion = expansionInfo.ExpansionVersion
                                };
                                await edits.Expansionfiles.Update(expansionRef, PackageName, appEdit.Id, versionCode.Value,
                                                                  EditsResource.ExpansionfilesResource.UpdateRequest.ExpansionFileTypeEnum.Main).ExecuteAsync(_cts.Token);
                                sb.AppendLine($"Expansion version {expansionInfo.ExpansionVersion} assigned");
                            }
                            else
                            {
                                sb.AppendLine("No existing expansion found!");
                            }
                        }

                        Track updateTrack = new Track {
                            VersionCodes = new List <int?> {
                                versionCode.Value
                            }
                        };
                        EditsResource.TracksResource.UpdateRequest updateRequest = edits.Tracks.Update(updateTrack, PackageName, appEdit.Id, track);
                        Track updatedTrack = await updateRequest.ExecuteAsync(_cts.Token);
                        sb.AppendLine($"Track updated: {updatedTrack.TrackValue}");
                        UpdateStatus(sb.ToString());

                        if (apkChanges != null)
                        {
                            foreach (UpdateInfo updateInfo in apkChanges)
                            {
                                ApkListing apkListing = new ApkListing
                                {
                                    RecentChanges = updateInfo.Changes
                                };
                                await edits.Apklistings.Update(apkListing, PackageName, appEdit.Id, versionCode.Value, updateInfo.Language).ExecuteAsync(_cts.Token);
                                sb.AppendLine($"Changes for language {updateInfo.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);
        }
Example #15
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool UpdateChanges(string track, List <UpdateInfo> apkChanges)
        {
            if (_serviceThread != null)
            {
                return(false);
            }

            if (apkChanges == null)
            {
                UpdateStatus("No language changes info");
                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);
                        Track trackResponse = await edits.Tracks.Get(PackageName, appEdit.Id, track).ExecuteAsync(_cts.Token);
                        sb.AppendLine($"Track: {track}");
                        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());

                        await edits.Apklistings.Deleteall(PackageName, appEdit.Id, currentVersion).ExecuteAsync(_cts.Token);
                        sb.AppendLine("All changes cleared");
                        UpdateStatus(sb.ToString());
                        foreach (UpdateInfo updateInfo in apkChanges)
                        {
                            ApkListing apkListing = new ApkListing
                            {
                                RecentChanges = updateInfo.Changes
                            };
                            await edits.Apklistings.Update(apkListing, PackageName, appEdit.Id, currentVersion, updateInfo.Language).ExecuteAsync(_cts.Token);
                            sb.AppendLine($"Changes for language {updateInfo.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);
        }
Example #16
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool AssignTrack(string track, int?versionAssign)
        {
            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);
                        try
                        {
                            Track trackResponse = await edits.Tracks.Get(PackageName, appEdit.Id, track).ExecuteAsync(_cts.Token);
                            sb.AppendLine($"Track: {track}");
                            foreach (int?version in trackResponse.VersionCodes)
                            {
                                if (version != null)
                                {
                                    sb.AppendLine($"Version: {version.Value}");
                                }
                            }
                        }
                        catch (Exception)
                        {
                            sb.AppendLine($"No version for track: {track}");
                        }

                        Track assignTrack = new Track {
                            VersionCodes = new List <int?>()
                        };
                        if (versionAssign.HasValue)
                        {
                            assignTrack.VersionCodes.Add(versionAssign);
                            sb.AppendLine($"Assign version: {versionAssign}");
                        }
                        else
                        {
                            sb.AppendLine("Unassign version");
                        }
                        UpdateStatus(sb.ToString());
                        await edits.Tracks.Update(assignTrack, PackageName, appEdit.Id, track).ExecuteAsync();
                        sb.AppendLine("Track 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);
        }
Example #17
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);
        }
Example #18
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);
        }
Example #19
0
        private static EditsResource.BundlesResource.UploadMediaUpload CreateUploadAabFileObject(BundleSettings configs, AndroidPublisherService androidPublisherService, AppEdit edit)
        {
            var upload = UploadAabFile(configs, androidPublisherService, edit);

            //Verify if exist any obb
            var needUploadExtensionsFiles = CheckIfNeedProcessObb(configs, out string[] obbs);

            upload.ResponseReceived += (aab) =>
            {
                if (aab == null)
                {
                    return;
                }
                var track = LoadTrackBranch(androidPublisherService, configs, edit);

                UpdateTrackInformation(aab.VersionCode, track, configs);

                if (needUploadExtensionsFiles)
                {
                    UploadObbFiles(androidPublisherService, edit, aab.VersionCode, configs, obbs);
                }

                var updatedTrack = androidPublisherService.Edits.Tracks
                                   .Update(track, configs.PackageName, edit.Id, track.TrackValue).Execute();
                Console.WriteLine("Track " + updatedTrack.TrackValue + " has been updated.");

                CommitChangesToGooglePlay(androidPublisherService, configs, edit);
            };

            return(upload);
        }
Example #20
0
        private async Task <ExpansionInfo> GetNewestExpansionFile(EditsResource edits, AppEdit appEdit)
        {
            try
            {
                ApksListResponse apksResponse = await edits.Apks.List(PackageName, appEdit.Id).ExecuteAsync(_cts.Token);

                int  apkVersion       = -1;
                int  expansionVersion = -1;
                long fileSize         = 0;
                foreach (Apk apk in apksResponse.Apks)
                {
                    // ReSharper disable once UseNullPropagation
                    if (apk.VersionCode != null)
                    {
                        if (apk.VersionCode.Value > apkVersion)
                        {
                            try
                            {
                                ExpansionFile expansionResponse = await edits.Expansionfiles.Get(PackageName, appEdit.Id, apk.VersionCode.Value, EditsResource.ExpansionfilesResource.GetRequest.ExpansionFileTypeEnum.Main).ExecuteAsync(_cts.Token);

                                if (expansionResponse.ReferencesVersion != null)
                                {
                                    expansionVersion = expansionResponse.ReferencesVersion.Value;
                                    ExpansionFile expansionRefResponse = await edits.Expansionfiles.Get(PackageName, appEdit.Id, expansionResponse.ReferencesVersion.Value, EditsResource.ExpansionfilesResource.GetRequest.ExpansionFileTypeEnum.Main).ExecuteAsync(_cts.Token);

                                    if (expansionRefResponse.FileSize != null && expansionRefResponse.FileSize.Value > 0)
                                    {
                                        apkVersion       = apk.VersionCode.Value;
                                        expansionVersion = expansionResponse.ReferencesVersion.Value;
                                        fileSize         = expansionRefResponse.FileSize.Value;
                                    }
                                }
                                else if (expansionResponse.FileSize != null && expansionResponse.FileSize.Value > 0)
                                {
                                    apkVersion       = apk.VersionCode.Value;
                                    expansionVersion = apkVersion;
                                    fileSize         = expansionResponse.FileSize.Value;
                                }
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                    }
                }
                if (apkVersion < 0)
                {
                    return(null);
                }
                return(new ExpansionInfo(apkVersion, expansionVersion, fileSize));
            }
            catch (Exception)
            {
                // ignored
            }

            return(null);
        }
Example #21
0
        private void OnUploadResponce(Apk apk, AndroidPublisherService androidPublisherService, IAndroidDistributionSettings configs, AppEdit edit)
        {
            if (apk == null)
            {
                return;
            }

            var track = androidPublisherService.LoadTrackBranch(configs, edit);

            track.UpdateTrackInformation(apk.VersionCode, configs);

            //Verify if exist any obb
            var needUploadExtensionsFiles = CheckIfNeedProcessObb(configs, out string[] obbs);

            if (needUploadExtensionsFiles)
            {
                UploadObbFiles(androidPublisherService, edit, apk, configs, obbs);
            }

            var updatedTrack = androidPublisherService.Edits.Tracks
                               .Update(track, configs.PackageName, edit.Id, track.TrackValue).Execute();

            Debug.Log("Track " + updatedTrack.TrackValue + " has been updated.");
        }