Represents the actual data stored in an audit entry, an AuditRecord/AuditEnvironment pair
        public async Task WriteAuditRecord(string resourceType, CloudStorageAccount storageAccount)
        {
            var entry = new AuditEntry(
                this,
                await AuditActor.GetCurrentMachineActor());

            // Write the blob to the storage account
            var client    = storageAccount.CreateCloudBlobClient();
            var container = client.GetContainerReference("auditing");
            await container.CreateIfNotExistsAsync();

            var blob = container.GetBlockBlobReference(
                resourceType + "/" + this.GetPath() + "/" + DateTime.UtcNow.ToString("s") + "-" + this.GetAction().ToLowerInvariant() + ".audit.v1.json");

            if (await blob.ExistsAsync())
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Strings.Package_DeleteCommand_AuditBlobExists,
                                                        blob.Uri.AbsoluteUri));
            }

            byte[] data = Encoding.UTF8.GetBytes(
                JsonFormat.Serialize(entry));
            await blob.UploadFromByteArrayAsync(data, 0, data.Length);
        }
Esempio n. 2
0
        public async Task WriteAuditRecord(string resourceType, CloudStorageAccount storageAccount)
        {
            var entry = new AuditEntry(
                this,
                await AuditActor.GetCurrentMachineActor());

            // Write the blob to the storage account
            var client = storageAccount.CreateCloudBlobClient();
            var container = client.GetContainerReference("auditing");
            await container.CreateIfNotExistsAsync();
            var blob = container.GetBlockBlobReference(
                resourceType + "/" + this.GetPath() + "/" + DateTime.UtcNow.ToString("s") + "-" + this.GetAction().ToLowerInvariant() + ".audit.v1.json");

            if (await blob.ExistsAsync())
            {
                throw new InvalidOperationException(String.Format(
                    CultureInfo.CurrentCulture,
                    Strings.Package_DeleteCommand_AuditBlobExists,
                    blob.Uri.AbsoluteUri));
            }

            byte[] data = Encoding.UTF8.GetBytes(
                JsonFormat.Serialize(entry));
            await blob.UploadFromByteArrayAsync(data, 0, data.Length);
        }