-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObixAbout.cs
More file actions
111 lines (101 loc) · 4 KB
/
ObixAbout.cs
File metadata and controls
111 lines (101 loc) · 4 KB
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
using ObixClientLibrary.Extensions;
using System;
using System.Xml.Linq;
namespace ObixClientLibrary
{
public class ObixAbout
{
public string Version { get; set; }
public string ServerName { get; set; }
public string ServerTime { get; set; }
public string ServerBootTime { get; set; }
public string VendorName { get; set; }
public string VendorUrl { get; set; }
public string ProductName { get; set; }
public string ProductVersion { get; set; }
public string ProductUrl { get; set; }
public override string ToString()
{
return String.Format("Obix Server v{0}: Name={1} Vendor={2} ({3}) Product={4} ({5})", this.Version, this.ServerName, this.VendorName, this.VendorUrl, this.ProductName, this.ProductUrl);
}
/// <summary>
/// Converts a provided obix:About XElement contract into an ObixAbout instance.
/// </summary>
/// <param name="parentElement">An instance an oBIX:About contract</param>
/// <returns>An ObixAbout object if conversion succeeded, null if an error was encountered.</returns>
public static ObixAbout FromXElement(XElement parentElement)
{
string version = null;
string serverName = null;
string serverTime = null;
string serverBootTime = null;
string vendorName = null;
string vendorUrl = null;
string productName = null;
string productVersion = null;
string productUrl = null;
if (parentElement == null
|| parentElement.Name.LocalName != "obj"
|| parentElement.Attribute("is") == null
|| string.IsNullOrEmpty(parentElement.Attribute("is").Value) == true
|| parentElement.Attribute("is").Value != "obix:About")
{
return null;
}
foreach (XElement child in parentElement.Elements())
{
if (child.IsNullOrNullContract() || child.HasObixValue() == false
|| string.IsNullOrEmpty(child.ObixName()) == true)
{
continue;
}
string name = child.ObixName();
string val = child.ObixValue();
switch (name)
{
case "obixVersion":
version = val;
break;
case "serverName":
serverName = val;
break;
case "serverTime":
serverTime = val;
break;
case "serverBootTime":
serverBootTime = val;
break;
case "vendorName":
vendorName = val;
break;
case "vendorUrl":
vendorUrl = val;
break;
case "productName":
productName = val;
break;
case "productVersion":
productVersion = val;
break;
case "productUrl":
productUrl = val;
break;
default: break;
}
}
ObixAbout about = new ObixAbout()
{
ProductName = productName,
ProductUrl = productUrl,
ProductVersion = productVersion,
ServerBootTime = serverBootTime,
ServerName = serverName,
ServerTime = serverTime,
VendorName = vendorName,
VendorUrl = vendorUrl,
Version = version
};
return about;
}
}
}