示例#1
0
        private bool PostToOktoStart(Machine machine, Product product, Datas datas)
        {
            if (!Config.POSTData.ToOktoStart)
            {
                return(true);
            }
            string msg;
            bool   success;

            try
            {
                LogPOSTOktoStart.Log.Info($"OktoStart 开始");
                LogPOSTOktoStart.Log.Info($"OktoStart 数据:{Config.POSTData.OktoStartParam.Replace("{sn}", datas.SN)}");
                var res = Http.PostJson(Config.POSTData.OkToStartUrl + "?" + Config.POSTData.OktoStartParam.Replace("{sn}", datas.SN), "");
                SaveRequestTime("PostOktoStart", res.Elapsed);
                LogPOSTOktoStart.Log.Info($"收到OktoStart 数据:{res.Contact}");
                if (res.Code == HttpStatusCode.OK)
                {
                    OktoStartResult result = res.Contact.ToEntity <OktoStartResult>();
                    if (result.result == "pass")
                    {
                        msg = $"OktoStart 成功";
                        LogPOSTOktoStart.Log.Error(msg);
                        datas.OktoStartPost            = true;
                        datas.OktoStartPostInformation = res.Contact;
                        product.PostOktoStartSuccess   = true;
                        //machine.AddCount(0, 0, 1);
                        success = true;
                    }
                    else
                    {
                        msg = $"OktoStart 失败:{string.Join("\r\n", result.errors)}";
                        LogPOSTOktoStart.Log.Error(msg);
                        product.AddNgMsg($"OktoStart 失败");
                        datas.OktoStartPost            = false;
                        datas.OktoStartPostInformation = res.Contact;
                        product.PostOktoStartSuccess   = false;
                        success = false;
                    }
                }
                else
                {
                    msg = $"请求 OktoStart 失败:{res.Code}";
                    product.AddNgMsg(msg);
                    LogPOSTOktoStart.Log.Error(msg);
                    datas.OktoStartPost            = false;
                    datas.OktoStartPostInformation = res.Contact;
                    product.PostOktoStartSuccess   = false;
                    success = false;
                }
                //更新数据库
                new DbContext().DatasDb.Update(datas);
            }
            catch (Exception ex)
            {
                msg = $"上抛OktoStart 失败:{ex.Message}";
                LogPOSTOktoStart.Log.Error(msg);
                product.AddNgMsg(msg);
                product.PostOktoStartSuccess = false;
                success = false;
            }
            return(success);
        }
示例#2
0
        private bool PostToIFactory(Machine machine, Product product, Datas datas)
        {
            if (!Config.POSTData.ToIFactory)
            {
                return(true);
            }
            string msg;
            bool   success;

            try
            {
                LogPOSTIFactory.Log.Info($"上抛IFactory 开始");
                LogPOSTIFactory.Log.Info($"上抛IFactory 数据:{Config.POSTData.IFactoryParam.Replace("{sn}", datas.SN)}");
                var res = Http.PostJson(Config.POSTData.IFactoryUrl + "?" + Config.POSTData.IFactoryParam.Replace("{sn}", datas.SN), "");
                SaveRequestTime("PostIFactory", res.Elapsed);
                LogPOSTIFactory.Log.Info($"收到IFactory 数据:{res.Contact}");
                if (res.Code == HttpStatusCode.OK)
                {
                    IfactoryResult result = res.Contact.ToEntity <IfactoryResult>();
                    if (result.result == "pass")
                    {
                        msg = $"上抛IFactory 成功";
                        LogPOSTIFactory.Log.Error(msg);
                        datas.IFactoryPost            = true;
                        datas.IFactoryPostInformation = res.Contact;
                        product.PostIfactorySuccess   = true;
                        machine.AddCount(0, 0, 1);
                        success = true;
                    }
                    else
                    {
                        var msgs_ch = PostToIFactoryAsChainese(result.errors);
                        msg = $"上抛IFactory 失败:{string.Join("\r\n", result.errors)}";
                        LogPOSTIFactory.Log.Error(msg);
                        product.AddNgMsg($"上抛IFactory 失败\r\n{string.Join("\r\n", msgs_ch)}");
                        datas.IFactoryPost            = false;
                        datas.IFactoryPostInformation = res.Contact;
                        product.PostIfactorySuccess   = false;
                        success = false;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(res.Contact) && res.Contact != "http error")
                    {
                        IfactoryResult result = res.Contact.ToEntity <IfactoryResult>();
                        msg = $"上抛IFactory 失败:{string.Join("\r\n", result.errors)}";
                        var msgs_ch = PostToIFactoryAsChainese(result.errors);
                        product.AddNgMsg($"上抛IFactory 失败\r\n{string.Join("\r\n", msgs_ch)}");
                    }
                    else
                    {
                        msg = $"上抛IFactory 失败:{res.Code}";
                        product.AddNgMsg(msg);
                    }
                    LogPOSTIFactory.Log.Error(msg);
                    datas.IFactoryPost            = false;
                    datas.IFactoryPostInformation = res.Contact;
                    product.PostIfactorySuccess   = false;
                    success = false;
                }
                //更新数据库
                new DbContext().DatasDb.Update(datas);
            }
            catch (Exception ex)
            {
                msg = $"上抛IFactory 失败:{ex.Message}";
                LogPOSTIFactory.Log.Error(msg);
                product.AddNgMsg(msg);
                product.PostIfactorySuccess = false;
                success = false;
            }
            return(success);
        }
示例#3
0
        private void PostToJPG(Machine machine, Product product, Datas datas)
        {
            if (!Config.POSTData.ToJGP)
            {
                return;
            }
            string msg;

            try
            {
                LogPOSTJGP.Log.Info($"上抛JGP 开始");
                List <string> list = new List <string> {
                    $"sn={datas.SN}",
                    $"stationid={Uri.EscapeDataString(datas.StationId)}",
                    $"ins1code={SetNullIns(datas.Ins1Code)}",
                    $"ins2code={SetNullIns(datas.Ins2Code)}",
                    $"ins3code={SetNullIns(datas.Ins3Code)}",
                    $"ins4code={SetNullIns(datas.Ins4Code)}",
                    $"ins5code={SetNullIns(datas.Ins5Code)}",
                    $"ins6code={SetNullIns(datas.Ins6Code)}",
                    $"ins7code={SetNullIns(datas.Ins7Code)}",
                    $"ins8code={SetNullIns(datas.Ins8Code)}",
                    $"ins9code={SetNullIns(datas.Ins9Code)}",
                    $"ins10code={SetNullIns(datas.Ins10Code)}",
                    $"ins1name={SetNullIns(datas.Ins1Name)}",
                    $"ins2name={SetNullIns(datas.Ins2Name)}",
                    $"ins3name={SetNullIns(datas.Ins3Name)}",
                    $"ins4name={SetNullIns(datas.Ins4Name)}",
                    $"ins5name={SetNullIns(datas.Ins5Name)}",
                    $"ins6name={SetNullIns(datas.Ins6Name)}",
                    $"ins7name={SetNullIns(datas.Ins7Name)}",
                    $"ins8name={SetNullIns(datas.Ins8Name)}",
                    $"ins9name={SetNullIns(datas.Ins9Name)}",
                    $"ins10name={SetNullIns(datas.Ins10Name)}",
                    $"color={Uri.EscapeDataString(datas.Color)}",
                    $"region={Uri.EscapeDataString(datas.Region)}",
                    $"project={Uri.EscapeDataString(datas.Project)}",
                    $"location={Uri.EscapeDataString(datas.Location)}",
                    $"pahse={Uri.EscapeDataString(datas.Pahse)}"
                };
                LogPOSTJGP.Log.Info($"上抛JGP数据:{string.Join("&", list)}");
                var r = Http.GetXml($"{Config.POSTData.JGPUrl}?{string.Join("&", list)}");
                SaveRequestTime("PostJGP", r.Elapsed);
                LogPOSTJGP.Log.Info($"收到JGP数据:{r.Contact}");
                if (r.Code != HttpStatusCode.OK)
                {
                    msg = $"上抛JGP失败 {r.Code}";
                    LogPOSTJGP.Log.Error(msg);
                    product.AddNgMsg(msg);
                    datas.JgpPost            = false;
                    datas.JgpPostInformation = r.Code.ToString();
                    product.PostJGPSuccess   = false;
                }
                else
                {
                    var res = r.Contact;
                    if (res.IndexOf("[PASS]") > -1)
                    {
                        msg = $"上抛JGP 成功:{res}";
                        LogPOSTJGP.Log.Info(msg);
                        datas.JgpPost            = true;
                        datas.JgpPostInformation = res;
                        product.PostJGPSuccess   = true;
                        machine.AddCount(1, 0, 0);
                    }
                    else
                    {
                        msg = $"上抛JGP:{res}";
                        LogPOSTJGP.Log.Error(msg);
                        product.AddNgMsg(msg);
                        datas.JgpPost            = false;
                        datas.JgpPostInformation = res;
                        product.PostJGPSuccess   = false;
                    }
                    //更新数据库
                    new DbContext().DatasDb.Update(datas);
                }
            }
            catch (Exception ex)
            {
                msg = $"上抛JGP 失败:{ex.Message}";
                LogPOSTJGP.Log.Error(msg);
                product.AddNgMsg(msg);
                product.PostJGPSuccess = false;
            }
        }
示例#4
0
        private void PostToTrace(Machine machine, Product product, Datas datas)
        {
            if (!Config.POSTData.ToTrace)
            {
                return;
            }
            machine.AddPostTotal();
            string dataJson = "";

            try
            {
                TraceData traceData = new TraceData
                {
                    ListData = new Dictionary <string, List <string> >(),
                    FuncData = new Dictionary <string, Func <JToken, string> >
                    {
                        { "unit_serial_number", (d) => { var b = Config.POSTData.SnType?.ToLower() == "fg"?datas.FGCode: datas.SN;  return(b.Length > 17 ? b.Substring(0, 17) : b); } }
                    },
                    DicData = new Dictionary <string, string>
                    {
                        { "fg", datas.FGCode },
                        { "fg_sn", Config.POSTData.SnType?.ToLower() == "fg"?datas.FGCode: datas.SN },
                        { "uut_start", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
                        { "uut_stop", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
                        { "software_version", Version }
                    },
                    ResultsData = GetTraceResults(datas)
                };
                dataJson = traceDataHelper.GetJson(traceData);
            }
            catch (Exception ex)
            {
                LogRead.Log.Error($"解码数据失败:{datas.FGCode}\r\n" + ex.Message);
                LogError.Log.Fatal("Trace 解码数据失败:" + ex.StackTrace);
                product.AddNgMsg("解码数据失败!");
                product.PostTraceSuccess = false;
                return;
            }

            //Process Control
            Result result = Config.POSTData.ProcessControl
                ? TracePost.ProcessControl(Config.POSTData.ProcessControlUrl, datas.SN, dataJson)
                : TracePost.PostTrace(Config.POSTData.TeaceUrl, dataJson);

            foreach (var one in result.Elapseds)
            {
                SaveRequestTime(one.Key, one.Value);
            }
            if (result.Success)
            {
                LogRead.Log.Info($"上抛Trace 成功 {datas.FGCode}");
                datas.TracePost            = true;
                datas.TracePostInformation = "";
                product.PostTraceSuccess   = true;
                machine.AddCount(0, 1, 0);
            }
            else
            {
                LogRead.Log.Info($"上抛Trace 失败 {datas.FGCode}");
                product.AddNgMsg(result.Message);
                datas.TracePost            = false;
                datas.TracePostInformation = string.Join("\r\n", result.Message);
                product.PostTraceSuccess   = false;
            }
            //更新数据库
            new DbContext().DatasDb.Update(datas);
        }
示例#5
0
        private void GetBand(Datas data, Product product)
        {
            var    db       = new DbContext();
            var    db_datas = db.DatasDb;
            string fgcode   = data.FGCode;

            if (Config.CheckIn)
            {
                var db_indatas = db.InDatasDb;
                var inData     = db_indatas.GetSingle(p => p.FG == data.FGCode);
                if (inData == null)
                {
                    LogRead.Log.Error($"线头数据验证失败,未找到对应线头数据!FGCode: {data.FGCode}");
                    product.AddNgMsg("线头未过站!");
                    //product.GetBandSuccess = false;
                    return;
                }
                data.SN = inData.SN;
                //更新数据库
                db_datas.Update(data);
            }
            else
            {
                if (Config.POSTData.GetBandType.ToLower() == "jgp")
                {
                    LogRead.Log.Info($"获取Band码 FGCode: {fgcode}");
                    var res = Http.Get(Config.POSTData.GetBandUrl.Replace("{fg}", fgcode.Replace("+", "%20")));
                    SaveRequestTime("GetBand", res.Elapsed);
                    if (res.Code != HttpStatusCode.OK)
                    {
                        product.AddNgMsg("获取Band码失败");
                        LogRead.Log.Error($"获取Band码失败 FGCode: {fgcode}");
                        product.GetBandSuccess = false;
                        return;
                    }
                    LogRead.Log.Info($"获取Band码响应结果: {res.Contact}");
                    try
                    {
                        CheckResult checkResult = res.Contact.ToEntity <CheckResult>();
                        if (!checkResult.status)
                        {
                            product.AddNgMsg("获取Band码失败:接口返回false");
                            LogRead.Log.Error($"获取Band码失败:接口返回false  {fgcode}");
                            product.GetBandSuccess = false;
                            return;
                        }
                        if (checkResult.msg.IndexOf("null") > -1)
                        {
                            product.AddNgMsg("获取Band码失败:接口返回空");
                            LogRead.Log.Error($"获取Band码失败:接口返回空  {fgcode}");
                            product.GetBandSuccess = false;
                            return;
                        }
                        if (string.IsNullOrEmpty(checkResult.msg))
                        {
                            product.AddNgMsg("获取Band码失败:接口返回空");
                            LogRead.Log.Error($"获取Band码失败:接口返回空  {fgcode}");
                            product.GetBandSuccess = false;
                            return;
                        }
                        data.SN = checkResult.msg;
                        LogRead.Log.Info($"获取Band码成功:{checkResult.msg}  {fgcode}");
                        //更新数据库
                        db_datas.Update(data);
                    }
                    catch (Exception ex)
                    {
                        product.AddNgMsg("获取Band码失败");
                        LogRead.Log.Error($"获取Band码失败:{ex.Message} {fgcode}");
                        product.GetBandSuccess = false;
                        return;
                    }
                }
                else if (Config.POSTData.GetBandType.ToLower() == "trace")
                {
                    var tsr = TraceSerial.GetSerial(Config.POSTData.GetBandUrl, "fg", fgcode, Config.POSTData.ProcessName, true);
                    SaveRequestTime("GetBand", tsr.Response.Elapsed);
                    if (tsr.Response.Code == HttpStatusCode.OK && tsr.TraceSerial != null)
                    {
                        if (string.IsNullOrEmpty(tsr.TraceSerial.Serials.Band))
                        {
                            product.AddNgMsg("获取Band码失败,接口未返回Band码");
                            LogRead.Log.Error($"获取Band码失败:接口未返回Band码 {fgcode}");
                            product.GetBandSuccess = false;
                        }
                        else
                        {
                            data.SN = tsr.TraceSerial.Serials.Band;
                            LogRead.Log.Info($"获取Band码成功:{tsr.TraceSerial.Serials.Band}  {fgcode}");
                            //更新数据库
                            db_datas.Update(data);
                        }
                    }
                    else
                    {
                        product.AddNgMsg("获取Band码失败,接口请求失败");
                        LogRead.Log.Error($"获取Band码失败:{tsr.Response.Error} {fgcode}");
                        product.GetBandSuccess = false;
                        return;
                    }
                }
                else
                {
                    product.AddNgMsg("获取Band码失败");
                    LogRead.Log.Error($"获取Band码失败:不支持的Band码获取类型 {fgcode}");
                    product.GetBandSuccess = false;
                    return;
                }
            }
        }
示例#6
0
        public Datas Get(string Id, SettingsModel settingsModel, ref string msg)
        {
            if (State == -1)
            {
                return(null);
            }
            var   db    = new DbContext();
            Datas datas = db.DatasDb.GetById(Id);

            if (datas != null)
            {
                return(datas);
            }
            datas = new Datas
            {
                Id         = Id,
                StationId  = settingsModel.StationId,
                Color      = settingsModel.Color,
                Region     = settingsModel.Region,
                Project    = settingsModel.Project,
                Location   = settingsModel.Location,
                Pahse      = settingsModel.Pahse,
                CreateDate = DateTime.Now
            };
            var ps = typeof(Datas).GetProperties();

            foreach (var one in Datas)
            {
                var d = one.Value;
                if (d.Data == null)
                {
                    continue;
                }
                var map = Config.DataMapping.FirstOrDefault(p => p.CAMNO.Contains(one.Key));
                if (map != null)
                {
                    foreach (var mapping in map.Mapping)
                    {
                        if (mapping.Name.ToLower().IndexOf("ins") > -1)
                        {
                            continue;
                        }
                        var pinfo = ps.Where(p => p.Name.ToLower() == mapping.Name.ToLower()).FirstOrDefault();
                        if (pinfo == null)
                        {
                            continue;
                        }
                        var v = d.Data[mapping.Index];
                        pinfo.SetValue(datas, v, null);
                    }
                }
                for (int i = 0; i < Config.Station.Count; i++)
                {
                    var pinfo  = ps.Where(p => p.Name.ToLower() == $"ins{i + 1}code").FirstOrDefault();
                    var npinfo = ps.Where(p => p.Name.ToLower() == $"ins{i + 1}name").FirstOrDefault();
                    if (pinfo == null)
                    {
                        continue;
                    }
                    var users = GetTypeData(i + 1, d.Data);
                    if (users != null)
                    {
                        pinfo.SetValue(datas, users.UserCode, null);
                        npinfo.SetValue(datas, users.UserNumber, null);
                    }
                }
            }
            if (string.IsNullOrEmpty(msg))
            {
                db.DatasDb.Insert(datas);
            }
            else
            {
                return(null);
            }
            return(datas);
        }