-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExtensions.cs
125 lines (100 loc) · 3.2 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer;
using SSMSObjectExplorerMenu.objects;
using System;
using System.IO;
using System.Xml.Serialization;
namespace SSMSObjectExplorerMenu
{
public static class Extensions
{
public static T DeserializeObject<T>(this string toDeserialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (StringReader textReader = new StringReader(toDeserialize))
{
return (T)xmlSerializer.Deserialize(textReader);
}
}
public static string SerializeObject<T>(this T toSerialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, toSerialize);
return textWriter.ToString();
}
}
public static NodeInfo GetInfo(this INodeInformation node)
{
NodeInfo info = new NodeInfo
{
UrnPath = node.UrnPath,
NavigationContext = node.NavigationContext
};
string[] context = node.NavigationContext.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (string s in context)
{
if (s.StartsWith("Server[@Name='"))
{
info.Server = s.Replace("Server[@Name='", "").Replace("']", "");
continue;
}
if (s.StartsWith("Database[@Name='"))
{
info.Database = s.Replace("Database[@Name='", "").Replace("']", "");
continue;
}
if (s.StartsWith("Table[@Name='"))
{
string[] t = s.Replace("Table[@Name='", "").Replace("' and @Schema='", "|").Replace("']", "").Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (t.Length == 2)
{
info.Table = t[0];
info.Schema = t[1];
}
continue;
}
if (s.StartsWith("View[@Name='"))
{
string[] t = s.Replace("View[@Name='", "").Replace("' and @Schema='", "|").Replace("']", "").Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (t.Length == 2)
{
info.View = t[0];
info.Schema = t[1];
}
continue;
}
if (s.StartsWith("StoredProcedure[@Name='"))
{
string[] t = s.Replace("StoredProcedure[@Name='", "").Replace("' and @Schema='", "|").Replace("']", "").Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (t.Length == 2)
{
info.StoredProcedure = t[0];
info.Schema = t[1];
}
continue;
}
if (s.StartsWith("UserDefinedFunction[@Name='"))
{
string[] t = s.Replace("UserDefinedFunction[@Name='", "").Replace("' and @Schema='", "|").Replace("']", "").Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (t.Length == 2)
{
info.Function = t[0];
info.Schema = t[1];
}
continue;
}
if (s.StartsWith("Job[@Name='"))
{
string[] t = s.Replace("Job[@Name='", "").Replace("' and @CategoryID='", "|").Replace("']", "").Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (t.Length == 2)
{
info.Job = t[0];
}
continue;
}
}
return info;
}
}
}