示例#1
0
        private async Task <string> UploadAndAddpackageAndEnsureItIsReady()
        {
            try
            {
                Log.LogMessage(
                    MessageImportance.High,
                    "Begin uploading Linux Package to feed service, RepositoryId {0}, Server {1}, Package to upload {2}.",
                    RepositoryId,
                    Server,
                    PathOfPackageToUpload);

                var linuxPackageRepositoryDestiny =
                    new LinuxPackageRepositoryDestiny(Username, Password, Server, RepositoryId);
                var uploadResponse = await new LinuxPackageRepositoryHttpPrepare(
                    linuxPackageRepositoryDestiny,
                    new FileUploadStrategy(PathOfPackageToUpload)).RemoteCall();

                var idInRepositoryService = new IdInRepositoryService(JObject.Parse(uploadResponse)["id"].ToString());

                var addPackageResponse = await new LinuxPackageRepositoryHttpPrepare(
                    linuxPackageRepositoryDestiny,
                    new AddPackageStrategy(
                        idInRepositoryService,
                        PackageNameInLinuxPackageRepository,
                        PackageVersionInLinuxPackageRepository,
                        linuxPackageRepositoryDestiny.RepositoryId)).RemoteCall();

                var queueResourceLocation = new QueueResourceLocation(addPackageResponse);

                Func <Task <string> > pullQueuedPackageStatus = new LinuxPackageRepositoryHttpPrepare(
                    linuxPackageRepositoryDestiny,
                    new PullQueuedPackageStatus(queueResourceLocation)).RemoteCall;

                await ExponentialRetry.ExecuteWithRetry(
                    pullQueuedPackageStatus,
                    s => s == "fileReady",
                    5,
                    () => ExponentialRetry.Timer(ExponentialRetry.Intervals),
                    $"PullQueuedPackageStatus location: {queueResourceLocation.Location}");

                Log.LogMessage(
                    MessageImportance.High,
                    "Upload to feed service is completed, queue resource location {0}",
                    queueResourceLocation.Location);

                return("");
            }
            catch (FailedToAddPackageToPackageRepositoryException e)
            {
                return(e.ToString());
            }
            catch (HttpRequestException e)
            {
                return(e.ToString());
            }
        }
示例#2
0
 public AddPackageStrategy(
     IdInRepositoryService idInRepositoryService,
     string packageName,
     string packageVersion,
     string repositoryId)
 {
     _idInRepositoryService = idInRepositoryService
                              ?? throw new ArgumentNullException(nameof(idInRepositoryService));
     _packageName    = packageName;
     _packageVersion = packageVersion;
     _repositoryId   = repositoryId;
 }