pre-trim leading comma, another string builder.
This commit is contained in:
Родитель
a8ca38c8ba
Коммит
7b34263faf
|
@ -5,7 +5,7 @@ using Microsoft.WindowsAzure.Storage.Table;
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
|
||||
namespace nsgFunc
|
||||
{
|
||||
|
@ -68,15 +68,21 @@ namespace nsgFunc
|
|||
new StorageAccountAttribute(nsgSourceDataAccount)
|
||||
};
|
||||
|
||||
string nsgMessagesString;
|
||||
string nsgMessagesString = "";
|
||||
try
|
||||
{
|
||||
byte[] nsgMessages = new byte[dataLength];
|
||||
|
||||
|
||||
CloudBlockBlob blob = nsgDataBlobBinder.BindAsync<CloudBlockBlob>(attributes).Result;
|
||||
await blob.DownloadRangeToByteArrayAsync(nsgMessages, 0, startingByte, dataLength);
|
||||
|
||||
nsgMessagesString = System.Text.Encoding.UTF8.GetString(nsgMessages);
|
||||
if (nsgMessages[0] == ',')
|
||||
{
|
||||
nsgMessagesString = System.Text.Encoding.UTF8.GetString(nsgMessages, 1, (int)(dataLength - 1));
|
||||
} else
|
||||
{
|
||||
nsgMessagesString = System.Text.Encoding.UTF8.GetString(nsgMessages);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CodeAnalysis.Formatting;
|
||||
|
||||
namespace nsgFunc
|
||||
{
|
||||
|
@ -48,11 +49,23 @@ namespace nsgFunc
|
|||
}
|
||||
|
||||
// skip past the leading comma
|
||||
string trimmedMessages = nsgMessagesString.Trim();
|
||||
int curlyBrace = trimmedMessages.IndexOf('{');
|
||||
string newClientContent = "{\"records\":[";
|
||||
newClientContent += trimmedMessages.Substring(curlyBrace);
|
||||
newClientContent += "]}";
|
||||
//string trimmedMessages = nsgMessagesString.Trim();
|
||||
//int curlyBrace = trimmedMessages.IndexOf('{');
|
||||
//string newClientContent = "{\"records\":[";
|
||||
//newClientContent += trimmedMessages.Substring(curlyBrace);
|
||||
//newClientContent += "]}";
|
||||
|
||||
StringBuilder sb = StringBuilderPool.Allocate();
|
||||
string newClientContent = "";
|
||||
try
|
||||
{
|
||||
sb.Append("{\"records\":[").Append(nsgMessagesString).Append("]}");
|
||||
newClientContent = sb.ToString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
StringBuilderPool.Free(sb);
|
||||
}
|
||||
|
||||
//
|
||||
// newClientContent looks like this:
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace nsgFunc
|
|||
{
|
||||
throw new System.Exception("Sending to Splunk. Unplanned exception.", f);
|
||||
}
|
||||
bytesSent += transmission.Length;
|
||||
bytesSent += transmission.Length;
|
||||
}
|
||||
return bytesSent;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче