public SubFrame(JsonObject jsonSchedule) : base() { JsonObjectCollection col = (JsonObjectCollection)jsonSchedule; //string jsonstr = col.ToString(); int xPos = int.Parse(col["xPos"].GetValue().ToString()); int yPos = int.Parse(col["yPos"].GetValue().ToString()); int hLen = int.Parse(col["hLen"].GetValue().ToString()); int vLen = int.Parse(col["vLen"].GetValue().ToString()); string media = (string)col["fileName"].GetValue(); int volum = int.Parse(col["volume"].GetValue().ToString()); BackColor = System.Drawing.Color.Black; Location = new System.Drawing.Point(xPos,yPos); Name = "NDS20 Player"; Size = new System.Drawing.Size(hLen, vLen); TabIndex = 0; Text = "NDSPlayerControl"; VlcLibDirectory = null; VlcLibDirectoryNeeded += new System.EventHandler<Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs> (this.OnVlcControlNeedLibDirectory); SetMedia(new FileInfo(@media)); // Audio.Volume = 10; Rate = 2.0f; }
public static string GetStringValue(JsonObject field) { if ((field == null) || (field.GetValue() == null)) { return null; } string str = null; string name = field.GetValue().GetType().Name; if (name == null) { return str; } if (!(name == "String")) { if (name != "Double") { if (name != "Boolean") { return str; } return field.GetValue().ToString(); } } else { return (string)field.GetValue(); } return field.GetValue().ToString(); }
private void GenerateDefaultConstructor(CodeTypeDeclaration classObject, JsonObject jsonObject) { CodeConstructor constructor = new CodeConstructor(); classObject.Members.Add(constructor); constructor.Attributes = MemberAttributes.Public; CodeAssignStatement statement = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeObjectCreateExpression(jsonObject.GetType(), new CodeExpression[0])); constructor.Statements.Add(statement); }
public static object GetJsonColValue(JsonObject jsonOject, string colName ) { try { var col = (JsonObjectCollection) jsonOject; return col[colName].GetValue(); } catch (Exception ex) { return null; } }
private void GenerateConstructorWithTextParameter(CodeTypeDeclaration classObject, JsonObject jsonObject) { CodeConstructor constructor = new CodeConstructor(); classObject.Members.Add(constructor); constructor.Attributes = MemberAttributes.Public; constructor.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "text")); CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(JsonTextParser), "parser", new CodeObjectCreateExpression(new CodeTypeReference(typeof(JsonTextParser)), new CodeExpression[0])); constructor.Statements.Add(statement); CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeVariableReferenceExpression("parser"), "Parse"), new CodeExpression[] { new CodeVariableReferenceExpression("text") }); CodeAssignStatement statement2 = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeCastExpression(new CodeTypeReference(jsonObject.GetType()), expression)); constructor.Statements.Add(statement2); constructor.Statements.Add(new CodeMethodReturnStatement()); }
public Subframe(JsonObject paramSchedule) { InitializeComponent(); JsonObjectCollection col = (JsonObjectCollection)paramSchedule; frameInfoStrc frameInfo = new frameInfoStrc(); frameInfo.xPos = int.Parse(col["xPos"].GetValue().ToString()); frameInfo.yPos = int.Parse(col["yPos"].GetValue().ToString()); frameInfo.width = int.Parse(col["width"].GetValue().ToString()); frameInfo.height = int.Parse(col["height"].GetValue().ToString()); frameInfo.contentsFileName = (string)col["fileName"].GetValue(); frameInfo.mute = bool.Parse(col["mute"].GetValue().ToString()); if (frameInfo.width == 0) { this.WindowState = FormWindowState.Maximized; } else { this.Width = frameInfo.width; this.Height = frameInfo.height; } this.Location = new System.Drawing.Point(frameInfo.xPos, frameInfo.yPos); # region ==== Create Player ==== m_factory = new MediaPlayerFactory(true); m_player = m_factory.CreatePlayer<IDiskPlayer>(); m_player.AspectRatio = AspectRatioMode.Default; m_player.Mute = frameInfo.mute; m_player.WindowHandle = this.pnlPlayerBack.Handle; UISync.Init(this); #endregion ====================== #region ==== Contents play ==== FileInfo contentsFileInfo = new FileInfo(@frameInfo.contentsFileName); m_media = m_factory.CreateMedia<IMediaFromFile>(contentsFileInfo.FullName); m_player.Open(m_media); m_media.Parse(true); m_player.Play(); #endregion ===================== }
public static int GetIntegerValue(JsonObject field) { string stringValue = GetStringValue(field); if (stringValue == null) { return -1; } try { return int.Parse(stringValue); } catch (OverflowException) { return -1; } catch (FormatException) { return -1; } }
public void GenerateLibrary(string objectName, JsonObject jsonObject, string path) { CodeCompileUnit unit = new CodeCompileUnit(); CodeNamespace namespace2 = new CodeNamespace("System.Net.Json.Generated"); namespace2.Imports.Add(new CodeNamespaceImport("System.Net.Json")); unit.ReferencedAssemblies.Add("System.Net.Json.dll"); unit.Namespaces.Add(namespace2); CodeTypeDeclaration declaration = new CodeTypeDeclaration(objectName); namespace2.Types.Add(declaration); declaration.TypeAttributes = TypeAttributes.Public; CodeMemberField field = new CodeMemberField(jsonObject.GetType(), "RootObject"); field.Attributes = MemberAttributes.Family; declaration.Members.Add(field); this.GenerateToStringDefaultMethod(declaration); this.GenerateDefaultConstructor(declaration, jsonObject); this.GenerateConstructorWithTextParameter(declaration, jsonObject); this.GenerateParseStaticMethod(declaration); if (typeof(JsonObjectCollection) != jsonObject.GetType()) { throw new NotImplementedException("Only objects supported in root level, not arrays or other variables."); } this.GenerateObjectCollection(declaration, (JsonObjectCollection)jsonObject); CodeDomProvider provider = CodeDomProvider.CreateProvider("cs"); CompilerParameters options = new CompilerParameters(); options.GenerateExecutable = false; if (!string.IsNullOrEmpty(path)) { options.OutputAssembly = Path.ChangeExtension(Path.Combine(path, objectName), ".dll"); } else { options.OutputAssembly = Path.ChangeExtension(objectName, ".dll"); } options.IncludeDebugInformation = false; CompilerResults results = provider.CompileAssemblyFromDom(options, new CodeCompileUnit[] { unit }); if (results.NativeCompilerReturnValue != 0) { throw new GeneratorException("Cannot compile your library.\r\nPlease send json text from which you trying to generate library to [email protected]", results); } }
public SyncFile(string _path, JsonObject obj) { path = _path; foreach (JsonObject field in obj as JsonObjectCollection) { if(field.Name == "hash"){ this.hash = (string)field.GetValue(); } if(field.Name == "time"){ DateTime.TryParseExact( (string)field.GetValue(), "yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out this.ModifiedDate); } if (field.Name == "size"){ this.FileSize = (int)field.GetValue(); } } }
private void GenerateDefaultConstructor(CodeTypeDeclaration classObject, JsonObject jsonObject) { CodeConstructor ctor = new CodeConstructor(); classObject.Members.Add(ctor); ctor.Attributes = MemberAttributes.Public; //RootObject = new JsonObjectCollection(); CodeAssignStatement assignRootObject = new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeObjectCreateExpression(jsonObject.GetType())); ctor.Statements.Add(assignRootObject); //JsonStringValue name = new JsonStringValue("Name"); //JsonStringValue surName = new JsonStringValue("SurName"); //RootObject.Add(name); //RootObject.Add(surName); }
// open new sub frame with JSON frame parameter private void OpenSubframe(JsonObject jsonFrame) { Subframe newSubframe = new Subframe(jsonFrame); newSubframe.TopLevel = false; newSubframe.Parent = this; newSubframe.BackColor = Color.Gold; newSubframe.Show(); }
//다운받을 동일한 콘텐츠 파일이 없도록 private static bool isAreadyExist(JsonArrayCollection jsonArrayCollection, JsonObject jsonObject) { foreach (JsonObject o in jsonArrayCollection) { if (o.ToString().Contains(jsonObject.ToString())) return true; } return false; }
// // for subscription // public void fromJSON(string msg) { string json; using (XmlReader xmlrd = XmlReader.Create(new StringReader(msg))) { xmlrd.ReadToFollowing(JSON); json = xmlrd.ReadElementString(); // Debug.WriteLine("json string after parsing xml data : " + json); JsonTextParser parser = new JsonTextParser(); m_jsonObj = parser.Parse(json); } }
public static JsonObjectCollection insert(JsonObjectCollection obj, JsonObject item, JsonObject newItem) { obj.Remove(item); obj.Add( newItem); return obj; }
private JsonCollection ParseCollection() { this.SkipWhiteSpace(); bool flag = false; JsonCollection jsonCollection; if ((int)this.s[this.c] == 123) { jsonCollection = (JsonCollection) new JsonObjectCollection(); } else { if ((int)this.s[this.c] != 91) { throw new FormatException(); } flag = true; jsonCollection = (JsonCollection) new JsonArrayCollection(); } ++this.c; this.SkipWhiteSpace(); if ((int)this.s[this.c] != 125 && (int)this.s[this.c] != 93) { while (true) { string str = string.Empty; if (!flag) { str = this.ParseName(); } JsonObject jsonObject = this.ParseSomethingWithoutName(); if (jsonObject != null) { if (!flag) { jsonObject.Name = str; } jsonCollection.Add(jsonObject); this.SkipWhiteSpace(); if ((int)this.s[this.c] == 44) { ++this.c; this.SkipWhiteSpace(); } else { goto label_14; } } else { break; } } throw new Exception(); label_14: this.SkipWhiteSpace(); } if (flag) { if ((int)this.s[this.c] != 93) { throw new FormatException(); } } else if ((int)this.s[this.c] != 125) { throw new FormatException(); } ++this.c; return(jsonCollection); }
/// <summary> /// Only his method is public /// </summary> /// <param name="objectName"></param> /// <param name="jsonObject"></param> public void GenerateLibrary(string objectName, JsonObject jsonObject, string path) { CodeCompileUnit ccu = new CodeCompileUnit(); CodeNamespace ns = new CodeNamespace("System.Net.Json.Generated"); ns.Imports.Add(new CodeNamespaceImport("System.Net.Json")); ccu.ReferencedAssemblies.Add(@"System.Net.Json.dll"); ccu.Namespaces.Add(ns); // root class CodeTypeDeclaration rootClass = new CodeTypeDeclaration(objectName); ns.Types.Add(rootClass); rootClass.TypeAttributes = TypeAttributes.Class | TypeAttributes.Public; // root object CodeMemberField rootObject = new CodeMemberField(jsonObject.GetType(), "RootObject"); rootObject.Attributes = MemberAttributes.Family; rootClass.Members.Add(rootObject); // [rootClass].ToString() method GenerateToStringDefaultMethod(rootClass); // .ctor() GenerateDefaultConstructor(rootClass, jsonObject); // .ctor(string text) GenerateConstructorWithTextParameter(rootClass, jsonObject); // static Parse(string text) GenerateParseStaticMethod(rootClass); // generate nested data. if (typeof(JsonObjectCollection) == jsonObject.GetType()) { GenerateObjectCollection(rootClass, (JsonObjectCollection)jsonObject); } else { throw new NotImplementedException("Only objects supported in root level, not arrays or other variables."); } // prepare for compile CodeDomProvider cdp = CodeDomProvider.CreateProvider("cs"); CompilerParameters cp = new CompilerParameters(); cp.GenerateExecutable = false; if (!string.IsNullOrEmpty(path)) { cp.OutputAssembly = System.IO.Path.ChangeExtension(System.IO.Path.Combine(path, objectName), ".dll"); } else { cp.OutputAssembly = System.IO.Path.ChangeExtension(objectName, ".dll"); } cp.IncludeDebugInformation = false; // compile code CompilerResults cr = cdp.CompileAssemblyFromDom(cp, ccu); if (cr.NativeCompilerReturnValue != 0) { throw new GeneratorException("Cannot compile your library.\r\n" + "Please send json text from which you trying to generate library to [email protected]", cr); } // show errors //Console.WriteLine("Returned code: " + cr.NativeCompilerReturnValue); //Console.WriteLine("Path: " + cr.PathToAssembly); //foreach (CompilerError e in cr.Errors) //{ //Console.WriteLine(e); //} }
public void GenerateLibrary(string objectName, JsonObject jsonObject) { GenerateLibrary(objectName, jsonObject); }
private void GenerateConstructorWithTextParameter(CodeTypeDeclaration classObject, JsonObject jsonObject) { CodeConstructor ctor = new CodeConstructor(); classObject.Members.Add(ctor); ctor.Attributes = MemberAttributes.Public; ctor.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "text")); // declare parser variable CodeVariableDeclarationStatement parserCreate = new CodeVariableDeclarationStatement( typeof(JsonTextParser), "parser", new CodeObjectCreateExpression(new CodeTypeReference(typeof(JsonTextParser)))); ctor.Statements.Add(parserCreate); // invoke Parse method on parser object CodeMethodInvokeExpression invokeParse = new CodeMethodInvokeExpression( new CodeMethodReferenceExpression(new CodeVariableReferenceExpression("parser"), "Parse"), new CodeVariableReferenceExpression("text")); // assign result of Parse method to RootObject CodeAssignStatement assignObject = new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeCastExpression(new CodeTypeReference(jsonObject.GetType()), invokeParse)); ctor.Statements.Add(assignObject); ctor.Statements.Add(new CodeMethodReturnStatement()); }
private static Object ParseJson(JsonObject jsonObject) { Type type = jsonObject.GetType(); if (type == typeof(JsonObjectCollection)) { Hashtable val = new Hashtable(); foreach (JsonObject subObj in (jsonObject as JsonObjectCollection)) { val.Add(subObj.Name, ParseJson(subObj)); } if (val.ContainsKey("__DataType")) { if (val["__DataType"] as string == "Date") { return BaseDateTime.AddMilliseconds((Double)val["__Value"]); } else if (val["__DataType"] as string == "Exception") { return new Exception((val["__Value"] as Hashtable)["Message"] as string); } else { return val; } } else { return val; } } else if (type == typeof(JsonArrayCollection)) { List<object> val = new List<object>(); foreach (JsonObject subObj in (jsonObject as JsonArrayCollection)) { val.Add(ParseJson(subObj)); } return val.ToArray(); } else if (type == typeof(JsonBooleanValue)) { return jsonObject.GetValue(); } else if (type == typeof(JsonStringValue)) { return jsonObject.GetValue(); } else if (type == typeof(JsonNumericValue)) { return jsonObject.GetValue(); } else return null; }