public bool ParallelInitial() { try { myFactory = new NateFactory(); DataTable dataTable_Equipment; DataTable equipmentLits = this.GetEquipmentInfo(out dataTable_Equipment); usedEquipments = new Dictionary <string, IEquipment>(); bool result = true; Parallel.For(0, equipmentLits.Rows.Count, (int i, ParallelLoopState pls) => { //get para of the current equipment string dataTable = "TopoEquipmentParameter"; string expression = "select * from " + dataTable + " where PID= " + equipmentLits.Rows[i]["id"].ToString() + " order by ID"; //DataTable dt = myDataIO.GetDataTable(expression, dataTable); DataRow[] drs = dataTable_Equipment.Select("id='" + equipmentLits.Rows[i]["id"].ToString() + "'"); Dictionary <string, string> currentEquipmentPara = new Dictionary <string, string>(); foreach (DataRow dr in drs) { string name = dr["ItemName"].ToString().Trim().ToUpper(); string value = dr["ItemValue"].ToString().Trim().ToUpper(); currentEquipmentPara.Add(name, value); } string role = dataTable_Equipment.Rows[i]["Role"].ToString().Trim().ToUpper(); // 0=NA,1=TX,2=RX currentEquipmentPara.Add("ROLE", role); //create equipment object string equipmentName = equipmentLits.Rows[i]["Name"].ToString().ToUpper(); string equipmentFullName = equipmentLits.Rows[i]["FullName"].ToString(); string equipmentType = equipmentLits.Rows[i]["TYPE"].ToString().ToUpper(); IEquipment equipment = myFactory.CreateEquipment(equipmentName); //config offset if (equipmentFullName.Contains("SCOPE")) { string[] settingArray = myXml.ScopeOffset.Split(','); for (int j = 1; j < settingArray.Length + 1; j++) { double offset = Convert.ToDouble(settingArray[j - 1]); equipment.ConfigOffset(j, offset); } } if (equipmentFullName.Contains("ATT")) { string[] settingArray = myXml.AttennuatorOffset.Split(','); for (int j = 1; j < settingArray.Length + 1; j++) { double offset = Convert.ToDouble(settingArray[j - 1]); equipment.ConfigOffset(j, offset); } } if (equipmentFullName.Contains("POWERSUPPLY")) { double offset_VCC = Convert.ToDouble(myXml.VccOffset); double offset_ICC = Convert.ToDouble(myXml.IccOffset); equipment.ConfigOffset(1, offset_VCC, offset_ICC); } if (equipmentFullName.Contains("NA_OPTICALSWITCH")) { Log.SaveLogToTxt("Failed."); Log.SaveLogToTxt("It can not parallel initial, due to Tx/Rx have common equipment NA_OPTICALSWITCH."); result = false; pls.Break(); } if (equipment.Initial(currentEquipmentPara) && equipment.Configure(1)) { usedEquipments.Add(equipmentType, equipment); result = true; } else { result = false; pls.Break(); //log.AdapterLogString(3, equipmentFullName + "Configure Error"); //Exception ex = new Exception(equipmentFullName + "Configure Error"); //throw ex; } currentEquipmentPara = null; equipment.OutPutSwitch(false); }); return(result); } catch (Exception ex) { Log.SaveLogToTxt(ex.ToString()); return(false); } }
public bool Initial() { try { myFactory = new NateFactory(); DataTable dataTable_Equipment; DataTable equipmentLits = this.GetEquipmentInfo(out dataTable_Equipment); usedEquipments = new Dictionary <string, IEquipment>(); for (int i = 0; i < equipmentLits.Rows.Count; i++) { //create equipment object string equipmentName = equipmentLits.Rows[i]["Name"].ToString().ToUpper(); string equipmentFullName = equipmentLits.Rows[i]["FullName"].ToString(); string equipmentType = equipmentLits.Rows[i]["TYPE"].ToString().ToUpper(); IEquipment equipment = myFactory.CreateEquipment(equipmentName); //config offset if (equipmentFullName.Contains("SCOPE")) { Log.SaveLogToTxt("Config offset for equipment " + equipmentName.ToLower()); string[] settingArray = myXml.ScopeOffset.Split(','); for (int j = 1; j < settingArray.Length + 1; j++) { double offset = Convert.ToDouble(settingArray[j - 1]); equipment.ConfigOffset(j, offset); } } if (equipmentFullName.Contains("ATT")) { Log.SaveLogToTxt("Config offset for equipment " + equipmentName.ToLower()); string[] settingArray = myXml.AttennuatorOffset.Split(','); for (int j = 1; j < settingArray.Length + 1; j++) { double offset = Convert.ToDouble(settingArray[j - 1]); equipment.ConfigOffset(j, offset); } } if (equipmentFullName.Contains("POWERSUPPLY")) { Log.SaveLogToTxt("Config offset for equipment " + equipmentName.ToLower()); double offset = Convert.ToDouble(myXml.VccOffset); equipment.ConfigOffset(1, offset); } //get para of the current equipment Log.SaveLogToTxt("Get parameter for equipment " + equipmentName.ToLower()); string dataTable = "TopoEquipmentParameter"; string expression = "select * from " + dataTable + " where PID= " + equipmentLits.Rows[i]["id"].ToString() + " order by ID"; //DataTable dt = myDataIO.GetDataTable(expression, dataTable); DataRow[] drs = dataTable_Equipment.Select("id='" + equipmentLits.Rows[i]["id"].ToString() + "'"); Dictionary <string, string> currentEquipmentPara = new Dictionary <string, string>(); foreach (DataRow dr in drs) { string name = dr["ItemName"].ToString().Trim().ToUpper(); string value = dr["ItemValue"].ToString().Trim().ToUpper(); currentEquipmentPara.Add(name, value); } string role = dataTable_Equipment.Rows[i]["Role"].ToString().Trim().ToUpper();// 0=NA,1=TX,2=RX currentEquipmentPara.Add("ROLE", role); Log.SaveLogToTxt("Initial equipment " + equipmentName.ToLower()); if (equipment.Initial(currentEquipmentPara) && equipment.Configure(1)) { usedEquipments.Add(equipmentType, equipment); } else { Log.SaveLogToTxt("Failed to initial equipment " + equipmentName.ToLower()); return(false); } currentEquipmentPara = null; equipment.OutPutSwitch(false); } Log.SaveLogToTxt("Initial equipment successfully."); return(true); } catch { Log.SaveLogToTxt("Failed to initial equipment."); return(false); } }