mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-15 09:35:37 -05:00
using the new smo method to initialize the smo collections (#367)
* using the new smo method to initialize the smo collections
This commit is contained in:
@@ -77,90 +77,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected HashSet<string> GetUrns(SmoQueryContext context, SqlSmoObject smoObject, string filter, string objectName)
|
||||
{
|
||||
HashSet<string> urns = null;
|
||||
string urn = string.Empty;
|
||||
try
|
||||
{
|
||||
string parentUrn = smoObject.Urn != null ? smoObject.Urn.Value : string.Empty;
|
||||
urn = parentUrn != null ? $"{parentUrn.ToString()}/{objectName}" + filter : string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(urn))
|
||||
{
|
||||
Enumerator en = new Enumerator();
|
||||
Request request = new Request(new Urn(urn));
|
||||
ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
|
||||
if (!serverConnection.IsOpen)
|
||||
{
|
||||
serverConnection.Connect();
|
||||
}
|
||||
EnumResult result = en.Process(serverConnection, request);
|
||||
|
||||
urns = GetUrns(result);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string error = string.Format(CultureInfo.InvariantCulture, "Failed getting urns. error:{0} inner:{1} stacktrace:{2}",
|
||||
ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
|
||||
Logger.Write(LogLevel.Error, error);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return urns;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the urn from the enumResult
|
||||
/// </summary>
|
||||
protected HashSet<string> GetUrns(EnumResult enumResult)
|
||||
{
|
||||
try
|
||||
{
|
||||
HashSet<string> urns = null;
|
||||
if (enumResult != null && enumResult.Data != null)
|
||||
{
|
||||
urns = new HashSet<string>();
|
||||
using (IDataReader reader = GetDataReader(enumResult.Data))
|
||||
{
|
||||
if (reader != null)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
urns.Add(reader.GetString(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return urns;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
string error = string.Format(CultureInfo.InvariantCulture, "Failed getting urns. error:{0} inner:{1} stacktrace:{2}",
|
||||
ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
|
||||
Logger.Write(LogLevel.Error, error);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected IEnumerable<T> GetSmoCollectionResult<T>(HashSet<string> urns, SmoCollectionBase retValue, SqlSmoObject parent) where T : SqlSmoObject
|
||||
{
|
||||
// the below code is filtering out tables on helsinki system
|
||||
return new SmoCollectionWrapper<T>(retValue);
|
||||
|
||||
// if (urns != null)
|
||||
// {
|
||||
// return new SmoCollectionWrapper<T>(retValue).Where(c => PassesFinalFilters(parent, c) && urns.Contains(c.Urn));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return new SmoCollectionWrapper<T>(retValue).Where(c => PassesFinalFilters(parent, c));
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user