Program.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading;
  9. using WCS.Data;
  10. using WCS.Data.Models;
  11. namespace ConsoleApp1
  12. {
  13. public class Program
  14. {
  15. //static CancellationTokenSource _cancelSource = new CancellationTokenSource();
  16. static void Main(string[] args)
  17. {
  18. SugarBase.DBConnectionString = "Data Source=192.168.249.101;Initial Catalog=YONGGUAN_WCS;Persist Security Info=True;User ID=sa;Pwd=Password@123$%^";
  19. try
  20. {
  21. int count = SugarBase.DB.Queryable<WCS_TASK>().Count(v => v.TASK_WKSTATUS > 1 && v.TASK_POSIDTO.Contains("Pvc_18"));
  22. if (SugarBase.DB.Queryable<WCS_TASK>().Any(v => !SqlFunc.IsNullOrEmpty(v.TASK_POSIDMOVE)))
  23. {
  24. }
  25. //SugarBase.DB.Queryable<WCS_TASK>().Any(v => v.TASK_BOXBARCODE == "agc");
  26. }
  27. catch (Exception ex)
  28. {
  29. Console.WriteLine(ex.Message);
  30. }
  31. //Console.WriteLine("------------Interrupt方法执行情况---------------");
  32. //Thread t1 = new Thread(DoWork);
  33. //t1.Start();
  34. //Thread.Sleep(1000);
  35. //t1.Interrupt();
  36. //t1.Join();
  37. //Console.WriteLine("------------Abort方法执行情况---------------");
  38. //Thread t2 = new Thread(DoWork);
  39. //t2.Start();
  40. //Thread.Sleep(1000);
  41. //t2.Abort();
  42. List<int> lst = new List<int> { 14, 8, 9, 78 };
  43. var abc = new[] { 78, 8, 9, 14 };
  44. string item7 = "6,5";
  45. var srmTunnelList = item7.Split(',');
  46. lst = lst.OrderBy(t => Array.IndexOf(abc, t)).ToList();
  47. var outinfoSet = new List<WCS_RGVOutInInfo>();
  48. outinfoSet.Add(new WCS_RGVOutInInfo { RGVOUTIN_CONVNO = "asdfsa", SrmTunnelNo = 5 });
  49. outinfoSet.Add(new WCS_RGVOutInInfo { RGVOUTIN_CONVNO = "asedfsa", SrmTunnelNo = 6 });
  50. var temp = new List<WCS_RGVOutInInfo>();
  51. srmTunnelList.ToList().ForEach(v => temp.Add(outinfoSet.First(t => t.SrmTunnelNo.ToString() == v)));
  52. Console.WriteLine("Begin:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  53. var result = OutTimeClass.OutTimeSomeParemReturn(WCS_GetInTask, 2000,new GetInTaskReply());
  54. //ThreadHelper.TaskThread(LongTimeFunc, 5000);
  55. //bool ret = Process(string.Empty, 10000);
  56. //Console.WriteLine("Result={0}", ret);
  57. Console.WriteLine("End:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  58. Console.WriteLine("Press any key to exit...");
  59. Console.ReadKey();
  60. }
  61. //private static bool Process(string param, int timeout)
  62. //{
  63. // bool ret = false;
  64. // var task = new System.Threading.Tasks.TaskFactory().StartNew(() =>
  65. // {
  66. // ret = LongTimeFunc();
  67. // }, _cancelSource.Token).Wait(timeout);
  68. // _cancelSource.Cancel();
  69. // return ret;
  70. //}
  71. private static void LongTimeFunc()
  72. {
  73. Console.WriteLine("执行方法LongTimeFunc开始:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  74. System.Threading.Thread.Sleep(200);
  75. Console.WriteLine("执行方法LongTimeFunc结束:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  76. //return true;
  77. }
  78. private static object WCS_GetInTask(object obj)
  79. {
  80. GetInTaskReply reply;
  81. try
  82. {
  83. reply = Text();
  84. if (reply == null)
  85. throw new Exception();
  86. }
  87. catch (Exception)
  88. {
  89. reply = new GetInTaskReply();
  90. reply.ResMessage = string.Format("WCS_GetInTask:接口报错或接口超时,请求位置[{0}]请求条码[{1}]", 1234, 34567);
  91. Console.WriteLine(reply.ResMessage + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  92. }
  93. return reply;
  94. }
  95. public static GetInTaskReply Text()
  96. {
  97. GetInTaskReply reply = null ;
  98. try
  99. {
  100. reply = new GetInTaskReply();
  101. Console.WriteLine("开始" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  102. Thread.Sleep(200);
  103. Console.WriteLine("结束" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  104. }
  105. catch(ThreadInterruptedException e)
  106. {
  107. Console.WriteLine("ThreadInterruptedException:"+e.Message);
  108. reply = null;
  109. }
  110. catch (Exception ex)
  111. {
  112. Console.WriteLine("Exception:" + ex.Message);
  113. reply = null;
  114. }
  115. return reply;
  116. }
  117. public static void Text2()
  118. {
  119. try
  120. {
  121. Console.WriteLine("Text2开始" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  122. Thread.Sleep(200);
  123. Console.WriteLine("Text2结束" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
  124. }
  125. catch (ThreadInterruptedException e)
  126. {
  127. Console.WriteLine("ThreadInterruptedException2:" + e.Message);
  128. }
  129. catch (Exception ex)
  130. {
  131. Console.WriteLine("Exception2:" + ex.Message);
  132. }
  133. }
  134. static void DoWork()
  135. {
  136. for (int i = 0; i < 10; i++)
  137. {
  138. try
  139. {
  140. Console.WriteLine("第" + i + "循环。");
  141. Thread.Sleep(500);
  142. }
  143. catch (ThreadInterruptedException e)
  144. {
  145. Console.WriteLine("第" + i + "循环中,线程被中断,下次循环线程将继续运行。");
  146. }
  147. catch (ThreadAbortException e)
  148. {
  149. Console.WriteLine("第" + i + "循环中,线程被终止,线程将不再继续运行");
  150. }
  151. }
  152. }
  153. [StructLayout(LayoutKind.Sequential)]
  154. class A
  155. {
  156. public bool d = false;
  157. public short a = 0;
  158. public int b = 0;
  159. public long c = 0;
  160. }
  161. }
  162. public class WCS_RGVOutInInfo
  163. {
  164. /// <summary>
  165. /// RGV对接口输送线编号
  166. /// </summary>
  167. public string RGVOUTIN_CONVNO { get; set; }
  168. /// <summary>
  169. /// RGV编号
  170. /// </summary>
  171. public string RGVOUTIN_RGVNO { get; set; }
  172. /// <summary>
  173. /// 所在plc名称
  174. /// </summary>
  175. public string PLCNAME { get; set; }
  176. /// <summary>
  177. /// 堆垛机巷道编号
  178. /// </summary>
  179. public int SrmTunnelNo { get; set; }
  180. }
  181. class Account
  182. {
  183. private object thisLock = new object();
  184. int balance;
  185. Random r = new Random();
  186. public Account(int initial)
  187. {
  188. balance = initial;
  189. }
  190. int WithDraw(int amount)
  191. {
  192. if (balance < 0)
  193. {
  194. throw new Exception("负的Balance.");
  195. }
  196. //确保只有一个线程使用资源,一个进入临界状态,使用对象互斥锁,10个启动了的线程不能全部执行该方法
  197. lock (thisLock)
  198. {
  199. if (balance >= amount)
  200. {
  201. Console.WriteLine("----------------------------:" + System.Threading.Thread.CurrentThread.Name + "---------------");
  202. Console.WriteLine("调用Withdrawal之前的Balance:" + balance);
  203. Console.WriteLine("把Amount输入 Withdrawal :-" + amount);
  204. //如果没有加对象互斥锁,则可能10个线程都执行下面的减法,加减法所耗时间片段非常小,可能多个线程同时执行,出现负数。
  205. balance = balance - amount;
  206. Console.WriteLine("调用Withdrawal之后的Balance :" + balance);
  207. return amount;
  208. }
  209. else
  210. {
  211. //最终结果
  212. return 0;
  213. }
  214. }
  215. }
  216. public void DoTransactions()
  217. {
  218. for (int i = 0; i < 100; i++)
  219. {
  220. //生成balance的被减数amount的随机数
  221. WithDraw(r.Next(1, 100));
  222. }
  223. }
  224. }
  225. public class GetInTaskReply
  226. {
  227. /// <summary>
  228. /// 1:成功,0:失败
  229. /// </summary>
  230. public bool ResType { get; set; }
  231. public string ResMessage { get; set; }
  232. public string WMSTaskNum { get; set; }
  233. /// <summary>
  234. /// 任务类型(1:入库2:出库3:移库4:移动(搬运) 5:异常 6:托盘异常退回)
  235. /// </summary>
  236. public int TaskType { get; set; }
  237. /// <summary>
  238. /// 仓库名称
  239. /// </summary>
  240. public string WareHouseName { get; set; }
  241. /// <summary>
  242. /// 入库巷道(集合巷道,由WCS自行判断入到哪一个巷道,最前面的最优先)
  243. /// </summary>
  244. public string TunnelNum { get; set; }
  245. /// <summary>
  246. /// 目标位置(入库该地址为srm.如果是移动任务,该地址为WCS传递的目标位置)
  247. /// </summary>
  248. public string EndPostion { get; set; }
  249. public int Priority { get; set; }
  250. public string Memo1 { get; set; }
  251. public string Memo2 { get; set; }
  252. public string Memo3 { get; set; }
  253. }
  254. }