예제 #1
0
 public void Marshall(object value, XStreamWriter writer, MarshallingContext context)
 {
     IList list = (IList) value;
     writer.WriteAttribute(LIST_TYPE, value.GetType().FullName);
     foreach (object o in list)
         context.ConvertOriginal(o);
 }
예제 #2
0
 public void WriteValueOn(XStreamWriter writer, object value)
 {
     writer.StartNode(SerializedName);
     object fieldValue = GetObjectFrom(value);
     if (fieldValue == null) return;
     Type actualType = fieldValue.GetType();
     if (!FieldType.Equals(actualType))
         writer.WriteAttribute(XsAttribute.classType, actualType.AssemblyQualifiedName);
 }
예제 #3
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context) {
     Array array = (Array) value;
     string typeName = value.GetType().AssemblyQualifiedName;
     int lastIndexOfBrackets = typeName.LastIndexOf("[]");
     string arrayType = string.Concat(typeName.Substring(0, lastIndexOfBrackets), typeName.Substring(lastIndexOfBrackets + 2));
     writer.WriteAttribute(ARRAY_TYPE, arrayType);
     foreach (object o in array)
         context.ConvertOriginal(o);
 }
        private static void WriteNode(XStreamWriter writer, MarshallingContext context, string node, object value)
        {
            writer.StartNode(node);
            Type type = value != null?value.GetType() : typeof(object);

            writer.WriteAttribute(Attributes.classType, type.AssemblyQualifiedName);
            context.ConvertAnother(value);
            writer.EndNode();
        }
예제 #5
0
        private void ProcessQueue(Action <string> _ErrorMessageAction, ManualResetEvent ProcessQueueWait, ConcurrentQueue <Node> ProcessQueue, EDeflateCompression QueueCompressMode)
        {
            BTaskWrapper.Run(() =>
            {
                try
                {
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Start processing Queue");
                    Dictionary <ENodeType, StreamStruct> WriteStreams = CreateStreams(QueueCompressMode);

                    using (XStreamWriter Writer = new XStreamWriter(WriteStreams))
                    {
                        while (!QueueComplete || ProcessQueue.Count > 0)
                        {
                            if (ProcessQueue.TryDequeue(out Node WriteNode))
                            {
                                if (WriteNode.GetNodeType() == ENodeType.Hierarchy)
                                {
                                    HierarchyNode CurrentHierarchyNode = (HierarchyNode)WriteNode;

                                    //Need to check that lists are not null
                                    CheckHierarchyNode(CurrentHierarchyNode);

                                    Writer.Write(CurrentHierarchyNode);
                                }

                                if (WriteNode.GetNodeType() == ENodeType.Geometry)
                                {
                                    GeometryNode CurrentGeometry = (GeometryNode)WriteNode;
                                    CheckGeometry(CurrentGeometry);

                                    Writer.Write((GeometryNode)WriteNode);
                                }

                                if (WriteNode.GetNodeType() == ENodeType.Metadata)
                                {
                                    Writer.Write((MetadataNode)WriteNode);
                                }
                            }
                            else
                            {
                                Thread.Sleep(10);
                            }
                        }
                        _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Closing Stream");
                    }
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Closed Stream");
                }
                catch (Exception ex)
                {
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] {ex.Message}\n{ex.StackTrace}");
                    State = FAILED_STATE;
                }

                ProcessQueueWait.Set();
            });
        }
예제 #6
0
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            IList list = (IList)value;

            writer.WriteAttribute(LIST_TYPE, value.GetType().FullName);
            foreach (object o in list)
            {
                context.ConvertOriginal(o);
            }
        }
예제 #7
0
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            byte[] bytes  = (byte[])value;
            string base64 = Convert.ToBase64String(bytes);

            writer.StartNode("byte-array");

            writer.SetValue(base64);

            writer.EndNode();
        }
 private void MarshalAs(object containingObject, Type type, XStreamWriter writer, MarshallingContext context)
 {
     if (type.Equals(typeof(object))) return;
     foreach (var field in mapper.GetSerializableFieldsIn(type))
     {
         field.WriteValueOn(writer, containingObject);
         context.ConvertAnother(field.GetObjectFrom(containingObject));
         writer.EndNode();
     }
     MarshalAs(containingObject, type.BaseType, writer, context);
 }
예제 #9
0
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            IList list = (IList)value;

            // classType is not valid for cross platform usage
            //writer.WriteAttribute(LIST_TYPE, value.GetType().FullName);

            foreach (object o in list)
            {
                context.ConvertOriginal(o);
            }
        }
예제 #10
0
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            Array  array               = (Array)value;
            string typeName            = value.GetType().AssemblyQualifiedName;
            int    lastIndexOfBrackets = typeName.LastIndexOf("[]");
            string arrayType           = string.Concat(typeName.Substring(0, lastIndexOfBrackets), typeName.Substring(lastIndexOfBrackets + 2));

            writer.WriteAttribute(ARRAY_TYPE, arrayType);
            foreach (object o in array)
            {
                context.ConvertOriginal(o);
            }
        }
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            IDictionary dictionary = (IDictionary)value;

            DoSpecificStuff(dictionary, writer);
            foreach (DictionaryEntry entry in dictionary)
            {
                writer.StartNode("entry");
                WriteNode(writer, context, BaseDictionaryConverter <Hashtable> .KEY, entry.Key);
                WriteNode(writer, context, BaseDictionaryConverter <Hashtable> .VALUE, entry.Value);
                writer.EndNode();
            }
        }
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            IDictionary dictionary = (IDictionary)value;

            DoSpecificStuff(dictionary, writer);
            foreach (DictionaryEntry entry in dictionary)
            {
                writer.StartNode("entry");

                context.ConvertOriginal(entry.Key);
                context.ConvertOriginal(entry.Value);

                writer.EndNode();
            }
        }
예제 #13
0
 public Marshaller(XStreamWriter writer, MarshallingContext context) {
     this.writer = writer;
     this.context = context;
 }
예제 #14
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     //  classType is not valid for cross platform usage
     //  writer.WriteAttribute(Attributes.AttributeType, value.GetType().AssemblyQualifiedName);
     writer.SetValue(value.ToString());
 }
예제 #15
0
 public void Marshall(object value, XStreamWriter writer, MarshallingContext context)
 {
     writer.WriteAttribute(XsAttribute.AttributeType, value.GetType().AssemblyQualifiedName);
     writer.SetValue(value.ToString());
 }
예제 #16
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     var folders = (Folders) value;
     foreach (var folder in folders)
         context.ConvertOriginal(folder);
 }
예제 #17
0
        public static void SimpleReadWriteTest(bool Compress = true)
        {
            string[][] LodList = new string[][]
            {
                new string[] { "Content/Models/monkey.obj", "Content/Models/monkeyLod1.obj", "Content/Models/monkeyLod2.obj" },
                new string[] { "Content/Models/squishymonkey.obj", "Content/Models/squishymonkeyLod1.obj" },
                new string[] { "Content/Models/HDmonkey.obj", "Content/Models/HDMonkeyLod1.obj", "Content/Models/HDMonkeyLod2.obj", "Content/Models/HDMonkeyLod3.obj" }
            };

            string[] MetadataStrings = new string[] { "Name:Monkey", "Name:Squishymonkey", "Name:HDmonkey" };

            string Ext = "";
            EDeflateCompression CompressEnum;

            if (Compress)
            {
                CompressEnum = EDeflateCompression.Compress;
                Ext          = "x3_c_";
            }
            else
            {
                CompressEnum = EDeflateCompression.DoNotCompress;
                Ext          = "x3_p_";
            }

            List <HierarchyNode> WriteHNodes   = new List <HierarchyNode>();
            List <GeometryNode>  WritePolygons = new List <GeometryNode>();
            List <MetadataNode>  WriteMNodes   = new List <MetadataNode>();

            Random Rand = new Random();

            for (int i = 0; i < 3; ++i)
            {
                HierarchyNode HNode = new HierarchyNode();
                HNode.UniqueID = GetId();


                MetadataNode Meta = new MetadataNode();
                Meta.Metadata = MetadataStrings[i];
                Meta.UniqueID = GetId();

                var Polygon = new GeometryNode();

                for (int f = 0; f < LodList[i].Length; ++f)
                {
                    Obj ObjFile = new Obj();
                    ObjFile.LoadObj(LodList[i][f]);
                    SetPolygonData(Polygon, ObjFile, f);
                }

                Polygon.UniqueID = GetId();

                HierarchyNode.GeometryPart Part = CreateGeometryPart(Rand, i, Polygon);

                HNode.GeometryParts.Add(Part);

                HNode.MetadataID = Meta.UniqueID;

                if (i != 0)
                {
                    HNode.ParentID = WriteHNodes[i - 1].UniqueID;
                    WriteHNodes[i - 1].ChildNodes.Add(HNode.UniqueID);

                    //HierarchyNode.GeometryPart InstancePart = CreateGeometryPart(Rand, i, WritePolygons[i - 1]);
                    //HNode.GeometryParts.Add(InstancePart);
                }

                WriteHNodes.Add(HNode);
                WritePolygons.Add(Polygon);
                WriteMNodes.Add(Meta);
            }

            Dictionary <ENodeType, StreamStruct> Streams = new Dictionary <ENodeType, StreamStruct>();

            FileStream   WriteFileStreamH = new FileStream($"m.{Ext}h", FileMode.Create);
            StreamStruct StreamStructH    = new StreamStruct(WriteFileStreamH, CompressEnum);

            FileStream   WriteFileStreamG = new FileStream($"m.{Ext}g", FileMode.Create);
            StreamStruct StreamStructG    = new StreamStruct(WriteFileStreamG, CompressEnum);

            FileStream   FileStreamM   = new FileStream($"m.{Ext}m", FileMode.Create);
            StreamStruct StreamStructM = new StreamStruct(FileStreamM, CompressEnum);

            Streams.Add(ENodeType.Hierarchy, StreamStructH);
            Streams.Add(ENodeType.Geometry, StreamStructG);
            Streams.Add(ENodeType.Metadata, StreamStructM);

            Console.WriteLine("Writing");

            using (XStreamWriter writer = new XStreamWriter(Streams))
            {
                for (int i = 0; i < WriteHNodes.Count; ++i)
                {
                    writer.Write(WriteHNodes[i]);
                }

                for (int i = 0; i < WritePolygons.Count; ++i)
                {
                    writer.Write(WritePolygons[i]);
                }

                for (int i = 0; i < WriteMNodes.Count; ++i)
                {
                    writer.Write(WriteMNodes[i]);
                }
            }
            //Dispose of stream here
            Streams[ENodeType.Hierarchy].IOStream.Dispose();
            Streams[ENodeType.Metadata].IOStream.Dispose();
            Streams[ENodeType.Geometry].IOStream.Dispose();


            Console.WriteLine("Done writing");
            Console.WriteLine("Reading");

            List <GeometryNode>  ReadPolygons = new List <GeometryNode>();
            List <HierarchyNode> ReadHNodes   = new List <HierarchyNode>();
            List <MetadataNode>  ReadMNodes   = new List <MetadataNode>();

            ManualResetEvent WaitReads = new ManualResetEvent(false);
            int ReadsLeft = WriteHNodes.Count + WriteMNodes.Count + WritePolygons.Count;

            FileStream ReadFileStreamH = new FileStream($"m.{Ext}h", FileMode.Open);
            FileStream ReadFileStreamG = new FileStream($"m.{Ext}g", FileMode.Open);
            FileStream ReadFileStreamM = new FileStream($"m.{Ext}m", FileMode.Open);

            using (XStreamReader ReaderH = new XStreamReader(ENodeType.Hierarchy, ReadFileStreamH,
                                                             (_Sdk) =>
            {
            },
                                                             (_Node) =>
            {
                Interlocked.Decrement(ref ReadsLeft);
                lock (ReadHNodes)
                {
                    ReadHNodes.Add((HierarchyNode)_Node);
                }
                if (ReadsLeft == 0)
                {
                    WaitReads.Set();
                }
            }, CompressEnum))
            {
                if (!ReaderH.Process(Console.WriteLine))
                {
                    throw new Exception("Failed");
                }
            }

            using (XStreamReader ReaderM = new XStreamReader(ENodeType.Metadata, ReadFileStreamM,
                                                             (_Sdk) =>
            {
            },
                                                             (_Node) =>
            {
                Interlocked.Decrement(ref ReadsLeft);
                lock (ReadMNodes)
                {
                    ReadMNodes.Add((MetadataNode)_Node);
                }
                if (ReadsLeft == 0)
                {
                    WaitReads.Set();
                }
            }, CompressEnum))
            {
                if (!ReaderM.Process(Console.WriteLine))
                {
                    throw new Exception("Failed");
                }
            }

            using (XStreamReader ReaderG = new XStreamReader(ENodeType.Geometry, ReadFileStreamG,
                                                             (_Sdk) =>
            {
            },
                                                             (_Node) =>
            {
                Interlocked.Decrement(ref ReadsLeft);
                lock (ReadPolygons)
                {
                    ReadPolygons.Add((GeometryNode)_Node);
                }
                if (ReadsLeft == 0)
                {
                    WaitReads.Set();
                }
            }, CompressEnum))
            {
                if (!ReaderG.Process(Console.WriteLine))
                {
                    throw new Exception("Failed");
                }
            }

            WaitReads.WaitOne();
            Console.WriteLine("Done Reading");

            WritePolygons = WritePolygons.OrderBy(x => x.UniqueID).ToList();
            ReadPolygons  = ReadPolygons.OrderBy(x => x.UniqueID).ToList();
            WriteMNodes   = WriteMNodes.OrderBy(x => x.UniqueID).ToList();
            ReadMNodes    = ReadMNodes.OrderBy(x => x.UniqueID).ToList();
            WriteHNodes   = WriteHNodes.OrderBy(x => x.UniqueID).ToList();
            ReadHNodes    = ReadHNodes.OrderBy(x => x.UniqueID).ToList();

            CheckInputVsOutput(WritePolygons, WriteHNodes, WriteMNodes, ReadPolygons, ReadHNodes, ReadMNodes);
        }
예제 #18
0
			public void ToXml (object value, XStreamWriter writer, MarshallingContext context) {
				throw new System.NotImplementedException ();
			}
예제 #19
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     writer.WriteAttribute(Attributes.AttributeType, value.GetType().AssemblyQualifiedName);
     writer.SetValue(value.ToString());
 }
예제 #20
0
 public void WriteOn(XStreamWriter writer)
 {
     writer.StartNode(serializedClassName);
     attributes.ForEach(x => x.WriteOn(writer));
 }
예제 #21
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     throw new System.NotImplementedException();
 }
 protected virtual void DoSpecificStuff(IDictionary dictionary, XStreamWriter writer)
 {
 }
예제 #23
0
 public void WriteOn(XStreamWriter writer)
 {
     writer.WriteAttribute(name, value);
 }
예제 #24
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     writer.SetValue(value.ToString());
 }
예제 #25
0
 internal MarshallingContext(XStreamWriter writer, ConverterLookup converterLookup, Aliases aliases) {
     this.writer = writer;
     this.converterLookup = converterLookup;
     this.aliases = aliases;
 }
 public void Marshall(object value, XStreamWriter writer, MarshallingContext context)
 {
     MarshalAs(value, value.GetType(), writer, context);
 }
예제 #27
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context) {}
 internal MarshallingContext(XStreamWriter writer, ConverterLookup converterLookup, IMapper mapper)
 {
     this.writer = writer;
     this.converterLookup = converterLookup;
     this.mapper = mapper;
 }
예제 #29
0
 public Marshaller(XStreamWriter writer, MarshallingContext context)
 {
     this.writer  = writer;
     this.context = context;
 }
예제 #30
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context) {
     writer.WriteAttribute(Attributes.Null, true.ToString());
 }
예제 #31
0
 internal MarshallingContext(XStreamWriter writer, ConverterLookup converterLookup, Aliases aliases)
 {
     this.writer          = writer;
     this.converterLookup = converterLookup;
     this.aliases         = aliases;
 }
예제 #32
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     writer.WriteAttribute(Attributes.Null, true.ToString());
 }