/// <summary> /// 处理事件 /// </summary> /// <param name="requestStr"></param> /// <returns></returns> private OutMessage HandleEventMsg(string requestStr) { var inMessage = XmlSerializeUtil.Deserialize <InMessageEvent>(requestStr); var outMessage = new OutMessageText { CreateTime = inMessage.CreateTime, FromUserName = inMessage.ToUserName, ToUserName = inMessage.FromUserName, Content = "未知事件类型" }; switch (inMessage.Event.ToLower()) { case "subscribe": return(HandleSubscribe(inMessage)); case "click": return(HandleClick(inMessage)); case "view": return(HandleView(inMessage)); case "scancode_push": return(HandleScancodePush(inMessage)); case "scancode_waitmsg": return(HandleScancodeWaitmsg(inMessage)); default: break; } return(outMessage); }
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); }
/// <summary> /// 处理文本消息 /// </summary> /// <param name="requestStr"></param> /// <returns></returns> private OutMessage HandleImageMsg(string requestStr) { var inMessage = XmlSerializeUtil.Deserialize <InMessageImage>(requestStr); var outMessage = new OutMessageImage { MsgType = inMessage.MsgType, CreateTime = inMessage.CreateTime, FromUserName = inMessage.ToUserName, ToUserName = inMessage.FromUserName, MediaId = inMessage.MediaId }; return(outMessage); }
/// <summary> /// 处理文本消息 /// </summary> /// <param name="requestStr"></param> /// <returns></returns> private OutMessage HandleTextMsg(string requestStr) { var inMessage = XmlSerializeUtil.Deserialize <InMessageText>(requestStr); var outMessage = new OutMessageText { Content = "您输入的内容是" + inMessage.Content, MsgType = inMessage.MsgType, CreateTime = inMessage.CreateTime, FromUserName = inMessage.ToUserName, ToUserName = inMessage.FromUserName }; if (inMessage.Content.Contains("hello") || inMessage.Content.Contains("你好") || inMessage.Content.Contains("你是谁") || inMessage.Content.Contains("从哪里来")) { outMessage.Content = "hello,我是何大鹏,欢迎来到召唤师峡谷,您的OPenid是" + inMessage.FromUserName; } return(outMessage); }
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(); }
/// <summary> /// 程序入口。 /// </summary> /// <param name="args"></param> static void Main(string[] args) { //启动容器 Container container = ContainerFactory.CreateContainer(); try { container.Start(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("按任意键退出。"); Console.ReadKey(); return; } WcfConfig config = null; if (!File.Exists("WcfConfig.xml")) { Console.WriteLine("找不到指定的文件WcfConfig.xml。"); return; } try { string xml = File.ReadAllText("WcfConfig.xml"); config = XmlSerializeUtil.XmlStringToObject <WcfConfig>(xml); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("按任意键退出。"); Console.ReadKey(); return; } if (config == null) { Console.WriteLine("WcfConfig.xml内容不合法。"); return; } if (string.IsNullOrWhiteSpace(config.BindingType)) { Console.WriteLine("WcfConfig.xml的BindingType节点的值不合法。"); return; } if (!"WebHttpBinding".Equals(config.BindingType) && !"BasicHttpBinding".Equals(config.BindingType) && !"NetTcpBinding".Equals(config.BindingType)) { Console.WriteLine("WcfConfig.xml的BindingType节点的值不合法。"); return; } #region 读取dll中的服务 //从dll文件中获取服务 string pathBusiness = @"./business/"; string[] files = Directory.GetFiles(pathBusiness, "*.dll"); foreach (string file in files) { try { Assembly assembly = Assembly.LoadFrom(file);//加载dll if (assembly != null) { Type[] classes = assembly.GetTypes(); //从dll中获取class foreach (Type type in classes) //遍历classes中实现了接口的class { if (type.IsClass && !type.IsAbstract) { Type[] interfaces = type.GetInterfaces(); foreach (Type t in interfaces)//遍历interfaces中有ServiceContract特性的interface { object[] attrsContract = t.GetCustomAttributes(typeof(ServiceContractAttribute), false); if (attrsContract != null && attrsContract.Length > 0) { ServiceInfo si = new ServiceInfo { ServiceName = type.Name, ServiceDll = type.Assembly.ManifestModule.Name, ServiceType = type, ContractType = t, ContractName = t.Name, ContractDll = t.Assembly.ManifestModule.Name, }; try { Attribute attributeContractAttribute = type.GetCustomAttribute(typeof(ContractAttribute)); if (attributeContractAttribute == null) { //si.Host = new ServiceHost(type); continue; } else { ContractAttribute contractAttribute = (ContractAttribute)attributeContractAttribute; string beanName = type.Name.Substring(0, 1).ToLower() + (type.Name.Length > 1 ? type.Name.Substring(1) : string.Empty); if (!string.IsNullOrWhiteSpace(contractAttribute.Name)) { beanName = contractAttribute.Name; } if (Container.BeanContainer.ContainsKey(beanName)) { if ("BasicHttpBinding".Equals(config.BindingType))//当协议类型为BasicHttpBinding时,创建Host实例需指定基地址。 { Uri baseAddress = new Uri(string.Format("http://{0}:{1}/api/{2}/", ip, port, version) + t.Name.Substring(1)); si.Host = new ServiceHost(Container.BeanContainer[beanName].Bean, baseAddress); } else { si.Host = new ServiceHost(Container.BeanContainer[beanName].Bean); } } else { continue; } } } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } wcfServers.Add(si.ServiceName, si); } } } } } } catch (Exception ex) { Console.WriteLine(ex.Message); continue; } } #endregion #region 设置Host foreach (KeyValuePair <string, ServiceInfo> kv in wcfServers) { kv.Value.Host.Opened += Host_Opened; kv.Value.Host.Closed += Host_Closed; if ("WebHttpBinding".Equals(config.BindingType)) { ServiceEndpoint se = kv.Value.Host.AddServiceEndpoint(kv.Value.ContractType, new WebHttpBinding() { CrossDomainScriptAccessEnabled = config.WebHttpBinding.CrossDomainScriptAccessEnabled, MaxReceivedMessageSize = config.WebHttpBinding.MaxReceivedMessageSize, ReaderQuotas = XmlDictionaryReaderQuotas.Max }, string.Format("http://{0}:{1}/api/{2}/", ip, port, version) + kv.Value.ContractName.Substring(1)); se.Behaviors.Add(new WebHttpBehavior() { HelpEnabled = true, DefaultOutgoingRequestFormat = WebMessageFormat.Json, DefaultOutgoingResponseFormat = WebMessageFormat.Json, DefaultBodyStyle = WebMessageBodyStyle.Wrapped }); kv.Value.Host.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute { RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed }); } else if ("BasicHttpBinding".Equals(config.BindingType)) { ServiceEndpoint se = kv.Value.Host.AddServiceEndpoint(kv.Value.ContractType, new BasicHttpBinding() { AllowCookies = config.BasicHttpBinding.AllowCookies, CloseTimeout = new TimeSpan(config.BasicHttpBinding.CloseTimeout * 10000000), OpenTimeout = new TimeSpan(config.BasicHttpBinding.OpenTimeout * 10000000), SendTimeout = new TimeSpan(config.BasicHttpBinding.SendTimeout * 10000000), ReceiveTimeout = new TimeSpan(config.BasicHttpBinding.ReceiveTimeout * 10000000), BypassProxyOnLocal = config.BasicHttpBinding.BypassProxyOnLocal, HostNameComparisonMode = HostNameComparisonMode.StrongWildcard, MaxBufferPoolSize = config.BasicHttpBinding.MaxBufferPoolSize, MaxReceivedMessageSize = config.BasicHttpBinding.MaxReceivedMessageSize, MessageEncoding = WSMessageEncoding.Text, TextEncoding = Encoding.GetEncoding(config.BasicHttpBinding.TextEncoding), UseDefaultWebProxy = config.BasicHttpBinding.UseDefaultWebProxy, ReaderQuotas = XmlDictionaryReaderQuotas.Max }, string.Format("http://{0}:{1}/api/{2}/", ip, port, version) + kv.Value.ContractName.Substring(1)); } else if ("NetTcpBinding".Equals(config.BindingType)) { ServiceEndpoint se = kv.Value.Host.AddServiceEndpoint(kv.Value.ContractType, new NetTcpBinding(SecurityMode.None) { CloseTimeout = new TimeSpan(config.NetTcpBinding.CloseTimeout * 10000000), OpenTimeout = new TimeSpan(config.NetTcpBinding.OpenTimeout * 10000000), SendTimeout = new TimeSpan(config.NetTcpBinding.SendTimeout * 10000000), ReceiveTimeout = new TimeSpan(config.NetTcpBinding.ReceiveTimeout * 10000000), TransferMode = TransferMode.StreamedResponse, TransactionProtocol = TransactionProtocol.OleTransactions, TransactionFlow = config.NetTcpBinding.TransactionFlow, HostNameComparisonMode = HostNameComparisonMode.StrongWildcard, MaxBufferPoolSize = config.NetTcpBinding.MaxBufferPoolSize, MaxReceivedMessageSize = config.NetTcpBinding.MaxReceivedMessageSize, MaxBufferSize = config.NetTcpBinding.MaxBufferSize, ListenBacklog = config.NetTcpBinding.ListenBacklog, MaxConnections = config.NetTcpBinding.MaxConnections, ReaderQuotas = XmlDictionaryReaderQuotas.Max }, string.Format("net.tcp://{0}:{1}/api/{2}/", ip, port, version) + kv.Value.ContractName.Substring(1)); } //设置默认服务实例及运行线程 ServiceBehaviorAttribute serviceBehavior = kv.Value.Host.Description.Behaviors.Find <ServiceBehaviorAttribute>(); if (null == serviceBehavior) { serviceBehavior = new ServiceBehaviorAttribute { InstanceContextMode = InstanceContextMode.Single, UseSynchronizationContext = false, ConcurrencyMode = ConcurrencyMode.Multiple }; kv.Value.Host.Description.Behaviors.Add(serviceBehavior); } serviceBehavior.InstanceContextMode = InstanceContextMode.Single; serviceBehavior.UseSynchronizationContext = false; serviceBehavior.ConcurrencyMode = ConcurrencyMode.Multiple; ServiceThrottlingBehavior throttle = kv.Value.Host.Description.Behaviors.Find <ServiceThrottlingBehavior>(); if (throttle == null) { throttle = new ServiceThrottlingBehavior(); throttle.MaxConcurrentCalls = 2147483647; throttle.MaxConcurrentSessions = 2147483647; throttle.MaxConcurrentInstances = 2147483647; kv.Value.Host.Description.Behaviors.Add(throttle); } kv.Value.Host.Open(); } Console.WriteLine("按下任意键退出服务!"); Console.ReadKey(); foreach (KeyValuePair <string, ServiceInfo> kv in wcfServers) { if (kv.Value.Host.State == CommunicationState.Opened) { kv.Value.Host.Close(); } } #endregion Console.WriteLine("正在退出..."); System.Threading.Thread.Sleep(1000); }
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); }
private void Awake() { LogConfig config = XmlSerializeUtil.DeserializeFromFile <LogConfig>(Application.dataPath + @"/Examples/TestLogger/logconfig.xml"); LogManager.Init(config); }