Program.cs 10 KB

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