Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net core compatible version #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Kavenegar-Core/Exceptions/ApiException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Kavenegar.Models.Enums;

namespace Kavenegar.Exceptions
{
public class ApiException : KavenegarException
{
readonly MetaCode _result;
public ApiException(string message, int code)
: base(message)
{
_result = (MetaCode)code;
}

public MetaCode Code
{
get { return _result; }
}

}
}
10 changes: 10 additions & 0 deletions Kavenegar-Core/Exceptions/BaseException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Kavenegar.Exceptions
{
public class KavenegarException : System.Exception
{
public KavenegarException(string message)
: base(message)
{
}
}
}
17 changes: 17 additions & 0 deletions Kavenegar-Core/Exceptions/HttpException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Kavenegar.Exceptions
{
public class HttpException : KavenegarException
{
private readonly int _code;
public HttpException(string message, int code)
: base(message)
{
_code = code;
}

public int Code
{
get { return _code; }
}
}
}
57 changes: 57 additions & 0 deletions Kavenegar-Core/Json/JsonArray.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;

namespace Kavenegar.Json
{

public class JsonArray : JsonObject
{
public List<JsonObject> Array { get; set; }
private List<JsonObject>.Enumerator _e;

public JsonArray()
{
Array = new List<JsonObject>();
}

public void AddElementToArray(JsonObject arrayElement)
{
Array.Add(arrayElement);
}

public JsonObject UpCast()
{
JsonObject objectJ = this;
return objectJ;
}

public void AddList(List<JsonObject> lista)
{
Array = lista;
}

public Boolean NextObject(out JsonObject o)
{

JsonObject outObject;
_e = Array.GetEnumerator();

if (_e.MoveNext())
{
outObject = _e.Current;
o = outObject;
return true;
}
outObject = new JsonObject();
o = outObject;
return false;
}

public int Count
{
get { return Array.Count; }
}

}

}
21 changes: 21 additions & 0 deletions Kavenegar-Core/Json/JsonBoolean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace Kavenegar.Json
{

public class JsonBoolean : JsonObject
{
public Boolean BooleanValue { get; set; }

public JsonBoolean(Boolean booleanValue)
{
BooleanValue = booleanValue;
}

public JsonObject UpCast()
{
JsonObject objectJ = this;
return objectJ;
}
}
}
20 changes: 20 additions & 0 deletions Kavenegar-Core/Json/JsonNullable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace Kavenegar.Json
{
public class JsonNullable : JsonObject
{
public String Nullable { get; set; }

public JsonNullable()
{
Nullable = "Null";
}

public JsonObject UpCast()
{
JsonObject objectJ = this;
return objectJ;
}
}
}
19 changes: 19 additions & 0 deletions Kavenegar-Core/Json/JsonNumber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Kavenegar.Json
{
public class JsonNumber : JsonObject
{
public float Number { get; set; }

public JsonNumber(float number)
{
Number = number;
}

public JsonObject UpCast()
{
JsonObject objectJ = this;
return objectJ;
}
}

}
100 changes: 100 additions & 0 deletions Kavenegar-Core/Json/JsonObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;

namespace Kavenegar.Json
{
/// <summary>
/// JsonObject is the base class.
/// JsonString,JsonNumber,JsonBoolean,JsonNullable and JsonArray inherits from JsonObject.
/// A JsonArray object may contain objects of the base class
/// </summary>

public class JsonObject
{
public Dictionary<String, JsonObject> Values;

public JsonObject()
{
Values = new Dictionary<String, JsonObject>();
}

public void AddJsonValue(String textTag, JsonObject newObject)
{
if (!Values.ContainsKey(textTag))
{
Values.Add(textTag, newObject);
}
}

public JsonObject GetObject(String key)
{
JsonObject current = Values[key];
return current;
}

public int ElementsOfDictionary()
{
return Values.Count;
}


public Boolean IsJsonString()
{
if (this is JsonString)
{
return true;
}
return false;
}

public Boolean IsJsonNumber()
{
if (this is JsonNumber)
{
return true;
}
return false;
}

public Boolean IsJsonBoolean()
{
if (this is JsonBoolean)
{
return true;
}
return false;
}

public Boolean IsJsonNullable()
{
if (this is JsonNullable)
{
return true;
}
return false;
}

public Boolean IsJsonArray()
{
if (this is JsonArray)
{
return true;
}
return false;
}

public JsonString GetAsString()
{
return (JsonString)this;
}
public JsonNumber GetAsNumber()
{
return (JsonNumber)this;
}
public JsonArray GetAsArray()
{
return (JsonArray)this;
}
}
}

22 changes: 22 additions & 0 deletions Kavenegar-Core/Json/JsonString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Kavenegar.Json
{
public class JsonString : JsonObject
{
public String Text { get; set; }

public JsonString(String text)
{
Text = text;
}

public JsonObject UpCast()
{
JsonObject objectJ = this;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, Formatting.

return objectJ;
}


}
}
Loading