protected override void SolveInstance(IGH_DataAccess DA) { object myObj = null; DA.GetData(0, ref myObj); if (myObj == null) { return; } var result = myObj.GetType().GetProperty("Value").GetValue(myObj); //object result = null; object conv; if (result != null) { conv = SpeckleCore.Converter.Serialise(result); } else { conv = SpeckleCore.Converter.Serialise(myObj); } var settings = new SNJ.JsonSerializerSettings() { ReferenceLoopHandling = SNJ.ReferenceLoopHandling.Ignore, Formatting = SNJ.Formatting.Indented }; DA.SetData(0, SNJ.JsonConvert.SerializeObject(conv, settings)); DA.SetData(1, conv); }
protected override void SolveInstance(IGH_DataAccess DA) { var xml_in = ""; DA.GetData(0, ref xml_in); var xml = new XmlDocument(); xml.LoadXml(xml_in); var jsonText = SNJ.JsonConvert.SerializeXmlNode(xml, SNJ.Formatting.Indented, false); SNJ.JsonSerializerSettings jsonSS = new SNJ.JsonSerializerSettings(); jsonSS.Formatting = SNJ.Formatting.Indented; jsonSS.ReferenceLoopHandling = SNJ.ReferenceLoopHandling.Ignore; jsonSS.PreserveReferencesHandling = SNJ.PreserveReferencesHandling.None; jsonSS.StringEscapeHandling = SNJ.StringEscapeHandling.EscapeNonAscii; jsonSS.NullValueHandling = SNJ.NullValueHandling.Include; jsonSS.Converters = new SNJ.JsonConverter[] { new SpecklePropertiesConverter() }; dynamic obj = SNJ.JsonConvert.DeserializeObject <Dictionary <string, object> >( jsonText, jsonSS); var so = new SpeckleObject() { Properties = obj }; DA.SetData("SpeckleObject", new GH_SpeckleObject(so)); DA.SetData("Dictionary", obj); }
private void SetSerialisationSettings() { _settings = new System.Lazy <SpeckleNewtonsoft.Newtonsoft.Json.JsonSerializerSettings>(() => { var settings = new SpeckleNewtonsoft.Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new SpeckleNewtonsoft.Newtonsoft.Json.Serialization.DefaultContractResolver() { NamingStrategy = new SpeckleNewtonsoft.Newtonsoft.Json.Serialization.CamelCaseNamingStrategy() }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Ignore }; UpdateJsonSerializerSettings(settings); return(settings); }); }
protected SpeckleApiClient(SerializationInfo info, StreamingContext context) { _settings = new System.Lazy <SpeckleNewtonsoft.Newtonsoft.Json.JsonSerializerSettings>(() => { var settings = new SpeckleNewtonsoft.Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new SpeckleNewtonsoft.Newtonsoft.Json.Serialization.DefaultContractResolver() { NamingStrategy = new SpeckleNewtonsoft.Newtonsoft.Json.Serialization.CamelCaseNamingStrategy() }, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; UpdateJsonSerializerSettings(settings); return(settings); }); UseGzip = true; BaseUrl = info.GetString("BaseUrl"); StreamId = info.GetString("StreamId"); Role = (ClientRole)info.GetInt32("Role"); ClientId = info.GetString("ClientId"); //AuthToken = info.GetString( "ApiToken" ); //string userEmail = null; // old clients will not have a user email field :/ try { var userEmail = info.GetString("UserEmail"); var acc = LocalContext.GetAccountByEmailAndRestApi(userEmail, BaseUrl); if (acc != null) { AuthToken = acc.Token; User = new User() { Email = acc.Email }; } else { throw new Exception("You do not have an account that matches this stream's server."); } } catch { var accs = LocalContext.GetAccountsByRestApi(BaseUrl); var sorted = accs.OrderByDescending(acc => acc.IsDefault).ToList(); if (sorted.Count == 0) { throw new Exception("You do not have an account that matches this stream's server."); } else { AuthToken = accs[0].Token; User = new User() { Email = sorted[0].Email }; } } Stream = StreamGetAsync(StreamId, null).Result.Resource; // does not need waiting for, as we already have a clientid. SetupClient(); SetupWebsocket(); SetReadyTimer(); SetWsReconnectTimer(); }