Ejemplo n.º 1
0
        public void GetApiFunctionsList(Newtonsoft.Json.Linq.JObject requestValue, Newtonsoft.Json.Linq.JToken Data, MESStationReturn StationReturn)
        {
            string     ClassName = Data["CLASSNAME"].ToString();
            Assembly   assemby   = Assembly.Load("MESStation");
            Type       t         = assemby.GetType(ClassName);
            object     obj       = assemby.CreateInstance(ClassName);
            MesAPIBase API       = (MesAPIBase)obj;

            MESReturnView.Public.GetApiFunctionsListReturn ret = new MESReturnView.Public.GetApiFunctionsListReturn();
            ret.APIS             = API.Apis;
            StationReturn.Data   = ret;
            StationReturn.Status = "Pass";
        }
Ejemplo n.º 2
0
        protected override void OnMessage(MessageEventArgs e)
        {
            MESStationReturn StationReturn = null; // new MESStationReturn();

            string[] Para = null;                  //add by LLF 2017-1-4
            try
            {
                //處理JSON
                //Newtonsoft.Json.Linq.JObject Request = (Newtonsoft.Json.Linq.JObject) Newtonsoft.Json.JsonConvert.DeserializeObject(
                //"{ TOKEN:null, CLASS: \"MESStation.ApiHelper\", FUNCTION:\"GetApiClassList\", DATA:{ } }");

                //Request = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject("{ TOKEN:null, CLASS: \"MESStation.ApiHelper\", FUNCTION:\"GetApiFunctionsList\", DATA:{ CLASSNAME:\"MESStation.ApiHelper\" } }");
                //Request = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(
                //    "{ TOKEN:null, CLASS: \"MESStation.ApiHelper\", FUNCTION:\"GetApiFunctionsList\", DATA:{ CLASSNAME:\"MESStation.UserManager\" } }");

                Newtonsoft.Json.Linq.JObject Request = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(e.Data);
                string CLASS    = Request["Class"].ToString();
                string FUNCTION = Request["Function"].ToString();
                string TOKEN    = Request["Token"].ToString();
                string MsgID    = Request["MessageID"]?.ToString();
                string ClientID = Request["ClientID"]?.ToString();
                Request.Add("IP", Newtonsoft.Json.Linq.JToken.Parse("{Value:\"" + this.ClientIP + "\"}"));


                StationReturn = new MESStationReturn(MsgID, ClientID);
                //反射加載

                //ApiHelper api = new ApiHelper();
                Type APIType;
                //加載類庫
                Assembly assembly = Assembly.Load("MESStation");

                APIType = assembly.GetType(CLASS);
                object     API_CLASS = assembly.CreateInstance(CLASS);
                MesAPIBase API       = (MesAPIBase)API_CLASS;
                if (!API.DBPools.ContainsKey("SFCDB"))
                {
                    API.DBPools.Add("SFCDB", SFCDBPool);
                }
                if (!API.DBPools.ContainsKey("APDB"))
                {
                    API.DBPools.Add("APDB", APDBPool);
                }
                //API.BU = "HWD";
                //API.BU = "VERTIV";
                ((MesAPIBase)API_CLASS).IP = this.ClientIP;

                API.Language = "CHINESE";  //CHINESE,CHINESE_TW,ENGLISH;

                //初始化異常類型的數據庫連接池
                MESReturnMessage.SetSFCDBPool(SFCDBPool);
                //獲取調用函數
                MethodInfo Function = APIType.GetMethod(FUNCTION);
                //
                bool CheckLogin = false;
                if (LoginUsers.ContainsKey(TOKEN))
                {
                    User lu = LoginUsers[TOKEN];
                    ((MesAPIBase)API_CLASS).LoginUser = lu;
                    CheckLogin = true;
                    API.BU     = lu.BU;
                }
                else
                {
                    if (FUNCTION != "Login" && ((MesAPIBase)API_CLASS).MastLogin)
                    {
                        StationReturn.Status  = StationReturnStatusValue.Fail;
                        StationReturn.Message = "No Login !";
                    }
                    else
                    {
                        if (FUNCTION == "Login")
                        {
                            CheckLogin = true;
                        }
                    }
                }
                if (CheckLogin)
                {
                    Function.Invoke(API_CLASS, new object[] { Request, Request["Data"], StationReturn });
                    if (FUNCTION == "Login")
                    {
                        if (StationReturn.Status == "Pass")
                        {
                            LoginReturn r  = (LoginReturn)StationReturn.Data;
                            User        lu = ((MesAPIBase)API_CLASS).LoginUser;
                            if (this.Token != null)
                            {
                                Report.LoginUsers.Remove(Token);
                                MESStation.Stations.CallStation.logout(Token);
                            }
                            string NewToken = r.Token;
                            Token = r.Token;
                            if (LoginUsers.ContainsKey(NewToken))
                            {
                                LoginUsers[NewToken] = lu;
                            }
                            else
                            {
                                LoginUsers.Add(NewToken, lu);
                            }
                        }
                    }
                }//函數不要求登錄
                else if (!((MesAPIBase)API_CLASS).MastLogin)
                {
                    Function.Invoke(API_CLASS, new object[] { Request, Request["Data"], StationReturn });
                    if (FUNCTION == "Login")
                    {
                        if (StationReturn.Status == "Pass")
                        {
                            LoginReturn r        = (LoginReturn)StationReturn.Data;
                            User        lu       = ((MesAPIBase)API_CLASS).LoginUser;
                            string      NewToken = r.Token;
                            if (LoginUsers.ContainsKey(NewToken))
                            {
                                LoginUsers[NewToken] = lu;
                            }
                            else
                            {
                                LoginUsers.Add(NewToken, lu);
                            }
                        }
                    }
                }

                //add by LLF 2017-12-27
                if (StationReturn.MessageCode != null)
                {
                    if (StationReturn.MessageCode.Length > 0)
                    {
                        if (StationReturn.MessagePara != null)
                        {
                            if (StationReturn.MessagePara.Count > 0)
                            {
                                Para = new string[StationReturn.MessagePara.Count];
                                for (int i = 0; i < StationReturn.MessagePara.Count; i++)
                                {
                                    Para[i] = StationReturn.MessagePara[i].ToString();
                                }
                            }
                        }
                        StationReturn.Message = MESReturnMessage.GetMESReturnMessage(StationReturn.MessageCode, Para);
                    }
                }
            }
            catch (MESReturnMessage ee)
            {
                StationReturn.Status  = StationReturnStatusValue.Fail;
                StationReturn.Message = ee.Message;
                if (ee.InnerException != null)
                {
                    StationReturn.Data = ee.InnerException.Message;
                }
            }
            catch (Exception ee)
            {
                StationReturn.Status  = StationReturnStatusValue.Fail;
                StationReturn.Message = ee.Message;
                if (ee.InnerException != null)
                {
                    StationReturn.Data = ee.InnerException.Message;
                }
            }



            System.Web.Script.Serialization.JavaScriptSerializer JsonMaker = new System.Web.Script.Serialization.JavaScriptSerializer();
            JsonMaker.MaxJsonLength = int.MaxValue;

            string json = JsonMaker.Serialize(StationReturn);

            //JavaScriptSerializer 實例在序列化對象的時候,遇到 DateTime 類型會序列化出不可讀的數據,
            //因此改用 Newtonsoft 的 JsonConvert 來進行序列化,序列化出來的 DateTime 形如 2017-12-06T11:14:37
            //另外如果遇到無法將 System.DBNull 類型轉換成 string 類型的,可以手動檢測下值的類型,
            //如果是 System.DBNull,直接將值改為 null 即可。
            //實在無法實現你所需要的功能,可將下面這句註釋掉。
            //
            // modify by 張官軍 2017/12/06

            //變更時間格式  modify by Wuq 2018/01/25
            json = Newtonsoft.Json.JsonConvert.SerializeObject(StationReturn, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.Converters.IsoDateTimeConverter {
                DateTimeFormat = "yyyy-MM-dd HH:mm:ss"
            });
            //json = Newtonsoft.Json.JsonConvert.SerializeObject(StationReturn);

            Send(json);
        }
Ejemplo n.º 3
0
        public static void LastScanRuleChecker(SN_KP config, LogicObject.SN sn, Row_R_SN_KP scan, List <Row_R_SN_KP> scans, MesAPIBase API, OleExec sfcdb)
        {
            T_R_SN_KP      t_r_sn_kp     = new T_R_SN_KP(sfcdb, DB_TYPE_ENUM.Oracle);
            List <R_SN_KP> kpList        = t_r_sn_kp.GetKPRecordBySnID(sn.ID, sfcdb);
            R_SN_KP        lastScan      = kpList.Find(k => k.SCANSEQ == (scan.SCANSEQ - 1));
            string         scanValue     = scan.VALUE.Substring(4, scan.VALUE.Length - 4);
            string         lastScanVlaue = lastScan.VALUE.Substring(0, scan.VALUE.Length - 4);

            if (lastScan != null)
            {
                if (scanValue != lastScanVlaue)
                {
                    throw new Exception("this value " + scan.VALUE + "is inconsistent with the last one");
                }
            }
        }
Ejemplo n.º 4
0
 public static void SystemSNScanRuleChecker(SN_KP config, LogicObject.SN sn, Row_R_SN_KP scan, List <Row_R_SN_KP> scans, MesAPIBase API, OleExec sfcdb)
 {
     LogicObject.SN kpsn = new LogicObject.SN(scan.VALUE, sfcdb, DB_TYPE_ENUM.Oracle);
     if (kpsn.CompletedFlag != "1")
     {
         throw new Exception($@"{kpsn.SerialNo} not finish !");
     }
     if (kpsn.ShippedFlag == "1")
     {
         throw new Exception($@"{kpsn.SerialNo} has being Shipped!");
     }
     if (kpsn.baseSN.SKUNO != scan.PARTNO)
     {
         throw new Exception($@"{kpsn.SerialNo} is {kpsn.SkuNo} config is {scan.PARTNO}");
     }
     kpsn.baseSN.SHIPPED_FLAG = "1";
     kpsn.baseSN.SHIPDATE     = DateTime.Now;
     kpsn.baseSN.EDIT_TIME    = DateTime.Now;
     kpsn.baseSN.EDIT_EMP     = API.LoginUser.EMP_NO;
     sfcdb.ORM.Updateable <R_SN>(kpsn.baseSN).Where(t => t.ID == kpsn.baseSN.ID).ExecuteCommand();
 }
Ejemplo n.º 5
0
 public static void CheckTEST(SN_KP config, LogicObject.SN sn, Row_R_SN_KP scan, List <Row_R_SN_KP> scans, MesAPIBase API, OleExec sfcdb)
 {
 }