Code cleanup
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Security.Cryptography;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace VAR.Focus.Web.Code
|
namespace VAR.Focus.Web.Code
|
||||||
@@ -8,7 +7,7 @@ namespace VAR.Focus.Web.Code
|
|||||||
{
|
{
|
||||||
public static string GetSHA1(string str)
|
public static string GetSHA1(string str)
|
||||||
{
|
{
|
||||||
SHA1 sha1 = SHA1Managed.Create();
|
SHA1 sha1 = SHA1.Create();
|
||||||
UTF8Encoding encoding = new UTF8Encoding();
|
UTF8Encoding encoding = new UTF8Encoding();
|
||||||
byte[] stream = null;
|
byte[] stream = null;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@@ -29,12 +28,12 @@ namespace VAR.Focus.Web.Code
|
|||||||
|
|
||||||
public static string GetCryptoToken()
|
public static string GetCryptoToken()
|
||||||
{
|
{
|
||||||
return CryptoUtils.GetSHA1(CryptoUtils.GetRandString(10));
|
return GetSHA1(GetRandString(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetHashedPassword(string password, string passwordSalt)
|
public static string GetHashedPassword(string password, string passwordSalt)
|
||||||
{
|
{
|
||||||
return CryptoUtils.GetSHA1(String.Format("{1}{0}{1}", password, passwordSalt));
|
return GetSHA1(string.Format("{1}{0}{1}", password, passwordSalt));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace VAR.Focus.Web.Code.Entities
|
|||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
private bool _active = true;
|
private bool _active = true;
|
||||||
public bool Active { get { return _active} set { _active = value; } }
|
public bool Active { get { return _active; } set { _active = value; } }
|
||||||
public string CreatedBy { get; set; }
|
public string CreatedBy { get; set; }
|
||||||
public DateTime CreatedDate { get; set; }
|
public DateTime CreatedDate { get; set; }
|
||||||
public string ModifiedBy { get; set; }
|
public string ModifiedBy { get; set; }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace VAR.Focus.Web.Code.Entities
|
|||||||
public int Y { get; set; }
|
public int Y { get; set; }
|
||||||
|
|
||||||
private bool _active = true;
|
private bool _active = true;
|
||||||
public bool Active { get { return _active} set { _active = value; } }
|
public bool Active { get { return _active; } set { _active = value; } }
|
||||||
public string CreatedBy { get; set; }
|
public string CreatedBy { get; set; }
|
||||||
public DateTime CreatedDate { get; set; }
|
public DateTime CreatedDate { get; set; }
|
||||||
public string ModifiedBy { get; set; }
|
public string ModifiedBy { get; set; }
|
||||||
|
|||||||
@@ -78,5 +78,4 @@ namespace VAR.Focus.Web.Code.Entities
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private ParserContext ctx;
|
private ParserContext _ctx;
|
||||||
private bool tainted = false;
|
private bool _tainted = false;
|
||||||
|
|
||||||
private List<Type> _knownTypes = new List<Type>();
|
private List<Type> _knownTypes = new List<Type>();
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
public bool Tainted
|
public bool Tainted
|
||||||
{
|
{
|
||||||
get { return tainted; }
|
get { return _tainted; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Type> KnownTypes
|
public List<Type> KnownTypes
|
||||||
@@ -64,7 +64,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ((float)count / (float)typeProperties.Length);
|
return ((float)count / typeProperties.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private object ConvertToType(Dictionary<string, object> obj, Type type)
|
private object ConvertToType(Dictionary<string, object> obj, Type type)
|
||||||
@@ -106,14 +106,14 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
int value = 0;
|
int value = 0;
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
char c = ctx.Next();
|
char c = _ctx.Next();
|
||||||
if (Char.IsDigit(c))
|
if (char.IsDigit(c))
|
||||||
{
|
{
|
||||||
value = (value << 4) | (c - '0');
|
value = (value << 4) | (c - '0');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c = Char.ToLower(c);
|
c = char.ToLower(c);
|
||||||
if (c >= 'a' && c <= 'f')
|
if (c >= 'a' && c <= 'f')
|
||||||
{
|
{
|
||||||
value = (value << 4) | ((c - 'a') + 10);
|
value = (value << 4) | ((c - 'a') + 10);
|
||||||
@@ -123,19 +123,19 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String ParseQuotedString()
|
private string ParseQuotedString()
|
||||||
{
|
{
|
||||||
StringBuilder scratch = new StringBuilder();
|
StringBuilder scratch = new StringBuilder();
|
||||||
char c = ctx.SkipWhite();
|
char c = _ctx.SkipWhite();
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
{
|
{
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
}
|
}
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (c == '\\')
|
if (c == '\\')
|
||||||
{
|
{
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
{
|
{
|
||||||
scratch.Append('"');
|
scratch.Append('"');
|
||||||
@@ -172,7 +172,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
{
|
{
|
||||||
scratch.Append((char)ParseHexShort());
|
scratch.Append((char)ParseHexShort());
|
||||||
}
|
}
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
}
|
}
|
||||||
else if (c == '"')
|
else if (c == '"')
|
||||||
{
|
{
|
||||||
@@ -181,55 +181,55 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
scratch.Append(c);
|
scratch.Append(c);
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
}
|
}
|
||||||
} while (!ctx.AtEnd());
|
} while (!_ctx.AtEnd());
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
}
|
}
|
||||||
return scratch.ToString();
|
return scratch.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String ParseString()
|
private string ParseString()
|
||||||
{
|
{
|
||||||
char c = ctx.SkipWhite();
|
char c = _ctx.SkipWhite();
|
||||||
if (c == '"')
|
if (c == '"')
|
||||||
{
|
{
|
||||||
return ParseQuotedString();
|
return ParseQuotedString();
|
||||||
}
|
}
|
||||||
StringBuilder scratch = new StringBuilder();
|
StringBuilder scratch = new StringBuilder();
|
||||||
|
|
||||||
while (!ctx.AtEnd()
|
while (!_ctx.AtEnd()
|
||||||
&& (Char.IsLetter(c) || Char.IsDigit(c) || c == '_'))
|
&& (char.IsLetter(c) || char.IsDigit(c) || c == '_'))
|
||||||
{
|
{
|
||||||
scratch.Append(c);
|
scratch.Append(c);
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
return scratch.ToString();
|
return scratch.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object ParseNumber()
|
private object ParseNumber()
|
||||||
{
|
{
|
||||||
StringBuilder scratch = new StringBuilder();
|
StringBuilder scratch = new StringBuilder();
|
||||||
bool isFloat = false;
|
bool isFloat = false;
|
||||||
int numberLenght = 0;
|
int numberLenght = 0;
|
||||||
char c;
|
char c;
|
||||||
c = ctx.SkipWhite();
|
c = _ctx.SkipWhite();
|
||||||
|
|
||||||
// Sign
|
// Sign
|
||||||
if (c == '-')
|
if (c == '-')
|
||||||
{
|
{
|
||||||
scratch.Append('-');
|
scratch.Append('-');
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integer part
|
// Integer part
|
||||||
while (Char.IsDigit(c))
|
while (char.IsDigit(c))
|
||||||
{
|
{
|
||||||
scratch.Append(c);
|
scratch.Append(c);
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
numberLenght++;
|
numberLenght++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,18 +238,18 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
{
|
{
|
||||||
isFloat = true;
|
isFloat = true;
|
||||||
scratch.Append('.');
|
scratch.Append('.');
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
while (Char.IsDigit(c))
|
while (char.IsDigit(c))
|
||||||
{
|
{
|
||||||
scratch.Append(c);
|
scratch.Append(c);
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
numberLenght++;
|
numberLenght++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberLenght == 0)
|
if (numberLenght == 0)
|
||||||
{
|
{
|
||||||
tainted = true;
|
_tainted = true;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,72 +258,72 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
{
|
{
|
||||||
isFloat = true;
|
isFloat = true;
|
||||||
scratch.Append('E');
|
scratch.Append('E');
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
if (c == '+' || c == '-')
|
if (c == '+' || c == '-')
|
||||||
{
|
{
|
||||||
scratch.Append(c);
|
scratch.Append(c);
|
||||||
}
|
}
|
||||||
while (Char.IsDigit(c))
|
while (char.IsDigit(c))
|
||||||
{
|
{
|
||||||
scratch.Append(c);
|
scratch.Append(c);
|
||||||
c = ctx.Next();
|
c = _ctx.Next();
|
||||||
numberLenght++;
|
numberLenght++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build number object from the parsed string
|
// Build number object from the parsed string
|
||||||
String s = scratch.ToString();
|
string s = scratch.ToString();
|
||||||
return isFloat ? (numberLenght < 17) ? (Object)Double.Parse(s)
|
return isFloat ? (numberLenght < 17) ? (object)double.Parse(s)
|
||||||
: Decimal.Parse(s) : (numberLenght < 19) ? (Object)System.Int32.Parse(s)
|
: decimal.Parse(s) : (numberLenght < 19) ? int.Parse(s)
|
||||||
: (Object)System.Int32.Parse(s);
|
: (object)int.Parse(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<object> ParseArray()
|
private List<object> ParseArray()
|
||||||
{
|
{
|
||||||
char c = ctx.SkipWhite();
|
char c = _ctx.SkipWhite();
|
||||||
List<object> array = new List<object>();
|
List<object> array = new List<object>();
|
||||||
if (c == '[')
|
if (c == '[')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
}
|
}
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = ctx.SkipWhite();
|
c = _ctx.SkipWhite();
|
||||||
if (c == ']')
|
if (c == ']')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (c == ',')
|
else if (c == ',')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
array.Add(ParseValue());
|
array.Add(ParseValue());
|
||||||
}
|
}
|
||||||
} while (!ctx.AtEnd());
|
} while (!_ctx.AtEnd());
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, object> ParseObject()
|
private Dictionary<string, object> ParseObject()
|
||||||
{
|
{
|
||||||
char c = ctx.SkipWhite();
|
char c = _ctx.SkipWhite();
|
||||||
Dictionary<string, object> obj = new Dictionary<string, object>();
|
Dictionary<string, object> obj = new Dictionary<string, object>();
|
||||||
if (c == '{')
|
if (c == '{')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
c = ctx.SkipWhite();
|
c = _ctx.SkipWhite();
|
||||||
}
|
}
|
||||||
String attributeName;
|
string attributeName;
|
||||||
Object attributeValue;
|
object attributeValue;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
attributeName = ParseString();
|
attributeName = ParseString();
|
||||||
c = ctx.SkipWhite();
|
c = _ctx.SkipWhite();
|
||||||
if (c == ':')
|
if (c == ':')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
attributeValue = ParseValue();
|
attributeValue = ParseValue();
|
||||||
if (attributeName.Length > 0)
|
if (attributeName.Length > 0)
|
||||||
{
|
{
|
||||||
@@ -332,21 +332,21 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
}
|
}
|
||||||
else if (c == ',')
|
else if (c == ',')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
c = ctx.SkipWhite();
|
c = _ctx.SkipWhite();
|
||||||
}
|
}
|
||||||
else if (c == '}')
|
else if (c == '}')
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Unexpected character
|
// Unexpected character
|
||||||
tainted = true;
|
_tainted = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (!ctx.AtEnd());
|
} while (!_ctx.AtEnd());
|
||||||
if (obj.Count == 0)
|
if (obj.Count == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -355,10 +355,10 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object ParseValue()
|
private object ParseValue()
|
||||||
{
|
{
|
||||||
Object token = null;
|
object token = null;
|
||||||
char c = ctx.SkipWhite();
|
char c = _ctx.SkipWhite();
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '"':
|
case '"':
|
||||||
@@ -372,13 +372,13 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
token = ParseArray();
|
token = ParseArray();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (Char.IsDigit(c) || c == '-')
|
if (char.IsDigit(c) || c == '-')
|
||||||
{
|
{
|
||||||
token = ParseNumber();
|
token = ParseNumber();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String aux = ParseString();
|
string aux = ParseString();
|
||||||
if (aux.CompareTo("true") == 0)
|
if (aux.CompareTo("true") == 0)
|
||||||
{
|
{
|
||||||
token = true;
|
token = true;
|
||||||
@@ -396,9 +396,9 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
// Unexpected string
|
// Unexpected string
|
||||||
if (aux.Length == 0)
|
if (aux.Length == 0)
|
||||||
{
|
{
|
||||||
ctx.Next();
|
_ctx.Next();
|
||||||
}
|
}
|
||||||
tainted = true;
|
_tainted = true;
|
||||||
token = null;
|
token = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,7 +407,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String CleanIdentifier(String input)
|
private string CleanIdentifier(string input)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
@@ -417,7 +417,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
c = input[i];
|
c = input[i];
|
||||||
while (Char.IsLetter(c) || Char.IsDigit(c) || c == '_')
|
while (char.IsLetter(c) || char.IsDigit(c) || c == '_')
|
||||||
{
|
{
|
||||||
i--;
|
i--;
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
@@ -433,31 +433,31 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
#region Public methods
|
#region Public methods
|
||||||
|
|
||||||
public Object Parse(String text)
|
public object Parse(string text)
|
||||||
{
|
{
|
||||||
// Get the first object
|
// Get the first object
|
||||||
ctx = new ParserContext(text);
|
_ctx = new ParserContext(text);
|
||||||
tainted = false;
|
_tainted = false;
|
||||||
ctx.Mark();
|
_ctx.Mark();
|
||||||
Object obj = ParseValue();
|
object obj = ParseValue();
|
||||||
if (ctx.AtEnd())
|
if (_ctx.AtEnd())
|
||||||
{
|
{
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "But wait, there is more!"
|
// "But wait, there is more!"
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
String name = "";
|
string name = "";
|
||||||
String strInvalidPrev = "";
|
string strInvalidPrev = "";
|
||||||
Dictionary<string, object> superObject = new Dictionary<string, object>();
|
Dictionary<string, object> superObject = new Dictionary<string, object>();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Add the object to the superObject
|
// Add the object to the superObject
|
||||||
if (!tainted && name.Length > 0 && obj != null)
|
if (!_tainted && name.Length > 0 && obj != null)
|
||||||
{
|
{
|
||||||
if (name.Length == 0)
|
if (name.Length == 0)
|
||||||
{
|
{
|
||||||
name = String.Format("{0:D2}", idx);
|
name = string.Format("{0:D2}", idx);
|
||||||
}
|
}
|
||||||
superObject.Add(name, obj);
|
superObject.Add(name, obj);
|
||||||
idx++;
|
idx++;
|
||||||
@@ -465,7 +465,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String strInvalid = ctx.GetMarked();
|
string strInvalid = _ctx.GetMarked();
|
||||||
strInvalid = strInvalid.Trim();
|
strInvalid = strInvalid.Trim();
|
||||||
if (strInvalidPrev.Length > 0
|
if (strInvalidPrev.Length > 0
|
||||||
&& "=".CompareTo(strInvalid) == 0)
|
&& "=".CompareTo(strInvalid) == 0)
|
||||||
@@ -480,14 +480,14 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check end
|
// Check end
|
||||||
if (ctx.AtEnd())
|
if (_ctx.AtEnd())
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get next object
|
// Get next object
|
||||||
tainted = false;
|
_tainted = false;
|
||||||
ctx.Mark();
|
_ctx.Mark();
|
||||||
obj = ParseValue();
|
obj = ParseValue();
|
||||||
|
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private bool indent = false;
|
private bool _indent = false;
|
||||||
private bool useTabForIndent = false;
|
private bool _useTabForIndent = false;
|
||||||
private int indentChars = 4;
|
private int _indentChars = 4;
|
||||||
private int indentThresold = 3;
|
private int _indentThresold = 3;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -23,30 +23,30 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
public JSONWriter(int indentChars)
|
public JSONWriter(int indentChars)
|
||||||
{
|
{
|
||||||
this.indent = true;
|
_indent = true;
|
||||||
this.indentChars = indentChars;
|
_indentChars = indentChars;
|
||||||
this.useTabForIndent = false;
|
_useTabForIndent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONWriter(bool useTabForIndent)
|
public JSONWriter(bool useTabForIndent)
|
||||||
{
|
{
|
||||||
this.indent = true;
|
_indent = true;
|
||||||
this.useTabForIndent = useTabForIndent;
|
_useTabForIndent = useTabForIndent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private methods
|
#region Private methods
|
||||||
|
|
||||||
private bool IsValue(Object obj)
|
private bool IsValue(object obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((obj is float) || (obj is double) ||
|
if ((obj is float) || (obj is double) ||
|
||||||
(obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64)
|
(obj is short) || (obj is int) || (obj is long)
|
||||||
|| (obj is String) || (obj is Boolean))
|
|| (obj is string) || (obj is bool))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -55,23 +55,23 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
private void WriteIndent(StringBuilder sbOutput, int level)
|
private void WriteIndent(StringBuilder sbOutput, int level)
|
||||||
{
|
{
|
||||||
if (!indent)
|
if (!_indent)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sbOutput.Append('\n');
|
sbOutput.Append('\n');
|
||||||
if (useTabForIndent)
|
if (_useTabForIndent)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < level; i++) { sbOutput.Append('\t'); }
|
for (int i = 0; i < level; i++) { sbOutput.Append('\t'); }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int n = level * indentChars;
|
int n = level * _indentChars;
|
||||||
for (int i = 0; i < n; i++) { sbOutput.Append(' '); }
|
for (int i = 0; i < n; i++) { sbOutput.Append(' '); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteString(StringBuilder sbOutput, String str)
|
private void WriteString(StringBuilder sbOutput, string str)
|
||||||
{
|
{
|
||||||
sbOutput.Append('"');
|
sbOutput.Append('"');
|
||||||
char c;
|
char c;
|
||||||
@@ -101,20 +101,20 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
sbOutput.Append("null");
|
sbOutput.Append("null");
|
||||||
}
|
}
|
||||||
else if ((obj is float) || (obj is double) ||
|
else if ((obj is float) || (obj is double) ||
|
||||||
(obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64))
|
(obj is short) || (obj is int) || (obj is long))
|
||||||
{
|
{
|
||||||
// Numbers
|
// Numbers
|
||||||
sbOutput.Append(obj.ToString());
|
sbOutput.Append(obj.ToString());
|
||||||
}
|
}
|
||||||
else if (obj is String)
|
else if (obj is string)
|
||||||
{
|
{
|
||||||
// Strings
|
// Strings
|
||||||
WriteString(sbOutput, (String)obj);
|
WriteString(sbOutput, (string)obj);
|
||||||
}
|
}
|
||||||
else if (obj is Boolean)
|
else if (obj is bool)
|
||||||
{
|
{
|
||||||
// Booleans
|
// Booleans
|
||||||
sbOutput.Append(((Boolean)obj) ? "true" : "false");
|
sbOutput.Append(((bool)obj) ? "true" : "false");
|
||||||
}
|
}
|
||||||
else if (obj is DateTime)
|
else if (obj is DateTime)
|
||||||
{
|
{
|
||||||
@@ -147,7 +147,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteList(StringBuilder sbOutput, Object obj, int level)
|
private void WriteList(StringBuilder sbOutput, object obj, int level)
|
||||||
{
|
{
|
||||||
IEnumerable list = (IEnumerable)obj;
|
IEnumerable list = (IEnumerable)obj;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
@@ -173,7 +173,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
// Write array
|
// Write array
|
||||||
bool first = true;
|
bool first = true;
|
||||||
sbOutput.Append("[ ");
|
sbOutput.Append("[ ");
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level + 1);
|
WriteIndent(sbOutput, level + 1);
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
if (!first)
|
if (!first)
|
||||||
{
|
{
|
||||||
sbOutput.Append(", ");
|
sbOutput.Append(", ");
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level + 1);
|
WriteIndent(sbOutput, level + 1);
|
||||||
}
|
}
|
||||||
@@ -190,14 +190,14 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
first = false;
|
first = false;
|
||||||
WriteValue(sbOutput, childObj, level + 1, true);
|
WriteValue(sbOutput, childObj, level + 1, true);
|
||||||
}
|
}
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level);
|
WriteIndent(sbOutput, level);
|
||||||
}
|
}
|
||||||
sbOutput.Append(" ]");
|
sbOutput.Append(" ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteObject(StringBuilder sbOutput, Object obj, int level)
|
private void WriteObject(StringBuilder sbOutput, object obj, int level)
|
||||||
{
|
{
|
||||||
IDictionary map = (IDictionary)obj;
|
IDictionary map = (IDictionary)obj;
|
||||||
int n = map.Count;
|
int n = map.Count;
|
||||||
@@ -223,7 +223,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
// Write object
|
// Write object
|
||||||
bool first = true;
|
bool first = true;
|
||||||
sbOutput.Append("{ ");
|
sbOutput.Append("{ ");
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level + 1);
|
WriteIndent(sbOutput, level + 1);
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
if (!first)
|
if (!first)
|
||||||
{
|
{
|
||||||
sbOutput.Append(", ");
|
sbOutput.Append(", ");
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level + 1);
|
WriteIndent(sbOutput, level + 1);
|
||||||
}
|
}
|
||||||
@@ -243,14 +243,14 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
sbOutput.Append(": ");
|
sbOutput.Append(": ");
|
||||||
WriteValue(sbOutput, value, level + 1, true);
|
WriteValue(sbOutput, value, level + 1, true);
|
||||||
}
|
}
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level);
|
WriteIndent(sbOutput, level);
|
||||||
}
|
}
|
||||||
sbOutput.Append(" }");
|
sbOutput.Append(" }");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteReflectedObject(StringBuilder sbOutput, Object obj, int level)
|
private void WriteReflectedObject(StringBuilder sbOutput, object obj, int level)
|
||||||
{
|
{
|
||||||
Type type = obj.GetType();
|
Type type = obj.GetType();
|
||||||
PropertyInfo[] rawProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
PropertyInfo[] rawProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||||
@@ -286,7 +286,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
// Write object
|
// Write object
|
||||||
bool first = true;
|
bool first = true;
|
||||||
sbOutput.Append("{ ");
|
sbOutput.Append("{ ");
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level + 1);
|
WriteIndent(sbOutput, level + 1);
|
||||||
}
|
}
|
||||||
@@ -302,7 +302,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
if (!first)
|
if (!first)
|
||||||
{
|
{
|
||||||
sbOutput.Append(", ");
|
sbOutput.Append(", ");
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level + 1);
|
WriteIndent(sbOutput, level + 1);
|
||||||
}
|
}
|
||||||
@@ -312,7 +312,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
sbOutput.Append(": ");
|
sbOutput.Append(": ");
|
||||||
WriteValue(sbOutput, value, level + 1, false);
|
WriteValue(sbOutput, value, level + 1, false);
|
||||||
}
|
}
|
||||||
if (!isLeaf || n > indentThresold)
|
if (!isLeaf || n > _indentThresold)
|
||||||
{
|
{
|
||||||
WriteIndent(sbOutput, level);
|
WriteIndent(sbOutput, level);
|
||||||
}
|
}
|
||||||
@@ -323,7 +323,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
#region Public methods
|
#region Public methods
|
||||||
|
|
||||||
public String Write(Object obj)
|
public string Write(object obj)
|
||||||
{
|
{
|
||||||
StringBuilder sbOutput = new StringBuilder();
|
StringBuilder sbOutput = new StringBuilder();
|
||||||
WriteValue(sbOutput, obj, 0, true);
|
WriteValue(sbOutput, obj, 0, true);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private String text;
|
private string text;
|
||||||
private int length;
|
private int length;
|
||||||
private int i;
|
private int i;
|
||||||
private int markStart;
|
private int markStart;
|
||||||
@@ -15,12 +15,12 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
#region Creator
|
#region Creator
|
||||||
|
|
||||||
public ParserContext(String text)
|
public ParserContext(string text)
|
||||||
{
|
{
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.length = text.Length;
|
length = text.Length;
|
||||||
this.i = 0;
|
i = 0;
|
||||||
this.markStart = 0;
|
markStart = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -29,7 +29,7 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
public char SkipWhite()
|
public char SkipWhite()
|
||||||
{
|
{
|
||||||
while (i < length && Char.IsWhiteSpace(text[i]))
|
while (i < length && char.IsWhiteSpace(text[i]))
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -57,10 +57,10 @@ namespace VAR.Focus.Web.Code.JSON
|
|||||||
|
|
||||||
public void Mark()
|
public void Mark()
|
||||||
{
|
{
|
||||||
markStart = this.i;
|
markStart = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String GetMarked()
|
public string GetMarked()
|
||||||
{
|
{
|
||||||
if (i < length && markStart < length)
|
if (i < length && markStart < length)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,9 +41,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Drawing" />
|
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Configuration" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="priv\keep.txt" />
|
<Content Include="priv\keep.txt" />
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
<compilation debug="true">
|
<compilation debug="true">
|
||||||
<assemblies>
|
<assemblies>
|
||||||
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||||
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
|
||||||
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
|
||||||
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
|
||||||
</assemblies>
|
</assemblies>
|
||||||
</compilation>
|
</compilation>
|
||||||
<httpHandlers>
|
<httpHandlers>
|
||||||
|
|||||||
Reference in New Issue
Block a user