public string ReceiveMessage() { string requestStr = Util.GetInputStream(); var inMessage = XmlSerializeUtil.Deserialize <InMessage>(requestStr); OutMessage outMessage = null; switch (inMessage.MsgType) { case "text": outMessage = HandleTextMsg(requestStr); break; case "image": outMessage = HandleImageMsg(requestStr); break; case "event": outMessage = HandleEventMsg(requestStr); break; case "voice": break; case "video": break; case "shortvideo": break; case "location": break; case "link": break; default: break; } if (outMessage == null) { return(null); } XmlDocument xml = new XmlDocument(); xml.LoadXml(XmlSerializeUtil.Serializer(outMessage)); var rootxml = xml.SelectSingleNode("xml"); rootxml.Attributes.RemoveAll(); var result = xml.OuterXml; return(result); }
public static void Test2() { //xml->model->xml string path = System.AppDomain.CurrentDomain.BaseDirectory; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@path + "test.xml"); Console.WriteLine(xmlDoc.OuterXml); AdsbEntity ad = XmlSerializeUtil.Deserialize(typeof(AdsbEntity), xmlDoc.OuterXml) as AdsbEntity; //Console.WriteLine(ad.Head.DatagramId); //Console.WriteLine(ad.Head.Fi); Console.WriteLine(ad.Unit[0].Name); string xml = XmlSerializeUtil.Serializer(typeof(AdsbEntity), ad); Console.WriteLine(xml); Console.ReadKey(); }
private Boolean ToSkin3DFile(string file) { string content = File.ReadAllText(file); JObject jobj = JObject.Parse(content); //遍历最外层识别实体个数 List <string> modelList = new List <string>(); foreach (var item in jobj) { if (item.Key == "format_version") { continue; } modelList.Add(item.Key); } //挨个取出序列化 foreach (string key in modelList) { try { McGeometryJson personlist = JsonConvert.DeserializeObject <McGeometryJson>(jobj.GetValue(key).ToString()); //Skin3DXml init List <Skin3dModelXml.TechneModelsModelGeometryFolderShape> shapelist = new List <Skin3dModelXml.TechneModelsModelGeometryFolderShape>(); //序列化默认Xml文件等候处理 string thisPath = System.Environment.CurrentDirectory; string contentXml = File.ReadAllText(thisPath + "/assets/dafault.xml"); Skin3dModelXml.Techne xmlObject = XmlSerializeUtil.Deserialize(typeof(Skin3dModelXml.Techne), contentXml) as Skin3dModelXml.Techne; //通过Json模型数据构造Xml 内容 xmlObject.Name = key; xmlObject.Models.Model.Name = key; xmlObject.Models.Model.TextureSize = "" + personlist.texturewidth + "," + personlist.textureheight; // foreach (Bone bone in personlist.bones) { try { foreach (Cube cube in bone.cubes) { //验证旋转值,防止null float[] rotation = bone.rotation == null ? new float[] { 0, 0, 0 } : bone.rotation; Console.WriteLine(String.Format("原点:[{0},{1},{2}] 点1:[{3},{4},{5}]", bone.pivot[0], bone.pivot[1], bone.pivot[2], cube.origin[0], cube.origin[1], cube.origin[2])); //修复坐标Y反转 cube.origin[1] = ((cube.origin[1] + (cube.size[1] / 2)) * -1) - (cube.size[1] / 2); //构造Shape Skin3dModelXml.TechneModelsModelGeometryFolderShape tempShape = new Skin3dModelXml.TechneModelsModelGeometryFolderShape(); tempShape.Type = "d9e621f7-957f-4b77-b1ae-20dcd0da7751"; tempShape.Name = bone.name + "-" + Guid.NewGuid().ToString("N"); //去重 tempShape.IsDecorative = "False"; tempShape.IsFixed = "False"; tempShape.IsMirrored = "" + (bone.mirror || cube.mirror); tempShape.IsSolid = "False"; //BB中实际坐标不受原点影响 Skin3D中受,此处进行补正 for (int index = 0; index < cube.origin.Length; index++) { cube.origin[index] -= bone.pivot[index]; } tempShape.Offset = string.Join(",", cube.origin); tempShape.Position = string.Join(",", bone.pivot); //继承父级旋转 if (bone.parent != null) { foreach (Bone findParentBone in personlist.bones) { if (findParentBone.name == bone.parent) { try { float[] parentRotation = findParentBone.rotation == null ? new float[] { 0, 0, 0 } : findParentBone.rotation; Console.WriteLine(bone.parent + ":" + bone.name + "=>" + rotation.Length + " =>" + parentRotation.Length); rotation[0] += parentRotation[0]; rotation[1] += parentRotation[1]; rotation[2] += parentRotation[2]; } catch (Exception e) { Console.WriteLine(e.ToString()); } } } } tempShape.Rotation = string.Join(",", rotation); tempShape.Size = string.Join(",", cube.size); tempShape.TextureOffset = string.Join(",", cube.uv); tempShape.Scale = (decimal)cube.inflate; tempShape.Part = "Chest"; tempShape.Hidden = "False"; tempShape.IsArmor = "False"; shapelist.Add(tempShape); } } catch (Exception e) { Console.WriteLine(e.ToString()); continue; } } xmlObject.Models.Model.Geometry.Folder.Shape = shapelist.ToArray(); //反序列化处理后的文件并保存 string xmlString = XmlSerializeUtil.Serializer(typeof(Skin3dModelXml.Techne), xmlObject); Utils.SaveString2File(new FileInfo(file).DirectoryName + "/" + key + ".xml", xmlString); } catch (Exception e) { Console.WriteLine(e.ToString()); MessageBox.Show(e.ToString(), "出现错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } } MessageBox.Show("成功处理下列实体:\n\n" + string.Join("\n", modelList.ToArray()), "处理完成", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }