| | |
| | | using System.Runtime.Serialization.Json;
|
| | | using System.Text;
|
| | | using System.Xml;
|
| | | using QtVsTools.Core;
|
| | |
|
| | | /// <summary>
|
| | | /// The classes in this namespace provide support to the serialization and deserialization of
|
| | |
| | | serializer.WriteObject(writer, obj);
|
| | | writer.Close();
|
| | | return new JsonData() { Stream = stream };
|
| | | } catch (Exception e) {
|
| | | } catch (Exception exception) {
|
| | | exception.Log();
|
| | | if (stream != null && stream.CanRead && stream.Length > 0)
|
| | | stream.Dispose();
|
| | | System.Diagnostics.Debug.WriteLine(
|
| | | e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
| | | using (reader = XmlReader.Create(data.XmlStream)) {
|
| | | var obj = serializer.ReadObject(reader, false);
|
| | |
|
| | | var container = obj as IDeferredObjectContainer;
|
| | | if (container != null)
|
| | | if (obj is IDeferredObjectContainer container)
|
| | | deferredObjects.ForEach(x => container.Add(x));
|
| | |
|
| | | return obj;
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | | System.Diagnostics.Debug.WriteLine(
|
| | | e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
|
| | | } catch (Exception exception) {
|
| | | exception.Log();
|
| | | return null;
|
| | |
|
| | | } finally {
|
| | |
| | | data.XmlStream = new MemoryStream(xmlData);
|
| | | }
|
| | | return true;
|
| | | } catch (Exception e) {
|
| | | System.Diagnostics.Debug.WriteLine(
|
| | | e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
|
| | | } catch (Exception exception) {
|
| | | exception.Log();
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | #region //////////////////// Data Contract Surrogate //////////////////////////////////////
|
| | |
|
| | | static Exclusive<Serializer> sharedInstance = new Exclusive<Serializer>();
|
| | | static readonly Exclusive<Serializer> sharedInstance = new Exclusive<Serializer>();
|
| | | private XmlReader reader = null;
|
| | | private List<IDeferredObject> deferredObjects = new List<IDeferredObject>();
|
| | | private readonly List<IDeferredObject> deferredObjects = new List<IDeferredObject>();
|
| | |
|
| | | public static IJsonData GetCurrentJsonData()
|
| | | {
|
| | |
| | | root.Append("</root>");
|
| | | var xmlData = Encoding.UTF8.GetBytes(root.ToString());
|
| | | return new JsonData { XmlStream = new MemoryStream(xmlData) };
|
| | | } catch (Exception e) {
|
| | | System.Diagnostics.Debug.WriteLine(
|
| | | e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
|
| | | } catch (Exception exception) {
|
| | | exception.Log();
|
| | | return null;
|
| | | }
|
| | | }
|