public static bool localtaskAdd(cat_server.taskTable task) { try { cat_local.task local_task = new cat_local.task(); using (cat_local.lab_local lab_local = new cat_local.lab_local()) { if (lab_local.Database.Exists()) { local_task.server_id = task.ID; local_task.task1 = task.task; local_task.state = task.state; local_task.start = task.startTime; local_task.finish = task.finishTime; local_task.series = task.series; local_task.result_ids = task.result_id; local_task.ap = task.ap; local_task.is_update = false.ToString(); local_task = lab_local.task.Add(local_task); if (lab_local.SaveChanges() > 0) { using (cat_server.lab_server lab_server = new cat_server.lab_server()) { lab_server.Entry(task).State = System.Data.Entity.EntityState.Modified; task.local_id = local_task.local_id; int ret = lab_server.SaveChanges(); var v = (from _v in lab_server.taskTable where _v.ID == task.ID select _v).FirstOrDefault(); if (v == task) { return(true); } } } } } } catch (DbEntityValidationException ex) { var entityError = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var getFullMessage = string.Join("; ", entityError); var exceptionMessage = string.Concat(ex.Message, "errors are: ", getFullMessage); //NLog Log(exceptionMessage); Console.WriteLine(exceptionMessage); } catch (Exception e) { Log(e.ToString()); Console.WriteLine(e.ToString()); return(false); } return(false); }
public static bool catinfoEnroll(deviceJson device) { try { cat_server.CAT_info currentinfo = new cat_server.CAT_info(); deviceRefresh(ref currentinfo, device); using (cat_server.lab_server lab_server = new cat_server.lab_server()) { if (CatReg.connect) { var serverinfo = (from _uut in lab_server.CAT_info where _uut.SN == device.sn select _uut).FirstOrDefault(); if (serverinfo == null) { currentinfo.STATUS = CatStatus.uutStatus.STANDBY.ToString(); currentinfo.CurrentTask = CatStatus.taskName.NO_TASK.ToString(); currentinfo.LastUsedTime = DateTime.Now; lab_server.Entry(currentinfo).State = System.Data.Entity.EntityState.Added; } else { lab_server.Entry(serverinfo).State = System.Data.Entity.EntityState.Modified; currentinfo.STATUS = CatReg.status.ToString(); currentinfo.CurrentTask = CatReg.task_name; currentinfo.LastUsedTime = DateTime.Now; currentinfoCompare(ref serverinfo, currentinfo); } lab_server.SaveChanges(); } } Console.WriteLine("enroll finish"); return(true); } catch (DbEntityValidationException ex) { var entityError = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var getFullMessage = string.Join("; ", entityError); var exceptionMessage = string.Concat(ex.Message, "errors are: ", getFullMessage); //NLog Log(exceptionMessage); Console.WriteLine(exceptionMessage); } catch (Exception e) { Log(e.ToString()); Console.WriteLine(e.ToString()); } return(false); }
public static bool catinfoUpdate(cat_server.CAT_info catinfo) { try { using (cat_server.lab_server lab_server = new cat_server.lab_server()) { if (CatReg.connect) { var uut = (from _uut in lab_server.CAT_info where _uut.SN == catinfo.SN select _uut).FirstOrDefault(); if (uut == null) { throw new Exception("UUT NOT FOUND"); } currentinfoCompare(ref uut, catinfo); lab_server.Entry(uut).State = System.Data.Entity.EntityState.Modified; lab_server.SaveChanges(); return(true); } } } catch (DbEntityValidationException ex) { var entityError = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var getFullMessage = string.Join("; ", entityError); var exceptionMessage = string.Concat(ex.Message, "errors are: ", getFullMessage); //NLog Log(exceptionMessage); Console.WriteLine(exceptionMessage); } catch (Exception e) { Log(e.ToString()); Console.WriteLine(e.ToString()); } return(false); }
public static bool taskUpdate(cat_local.task task) { try { using (cat_local.lab_local lab_local = new cat_local.lab_local()) { if (lab_local.Database.Exists()) { using (cat_server.lab_server lab_server = new cat_server.lab_server()) { if (CatReg.connect) { var server_task = (from __task in lab_server.taskTable where (task.local_id == __task.local_id) && (__task.SN == CatCore.device.sn) select __task).FirstOrDefault(); var _serverid_require_update = false; if (server_task == null) { server_task = new cat_server.taskTable(); lab_server.Entry(server_task).State = System.Data.Entity.EntityState.Added; _serverid_require_update = true; } else { Console.WriteLine($"server_task.local/server id:{server_task.local_id}/{server_task.ID}"); lab_server.Entry(server_task).State = System.Data.Entity.EntityState.Modified; } Console.WriteLine($"lab_server.Entry(server_task).State:{ lab_server.Entry(server_task).State}"); server_task.SN = CatCore.device.sn; server_task.task = task.task1; server_task.state = task.state; server_task.startTime = task.start; server_task.finishTime = task.finish; server_task.result_id = task.result_ids; server_task.local_id = task.local_id; lab_server.SaveChanges(); Console.WriteLine($"#lab_server.Entry(server_task).State:{ lab_server.Entry(server_task).State}"); if (_serverid_require_update) { server_task = (from __task in lab_server.taskTable where task.local_id == __task.local_id select __task).FirstOrDefault(); task.server_id = server_task.ID; } } } lab_local.Entry(task).State = System.Data.Entity.EntityState.Modified; lab_local.SaveChanges(); if (task == lab_local.task.Find(task.local_id)) { return(true); } } } } catch (DbEntityValidationException ex) { var entityError = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var getFullMessage = string.Join("; ", entityError); var exceptionMessage = string.Concat(ex.Message, "errors are: ", getFullMessage); //NLog Log(exceptionMessage); Console.WriteLine(exceptionMessage); } catch (Exception e) { Log(e.ToString()); Console.WriteLine(e.ToString()); } return(false); }
public static bool localtaskAdd(cat_local.task task) { using (cat_local.lab_local lab_local = new cat_local.lab_local()) { if (lab_local.Database.Exists()) { Console.WriteLine($"lab_local.Entry(task).State ={lab_local.Entry(task).State}"); lab_local.Entry(task).State = System.Data.Entity.EntityState.Added; Console.WriteLine($"#lab_local.Entry(task).State ={lab_local.Entry(task).State}"); Console.WriteLine($"Adding {task.task1}"); var ret = lab_local.SaveChanges(); Console.WriteLine($"Added ret{ret}"); if (ret > 0) { if (CatNet.ServerConnection) { using (cat_server.lab_server lab_server = new cat_server.lab_server()) { if (lab_server.Database.Exists()) { cat_server.taskTable server_task = new cat_server.taskTable(); server_task.local_id = task.local_id; server_task.SN = CatCore.device.sn; server_task.state = task.state; server_task.task = task.task1; server_task.result_id = task.result_ids; server_task.startTime = task.start; server_task.finishTime = task.finish; server_task.series = task.series; server_task = lab_server.taskTable.Add(server_task); if (lab_server.SaveChanges() > 0) { task.server_id = server_task.ID; task.is_update = false.ToString(); try { lab_local.SaveChanges(); return(true); } catch (DbEntityValidationException ex) { var entityError = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage); var getFullMessage = string.Join("; ", entityError); var exceptionMessage = string.Concat(ex.Message, "errors are: ", getFullMessage); //NLog Log(exceptionMessage); Console.WriteLine(exceptionMessage); } catch (Exception e) { Log(e.ToString()); Console.WriteLine(e.ToString()); return(false); } } } } } return(true); } } } return(false); }