private async Task <PublishEnvironment> TransactionalPublishArtifact(PublishParameters parameters,
                                                                             IList <int> artifactIdsList,
                                                                             IDbTransaction transaction)
        {
            int publishRevision = parameters.RevisionId ?? await
                                  _sqlHelper.CreateRevisionInTransactionAsync(transaction, parameters.UserId,
                                                                              "New Publish: publishing artifacts.");

            parameters.RevisionId = publishRevision;
            parameters.AffectedArtifactIds.Clear();
            parameters.AffectedArtifactIds.AddRange(artifactIdsList);
            var publishResults = new List <SqlPublishResult>(parameters.AffectedArtifactIds.Count);
            var artifactStates =
                await _versionControlRepository.GetPublishStates(parameters.UserId, parameters.AffectedArtifactIds, transaction : transaction);

            var artifactsCannotBePublished = _versionControlRepository.CanPublish(artifactStates);

            parameters.AffectedArtifactIds.ExceptWith(artifactsCannotBePublished.Keys);

            // Notify about artifactsCannotBePublished - callback
            // if (onError != null && onError(new ReadOnlyDictionary<int, PublishErrors>(artifactsCannotBePublished)))
            // {
            //    throw new DataAccessException("Publish interrupted", BusinessLayerErrorCodes.RequiredArtifactHasNotBeenPublished);
            // }

            if (parameters.AffectedArtifactIds.Count == 0)
            {
                return(null);
            }

            var env = new PublishEnvironment
            {
                RevisionId           = publishRevision,
                Timestamp            = DateTime.UtcNow, // Need to get if from created revision - DB timestamp
                KeepLock             = false,
                ArtifactStates       = artifactStates.ToDictionary(s => s.ItemId),
                Repositories         = null,
                SensitivityCollector = new ReuseSensitivityCollector()
            };

            if (parameters.AffectedArtifactIds.Count <= 0)
            {
                return(env);
            }

            env.DeletedArtifactIds.Clear();
            env.DeletedArtifactIds.AddRange(
                await _versionControlRepository.DetectAndPublishDeletedArtifacts(parameters.UserId,
                                                                                 parameters.AffectedArtifactIds,
                                                                                 env, transaction));
            parameters.AffectedArtifactIds.ExceptWith(env.DeletedArtifactIds);

            // Release lock
            if (!env.KeepLock)
            {
                await _versionControlRepository.ReleaseLock(parameters.UserId, parameters.AffectedArtifactIds, transaction);
            }

            await _publishRepositoryComposer.Execute(publishRevision, parameters, env, transaction);

            // Add history
            await _revisionRepository.AddHistory(publishRevision, parameters.AffectedArtifactIds, transaction);

            // });

            publishResults.AddRange(env.GetChangeSqlPublishResults());

            return(env);
        }
Beispiel #2
0
        private async Task <int> CreateRevision(IDbTransaction transaction)
        {
            var publishRevision = await _sqlHelper.CreateRevisionInTransactionAsync(transaction, _userId, I18NHelper.FormatInvariant("State Change Publish: publishing changes and changing artifact {0} state to {1}", _input.ArtifactId, _input.ToStateId));

            return(publishRevision);
        }
 public Task <int> CreateRevisionInTransactionAsync(IDbTransaction transaction, int userId, string description)
 {
     return(_sqlHelper.CreateRevisionInTransactionAsync(transaction, userId, description));
 }