예제 #1
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("---OnNavigatedTo---");
            try
            {
                if (service.State.ContainsKey(School.KEY))
                {
                    School s = DataContractSerializerHelper.Deserialize <School>(service.State[School.KEY] as string);
                    System.Diagnostics.Debug.WriteLine(s.ToString());
                }
            }
            catch (System.ArgumentNullException)
            {
                System.Diagnostics.Debug.WriteLine("No such key.");
            }

            if (NavigationContext.QueryString.ContainsKey("pinned"))
            {
                System.Diagnostics.Debug.WriteLine("Launching from a tile.");
            }

            LoadFromLocalStorage();

            base.OnNavigatedTo(e);
        }
        public void When_deserializing_Then_works()
        {
            var result = new DataContractSerializerHelper().Deserialize <TestClass>(@"<GivenDataContractSerializerHelper.TestClass>
  <Value>Wot</Value>
</GivenDataContractSerializerHelper.TestClass>");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Value, Is.EqualTo("Wot"));
        }
    public ExtensionDataObjectSerializationProxy(SerializationInfo info, StreamingContext context)
    {
        var xml = (string)info.GetValue("ExtensionData", typeof(string));

        if (!string.IsNullOrEmpty(xml))
        {
            var wrapper = DataContractSerializerHelper.LoadFromXML <ExtensionDataObjectSerializationContractProxy>(xml);
            this.ExtensionData = (wrapper == null ? null : wrapper.ExtensionData);
        }
    }
예제 #4
0
        void button2_Click(object sender, RoutedEventArgs e)
        {
            School s = new School();

            s.Name    = "Metropolia";
            s.Address = "Vanha maantie 6, Espoo";
            service.State[School.KEY] = DataContractSerializerHelper.Serialize(s);

            NavigationService.Navigate(new Uri("/View/FirstPage.xaml", UriKind.Relative));
        }
 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
 {
     if (ExtensionData != null)
     {
         var xml = DataContractSerializerHelper.GetXml(new ExtensionDataObjectSerializationContractProxy {
             ExtensionData = this.ExtensionData
         });
         info.AddValue("ExtensionData", xml);
     }
 }
        public void When_serializing_Then_works()
        {
            string result = new DataContractSerializerHelper().Serialize(new TestClass()
            {
                Value = "Wot"
            });

            Assert.That(result, Is.EqualTo(@"<?xml version=""1.0"" encoding=""utf-8""?>
<GivenDataContractSerializerHelper.TestClass xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
  <Value>Wot</Value>
</GivenDataContractSerializerHelper.TestClass>"));
        }
예제 #7
0
        public static ElementQuery Get(Input <ElementQuery> input)
        {
            var value = input.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(input).ToString();

            if (value == string.Empty)
            {
                return(null);
            }

            var query = new ElementQuery(DataContractSerializerHelper.ToObject <List <Condition> >(value));

            return(query);
        }
예제 #8
0
    public static void Test()
    {
        var response = CreateTest();

        try
        {
            var xml = DataContractSerializerHelper.GetXml(response);
            Debug.Write(xml);
        }
        catch (Exception ex)
        {
            Debug.Assert(false, ex.ToString());
        }
    }
예제 #9
0
    public static void TestSimple()
    {
        var item1 = new Item {
            Id = 1
        };
        var item2 = new Item {
            Id = 2
        };

        item1.SubItem = item2;
        var xml = DataContractSerializerHelper.GetXml(new[] { item1, item2 });

        Debug.WriteLine(xml);
    }
예제 #10
0
        /// <summary>
        /// Specifies the payload to use with the request.
        /// Automatically overrides the ContentSize property.
        /// </summary>
        /// <typeparam name="TPayload">The entity type of payload.</typeparam>
        /// <param name="payload">The payload entity.</param>
        /// <param name="requestEncoding">The value to encode the payload.</param>
        /// <param name="format">The format of the payload (xml or json).</param>
        /// <param name="serializer">Specifies which serializer to use to serialize the payload. It will user DataContract as default.</param>
        /// <returns>Itself.</returns>
        public Http SetPayload <TPayload>(TPayload payload, Encoding requestEncoding, Format format, Serializer serializer)
        {
            string p;

            if (serializer == Serializer.Xml)
            {
                p = XmlSerializerHelper.ToXmlString(payload);
            }
            else
            {
                p = format == Format.Xml
                        ? DataContractSerializerHelper.ToXmlString(payload, requestEncoding)
                        : DataContractSerializerHelper.ToJsonString(payload, requestEncoding);
            }
            return(SetPayload(p));
        }
    public static void Test()
    {
        var test = new TestConfiguration();

        Debug.WriteLine("\nTesting Xmlserializer...");
        var xml = XmlSerializationHelper.GetXml(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromXml = XmlSerializationHelper.LoadFromXML <TestConfiguration>(xml);
            Debug.WriteLine("XmlSerializer result: " + testFromXml.ToString());
        }
        Debug.WriteLine("\nTesting Json.NET...");
        var json = JsonConvert.SerializeObject(test, Formatting.Indented);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromJson = JsonConvert.DeserializeObject <TestConfiguration>(json);
            Debug.WriteLine("Json.NET result: " + testFromJson.ToString());
        }
        Debug.WriteLine("\nTesting DataContractSerializer...");
        var contractXml = DataContractSerializerHelper.GetXml(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromContractXml = DataContractSerializerHelper.LoadFromXML <TestConfiguration>(contractXml);
            Debug.WriteLine("DataContractSerializer result: " + testFromContractXml.ToString());
        }
        Debug.WriteLine("\nTesting BinaryFormatter...");
        var binary = BinaryFormatterHelper.ToBase64String(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromBinary = BinaryFormatterHelper.FromBase64String <TestConfiguration>(binary);
            Debug.WriteLine("BinaryFormatter result: " + testFromBinary.ToString());
        }
        Debug.WriteLine("\nTesting JavaScriptSerializer...");
        var javaScript = new JavaScriptSerializer().Serialize(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromJavaScript = new JavaScriptSerializer().Deserialize <TestConfiguration>(javaScript);
            Debug.WriteLine("JavaScriptSerializer result: " + testFromJavaScript.ToString());
        }
    }
    public static void Test()
    {
        var response = CreateTest();

        try
        {
            var xml = DataContractSerializerHelper.GetXml(response);
            Debug.Write(xml);
            var newResponse = DataContractSerializerHelper.GetObject <CFCConnectResponse>(xml);
            Debug.Assert(newResponse != null);
            Debug.Assert(response.StatusCode == newResponse.StatusCode);
            Debug.Assert(response.StatusDescription == newResponse.StatusDescription);
            Debug.Assert(newResponse.Comments.SequenceEqual(response.Comments));
        }
        catch (Exception ex)
        {
            Debug.Assert(false, ex.ToString());
        }
    }
예제 #13
0
        /// <summary>
        /// Sends a specified request.
        /// </summary>
        /// <typeparam name="TReturn">The entity type of the response.</typeparam>
        /// <param name="format">The format of the response (xml or json).</param>
        /// <param name="serializer">Specifies which serializer to use to serialize the payload. It will user DataContract as default.</param>
        /// <returns>The response entity.</returns>
        public TReturn DoRequest <TReturn>(Format format, Serializer serializer)
        {
            var response = DoRequest();

            if (Response != null && response != null)
            {
                try
                {
                    var result = (serializer == Serializer.Xml)
                        ? XmlSerializerHelper.FromXmlString <TReturn>(response)
                        : format == Format.Xml
                            ? DataContractSerializerHelper.FromXmlString <TReturn>(response)
                            : DataContractSerializerHelper.FromJsonString <TReturn>(response, _responseEncoding);
                    return(result);
                }
                catch { }
            }
            return(default(TReturn));
        }
    public static void Test()
    {
        Student kid = new Student();

        kid.Id        = Guid.NewGuid();
        kid.FirstName = "foo";
        kid.LastName  = "bar";
        DataContractSerializer dcs = new DataContractSerializer(
            typeof(Student),
            new Type [] { typeof(StudentId) },
            Int32.MaxValue,
            false, true, new StudentSurrogate());

        SerializationFlags.StudentGuidOnly = false;
        string xml1 = DataContractSerializerHelper.GetXml(kid, dcs);

        SerializationFlags.StudentGuidOnly = true;
        string xml2 = DataContractSerializerHelper.GetXml(kid, dcs);
    }
예제 #15
0
        public static void DCS_RectangleF()
        {
            var objs = new RectangleF[]
            {
                new RectangleF(0, 0, 0, 0),
                new RectangleF(new PointF(1.5000f, 2.5000f), new SizeF(1.5000f, 2.5000f)),
                new RectangleF(1.50001f, -2.5000f, 1.5000f, -2.5000f)
            };
            var serializedStrings = new string[]
            {
                @"<RectangleF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>0</height><width>0</width><x>0</x><y>0</y></RectangleF>",
                @"<RectangleF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2.5</height><width>1.5</width><x>1.5</x><y>2.5</y></RectangleF>",
                @"<RectangleF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>-2.5</height><width>1.5</width><x>1.50001</x><y>-2.5</y></RectangleF>"
            };

            for (int i = 0; i < objs.Length; i++)
            {
                Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize <RectangleF>(objs[i], serializedStrings[i]), objs[i]);
            }
        }
예제 #16
0
        public static void DCS_PointF()
        {
            var objs = new PointF[]
            {
                new PointF(0, 0),
                new PointF(1, 2),
                new PointF(1.5000f, -1.5000f)
            };
            var serializedStrings = new string[]
            {
                @"<PointF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>0</x><y>0</y></PointF>",
                @"<PointF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>1</x><y>2</y></PointF>",
                @"<PointF xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><x>1.5</x><y>-1.5</y></PointF>"
            };

            for (int i = 0; i < objs.Length; i++)
            {
                Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize <PointF>(objs[i], serializedStrings[i]), objs[i]);
            }
        }
예제 #17
0
        public static void DCS_Size()
        {
            var objs = new Size[]
            {
                new Size(0, 0),
                new Size(new Point(1, 2)),
                new Size(1, 2)
            };
            var serializedStrings = new string[]
            {
                @"<Size xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>0</height><width>0</width></Size>",
                @"<Size xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2</height><width>1</width></Size>",
                @"<Size xmlns=""http://schemas.datacontract.org/2004/07/System.Drawing"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><height>2</height><width>1</width></Size>"
            };

            for (int i = 0; i < objs.Length; i++)
            {
                Assert.StrictEqual(DataContractSerializerHelper.SerializeAndDeserialize <Size>(objs[i], serializedStrings[i]), objs[i]);
            }
        }
예제 #18
0
        public static Document TestWorkflowSerialization()
        {
            var doc  = new Document();
            var page = doc.Pages.First();

            page.AddNode <ProcessNode>();
            page.AddNode <DecisionNode>();
            page.AddNode <ProcessNode>();
            page.AddNode <EndNode>();

            Console.Clear();
            Console.WriteLine("Serializing Object to XML . . .");
            var a = DataContractSerializerHelper.ToString(doc);

            Console.WriteLine();
            Console.WriteLine(a);
            Console.WriteLine();
            Console.WriteLine("Serializing Object to XML completed.");
            Console.WriteLine("Deserializing XML to Object . . .");
            var o = DataContractSerializerHelper.ToObject <Document>(a);
            var b = DataContractSerializerHelper.ToString(o);

            Console.WriteLine();
            Console.WriteLine(b);
            Console.WriteLine();
            Console.WriteLine("Deserializing XML to Object completed.");
            Console.WriteLine("Matched: {0}", a == b);
            Console.WriteLine();

            return(doc);

            //        var activities = AppDomain.CurrentDomain.GetAssemblies()
            //.SelectMany(x => x.GetTypes())
            //.Where(x => x.BaseType == typeof(Roro.Activities.Activity));
            //        foreach (var act in activities)
            //        {
            //            Console.WriteLine(act);
            //        }
        }
예제 #19
0
 public override string ToString()
 {
     return(DataContractSerializerHelper.ToString(this.Value));
 }
예제 #20
0
 public ElementQuery(string xml) : this(DataContractSerializerHelper.ToObject <List <Condition> >(xml))
 {
 }
예제 #21
0
 private PomodoroInventory DeserializeDataFromXmlString(string xmlString)
 {
     return(DataContractSerializerHelper.Deserialize <PomodoroInventory>(xmlString));
 }