Cleanup : TBF.Tools removed
This commit is contained in:
@@ -1994,9 +1994,6 @@
|
|||||||
<DependentUpon>Strings.resx</DependentUpon>
|
<DependentUpon>Strings.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Strings.Designer.cs" />
|
<Compile Include="Strings.Designer.cs" />
|
||||||
<Compile Include="Tools\ByteFormatter.cs" />
|
|
||||||
<Compile Include="Tools\IniUtil.cs" />
|
|
||||||
<Compile Include="Tools\XmlTools.cs" />
|
|
||||||
<Compile Include="UiBridge\ActivityEventArgs.cs" />
|
<Compile Include="UiBridge\ActivityEventArgs.cs" />
|
||||||
<Compile Include="UiBridge\AdjustmentInProgressEventArgs.cs" />
|
<Compile Include="UiBridge\AdjustmentInProgressEventArgs.cs" />
|
||||||
<Compile Include="UiBridge\Bridge.cs" />
|
<Compile Include="UiBridge\Bridge.cs" />
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
///
|
|
||||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
||||||
///
|
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace TBF.Tools
|
|
||||||
{
|
|
||||||
public class ByteFormatter : IFormatProvider, ICustomFormatter
|
|
||||||
{
|
|
||||||
public ByteFormatter()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public object GetFormat(Type formatType)
|
|
||||||
{
|
|
||||||
if (formatType == typeof(ICustomFormatter))
|
|
||||||
return this;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Format(string fmt, object arg, IFormatProvider formatProvider)
|
|
||||||
{
|
|
||||||
if (arg.GetType() != typeof(byte))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return HandleOtherFormats(fmt, arg);
|
|
||||||
}
|
|
||||||
catch (FormatException e)
|
|
||||||
{
|
|
||||||
throw new FormatException(String.Format("The format of '{0}' is invalid.", fmt), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Convert one byte to string
|
|
||||||
///
|
|
||||||
byte b = (byte)arg;
|
|
||||||
if ((32 <= b) && (b <= 127)) return "'" + ((char)b).ToString() + "'";
|
|
||||||
if ((char)b == '\r') return "'\\r'";
|
|
||||||
if ((char)b == '\n') return "'\\n'";
|
|
||||||
if ((char)b == '\t') return "'\\t'";
|
|
||||||
if (b == 17) return "XON";
|
|
||||||
if (b == 19) return "XOFF";
|
|
||||||
if (b == 26) return "Ctrl-Z";
|
|
||||||
return b.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private string HandleOtherFormats(string format, object arg)
|
|
||||||
{
|
|
||||||
if (arg is IFormattable)
|
|
||||||
return ((IFormattable)arg).ToString(format, CultureInfo.CurrentCulture);
|
|
||||||
else if (arg != null)
|
|
||||||
return arg.ToString();
|
|
||||||
else
|
|
||||||
return String.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
///
|
|
||||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
||||||
///
|
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
namespace TBF.Tools
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The class use the WinApi GetPrivateProfileSectionNames,
|
|
||||||
/// GetPrivateProfileSection, GetPrivateProfileString, WritePrivateProfileString
|
|
||||||
/// and present easy methods to work from a NET point of view.
|
|
||||||
/// Usage:
|
|
||||||
/// IniUtil ini = new IniUtil(@"C:\program files (x86)\myapp\myapp.ini");
|
|
||||||
/// string country = ini.GetValue("Carrier","Country","NoCountry");
|
|
||||||
/// </summary>
|
|
||||||
public class IniUtil
|
|
||||||
{
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern int GetPrivateProfileSectionNames(byte[] lpszReturnBuffer, int nSize, string lpFileName);
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern int GetPrivateProfileSection(string lpAppName, byte[] lpReturnedString, int nSize, string lpFileName);
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern int GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, byte[] lpReturnedString, int nSize, string lpFileName);
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
private static extern bool WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
|
|
||||||
|
|
||||||
private const int VALUE_BUFFER = 511;
|
|
||||||
private const int SECTION_BUFFER = (1024 * 16);
|
|
||||||
private string m_sIniFile;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// .ctor with INI file name
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="fileName">Fullpath to the INI file</param>
|
|
||||||
public IniUtil(string fileName)
|
|
||||||
{
|
|
||||||
m_sIniFile = fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set the value for a specific key in a section
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="section">Section containing the key to write to</param>
|
|
||||||
/// <param name="key">Key to insert/update</param>
|
|
||||||
/// <param name="keyvalue">Value for the key</param>
|
|
||||||
/// <returns>True if OK</returns>
|
|
||||||
public bool SetValue(string section, string key, string keyvalue)
|
|
||||||
{
|
|
||||||
return WritePrivateProfileString(section, key, keyvalue, m_sIniFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the value of the specidied key in the specified section,
|
|
||||||
/// If the key doesn't exists returns the default value
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="section">Section containing the key to read from</param>
|
|
||||||
/// <param name="key">Required key</param>
|
|
||||||
/// <param name="ifMissing">Value to return in case the key is missing</param>
|
|
||||||
/// <returns>string value of the key or missing value</returns>
|
|
||||||
public string GetValue(string section, string key, string ifMissing)
|
|
||||||
{
|
|
||||||
byte[] by = new byte[VALUE_BUFFER];
|
|
||||||
int n = GetPrivateProfileString(section, key, ifMissing, by, VALUE_BUFFER, m_sIniFile);
|
|
||||||
string s = Encoding.ASCII.GetString(by);
|
|
||||||
return s.Substring(0, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the NameValueCollection for every key in the section
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="section">Section name</param>
|
|
||||||
/// <returns>NameValueCollection with nake=Key and value=value</returns>
|
|
||||||
public NameValueCollection GetSectionKeysvalues(string section)
|
|
||||||
{
|
|
||||||
NameValueCollection n = new NameValueCollection();
|
|
||||||
if(section.Length > 0)
|
|
||||||
{
|
|
||||||
byte[] by = new byte[SECTION_BUFFER];
|
|
||||||
int x = GetPrivateProfileSection(section, by, SECTION_BUFFER, m_sIniFile);
|
|
||||||
if(x > 0) x--;
|
|
||||||
string keysvalues = Encoding.ASCII.GetString(by, 0, x);
|
|
||||||
string[] temp = keysvalues.Split('\0');
|
|
||||||
foreach(string s in temp)
|
|
||||||
{
|
|
||||||
string[] t = s.Split('=');
|
|
||||||
n.Add(t[0], t[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the names of all sections in .INI
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>string array with all the key names</returns>
|
|
||||||
public string[] GetSectionNames()
|
|
||||||
{
|
|
||||||
byte[] by = new byte[SECTION_BUFFER];
|
|
||||||
int x = GetPrivateProfileSectionNames(by, SECTION_BUFFER, m_sIniFile);
|
|
||||||
if(x > 0) x--;
|
|
||||||
string keys = Encoding.ASCII.GetString(by, 0, x);
|
|
||||||
return keys.Split('\0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
///
|
|
||||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
||||||
///
|
|
||||||
using System.IO;
|
|
||||||
using System.Xml.Serialization;
|
|
||||||
|
|
||||||
namespace TBF.Tools
|
|
||||||
{
|
|
||||||
public static class XmlTools
|
|
||||||
{
|
|
||||||
public static string ToXmlString<T>(this T input)
|
|
||||||
{
|
|
||||||
using (var writer = new StringWriter())
|
|
||||||
{
|
|
||||||
input.ToXml(writer);
|
|
||||||
return writer.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ToXml<T>(this T objectToSerialize, Stream stream)
|
|
||||||
{
|
|
||||||
new XmlSerializer(typeof(T)).Serialize(stream, objectToSerialize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ToXml<T>(this T objectToSerialize, StringWriter writer)
|
|
||||||
{
|
|
||||||
new XmlSerializer(typeof(T)).Serialize(writer, objectToSerialize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user