private void UpdateOrSaveBOMIfNotExists(IBOM bom, bool Update = true, bool CheckExists = true, INotifier notifier = null) { object obj = null; string xmlBom = bom.Serialize(); company.XmlExportType = BoXmlExportTypes.xet_ExportImportMode; company.XMLAsString = true; int length = company.GetXMLelementCount(xmlBom); for (int i = 0; i < length; i++) { Logger.Debug(DebugString.Format(Messages.StartUpdateOrSave, bom.BO[i].GetName())); Type type = bom.BO[i].GetBOClassType(); try { obj = company.GetBusinessObject(bom.BO[i].GetBOType()); if (CheckExists) { var browser = type.InvokeMember("Browser", BindingFlags.GetProperty | BindingFlags.Public, null, obj, null); browser.GetType().InvokeMember("ReadXml", BindingFlags.InvokeMethod | BindingFlags.Public, null, browser, new object[] { xmlBom, i }); string xml = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null); var resourceXml = XDocument.Parse(xml); object[] keys = GetKeys(obj, bom.BO[i].GetBOType(), bom.BO[i].GetKey()); bool found = (bool)type.InvokeMember("GetByKey", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, keys); if (found) { if (Update) { UpdateDIObject(obj, xml, resourceXml, bom.BO[i].GetName(), bom.BO[i].GetFormattedKey(), notifier); } } else { AddDIObject(obj, xmlBom, i, bom.BO[i].GetName(), bom.BO[i].GetFormattedKey(), notifier); } } else { AddDIObject(obj, xmlBom, i, bom.BO[i].GetName(), bom.BO[i].GetFormattedKey(), notifier); } } finally { if (obj != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); } } Logger.Debug(DebugString.Format(Messages.EndUpdateOrSave, bom.BO[i].GetName())); } }
private List <int> ListMissingOrOutdatedKeysBOM(IBOM bom, bool update = false) { object obj = null; List <int> missingKeys = new List <int>(); string xmlBom = bom.Serialize(); company.XmlExportType = BoXmlExportTypes.xet_ExportImportMode; company.XMLAsString = true; int length = company.GetXMLelementCount(xmlBom); for (int i = 0; i < length; i++) { Logger.Debug(DebugString.Format(Messages.StartListMissingBOMKeys, bom.BO[i].GetName())); Type type = bom.BO[i].GetBOClassType(); try { obj = company.GetBusinessObject(bom.BO[i].GetBOType()); var browser = type.InvokeMember("Browser", BindingFlags.GetProperty | BindingFlags.Public, null, obj, null); browser.GetType().InvokeMember("ReadXml", BindingFlags.InvokeMethod | BindingFlags.Public, null, browser, new object[] { xmlBom, i }); string xml = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null); var resourceXml = XDocument.Parse(xml); object[] keys = GetKeys(obj, bom.BO[i].GetBOType(), bom.BO[i].GetKey()); bool found = (bool)type.InvokeMember("GetByKey", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, keys); if (!found) { missingKeys.Add(i); } else if (update) { xml = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null); var currXml = XDocument.Parse(xml); if (!XDocument.DeepEquals(currXml, resourceXml)) { missingKeys.Add(i); } } } finally { if (obj != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); } } Logger.Debug(DebugString.Format(Messages.EndListMissingBOMKeys, bom.BO[i].GetName())); } return(missingKeys); }
private void UpdateDataTableFromKeys(IBOM bom, List <int> keys, XDocument dataTable, string bomName) { var rows = dataTable.Element("DataTable").Element("Rows"); if (rows == null) { rows = new XElement("Rows"); dataTable.Element("DataTable").Add(rows); } foreach (var key in keys) { rows.Add(CreateRow(bomName, bom.BO[key].GetFormattedKey(), bom.BO[key].GetFormattedDescription())); } }
public void UpdateOrSaveBOMIfNotExists(IBOM bom, INotifier notifier = null) { UpdateOrSaveBOMIfNotExists(bom, true, true, notifier); }
public void SaveBOM(IBOM bom, INotifier notifier = null) { UpdateOrSaveBOMIfNotExists(bom, false, false, notifier); }
public List <int> ListMissingBOMKeys(IBOM bom) { return(ListMissingOrOutdatedKeysBOM(bom)); }
private void UpdateDataTableMissingItems(XDocument dataTable, IBOM bom, string bomName) { List <int> keys = b1DAO.ListMissingBOMKeys(bom); UpdateDataTableFromKeys(bom, keys, dataTable, bomName); }
private void UpdateDataTableMissingItems(XDocument dataTable, IBOM bom, string bomName) { List<int> keys = b1DAO.ListMissingBOMKeys(bom); UpdateDataTableFromKeys(bom, keys, dataTable, bomName); }
private void UpdateDataTableFromKeys(IBOM bom, List<int> keys, XDocument dataTable, string bomName) { var rows = dataTable.Element("DataTable").Element("Rows"); if (rows == null) { rows = new XElement("Rows"); dataTable.Element("DataTable").Add(rows); } foreach (var key in keys) { rows.Add(CreateRow(bomName, bom.BO[key].GetFormattedKey(), bom.BO[key].GetFormattedDescription())); } }