示例#1
0
        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()));
            }
        }
示例#2
0
        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);
        }