mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 17:23:38 -05:00
Adding sr.strings file and removing hard-coded strings (#52)
* Strings sweep for connection service * String sweep for credentials service * String sweep for hosting * String sweep for query execution service * String sweep for Workspace service * Renaming utility namespace to match standards Renaming Microsoft.SqlTools.EditorServices.Utility to Microsoft.SqlTools.ServiceLayer.Utility to match the naming changes done a while back. Also renaming them on the files that use them * Namespace change on reliable connection * Adding the new resx and designer files * Final bug fixes for srgen Fixing flakey moq package name * Removing todo as per @kevcunnane * Adding using statements as per @llali's comment * Fixing issues from broken unit tests Note: This feature contains changes that will break the contract for saving as CSV and JSON. On success, null is returned as a message instead of "Success". Changes will be made to the vscode component to handle this change.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
@@ -51,17 +52,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
public void Init(string fileName, int bufferLength, FileAccess accessMethod)
|
||||
{
|
||||
// Sanity check for valid buffer length, fileName, and accessMethod
|
||||
if (bufferLength <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(bufferLength), "Buffer length must be a positive value");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName), "File name cannot be null or whitespace");
|
||||
}
|
||||
Validate.IsGreaterThan(nameof(bufferLength), bufferLength, 0);
|
||||
Validate.IsNotNullOrEmptyString(nameof(fileName), fileName);
|
||||
if (accessMethod == FileAccess.Write)
|
||||
{
|
||||
throw new ArgumentException("Access method cannot be write-only", nameof(fileName));
|
||||
throw new ArgumentException(SR.QueryServiceFileWrapperWriteOnly, nameof(fileName));
|
||||
}
|
||||
|
||||
// Setup the buffer
|
||||
@@ -95,7 +90,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
// Make sure that we're initialized before performing operations
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new InvalidOperationException("FileStreamWrapper must be initialized before performing operations");
|
||||
throw new InvalidOperationException(SR.QueryServiceFileWrapperNotInitialized);
|
||||
}
|
||||
|
||||
MoveTo(offset);
|
||||
@@ -135,11 +130,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
// Make sure that we're initialized before performing operations
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new InvalidOperationException("FileStreamWrapper must be initialized before performing operations");
|
||||
throw new InvalidOperationException(SR.QueryServiceFileWrapperNotInitialized);
|
||||
}
|
||||
if (!fileStream.CanWrite)
|
||||
{
|
||||
throw new InvalidOperationException("This FileStreamWrapper canot be used for writing");
|
||||
throw new InvalidOperationException(SR.QueryServiceFileWrapperReadOnly);
|
||||
}
|
||||
|
||||
int bytesCopied = 0;
|
||||
@@ -172,11 +167,11 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
// Make sure that we're initialized before performing operations
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new InvalidOperationException("FileStreamWrapper must be initialized before performing operations");
|
||||
throw new InvalidOperationException(SR.QueryServiceFileWrapperNotInitialized);
|
||||
}
|
||||
if (!fileStream.CanWrite)
|
||||
{
|
||||
throw new InvalidOperationException("This FileStreamWrapper cannot be used for writing");
|
||||
throw new InvalidOperationException(SR.QueryServiceFileWrapperReadOnly);
|
||||
}
|
||||
|
||||
// Make sure we are at the right place in the file
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
|
||||
// Workaround .NET bug, see sqlbu# 440643 and vswhidbey# 599834
|
||||
// TODO: Is this workaround necessary for .NET Core?
|
||||
if (colType == null && sqlVariantTypeResult.Value == "System.Data.SqlTypes.SqlSingle")
|
||||
if (colType == null && sqlVariantTypeResult.Value == @"System.Data.SqlTypes.SqlSingle")
|
||||
{
|
||||
colType = typeof(SqlSingle);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
@@ -603,10 +604,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// <returns>Number of bytes used to store the string</returns>
|
||||
public int WriteString(string sVal)
|
||||
{
|
||||
if (sVal == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sVal), "String to store must be non-null.");
|
||||
}
|
||||
Validate.IsNotNull(nameof(sVal), sVal);
|
||||
|
||||
int iTotalLen;
|
||||
if (0 == sVal.Length) // special case of 0 length string
|
||||
@@ -640,10 +638,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// <returns>Number of bytes used to store the byte[]</returns>
|
||||
public int WriteBytes(byte[] bytesVal, int iLen)
|
||||
{
|
||||
if (bytesVal == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(bytesVal), "Byte array to store must be non-null.");
|
||||
}
|
||||
Validate.IsNotNull(nameof(bytesVal), bytesVal);
|
||||
|
||||
int iTotalLen;
|
||||
if (0 == iLen) // special case of 0 length byte array "0x"
|
||||
|
||||
@@ -13,8 +13,8 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlTools.EditorServices.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
@@ -135,7 +135,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
if (maxNumBytesToReturn <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(maxNumBytesToReturn), "Maximum number of bytes to return must be greater than zero.");
|
||||
throw new ArgumentOutOfRangeException(nameof(maxNumBytesToReturn), SR.QueryServiceDataReaderByteCountInvalid);
|
||||
}
|
||||
|
||||
//first, ask provider how much data it has and calculate the final # of bytes
|
||||
@@ -177,7 +177,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
{
|
||||
if (maxCharsToReturn <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(maxCharsToReturn), "Maximum number of chars to return must be greater than zero");
|
||||
throw new ArgumentOutOfRangeException(nameof(maxCharsToReturn), SR.QueryServiceDataReaderCharCountInvalid);
|
||||
}
|
||||
|
||||
//first, ask provider how much data it has and calculate the final # of chars
|
||||
@@ -221,37 +221,47 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
|
||||
/// <returns>String</returns>
|
||||
public string GetXmlWithMaxCapacity(int iCol, int maxCharsToReturn)
|
||||
{
|
||||
if (supportSqlXml)
|
||||
if (maxCharsToReturn <= 0)
|
||||
{
|
||||
SqlXml sm = GetSqlXml(iCol);
|
||||
if (sm == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
throw new ArgumentOutOfRangeException(nameof(maxCharsToReturn), SR.QueryServiceDataReaderXmlCountInvalid);
|
||||
}
|
||||
|
||||
//this code is mostly copied from SqlClient implementation of returning value for XML data type
|
||||
StringWriterWithMaxCapacity sw = new StringWriterWithMaxCapacity(null, maxCharsToReturn);
|
||||
XmlWriterSettings writerSettings = new XmlWriterSettings
|
||||
{
|
||||
CloseOutput = false,
|
||||
ConformanceLevel = ConformanceLevel.Fragment
|
||||
};
|
||||
// don't close the memory stream
|
||||
XmlWriter ww = XmlWriter.Create(sw, writerSettings);
|
||||
// If we're not in SQL XML mode, just return the entire thing as a string
|
||||
if (!supportSqlXml)
|
||||
{
|
||||
object o = GetValue(iCol);
|
||||
return o?.ToString();
|
||||
}
|
||||
|
||||
XmlReader reader = sm.CreateReader();
|
||||
// We have SQL XML support, so write it properly
|
||||
SqlXml sm = GetSqlXml(iCol);
|
||||
if (sm == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Setup the writer so that we don't close the memory stream and can process fragments
|
||||
// of XML
|
||||
XmlWriterSettings writerSettings = new XmlWriterSettings
|
||||
{
|
||||
CloseOutput = false, // don't close the memory stream
|
||||
ConformanceLevel = ConformanceLevel.Fragment
|
||||
};
|
||||
|
||||
using (StringWriterWithMaxCapacity sw = new StringWriterWithMaxCapacity(null, maxCharsToReturn))
|
||||
using (XmlWriter ww = XmlWriter.Create(sw, writerSettings))
|
||||
using (XmlReader reader = sm.CreateReader())
|
||||
{
|
||||
reader.Read();
|
||||
|
||||
while (!reader.EOF)
|
||||
{
|
||||
ww.WriteNode(reader, true);
|
||||
}
|
||||
|
||||
ww.Flush();
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
object o = GetValue(iCol);
|
||||
return o?.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user