private static bool ProcessErrorXml(string importXmlLog) { importXmlLog.RequireNotEmpty(nameof(importXmlLog)); var isfailed = false; try { var doc = new XmlDocument(); doc.LoadXml(importXmlLog); var error = doc.SelectSingleNode("//result[@result='failure']/@errortext")?.Value; if (error == null) { return(false); } isfailed = true; log.LogError($"Import failed with the following error (Full log written to import.log):\r\n{error}."); } finally { if (isfailed) { try { var latestIndex = Directory.GetFiles(".") .Select(f => Regex.Match(f, @"import(?:-(\d+))?\.log").Groups[1].Value) .Where(f => f.IsNotEmpty()) .Select(int.Parse) .OrderByDescending(f => f) .FirstOrDefault(); File.WriteAllText($"import{(latestIndex == 0 && !File.Exists("import.log") ? "" : $"-{latestIndex + 1}")}.log", importXmlLog); }
private static CrmServiceClient ConnectToCrm(string connectionString, CrmLog log) { log.Log($"Connecting to '{connectionString}' ..."); var service = new CrmServiceClient(connectionString); if (!string.IsNullOrWhiteSpace(service.LastCrmError) || service.LastCrmException != null) { log.LogError($"Failed to connect => {service.LastCrmError}"); if (service.LastCrmException != null) { throw service.LastCrmException; } return(null); } log.Log($"Connected!"); return(service); }