public static void OnConvertToJSONElement(object obj, JSONElement node) { //Add to nodes for x and y Vector3 vector = (Vector3)obj; JSONConverter.AppendFieldObject(node, vector.x, "x"); JSONConverter.AppendFieldObject(node, vector.y, "y"); JSONConverter.AppendFieldObject(node, vector.z, "z"); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } return(StringUtils.HexToColor(node.InnerText)); }
public static void OnConvertToJSONElement(object obj, JSONElement node) { Quaternion quaternion = (Quaternion)obj; Vector3 euler = quaternion.eulerAngles; JSONConverter.AppendFieldObject(node, euler.x, "x"); JSONConverter.AppendFieldObject(node, euler.y, "y"); JSONConverter.AppendFieldObject(node, euler.z, "z"); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null || !(node is JSONBool)) { return(obj); } return(((JSONBool)node)._value); }
private static void AddRuntimeTypeInfoIfNecessary(Type fieldType, Type objType, JSONElement parentNode) { //If field is abstract or generic AND node is abstract or generic, insert type node so we can convert it if (parentNode is JSONObject && NeedsRuntimeTypeInfo(fieldType, objType)) { JSONElement typeNode = ToJSONElement(objType); ((JSONObject)parentNode)._fields[kJSONElementRuntimeTypeAttributeTag] = typeNode; } }
public static T FromJSONString <T>(string text) { if (!string.IsNullOrEmpty(text)) { JsonParser parser = new JsonParser(); JSONElement json = parser.Decode(text); return(FromJSONElement <T>(json)); } return(default(T)); }
public static bool DoesAssetContainNode <T>(TextAsset asset) { if (asset != null) { //Hmm this is harder as not all objects have a type? //Maybe only return true if find one? JsonParser parser = new JsonParser(); JSONElement json = parser.Decode(asset.text); } return(false); }
public static T CreateCopy <T>(T obj) { if (obj != null) { //Convert to JSON and then back again as a new node JSONElement node = ToJSONElement(obj); object defaultObj = CreateInstance(obj.GetType()); return((T)FromJSONElement(obj.GetType(), node, defaultObj)); } return(default(T)); }
/// <summary> /// Deserialize the content into a full JSON /// </summary> /// <param name="content">String data to deserialize</param> /// <exception cref="DataException">Exception thrown when invalid json is found</exception> public void Deserialize(string content) { // Remove all whitespace from the content leaving just the data string data = Regex.Replace(content, @"\s+", ""); // Make sure that data starts with JSONObject if (!(data[0] == '{' || data[0] == '[')) { throw new DataException("content is not of type json or doesn't start with '{' or '['"); } _root = JSONElement.Deserialize(data); }
public static object FromJSONString(Type type, string text) { if (!string.IsNullOrEmpty(text)) { if (!string.IsNullOrEmpty(text)) { JsonParser parser = new JsonParser(); JSONElement json = parser.Decode(text); return(FromJSONElement(type, json)); } } return(null); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } FloatRange floatRange = (FloatRange)obj; floatRange._min = JSONConverter.FieldObjectFromJSONElement <float>(node, "min"); floatRange._max = JSONConverter.FieldObjectFromJSONElement <float>(node, "max"); return(floatRange); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } if (!string.IsNullOrEmpty(node.InnerText)) { return(SystemUtils.GetType(node.InnerText)); } return(null); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } IntRange intRange = (IntRange)obj; intRange._min = JSONConverter.FieldObjectFromJSONElement <int>(node, "min"); intRange._max = JSONConverter.FieldObjectFromJSONElement <int>(node, "max"); return(intRange); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } Vector2 vector = (Vector2)obj; vector.x = JSONConverter.FieldObjectFromJSONElement <float>(node, "x"); vector.y = JSONConverter.FieldObjectFromJSONElement <float>(node, "y"); return(vector); }
private static Type ReadTypeFromRuntimeTypeInfo(JSONElement node) { Type type = null; if (node != null) { JSONElement childJSONElement = JSONUtils.FindChildWithAttributeValue(node, kJSONElementRuntimeTypeAttributeTag, ""); if (childJSONElement != null) { type = (Type)FromJSONElement(typeof(Type), childJSONElement); } } return(type); }
public static string InstallApp(WebSocketSession client, string line) { using (WebClient wc = new WebClient()) { string[] lines = File.ReadAllLines(ProgramData.Directory + "bin\\app-list.txt"); foreach (string l in lines) { JSONElement e = JSON.Parse(line); if (e.c["keyword"].ToString().Equals(Command.GetString(line, "name").ToLower())) { Stream stream = wc.OpenRead(e.c["url"].ToString()); int filesize = Convert.ToInt32(wc.ResponseHeaders["Content-Length"]); stream.Dispose(); wc.DownloadFileAsync(new Uri(e.c["url"].ToString()), ProgramData.Directory + "bin\\downloads\\" + e.c["bin"].ToString()); bool done = false; client.Send($"Ukupna velicina: {filesize / (1024 * 1024)}.{("" + filesize % (1024 * 1024)).Substring(0, 2)}MB"); wc.DownloadFileCompleted += (o, s) => done = true; while (!done) { client.Send($"Preuzeto: {(int)(new FileInfo(ProgramData.Directory + "bin\\downloads\\" + e.c["bin"].ToString()).Length / (double)filesize * 100)}%"); Thread.Sleep(500); } ; Console.WriteLine(); client.Send("Cekam da se instalacija zavrsi..."); Process.Start(new ProcessStartInfo() { FileName = ProgramData.Directory + "bin\\downloads\\" + e.c["bin"].ToString() }).WaitForExit(); client.Send("Brisem setup"); Thread.Sleep(2000); File.Delete(ProgramData.Directory + "downloads\\" + e.c["bin"].ToString()); client.Send("Instalacija zavrsena"); break; } } } return(""); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } Quaternion quaternion = (Quaternion)obj; Vector3 euler; euler.x = JSONConverter.FieldObjectFromJSONElement <float>(node, "x"); euler.y = JSONConverter.FieldObjectFromJSONElement <float>(node, "y"); euler.z = JSONConverter.FieldObjectFromJSONElement <float>(node, "z"); return(Quaternion.Euler(euler)); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } string valueName = JSONConverter.FieldObjectFromJSONElement <string>(node, "valueName"); //First try to get value from string, If not possible, use the int value of the enum int valueInt; if (!ConvertFlagsFromString(obj, valueName, out valueInt)) { valueInt = JSONConverter.FieldObjectFromJSONElement <int>(node, "valueIndex"); } return(Enum.ToObject(obj.GetType(), valueInt)); }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } Gradient gradient = new Gradient(); JSONElement colorKeysJSONElement = JSONUtils.FindChildWithAttributeValue(node, JSONConverter.kJSONFieldIdAttributeTag, "colorKeys"); if (colorKeysJSONElement != null) { List <GradientColorKey> colorKeys = new List <GradientColorKey>(); foreach (JSONElement child in colorKeysJSONElement.ChildNodes) { GradientColorKey colorKey = new GradientColorKey(); colorKey.color = JSONConverter.FieldObjectFromJSONElement <Color>(child, "color"); colorKey.time = JSONConverter.FieldObjectFromJSONElement <float>(child, "time"); colorKeys.Add(colorKey); } gradient.colorKeys = colorKeys.ToArray(); } JSONElement alphaKeysJSONElement = JSONUtils.FindChildWithAttributeValue(node, JSONConverter.kJSONFieldIdAttributeTag, "alphaKeys"); if (alphaKeysJSONElement != null) { List <GradientAlphaKey> alphaKeys = new List <GradientAlphaKey>(); foreach (JSONElement child in alphaKeysJSONElement.ChildNodes) { GradientAlphaKey alphaKey = new GradientAlphaKey(); alphaKey.alpha = JSONConverter.FieldObjectFromJSONElement <float>(child, "alpha"); alphaKey.time = JSONConverter.FieldObjectFromJSONElement <float>(child, "time"); alphaKeys.Add(alphaKey); } gradient.alphaKeys = alphaKeys.ToArray(); } return(gradient); }
public override void Execute(string[] Args) { Program.Print("Saljem podatke na stranicu..."); string mac = Program.ArgValue(Args, "mac"), pass = Program.ArgValue(Args, "pass"); Program.PUBLIC_IP = Program.HtmlResponse("https://ifconfig.me/ip"); JSONElement json = JSON.Parse(Program.HtmlResponse("http://alantr7.uwebweb.com/alan/request/device.php", $"device={mac}&password={pass}")); if (json.c["status"].ToString() == "success") { string ip = json.c["ip"].ToString(); Program.Print("IP preuzet. Povezivanje..."); Remote.Connect(ip, mac).Wait(); } else { Program.Print($"Greska: " + json.c["error"].ToString()); } }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node == null) { return(obj); } string valueName = JSONConverter.FieldObjectFromJSONElement <string>(node, "valueName"); int valueIndex = JSONConverter.FieldObjectFromJSONElement <int>(node, "valueIndex"); //First try to get value from string if (!string.IsNullOrEmpty(valueName) && Enum.IsDefined(obj.GetType(), valueName)) { return(Enum.Parse(obj.GetType(), valueName)); } //If not possible, use the int value of the enum else { return(Enum.ToObject(obj.GetType(), valueIndex)); } }
public static string StartApp(WebSocketSession client, string line) { string name = Command.GetString(line, "name"); foreach (string l in File.ReadAllLines(ProgramData.Directory + "bin\\app-installed.txt")) { JSONElement json = JSON.Parse(l); if (json.c["keyword"].ToString().ToLower().Equals(name.ToLower())) { Process.Start(new ProcessStartInfo() { FileName = json.c["path"].ToString(), RedirectStandardOutput = true, UseShellExecute = false }); return($"Aplikacija §a{name} §7pokrenuta"); } } return($"Aplikacija §c{name} §7nije pronadjena"); }
public static string ToString(JSONElement jsonElement) { if (jsonElement is JSONBool) { return(ToString((JSONBool)jsonElement)); } else if (jsonElement is JSONNumber) { return(ToString((JSONNumber)jsonElement)); } else if (jsonElement is JSONArray) { return(ToString((JSONArray)jsonElement)); } else if (jsonElement is JSONObject) { return(ToString((JSONObject)jsonElement)); } return(string.Empty); }
private JSONArray ParseArray() { JSONArray array = new JSONArray(); array._elements = new List <JSONElement>(); // [ lexer.NextToken(); while (true) { var token = lexer.LookAhead(); switch (token) { case Lexer.Token.None: TriggerError("Invalid token"); return(null); case Lexer.Token.Comma: lexer.NextToken(); break; case Lexer.Token.SquaredClose: lexer.NextToken(); return(array); default: JSONElement value = ParseValue(); if (errorMessage != null) { return(null); } array._elements.Add(value); break; } } }
public static void OnConvertToJSONElement(object obj, JSONElement node) { AnimationCurve curve = (AnimationCurve)obj; if (curve != null) { JSONElement keyframesJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, JSONConverter.kJSONArrayTag); for (int i = 0; i < curve.length; i++) { Keyframe keyFrame = curve[i]; JSONElement keyFrameJSONElement = JSONUtils.CreateJSONElement(node.OwnerDocument, "KeyFrame"); JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.inTangent, "inTangent"); JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.outTangent, "outTangent"); JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.tangentMode, "tangentMode"); JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.time, "time"); JSONConverter.AppendFieldObject(keyFrameJSONElement, keyFrame.value, "value"); JSONUtils.SafeAppendChild(keyframesJSONElement, keyFrameJSONElement); } JSONUtils.AddAttribute(node.OwnerDocument, keyframesJSONElement, JSONConverter.kJSONFieldIdAttributeTag, "keyFrames"); JSONUtils.SafeAppendChild(node, keyframesJSONElement); } }
public static void Connect(string id) { string r = cmdHttp.RequestWithCookies(Controller.URL + "remote/list", "get", ProgramData.LoginCookie); int Start, End; while ((Start = r.IndexOf('{')) > 0 && (End = r.IndexOf('}')) > 0) { string device = r.Substring(Start, End - Start + 1); Console.WriteLine("Parsing " + device); JSONElement json = JSON.Parse(device); Console.WriteLine(JSON.Stringify(json)); string device_id = json.c["device_id"].ToString(); if (device_id.Equals(id)) { Console.WriteLine("Found device."); string ipv4 = json.c["ipv4"].ToString(); string public_ip = json.c["public_ip"].ToString(); // User is allowed to device Console.WriteLine("Trying ip: " + ipv4 + ", then: " + public_ip); ws = new WebSocket($"ws://{ipv4}:25000"); ws.Open(); ws.Error += Ws_Error1; ws.Opened += Ws_Opened; ws.MessageReceived += Ws_MessageReceived; break; } r = r.Substring(End + 1); } }
public static object OnConvertFromJSONElement(object obj, JSONElement node) { if (node != null && obj != null) { IDictionary dictionary = (IDictionary)obj; Type[] dictionaryTypes = SystemUtils.GetGenericImplementationTypes(typeof(Dictionary <,>), obj.GetType()); foreach (JSONElement entryNode in node.ChildNodes) { JSONElement att = entryNode.Attributes.GetNamedItem("key"); if (att != null) { object arrayNode = JSONConverter.FromJSONElement(dictionaryTypes[1], entryNode); dictionary.Add(att.Value, arrayNode); } } return(dictionary); } return(obj); }
void Load(int windowID) { trash = GUILayout.TextField(trash); string path = ".\\" + trash; if (GUILayout.Button("Load Team") && trash != "") { if (File.Exists(path)) { JSONElement T = JSON.ParseJSONFile(path); // File.WriteAllText(path + "0", JSON.PrintJSON(T)); if (T != null) { ParseTeam(JSON.SearchJSON(T, "Team")); money = JSON.SearchJSON(T, "Money").int_value; Debug.Log(JSON.SearchJSON(T, "Money").int_value); baseLevel = JSON.SearchJSON(T, "Base Level").int_value; Debug.Log(JSON.SearchJSON(T, "Base Level").int_value); } load = false; } } }
private static Type GetRuntimeType(JSONElement node) { Type type = null; if (node is JSONObject) { JSONObject jsonObj = (JSONObject)node; JSONElement typeElement; //If the object contains a valid object type field, find type from attribute map if (jsonObj._fields.TryGetValue(kTypeFieldName, out typeElement) && typeElement is JSONString) { string JSONTag = ((JSONString)typeElement)._value; BuildTypeMap(); if (!_tagToTypeMap.TryGetValue(JSONTag, out type)) { Debug.LogError("JSON Node tag '" + JSONTag + "' is not mapped to a type, check a class has a JSONTagAttribute with the same tag"); } } } return(type); }
public static void OnConvertToJSONElement(object obj, JSONElement node) { DateTime dateTime = (DateTime)obj; node.InnerText = dateTime.ToString(); }