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);
        }
示例#2
0
        /// <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 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);
        }
示例#4
0
 //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);
        }
示例#6
0
        /// <summary>
        /// Gets string representation of this object.
        /// </summary>
        public override string ToString()
        {
            IJSonWriter output = new JSonWriter(true);

            output.Write(_jsonResponse);
            return output.ToString();
        }