void LogDataReceived(object sender, BayeuxConnectionEventArgs e) { IJSonWriter output = new JSonWriter(true); output.Write(e.Message); Console.WriteLine("Response: {0}", output); Console.WriteLine(); }
public void ParseSerializedCurrentDateAsISO() { var writer = new JSonWriter(); var now = DateTime.Now; // remove miliseconds: now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0, now.Kind); using(writer.WriteObject()) writer.WriteMember("date", now); var reader = new JSonReader(writer.ToString()); var item = reader.ReadAsJSonObject(); var date = item["date"].DateTimeValue; Assert.AreEqual(now, date); }
/// <summary> /// Init constructor. /// </summary> public BayeuxConnection(IHttpDataSource connection, IHttpDataSource longPollingConnection) { if (connection == null) throw new ArgumentNullException("connection"); _syncObject = new object(); _writerCache = new StringBuilder(); _jsonWriter = new JSonWriter(_writerCache, false); _jsonWriter.CompactEnumerables = true; _jsonReader = new JSonReader(); _state = BayeuxConnectionState.Disconnected; _subscribedChannels = new List<string>(); LongPollingRetryDelay = DefaultRetryDelay; LongPollingConnectRetries = DefaultNumberOfConnectRetries; _httpConnection = connection; _httpConnection.DataReceived += DataSource_OnDataReceived; _httpConnection.DataReceiveFailed += DataSource_OnDataReceiveFailed; if (longPollingConnection != null) { _httpLongPollingConnection = longPollingConnection; _httpLongPollingConnection.DataReceived += LongPollingDataSource_OnDataReceived; _httpLongPollingConnection.DataReceiveFailed += LongPollingDataSource_OnDataReceiveFailed; } }
public void Reset() { _writer.Dispose(); _writer = new JSonWriter(); }
/// <summary> /// Gets the JSON string representation of this request. /// </summary> public override string ToString() { JSonWriter output = new JSonWriter(FormattedOutput); Write(output); return output.ToString(); }
public void TestInit() { writer = new JSonWriter(true); }
public void ParseSerializedCurrentDateAsEpochSeconds() { var writer = new JSonWriter(); var now = DateTime.Now; using (writer.WriteObject()) writer.WriteMember("date", now, JSonWriterDateFormat.UnixEpochSeconds); // remove below seconds: now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, 0, now.Kind); var reader = new JSonReader(writer.ToString()); var item = reader.ReadAsJSonObject(); var date = item["date"].ToDateTimeValue(JSonDateTimeKind.UnixEpochSeconds); Assert.AreNotEqual(0, item["date"].Int64Value); Assert.AreEqual(now, date); }
//data parameter MUST be a valid JSON object already //the iv parameter specifies if a new IV should be generated and sent with json message //by default for security a new IV is used each message public String formJson(String data, bool iv = true) { Console.Write("Data param received: "); Console.WriteLine(data); JSonWriter jw = new JSonWriter(); Object payload; SHA512Managed checksum = new SHA512Managed(); //And RIGHT HERE is where I messed up for message sending String sha512 = System.Convert.ToBase64String(checksum.ComputeHash(Encoding.UTF8.GetBytes(data))); if (encryption) { String e; if (iv) { RijndaelManaged rijn = new RijndaelManaged(); rijn.BlockSize = 256; e = EncryptIt(data, Convert.FromBase64String(Properties.Settings.Default.cryptKey), rijn.IV); payload = new Object[4] { Convert.ToInt32(encryption), sha512, e, Convert.ToBase64String(rijn.IV) }; } else { e = EncryptIt(data); payload = new Object[3] { Convert.ToInt32(encryption), sha512, e }; } } else { payload = new Object[3]{ Convert.ToInt32(encryption), sha512, Convert.ToBase64String(Encoding.ASCII.GetBytes(data)) }; } jw.Write(payload); return (jw.ToString()); }
public void ParseAdvancedStructure() { var jsonText = LoadTestInputFile("advanced.json"); var watchReader = Stopwatch.StartNew(); var reader = new JSonReader(jsonText); var result = reader.ReadAsJSonObject(); watchReader.Stop(); var watchWriter = Stopwatch.StartNew(); var writer = new JSonWriter(true); writer.Write(result); watchWriter.Stop(); Console.WriteLine("Parsing taken: {0}", watchReader.Elapsed); Console.WriteLine("Serializing taken: {0}", watchWriter.Elapsed); Console.WriteLine("{0}", writer.ToString()); Assert.IsNotNull(result); }
public void TestInit() { writer = new JSonWriter(true); writerNoIndent = new JSonWriter(false); }
/// <summary> /// Gets string representation of this object. /// </summary> public override string ToString() { IJSonWriter output = new JSonWriter(true); output.Write(_jsonResponse); return output.ToString(); }