123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using WCS.Data;
- using WCS.Data.Models;
- namespace ConsoleApp1
- {
- public class Program
- {
- //static CancellationTokenSource _cancelSource = new CancellationTokenSource();
- static void Main(string[] args)
- {
- SugarBase.DBConnectionString = "Data Source=192.168.249.101;Initial Catalog=YONGGUAN_WCS;Persist Security Info=True;User ID=sa;Pwd=Password@123$%^";
- try
- {
- int count = SugarBase.DB.Queryable<WCS_TASK>().Count(v => v.TASK_WKSTATUS > 1 && v.TASK_POSIDTO.Contains("Pvc_18"));
- if (SugarBase.DB.Queryable<WCS_TASK>().Any(v => !SqlFunc.IsNullOrEmpty(v.TASK_POSIDMOVE)))
- {
- }
- //SugarBase.DB.Queryable<WCS_TASK>().Any(v => v.TASK_BOXBARCODE == "agc");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- //Console.WriteLine("------------Interrupt方法执行情况---------------");
- //Thread t1 = new Thread(DoWork);
- //t1.Start();
- //Thread.Sleep(1000);
- //t1.Interrupt();
- //t1.Join();
- //Console.WriteLine("------------Abort方法执行情况---------------");
- //Thread t2 = new Thread(DoWork);
- //t2.Start();
- //Thread.Sleep(1000);
- //t2.Abort();
- List<int> lst = new List<int> { 14, 8, 9, 78 };
- var abc = new[] { 78, 8, 9, 14 };
- string item7 = "6,5";
- var srmTunnelList = item7.Split(',');
- lst = lst.OrderBy(t => Array.IndexOf(abc, t)).ToList();
- var outinfoSet = new List<WCS_RGVOutInInfo>();
- outinfoSet.Add(new WCS_RGVOutInInfo { RGVOUTIN_CONVNO = "asdfsa", SrmTunnelNo = 5 });
- outinfoSet.Add(new WCS_RGVOutInInfo { RGVOUTIN_CONVNO = "asedfsa", SrmTunnelNo = 6 });
- var temp = new List<WCS_RGVOutInInfo>();
- srmTunnelList.ToList().ForEach(v => temp.Add(outinfoSet.First(t => t.SrmTunnelNo.ToString() == v)));
- Console.WriteLine("Begin:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- var result = OutTimeClass.OutTimeSomeParemReturn(WCS_GetInTask, 2000,new GetInTaskReply());
- //ThreadHelper.TaskThread(LongTimeFunc, 5000);
- //bool ret = Process(string.Empty, 10000);
- //Console.WriteLine("Result={0}", ret);
- Console.WriteLine("End:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- Console.WriteLine("Press any key to exit...");
- Console.ReadKey();
- }
- //private static bool Process(string param, int timeout)
- //{
- // bool ret = false;
- // var task = new System.Threading.Tasks.TaskFactory().StartNew(() =>
- // {
- // ret = LongTimeFunc();
- // }, _cancelSource.Token).Wait(timeout);
- // _cancelSource.Cancel();
- // return ret;
- //}
- private static void LongTimeFunc()
- {
- Console.WriteLine("执行方法LongTimeFunc开始:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- System.Threading.Thread.Sleep(200);
- Console.WriteLine("执行方法LongTimeFunc结束:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- //return true;
- }
- private static object WCS_GetInTask(object obj)
- {
- GetInTaskReply reply;
- try
- {
- reply = Text();
- if (reply == null)
- throw new Exception();
- }
- catch (Exception)
- {
- reply = new GetInTaskReply();
- reply.ResMessage = string.Format("WCS_GetInTask:接口报错或接口超时,请求位置[{0}]请求条码[{1}]", 1234, 34567);
- Console.WriteLine(reply.ResMessage + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- }
- return reply;
- }
- public static GetInTaskReply Text()
- {
- GetInTaskReply reply = null ;
- try
- {
- reply = new GetInTaskReply();
- Console.WriteLine("开始" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- Thread.Sleep(200);
- Console.WriteLine("结束" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- }
- catch(ThreadInterruptedException e)
- {
- Console.WriteLine("ThreadInterruptedException:"+e.Message);
- reply = null;
- }
- catch (Exception ex)
- {
- Console.WriteLine("Exception:" + ex.Message);
- reply = null;
- }
- return reply;
- }
- public static void Text2()
- {
- try
- {
- Console.WriteLine("Text2开始" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- Thread.Sleep(200);
- Console.WriteLine("Text2结束" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
- }
- catch (ThreadInterruptedException e)
- {
- Console.WriteLine("ThreadInterruptedException2:" + e.Message);
- }
- catch (Exception ex)
- {
- Console.WriteLine("Exception2:" + ex.Message);
- }
- }
- static void DoWork()
- {
- for (int i = 0; i < 10; i++)
- {
- try
- {
- Console.WriteLine("第" + i + "循环。");
- Thread.Sleep(500);
- }
- catch (ThreadInterruptedException e)
- {
- Console.WriteLine("第" + i + "循环中,线程被中断,下次循环线程将继续运行。");
- }
- catch (ThreadAbortException e)
- {
- Console.WriteLine("第" + i + "循环中,线程被终止,线程将不再继续运行");
- }
- }
- }
- [StructLayout(LayoutKind.Sequential)]
- class A
- {
- public bool d = false;
- public short a = 0;
- public int b = 0;
- public long c = 0;
- }
- }
- public class WCS_RGVOutInInfo
- {
- /// <summary>
- /// RGV对接口输送线编号
- /// </summary>
- public string RGVOUTIN_CONVNO { get; set; }
- /// <summary>
- /// RGV编号
- /// </summary>
- public string RGVOUTIN_RGVNO { get; set; }
- /// <summary>
- /// 所在plc名称
- /// </summary>
- public string PLCNAME { get; set; }
- /// <summary>
- /// 堆垛机巷道编号
- /// </summary>
- public int SrmTunnelNo { get; set; }
- }
- class Account
- {
- private object thisLock = new object();
- int balance;
- Random r = new Random();
- public Account(int initial)
- {
- balance = initial;
- }
- int WithDraw(int amount)
- {
- if (balance < 0)
- {
- throw new Exception("负的Balance.");
- }
- //确保只有一个线程使用资源,一个进入临界状态,使用对象互斥锁,10个启动了的线程不能全部执行该方法
- lock (thisLock)
- {
- if (balance >= amount)
- {
- Console.WriteLine("----------------------------:" + System.Threading.Thread.CurrentThread.Name + "---------------");
- Console.WriteLine("调用Withdrawal之前的Balance:" + balance);
- Console.WriteLine("把Amount输入 Withdrawal :-" + amount);
- //如果没有加对象互斥锁,则可能10个线程都执行下面的减法,加减法所耗时间片段非常小,可能多个线程同时执行,出现负数。
- balance = balance - amount;
- Console.WriteLine("调用Withdrawal之后的Balance :" + balance);
- return amount;
- }
- else
- {
- //最终结果
- return 0;
- }
- }
- }
- public void DoTransactions()
- {
- for (int i = 0; i < 100; i++)
- {
- //生成balance的被减数amount的随机数
- WithDraw(r.Next(1, 100));
- }
- }
- }
- public class GetInTaskReply
- {
- /// <summary>
- /// 1:成功,0:失败
- /// </summary>
- public bool ResType { get; set; }
- public string ResMessage { get; set; }
- public string WMSTaskNum { get; set; }
- /// <summary>
- /// 任务类型(1:入库2:出库3:移库4:移动(搬运) 5:异常 6:托盘异常退回)
- /// </summary>
- public int TaskType { get; set; }
- /// <summary>
- /// 仓库名称
- /// </summary>
- public string WareHouseName { get; set; }
- /// <summary>
- /// 入库巷道(集合巷道,由WCS自行判断入到哪一个巷道,最前面的最优先)
- /// </summary>
- public string TunnelNum { get; set; }
- /// <summary>
- /// 目标位置(入库该地址为srm.如果是移动任务,该地址为WCS传递的目标位置)
- /// </summary>
- public string EndPostion { get; set; }
- public int Priority { get; set; }
- public string Memo1 { get; set; }
- public string Memo2 { get; set; }
- public string Memo3 { get; set; }
- }
- }
|