internal static void RemoveBrokenTopLevelObjects(ProcessEdit procEdit, ImportReport report) { var propList = procEdit.GetType().GetProperties().Where(p => p.GetCustomAttributes(typeof(ExportableAttribute), false).Any(x => ((ExportableAttribute)x).PropertyType == ExportType.Expandable)); foreach (var prop in propList) { var itemList = prop.GetValue(procEdit) as IList; if (itemList == null) continue; var brokenItemList = itemList.Cast<IEditableBusinessObject>().Where(x => x.IsValid == false).ToList(); foreach (var item in brokenItemList) { var reportProcess = report.Processes.First(x => x.ProcessName == procEdit.Name); switch (prop.Name) { case "ActionRuleList": reportProcess.BrokenRules.Add(itemList[itemList.IndexOf(item)].GetType().GetProperty("Name").GetValue(itemList[itemList.IndexOf(item)]).ToString() + " skipped due to errors"); break; case "FilterList": reportProcess.BrokenFilters.Add(itemList[itemList.IndexOf(item)].GetType().GetProperty("Name").GetValue(itemList[itemList.IndexOf(item)]).ToString() + " skipped due to errors"); break; case "TriggerList": reportProcess.BrokenTriggers.Add(itemList[itemList.IndexOf(item)].GetType().GetProperty("Name").GetValue(itemList[itemList.IndexOf(item)]).ToString() + " skipped due to errors"); break; case "ESyncProcessList": reportProcess.BrokenESyncDesigner.Add(itemList[itemList.IndexOf(item)].GetType().GetProperty("Name").GetValue(itemList[itemList.IndexOf(item)]).ToString() + " skipped due to errors"); break; case "ExternalDataList": reportProcess.BrokenExternalData.Add(itemList[itemList.IndexOf(item)].GetType().GetProperty("Name").GetValue(itemList[itemList.IndexOf(item)]).ToString() + " skipped due to errors"); break; default: reportProcess.OtherErrors.Add(prop.Name + " \"" + itemList[itemList.IndexOf(item)].GetType().GetProperty("Name").GetValue(itemList[itemList.IndexOf(item)]).ToString() + "\"" + " skipped due to errors"); break; } itemList.Remove(item); } } }
/// <summary> /// Fills the values. /// </summary> /// <param name="procEdit"> /// The proc edit. /// </param> /// <param name="proc"> /// The proc. /// </param> /// <param name="includeIds"> /// The include Ids. /// </param> /// <param name="skipBaseProcess">Skip Base Process configuration.</param> private static void FillValues(ProcessEdit procEdit, XContainer proc, bool includeIds = false, bool skipBaseProcess = false) { foreach (var propertyInfo in procEdit.GetType().GetProperties().Where(IsExportable(ExportType.Regular, includeIds))) { try { ImportProcessHelper.FillRegularValue(propertyInfo, proc.Element(propertyInfo.Name), procEdit); } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Import Process", ex); _report.Processes.First(x => x.ProcessName == _currentProcessName).OtherErrors.Add(propertyInfo.Name + " (Error: " + ex.Message + ")"); } } foreach (var propertyInfo in procEdit.GetType().GetProperties().Where(IsExportable(ExportType.Expandable, includeIds))) { if (skipBaseProcess && propertyInfo.Name == "SectionList") continue; IList<XElement> innerElements; Type propType; IList property; if (ImportProcessHelper.FillExpandableValue(propertyInfo, proc.Element(propertyInfo.Name), procEdit, out innerElements, out propType, out property)) continue; foreach (var innerElement in innerElements) { try { var obj = FillInnerValues(propType, innerElement, includeIds: includeIds); if (obj != null) property.Add(obj); } catch (WebException) { _report.Processes.First(x => x.ProcessName == _currentProcessName).BrokenIntegration.Add(innerElement.Element("Name").Value + " - Call (End Point Mapping)"); } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Import Process", ex); var valName = innerElement.Element("Name") != null ? innerElement.Element("Name").Value : ""; var reportProcess = _report.Processes.First(x => x.ProcessName == _currentProcessName); switch (propertyInfo.Name) { case "ActionRuleList": reportProcess.BrokenRules.Add(valName + " (Error: " + ex.Message + ")"); break; case "FilterList": reportProcess.BrokenFilters.Add(valName + " (Error: " + ex.Message + ")"); break; case "TriggerList": reportProcess.BrokenTriggers.Add(valName + " (Error: " + ex.Message + ")"); break; case "ESyncProcessList": reportProcess.BrokenESyncDesigner.Add(valName + " (Error: " + ex.Message + ")"); break; case "ExternalDataList": reportProcess.BrokenExternalData.Add(valName + " (Error: " + ex.Message + ")"); break; default: reportProcess.OtherErrors.Add(propertyInfo.Name + ": " + valName + " (Error: " + ex.Message + ")"); break; } } } } foreach (var propertyInfo in procEdit.GetType().GetProperties().Where(IsExportable(ExportType.Resolvable, includeIds))) { IList<XElement> innerElements; object property; if (ImportProcessHelper.FillResolvableValue(propertyInfo, proc.Element(propertyInfo.Name), procEdit, out innerElements, out property)) continue; try { propertyInfo.SetValue(procEdit, FillResolvableValues(property, innerElements)); } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Import Process", ex); _report.Processes.First(x => x.ProcessName == _currentProcessName).OtherErrors.Add(propertyInfo.Name + " (Error: " + ex.Message + ")"); } } foreach (var propertyInfo in procEdit.GetType().GetProperties().Where(IsExportable(ExportType.Convertible, includeIds))) { switch (propertyInfo.Name) { case "BaseProcess": if (proc.Element("BaseProcess").Value == "Null" || skipBaseProcess) continue; var procInfo = ProcessList.GetProcessList().FirstOrDefault(x => x.SystemName == proc.Element("BaseProcess").Value); if (procInfo == null) { _missingBaseProcessList.Add(new MissingBaseProcessInfo { ProcessName = procEdit.Name, ProcessSystemName = procEdit.SystemName, MissingProcessSystemName = proc.Element("BaseProcess").Value }); continue; } var xElement = PublishedProcesses.GetPublishedProcesses().FirstOrDefault(x => x.SystemName == procInfo.SystemName); if (xElement == null) { continue; } try { ImportProcessHelper.FillRegularValue(procEdit.GetType().GetProperty("BaseProcessId"), xElement.Id, procEdit); } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Import Process", ex); _report.Processes.First(x => x.ProcessName == _currentProcessName).OtherErrors.Add(propertyInfo.Name + " (Error: " + ex.Message + ")"); } break; } } foreach (var propertyInfo in procEdit.GetType().GetProperties().Where(IsExportable(ExportType.Regular, includeIds))) { switch (propertyInfo.Name) { case "DefaultStateName": var xElement = proc.Element("DefaultStateName"); if (xElement == null || xElement.Value == "Null") continue; try { ImportProcessHelper.FillRegularValue(propertyInfo, proc.Element(propertyInfo.Name), procEdit); } catch (Exception ex) { Log4NetLogger.Instance.Log(LogSeverity.Error, "Import Process", ex); _report.Processes.First(x => x.ProcessName == _currentProcessName).OtherErrors.Add(propertyInfo.Name + " (Error: " + ex.Message + ")"); } break; } } }