示例#1
0
        private void UpdateDIObject <T>(T obj, string resourceXmlString, XDocument resourceXml, string name, string formatName, INotifier notifier)
        {
            Type   type    = typeof(T);
            string xml     = (string)type.InvokeMember("GetAsXML", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null);
            var    currXml = XDocument.Parse(xml);

            if (!XDocument.DeepEquals(currXml, resourceXml))
            {
                var browser = type.InvokeMember("Browser", BindingFlags.GetProperty | BindingFlags.Public, null, obj, null);
                browser.GetType().InvokeMember("ReadXml", BindingFlags.InvokeMethod | BindingFlags.Public,
                                               null, browser, new object[] { resourceXmlString, 0 });
                int ret = (int)type.InvokeMember("Update", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null);
                if (ret != 0)
                {
                    string err;
                    company.GetLastError(out ret, out err);
                    string exceptionErr = String.Format(Messages.ErrorUpdatingDI, name, formatName, err);
                    Logger.Error(exceptionErr);
                    notifier.Do(x => x.OnError(resourceXml.ToString(), ret, err));
                    throw new Exception(exceptionErr);
                }
                else
                {
                    Logger.Info(String.Format(Messages.SuccessUpdatingDI, name, formatName));
                    notifier.Do(x => x.OnSuccess(resourceXml.ToString(), ""));
                }
            }
            else
            {
                Logger.Debug(DebugString.Format(Messages.UpdateDINotNecessary, name));
            }
        }
示例#2
0
        private void AddDIObject <T>(T obj, string xmlBom, int i, string name, string formatName, INotifier notifier)
        {
            Type type    = typeof(T);
            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 });
            int ret = (int)type.InvokeMember("Add", BindingFlags.InvokeMethod | BindingFlags.Public, null, obj, null);

            if (ret != 0)
            {
                string err;
                company.GetLastError(out ret, out err);
                string exceptionErr = String.Format(Messages.ErrorAddingDI, name, formatName, err);
                Logger.Error(exceptionErr);
                notifier.Do(x => x.OnError(xmlBom, ret, err));
                throw new Exception(exceptionErr);
            }
            else
            {
                string key = company.GetNewObjectKey();
                Logger.Info(String.Format(Messages.SuccessAddindDI, name, formatName));
                notifier.Do(x => x.OnSuccess(xmlBom, key));
            }
        }