コード例 #1
0
        public void SerializeDateTime()
        {
            DateTime dt       = new DateTime(2008, 1, 1, 20, 10, 31, 0, DateTimeKind.Utc);
            OSD      llsdDate = OSD.FromDate(dt);

            byte[] binaryDateSerialized = OSDParser.SerializeLLSDBinary(llsdDate);
            Assert.AreEqual(binaryDateTime, binaryDateSerialized);

            // check if a *local* time can be serialized and deserialized
            DateTime dtOne       = new DateTime(2009, 12, 30, 8, 25, 10, DateTimeKind.Local);
            OSD      llsdDateOne = OSD.FromDate(dtOne);

            byte[] binaryDateOneSerialized = OSDParser.SerializeLLSDBinary(llsdDateOne);
            OSD    llsdDateOneDS           = OSDParser.DeserializeLLSDBinary(binaryDateOneSerialized);

            Assert.AreEqual(OSDType.Date, llsdDateOneDS.Type);
            Assert.AreEqual(dtOne, llsdDateOneDS.AsDate());

            DateTime dtTwo       = new DateTime(2010, 11, 11, 10, 8, 20, DateTimeKind.Utc);
            OSD      llsdDateTwo = OSD.FromDate(dtTwo);

            byte[] binaryDateTwoSerialized = OSDParser.SerializeLLSDBinary(llsdDateTwo);
            OSD    llsdDateTwoDS           = OSDParser.DeserializeLLSDBinary(binaryDateTwoSerialized);

            Assert.AreEqual(OSDType.Date, llsdDateOneDS.Type);
            Assert.AreEqual(dtTwo.ToLocalTime(), llsdDateTwoDS.AsDate());
        }
コード例 #2
0
        public void SerializeDate()
        {
            DateTime dtOne     = new DateTime(2005, 8, 10, 11, 23, 4, DateTimeKind.Utc);
            OSD      llsdOne   = OSD.FromDate(dtOne);
            string   sDtOne    = OSDParser.SerializeLLSDNotation(llsdOne);
            OSD      llsdOneDS = OSDParser.DeserializeLLSDNotation(sDtOne);

            Assert.AreEqual(OSDType.Date, llsdOneDS.Type);
            DateTime dtOneDS = llsdOneDS.AsDate();

            Assert.AreEqual(dtOne, dtOneDS.ToUniversalTime());

            DateTime dtTwo     = new DateTime(2010, 10, 11, 23, 00, 10, 100, DateTimeKind.Utc);
            OSD      llsdTwo   = OSD.FromDate(dtTwo);
            string   sDtTwo    = OSDParser.SerializeLLSDNotation(llsdTwo);
            OSD      llsdTwoDS = OSDParser.DeserializeLLSDNotation(sDtTwo);

            Assert.AreEqual(OSDType.Date, llsdTwoDS.Type);
            DateTime dtTwoDS = llsdTwoDS.AsDate();

            Assert.AreEqual(dtTwo, dtTwoDS.ToUniversalTime());

            // check if a *local* time can be serialized and deserialized
            DateTime dtThree              = new DateTime(2009, 12, 30, 8, 25, 10, DateTimeKind.Local);
            OSD      llsdDateThree        = OSD.FromDate(dtThree);
            string   sDateThreeSerialized = OSDParser.SerializeLLSDNotation(llsdDateThree);
            OSD      llsdDateThreeDS      = OSDParser.DeserializeLLSDNotation(sDateThreeSerialized);

            Assert.AreEqual(OSDType.Date, llsdDateThreeDS.Type);
            Assert.AreEqual(dtThree, llsdDateThreeDS.AsDate());
        }
コード例 #3
0
ファイル: BinaryLLSDTests.cs プロジェクト: hibecki/workb
 public void DeserializeDateTime()
 {
     OSD llsdDateTime = OSDParser.DeserializeLLSDBinary(binaryDateTime);
     Assert.AreEqual(OSDType.Date, llsdDateTime.Type);
     DateTime dt = new DateTime(2008, 1, 1, 20, 10, 31, 0, DateTimeKind.Utc);
     DateTime dateLocal = llsdDateTime.AsDate();
     Assert.AreEqual(dt, dateLocal.ToUniversalTime());
 }
コード例 #4
0
        public void DeserializeDate()
        {
            string sDateOne = "d\"2007-12-31T20:49:10Z\"";
            OSD    llsdOne  = OSDParser.DeserializeLLSDNotation(sDateOne);

            Assert.AreEqual(OSDType.Date, llsdOne.Type);
            DateTime dt   = new DateTime(2007, 12, 31, 20, 49, 10, 0, DateTimeKind.Utc);
            DateTime dtDS = llsdOne.AsDate();

            Assert.AreEqual(dt, dtDS.ToUniversalTime());
        }
コード例 #5
0
        public static object SerializeLisp(OSD osd)
        {
            switch (osd.Type)
            {
            case OSDType.Unknown:
                throw new InvalidCastException();

            case OSDType.Boolean:
                return(osd.AsBoolean());

            case OSDType.Integer:
                return(osd.AsInteger());

            case OSDType.Real:
                return(osd.AsReal());

            case OSDType.String:
                return(osd.AsString());

            case OSDType.Date:
                return(osd.AsDate());

            case OSDType.URI:
                return(osd.AsUri());

            case OSDType.UUID:
                return(osd.AsUUID());

            case OSDType.Binary:
                return(osd.AsBinary());

            case OSDType.Array:
                OSDArray args = (OSDArray)osd;
                Cons     ret  = null;
                for (int i = args.Count - 1; i >= 0; --i)
                {
                    ret = new Cons(args[i], ret);
                }
                return(ret);

            case OSDType.Map:
                Cons   list = null;
                OSDMap map  = (OSDMap)osd;
                foreach (KeyValuePair <string, OSD> kvp in map)
                {
                    Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value)));
                    list = new Cons(kv, list);
                }
                return(Cons.Reverse(list));

            default:
                return(osd);
            }
        }
コード例 #6
0
ファイル: WorldBuilding.cs プロジェクト: drzo/opensim4opencog
        public static object SerializeLisp(OSD osd)
        {
            switch (osd.Type)
            {
                case OSDType.Unknown:
                    throw new InvalidCastException();
                case OSDType.Boolean:
                    return osd.AsBoolean();
                case OSDType.Integer:
                    return osd.AsInteger();
                case OSDType.Real:
                    return osd.AsReal();
                case OSDType.String:
                    return osd.AsString();
                case OSDType.Date:
                    return osd.AsDate();
                case OSDType.URI:
                    return osd.AsUri();
                case OSDType.UUID:
                    return osd.AsUUID();

                case OSDType.Binary:
                    return osd.AsBinary();
                case OSDType.Array:
                    OSDArray args = (OSDArray) osd;
                    Cons ret = null;
                    for (int i = args.Count - 1; i >= 0; --i)
                    {
                        ret = new Cons(args[i], ret);
                    }
                    return ret;
                case OSDType.Map:
                    Cons list = null;
                    OSDMap map = (OSDMap) osd;
                    foreach (KeyValuePair<string, OSD> kvp in map)
                    {
                        Cons kv = new Cons(kvp.Key, new Cons(SerializeLisp(kvp.Value)));
                        list = new Cons(kv,list);
                    }
                    return Cons.Reverse(list);
                default:
                    return osd;
            }

        }