public static void AssertLogItemsEqual(LogRecord expected, LogRecord actual) { Assert.AreEqual(expected.VersionNumber, actual.VersionNumber); Assert.AreEqual(expected.RequestStartTime, actual.RequestStartTime); Assert.AreEqual(expected.OperationType, actual.OperationType); Assert.AreEqual(expected.RequestStatus, actual.RequestStatus); Assert.AreEqual(expected.HttpStatusCode, actual.HttpStatusCode); Assert.AreEqual(expected.EndToEndLatency, actual.EndToEndLatency); Assert.AreEqual(expected.ServerLatency, actual.ServerLatency); Assert.AreEqual(expected.AuthenticationType, actual.AuthenticationType); Assert.AreEqual(expected.RequesterAccountName, actual.RequesterAccountName); Assert.AreEqual(expected.OwnerAccountName, actual.OwnerAccountName); Assert.AreEqual(expected.ServiceType, actual.ServiceType); Assert.AreEqual(expected.RequestUrl, actual.RequestUrl); Assert.AreEqual(expected.RequestedObjectKey, actual.RequestedObjectKey); Assert.AreEqual(expected.RequestIdHeader, actual.RequestIdHeader); Assert.AreEqual(expected.OperationCount, actual.OperationCount); Assert.AreEqual(expected.RequesterIPAddress, actual.RequesterIPAddress); Assert.AreEqual(expected.RequestVersionHeader, actual.RequestVersionHeader); Assert.AreEqual(expected.RequestHeaderSize, actual.RequestHeaderSize); Assert.AreEqual(expected.RequestPacketSize, actual.RequestPacketSize); Assert.AreEqual(expected.ResponseHeaderSize, actual.ResponseHeaderSize); Assert.AreEqual(expected.ResponsePacketSize, actual.ResponsePacketSize); Assert.AreEqual(expected.RequestContentLength, actual.RequestContentLength); Assert.AreEqual(expected.RequestMD5, actual.RequestMD5); Assert.AreEqual(expected.ServerMD5, actual.ServerMD5); Assert.AreEqual(expected.ETagIdentifier, actual.ETagIdentifier); Assert.AreEqual(expected.LastModifiedTime, actual.LastModifiedTime); Assert.AreEqual(expected.ConditionsUsed, actual.ConditionsUsed); Assert.AreEqual(expected.UserAgentHeader, actual.UserAgentHeader); Assert.AreEqual(expected.ReferrerHeader, actual.ReferrerHeader); Assert.AreEqual(expected.ClientRequestId, actual.ClientRequestId); }
/// <summary> /// Returns an enumerable collection of Analytics log records, retrieved lazily. /// </summary> /// <param name="stream">The <see cref="System.IO.Stream"/> object from which to parse log records.</param> /// <returns>An enumerable collection of objects that implement <see cref="LogRecord"/> and are retrieved lazily.</returns> public static IEnumerable<LogRecord> ParseLogStream(Stream stream) { LogRecordStreamReader reader = new LogRecordStreamReader(stream, (int)stream.Length); LogRecord log; while (!reader.IsEndOfFile) { log = new LogRecord(reader); yield return log; } }
/// <summary> /// Returns an enumerable collection of Analytics log records, retrieved lazily. /// </summary> /// <param name="logBlob">The <see cref="ICloudBlob"/> object from which to parse log records.</param> /// <returns>An enumerable collection of objects that implement <see cref="LogRecord"/> and are retrieved lazily.</returns> public static IEnumerable<LogRecord> ParseLogBlob(ICloudBlob logBlob) { using (Stream stream = ((CloudBlockBlob)logBlob).OpenRead()) { using (LogRecordStreamReader reader = new LogRecordStreamReader(stream, (int)stream.Length)) { LogRecord log; while (!reader.IsEndOfFile) { log = new LogRecord(reader); yield return log; } } } }
public void CloudAnalyticsClientParseLogs() { string logText = "1.0;2011-08-09T18:52:40.9241789Z;GetBlob;AnonymousSuccess;200;18;10;anonymous;;myaccount;blob;\"https://myaccount.blob.core.windows.net/thumb&nails/lake.jpg?timeout=30000\";\"/myaccount/thumbnails/lake.jpg\";a84aa705-8a85-48c5-b064-b43bd22979c3;0;123.100.2.10;2009-09-19;252;0;265;100;0;;;\"0x8CE1B6EA95033D5\";Tuesday, 09-Aug-11 18:52:40 GMT;;;;\"8/9/2011 6:52:40 PM ba98eb12-700b-4d53-9230-33a3330571fc\"" + '\n' + "1.0;2011-08-09T18:02:40.6271789Z;PutBlob;Success;201;28;21;authenticated;myaccount;myaccount;blob;\"https://myaccount.blob.core.windows.net/thumbnails/lake.jpg?timeout=30000\";\"/myaccount/thumbnails/lake.jpg\";fb658ee6-6123-41f5-81e2-4bfdc178fea3;0;201.9.10.20;2009-09-19;438;100;223;0;100;;\"66CbMXKirxDeTr82SXBKbg==\";\"0x8CE1B67AD25AA05\";Tuesday, 09-Aug-11 18:02:40 GMT;;;;\"8/9/2011 6:02:40 PM ab970a57-4a49-45c4-baa9-20b687941e32\"" + '\n' + "2.0;2011-08-09T18:02:40.6271789Z;PutBlob;Success;201;28;21;authenticated;myaccount;myaccount;blob;\"https://myaccount.blob.core.windows.net/thumbnails/lake.jpg?timeout=30000\";\"/myaccount/thumbnails/lake.jpg\";fb658ee6-6123-41f5-81e2-4bfdc178fea3;0;201.9.10.20;2009-09-19;438;100;223;0;100;;\"66CbMXKirxDeTr82SXBKbg==\";\"0x8CE1B67AD25AA05\";Tuesday, 09-Aug-11 18:02:40 GMT;;;;\"8/9/2011 6:02:40 PM ab970a57-4a49-45c4-baa9-20b687941e32\"" + '\n'; Blob.CloudBlobClient blobClient = CloudAnalyticsClientTests.GenerateCloudBlobClient(); Table.CloudTableClient tableClient = CloudAnalyticsClientTests.GenerateCloudTableClient(); CloudAnalyticsClient analyticsClient = new CloudAnalyticsClient(blobClient.StorageUri, tableClient.StorageUri, tableClient.Credentials); IEnumerable <LogRecord> logRecordsEnumerable = analyticsClient.ListLogRecords(StorageService.Blob); CloudBlobContainer container = blobClient.GetContainerReference(CloudAnalyticsClientTests.GetRandomContainerName()); container.CreateIfNotExists(); CloudBlockBlob blob = container.GetBlockBlobReference("blob1"); blob.UploadText(logText); IEnumerable <LogRecord> enumerable = CloudAnalyticsClient.ParseLogBlob(blob); IEnumerator <LogRecord> enumerator = enumerable.GetEnumerator(); enumerator.MoveNext(); LogRecord actualItemOne = enumerator.Current; enumerator.MoveNext(); LogRecord actualItemTwo = enumerator.Current; try { enumerator.MoveNext(); LogRecord actualItemThree = enumerator.Current; Assert.Fail(); } catch (ArgumentException e) { Assert.AreEqual(e.Message, "A storage log version of 2.0 is unsupported."); } LogRecord expectedItemOne = new LogRecord(); expectedItemOne.VersionNumber = "1.0"; expectedItemOne.RequestStartTime = DateTimeOffset.ParseExact("2011-08-09T18:52:40.9241789Z", "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemOne.OperationType = "GetBlob"; expectedItemOne.RequestStatus = "AnonymousSuccess"; expectedItemOne.HttpStatusCode = "200"; expectedItemOne.EndToEndLatency = new TimeSpan(0, 0, 0, 0, 18); expectedItemOne.ServerLatency = new TimeSpan(0, 0, 0, 0, 10); expectedItemOne.AuthenticationType = "anonymous"; expectedItemOne.RequesterAccountName = null; expectedItemOne.OwnerAccountName = "myaccount"; expectedItemOne.ServiceType = "blob"; expectedItemOne.RequestUrl = new Uri("https://myaccount.blob.core.windows.net/thumb&nails/lake.jpg?timeout=30000"); expectedItemOne.RequestedObjectKey = "/myaccount/thumbnails/lake.jpg"; expectedItemOne.RequestIdHeader = new Guid("a84aa705-8a85-48c5-b064-b43bd22979c3"); expectedItemOne.OperationCount = 0; expectedItemOne.RequesterIPAddress = "123.100.2.10"; expectedItemOne.RequestVersionHeader = "2009-09-19"; expectedItemOne.RequestHeaderSize = 252; expectedItemOne.RequestPacketSize = 0; expectedItemOne.ResponseHeaderSize = 265; expectedItemOne.ResponsePacketSize = 100; expectedItemOne.RequestContentLength = 0; expectedItemOne.RequestMD5 = null; expectedItemOne.ServerMD5 = null; expectedItemOne.ETagIdentifier = "0x8CE1B6EA95033D5"; expectedItemOne.LastModifiedTime = DateTimeOffset.ParseExact("Tuesday, 09-Aug-11 18:52:40 GMT", "dddd, dd-MMM-yy HH':'mm':'ss 'GMT'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemOne.ConditionsUsed = null; expectedItemOne.UserAgentHeader = null; expectedItemOne.ReferrerHeader = null; expectedItemOne.ClientRequestId = "8/9/2011 6:52:40 PM ba98eb12-700b-4d53-9230-33a3330571fc"; LogRecord expectedItemTwo = new LogRecord(); expectedItemTwo.VersionNumber = "1.0"; expectedItemTwo.RequestStartTime = DateTimeOffset.ParseExact("2011-08-09T18:02:40.6271789Z", "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemTwo.OperationType = "PutBlob"; expectedItemTwo.RequestStatus = "Success"; expectedItemTwo.HttpStatusCode = "201"; expectedItemTwo.EndToEndLatency = new TimeSpan(0, 0, 0, 0, 28); expectedItemTwo.ServerLatency = new TimeSpan(0, 0, 0, 0, 21); expectedItemTwo.AuthenticationType = "authenticated"; expectedItemTwo.RequesterAccountName = "myaccount"; expectedItemTwo.OwnerAccountName = "myaccount"; expectedItemTwo.ServiceType = "blob"; expectedItemTwo.RequestUrl = new Uri("https://myaccount.blob.core.windows.net/thumbnails/lake.jpg?timeout=30000"); expectedItemTwo.RequestedObjectKey = "/myaccount/thumbnails/lake.jpg"; expectedItemTwo.RequestIdHeader = new Guid("fb658ee6-6123-41f5-81e2-4bfdc178fea3"); expectedItemTwo.OperationCount = 0; expectedItemTwo.RequesterIPAddress = "201.9.10.20"; expectedItemTwo.RequestVersionHeader = "2009-09-19"; expectedItemTwo.RequestHeaderSize = 438; expectedItemTwo.RequestPacketSize = 100; expectedItemTwo.ResponseHeaderSize = 223; expectedItemTwo.ResponsePacketSize = 0; expectedItemTwo.RequestContentLength = 100; expectedItemTwo.RequestMD5 = null; expectedItemTwo.ServerMD5 = "66CbMXKirxDeTr82SXBKbg=="; expectedItemTwo.ETagIdentifier = "0x8CE1B67AD25AA05"; expectedItemTwo.LastModifiedTime = DateTimeOffset.ParseExact("Tuesday, 09-Aug-11 18:02:40 GMT", "dddd, dd-MMM-yy HH':'mm':'ss 'GMT'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemTwo.ConditionsUsed = null; expectedItemTwo.UserAgentHeader = null; expectedItemTwo.ReferrerHeader = null; expectedItemTwo.ClientRequestId = "8/9/2011 6:02:40 PM ab970a57-4a49-45c4-baa9-20b687941e32"; CloudAnalyticsClientTests.AssertLogItemsEqual(expectedItemOne, actualItemOne); CloudAnalyticsClientTests.AssertLogItemsEqual(expectedItemTwo, actualItemTwo); }
public void CloudAnalyticsClientParseLogs() { string logText = "1.0;2011-08-09T18:52:40.9241789Z;GetBlob;AnonymousSuccess;200;18;10;anonymous;;myaccount;blob;\"https://myaccount.blob.core.windows.net/thumb&nails/lake.jpg?timeout=30000\";\"/myaccount/thumbnails/lake.jpg\";a84aa705-8a85-48c5-b064-b43bd22979c3;0;123.100.2.10;2009-09-19;252;0;265;100;0;;;\"0x8CE1B6EA95033D5\";Tuesday, 09-Aug-11 18:52:40 GMT;;;;\"8/9/2011 6:52:40 PM ba98eb12-700b-4d53-9230-33a3330571fc\"" + '\n' + "1.0;2011-08-09T18:02:40.6271789Z;PutBlob;Success;201;28;21;authenticated;myaccount;myaccount;blob;\"https://myaccount.blob.core.windows.net/thumbnails/lake.jpg?timeout=30000\";\"/myaccount/thumbnails/lake.jpg\";fb658ee6-6123-41f5-81e2-4bfdc178fea3;0;201.9.10.20;2009-09-19;438;100;223;0;100;;\"66CbMXKirxDeTr82SXBKbg==\";\"0x8CE1B67AD25AA05\";Tuesday, 09-Aug-11 18:02:40 GMT;;;;\"8/9/2011 6:02:40 PM ab970a57-4a49-45c4-baa9-20b687941e32\"" + '\n' + "2.0;2011-08-09T18:02:40.6271789Z;PutBlob;Success;201;28;21;authenticated;myaccount;myaccount;blob;\"https://myaccount.blob.core.windows.net/thumbnails/lake.jpg?timeout=30000\";\"/myaccount/thumbnails/lake.jpg\";fb658ee6-6123-41f5-81e2-4bfdc178fea3;0;201.9.10.20;2009-09-19;438;100;223;0;100;;\"66CbMXKirxDeTr82SXBKbg==\";\"0x8CE1B67AD25AA05\";Tuesday, 09-Aug-11 18:02:40 GMT;;;;\"8/9/2011 6:02:40 PM ab970a57-4a49-45c4-baa9-20b687941e32\"" + '\n'; Blob.CloudBlobClient blobClient = CloudAnalyticsClientTests.GenerateCloudBlobClient(); Table.CloudTableClient tableClient = CloudAnalyticsClientTests.GenerateCloudTableClient(); CloudAnalyticsClient analyticsClient = new CloudAnalyticsClient(blobClient.StorageUri, tableClient.StorageUri, tableClient.Credentials); IEnumerable<LogRecord> logRecordsEnumerable = analyticsClient.ListLogRecords(StorageService.Blob); CloudBlobContainer container = blobClient.GetContainerReference(CloudAnalyticsClientTests.GetRandomContainerName()); container.CreateIfNotExists(); CloudBlockBlob blob = container.GetBlockBlobReference("blob1"); blob.UploadText(logText); IEnumerable<LogRecord> enumerable = CloudAnalyticsClient.ParseLogBlob(blob); IEnumerator<LogRecord> enumerator = enumerable.GetEnumerator(); enumerator.MoveNext(); LogRecord actualItemOne = enumerator.Current; enumerator.MoveNext(); LogRecord actualItemTwo = enumerator.Current; try { enumerator.MoveNext(); LogRecord actualItemThree = enumerator.Current; Assert.Fail(); } catch(ArgumentException e) { Assert.AreEqual(e.Message, "A storage log version of 2.0 is unsupported."); } LogRecord expectedItemOne = new LogRecord(); expectedItemOne.VersionNumber = "1.0"; expectedItemOne.RequestStartTime = DateTimeOffset.ParseExact("2011-08-09T18:52:40.9241789Z", "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemOne.OperationType = "GetBlob"; expectedItemOne.RequestStatus = "AnonymousSuccess"; expectedItemOne.HttpStatusCode = "200"; expectedItemOne.EndToEndLatency = new TimeSpan(0, 0, 0, 0, 18); expectedItemOne.ServerLatency = new TimeSpan(0, 0, 0, 0, 10); expectedItemOne.AuthenticationType = "anonymous"; expectedItemOne.RequesterAccountName = null; expectedItemOne.OwnerAccountName = "myaccount"; expectedItemOne.ServiceType = "blob"; expectedItemOne.RequestUrl = new Uri("https://myaccount.blob.core.windows.net/thumb&nails/lake.jpg?timeout=30000"); expectedItemOne.RequestedObjectKey = "/myaccount/thumbnails/lake.jpg"; expectedItemOne.RequestIdHeader = new Guid("a84aa705-8a85-48c5-b064-b43bd22979c3"); expectedItemOne.OperationCount = 0; expectedItemOne.RequesterIPAddress = "123.100.2.10"; expectedItemOne.RequestVersionHeader = "2009-09-19"; expectedItemOne.RequestHeaderSize = 252; expectedItemOne.RequestPacketSize = 0; expectedItemOne.ResponseHeaderSize = 265; expectedItemOne.ResponsePacketSize = 100; expectedItemOne.RequestContentLength = 0; expectedItemOne.RequestMD5 = null; expectedItemOne.ServerMD5 = null; expectedItemOne.ETagIdentifier = "0x8CE1B6EA95033D5"; expectedItemOne.LastModifiedTime = DateTimeOffset.ParseExact("Tuesday, 09-Aug-11 18:52:40 GMT", "dddd, dd-MMM-yy HH':'mm':'ss 'GMT'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemOne.ConditionsUsed = null; expectedItemOne.UserAgentHeader = null; expectedItemOne.ReferrerHeader = null; expectedItemOne.ClientRequestId = "8/9/2011 6:52:40 PM ba98eb12-700b-4d53-9230-33a3330571fc"; LogRecord expectedItemTwo = new LogRecord(); expectedItemTwo.VersionNumber = "1.0"; expectedItemTwo.RequestStartTime = DateTimeOffset.ParseExact("2011-08-09T18:02:40.6271789Z", "o", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemTwo.OperationType = "PutBlob"; expectedItemTwo.RequestStatus = "Success"; expectedItemTwo.HttpStatusCode = "201"; expectedItemTwo.EndToEndLatency = new TimeSpan(0, 0, 0, 0, 28); expectedItemTwo.ServerLatency = new TimeSpan(0, 0, 0, 0, 21); expectedItemTwo.AuthenticationType = "authenticated"; expectedItemTwo.RequesterAccountName = "myaccount"; expectedItemTwo.OwnerAccountName = "myaccount"; expectedItemTwo.ServiceType = "blob"; expectedItemTwo.RequestUrl = new Uri("https://myaccount.blob.core.windows.net/thumbnails/lake.jpg?timeout=30000"); expectedItemTwo.RequestedObjectKey = "/myaccount/thumbnails/lake.jpg"; expectedItemTwo.RequestIdHeader = new Guid("fb658ee6-6123-41f5-81e2-4bfdc178fea3"); expectedItemTwo.OperationCount = 0; expectedItemTwo.RequesterIPAddress = "201.9.10.20"; expectedItemTwo.RequestVersionHeader = "2009-09-19"; expectedItemTwo.RequestHeaderSize = 438; expectedItemTwo.RequestPacketSize = 100; expectedItemTwo.ResponseHeaderSize = 223; expectedItemTwo.ResponsePacketSize = 0; expectedItemTwo.RequestContentLength = 100; expectedItemTwo.RequestMD5 = null; expectedItemTwo.ServerMD5 = "66CbMXKirxDeTr82SXBKbg=="; expectedItemTwo.ETagIdentifier = "0x8CE1B67AD25AA05"; expectedItemTwo.LastModifiedTime = DateTimeOffset.ParseExact("Tuesday, 09-Aug-11 18:02:40 GMT", "dddd, dd-MMM-yy HH':'mm':'ss 'GMT'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); expectedItemTwo.ConditionsUsed = null; expectedItemTwo.UserAgentHeader = null; expectedItemTwo.ReferrerHeader = null; expectedItemTwo.ClientRequestId = "8/9/2011 6:02:40 PM ab970a57-4a49-45c4-baa9-20b687941e32"; CloudAnalyticsClientTests.AssertLogItemsEqual(expectedItemOne, actualItemOne); CloudAnalyticsClientTests.AssertLogItemsEqual(expectedItemTwo, actualItemTwo); }