Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
int32at committed Aug 6, 2013
2 parents 38fbe26 + fafea14 commit 97596f5
Show file tree
Hide file tree
Showing 39 changed files with 810 additions and 784 deletions.
Binary file modified lib/Sponge.Client.dll
Binary file not shown.
Binary file modified lib/Sponge.dll
Binary file not shown.
Binary file modified lib/Sponge.wsp
Binary file not shown.
71 changes: 20 additions & 51 deletions src/Sponge.Client/Configuration/ClientConfigurationManager.cs
Original file line number Diff line number Diff line change
@@ -1,70 +1,39 @@
using System;
using System.Collections.Generic;
using System.Xml;
using System.Linq;
using Sponge.Client.ConfigServiceReference;

namespace Sponge.Client.Configuration
{
public class ClientConfigurationManager: IDisposable
public class ClientConfigurationManager
{
private ConfigService _svc;

public ClientConfigurationManager(string url)
public static Configuration GetOnline(string spongeUrl, string appName, bool central)
{
if (!url.EndsWith("/"))
url += "/";

url += "_layouts/Sponge/ConfigService.asmx";

_svc = new ConfigService();
_svc.Url = url;
_svc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
}

public T Get<T>(string app, string key)
{
object result = _svc.Get(app, key);
return (T)result;
using (var svc = GetConfigService(spongeUrl))
{
var cfg = central ? svc.GetCentral(appName) : svc.GetRelative(spongeUrl, appName);
return GetConfig(cfg);
}
}

public object Get(string app, string key)
private static Configuration GetConfig(ConfigServiceReference.Configuration cfg)
{
return _svc.Get(app, key);
}
var items = (from i in cfg.ConfigurationItems
select new ConfigurationItem { Key = i.Key, Value = i.Value }).ToList();

public Dictionary<string, string> GetAll(string app)
{
return FromXml(_svc.GetAll(app));
return new Configuration(cfg.Name, cfg.SpongeUrl, cfg.IsOnline, items);
}

public void Set(string app, string key, string value)
private static ConfigService GetConfigService(string url)
{
_svc.Set(app, key, value);
}

public void CreateApplication(string appName)
{
_svc.CreateApplication(appName);
}

public bool ApplicationExists(string appName)
{
return _svc.ApplicationExists(appName);
}
if (!url.EndsWith("/"))
url = url += "/";

public void Dispose()
{
if (_svc != null)
_svc.Dispose();
}
url = url + "_layouts/Sponge/ConfigService.asmx";

private Dictionary<string, string> FromXml(XmlNode doc)
{
var dict = new Dictionary<string, string>();
foreach (XmlNode el in doc.ChildNodes)
dict.Add(el.Name, el.InnerText);
var svc = new ConfigService();
svc.Url = url;
svc.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

return dict;
return svc;
}
}
}
52 changes: 52 additions & 0 deletions src/Sponge.Client/Configuration/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Xml.Serialization;

namespace Sponge.Client.Configuration
{
[XmlRoot("Configuration")]
public class Configuration
{
[XmlElement("Name")]
public string Name { get; set; }

[XmlElement("SpongeUrl")]
public string SpongeUrl { get; set; }

[XmlElement("IsOnline")]
public bool IsOnline { get; set; }

[XmlArray("ConfigurationItems")]
[XmlArrayItem("ConfigurationItem")]
public List<ConfigurationItem> Items;

public Configuration(string name, string spongeUrl, bool isOnline, IEnumerable<ConfigurationItem> items)
{
Name = name;
SpongeUrl = spongeUrl;
IsOnline = IsOnline;
Items = items.ToList();
}

public Configuration()
{
}

public T Get<T>(string key)
{
if (Items != null && Items.Count > 0)
{
var result = Items.Single(i => i.Key.Equals(key));

if (result == null)
throw new Exception(string.Format("No Item with Key '{0}' found", key));

return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(result.Value);
}
else
throw new Exception("Configuration does not contain any items");
}
}
}
19 changes: 19 additions & 0 deletions src/Sponge.Client/Configuration/ConfigurationItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Xml.Serialization;

namespace Sponge.Client.Configuration
{
[XmlType("Item")]
public class ConfigurationItem
{
[XmlElement("Key")]
public string Key { get; set; }

[XmlElement("Value")]
public object Value { get; set; }

public ConfigurationItem()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Sponge.Client.Logging
{
public class ClientLogManager
{
public static Logger GetOnline(string webUrl, string loggerName)
public static Logger GetOnline(string webUrl, string loggerName, bool central)
{
using (var reader = GetXml(webUrl, loggerName))
using (var reader = GetXml(webUrl, loggerName, central))
{
var config = new XmlLoggingConfiguration(reader, null);
NLog.LogManager.Configuration = config;
Expand Down Expand Up @@ -47,12 +47,12 @@ public static Logger GetOffline()
return NLog.LogManager.GetLogger(Constants.SPONGE_LOGGER_NAME);
}

private static XmlReader GetXml(string webUrl, string loggerName)
private static XmlReader GetXml(string webUrl, string loggerName, bool central)
{
XmlReader reader = null;
using (var svc = GetLoggingService(webUrl))
{
var result = svc.Get(loggerName);
var result = central ? svc.GetCentral(loggerName) : svc.GetRelative(webUrl, loggerName);

if (result == null)
throw new Exception(string.Format("Invalid Result for Logger '{0}'", loggerName));
Expand All @@ -64,7 +64,7 @@ private static XmlReader GetXml(string webUrl, string loggerName)
return reader;
}

public static LoggingService GetLoggingService(string url)
private static LoggingService GetLoggingService(string url)
{
if (!url.EndsWith("/"))
url = url += "/";
Expand Down
7 changes: 6 additions & 1 deletion src/Sponge.Client/Sponge.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Configuration\ClientConfigurationManager.cs" />
<Compile Include="Logging\ClientLogger.cs" />
<Compile Include="Configuration\Configuration.cs" />
<Compile Include="Configuration\ConfigurationItem.cs" />
<Compile Include="Logging\ClientLogManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -75,6 +77,9 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="Web References\ConfigServiceReference\COnfigService.wsdl" />
<None Include="Web References\ConfigServiceReference\Configuration.datasource">
<DependentUpon>Reference.map</DependentUpon>
</None>
<None Include="Web References\ConfigServiceReference\Reference.map">
<Generator>MSDiscoCodeGenerator</Generator>
<LastGenOutput>Reference.cs</LastGenOutput>
Expand Down

0 comments on commit 97596f5

Please sign in to comment.