96 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			96 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Linq; | |||
|  | using System.Runtime.Serialization; | |||
|  | using System.ServiceModel; | |||
|  | using System.Text; | |||
|  | 
 | |||
|  | namespace DNLightSvr | |||
|  | { | |||
|  | 
 | |||
|  |     // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“LightService”。 | |||
|  |     [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] | |||
|  |     public class LightService : ILightService | |||
|  |     { | |||
|  |         static log4net.ILog log = log4net.LogManager.GetLogger("light"); | |||
|  | 
 | |||
|  |         public delegate bool lightLable(ELabel[] lables); | |||
|  |         public delegate bool clsOrder(ClearOrder clearOrder); | |||
|  |         public clsOrder clearO = null; | |||
|  |         public lightLable lightUp = null; | |||
|  |         public string lightLabels(ELabel[] labels) | |||
|  |         {  | |||
|  |             if (lightUp != null) | |||
|  |             { | |||
|  |                 if (lightUp(labels)) | |||
|  |                 { | |||
|  |                     | |||
|  |                     return "success"; | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  |             return "failure"; | |||
|  |         } | |||
|  |         public string clearOrder(ClearOrder clearOrder) | |||
|  |         { | |||
|  |             if (clearO != null) | |||
|  |             { | |||
|  |                 if (clearO(clearOrder)) | |||
|  |                 { | |||
|  |                     return "success"; | |||
|  |                 } | |||
|  |             } | |||
|  |             return "failure"; | |||
|  |         } | |||
|  |         public string testPost(ELabel label) | |||
|  |         { | |||
|  |             string json = getJson(label); | |||
|  |            // Console.Write("get the lable:  " + json ); | |||
|  | 
 | |||
|  |             return json;// "succeed"; | |||
|  |         } | |||
|  |        public string  test() | |||
|  |         { | |||
|  |             Console.Write("get request"); | |||
|  |             return "服务响应 success"; | |||
|  |         } | |||
|  | 
 | |||
|  |        public string getJson(ELabel label) | |||
|  |        { | |||
|  |            string json = String.Format("\"labelId\":{0},\"address\":{1},\"count\":{2},\"color\":{3},\"port\":{4},\"orderNo\":{5}" | |||
|  |              , label.labelId, label.address, label.count, label.color, label.port, label.orderNo); | |||
|  |          //  Console.Write("get the lable:  " + json); | |||
|  | 
 | |||
|  |            return "{" + json + "}"; | |||
|  |        } | |||
|  | 
 | |||
|  |        static string getMsg(string className, string msg) | |||
|  |        { | |||
|  |            return string.Format("{0}  {1}", className, msg); | |||
|  |        } | |||
|  | 
 | |||
|  |        public List<ELabel> getLabels() | |||
|  |        { | |||
|  |            ELabel el = new ELabel(); | |||
|  | 
 | |||
|  |            List<ELabel> lst = new List<ELabel>(); | |||
|  | 
 | |||
|  |            for (int i = 0; i < 10; i++) | |||
|  |            { | |||
|  |                el = new ELabel(); | |||
|  |                el.address = 20+i; | |||
|  |                el.color = 2; | |||
|  |                el.count = 100+i; | |||
|  |                el.labelId = i + 1; | |||
|  |                el.orderNo = i + 1; | |||
|  |                el.port = 12; | |||
|  |                lst.Add(el); | |||
|  |            } | |||
|  | 
 | |||
|  |            return lst; | |||
|  | 
 | |||
|  |        } | |||
|  | 
 | |||
|  |     } | |||
|  | } |