public TagTransactionEntity(TagTransactionOperation operation, string channel, string alias, string username)
        {
            if (String.IsNullOrEmpty(alias))
            {
                throw new ArgumentNullException(nameof(alias));
            }
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            channel = String.IsNullOrEmpty(channel) ? "@" : channel;

            var now = DateTime.UtcNow.ToString("yyyy-MMdd-HHmm-ss");

            var uniquifier = Uniquifier++;

            var transactionId = $"{username}|{now}-{uniquifier % 10000}";

            this.PartitionKey = TagTransactionEntity.CalculatePartitionKey(channel, transactionId);
            this.RowKey       = TagTransactionEntity.CalculateRowKey();

            this.Channel  = channel;
            this.Alias    = alias;
            this.Username = username;
            this.Id       = transactionId;

            this.Operation     = operation.ToString();
            this.StagedBlobUri = $"{channel}/{alias}/{transactionId}";
        }
Exemple #2
0
        public async Task <string> DownloadTextAsync(TagTransactionEntity tagTx)
        {
            var container = await this.ConnectAsync();

            var blob = container.GetBlockBlobReference(tagTx.StagedBlobUri);

            return(await blob.DownloadTextAsync());
        }
        public TagTransactionMessageEntity(TagTransactionEntity tagTransaction, string message)
        {
            this.PartitionKey = TagTransactionMessageEntity.CalculatePartitionKey(tagTransaction.Channel, tagTransaction.Id);
            this.RowKey       = TagTransactionMessageEntity.CalculateRowKey();

            this.Channel = tagTransaction.Channel;
            this.Id      = tagTransaction.Id;

            this.Operation = tagTransaction.Operation;
            this.Message   = (message.Length > MaxMessageLength) ? message.Substring(0, MaxMessageLength) : message;
        }
        public async Task<TagTransactionEntity> GetTagTransactionAsync(string channel, string transactionId)
        {
            var partitionKey = TagTransactionEntity.CalculatePartitionKey(channel, transactionId);

            var rowKey = TagTransactionEntity.CalculateRowKey();

            var op = TableOperation.Retrieve<TagTransactionEntity>(partitionKey, rowKey);

            var result = await this.Table.ExecuteAsync(op);

            return (TagTransactionEntity)result.Result;
        }
Exemple #5
0
        public async Task UploadFromStreamAsync(TagTransactionEntity tagTx, Stream stream)
        {
            var container = await this.ConnectAsync();

            var blob = container.GetBlockBlobReference(tagTx.StagedBlobUri);

            blob.Properties.ContentType = "application/swid-tag";
            blob.Metadata.Add("channel", tagTx.Channel);
            blob.Metadata.Add("alias", tagTx.Alias);
            blob.Metadata.Add("username", tagTx.Username);

            await blob.UploadFromStreamAsync(stream);
        }
        public async Task AddTagTransactionErrorMessageAsync(TagTransactionEntity entity, string message)
        {
            var change = this.Batch();

            if (entity.TryUpdateOperation(TagTransactionOperation.Error))
            {
                var errorEntity = entity.AsError();

                change.Update(errorEntity);
            }

            var messageEntity = new TagTransactionMessageEntity(entity, message);

            change.Create(messageEntity);

            await change.WhenAll();
        }
 internal static string CalculatePartitionKey(string channel, string transactionId)
 {
     return(TagTransactionEntity.CalculatePartitionKey(channel, transactionId));
 }