void RemoveFac(Fac fac) { try { IRestResponse response = CiscoAXL($@" <soapenv:Envelope xmlns:soapenv=""{nsSoap}"" xmlns:ns=""{nsCucm}""> <soapenv:Header/> <soapenv:Body> <ns:removeFacInfo sequence=""?""> <name>{fac.Name}</name> </ns:removeFacInfo> </soapenv:Body> </soapenv:Envelope> "); if (!response.StatusCode.ToString().Equals("OK")) { var resXml = XDocument.Parse(response.Content); var error = resXml.Descendants(nsSoap + "Body").First().Element(nsSoap + "Fault").Element("faultstring").Value; Log.Error($"CUCM: Error on try remove FacInfo {fac.Name}, message={error}"); } else { var resXml = XDocument.Parse(response.Content); var @return = resXml.Descendants(nsSoap + "Body").First().Element(nsCucm + "removeFacInfoResponse").Element("return").Value; Log.Info($"CUCM: Success on remove FacInfo {fac.Name}, return={@return}"); } } catch (Exception ex) { Log.Error($"CUCM: Error on try remove FacInfo {fac.Name}, message={ex.Message}"); } }
void Start() { log4net.Config.XmlConfigurator.Configure(); appSettings = ConfigurationManager.AppSettings; sessionOptions = new SessionOptions { //Protocol = Protocol.Sftp, Protocol = Protocol.Ftp, Timeout = new TimeSpan(0, 2, 0), HostName = appSettings["ip_ftp"], UserName = appSettings["login_ftp"], Password = appSettings["senha_ftp"], PortNumber = int.Parse(appSettings["port_ftp"]), //SshHostKeyFingerprint = appSettings["SFTPhostKey"], }; nsSoap = "http://schemas.xmlsoap.org/soap/envelope/"; nsCucm = "http://www.cisco.com/AXL/API/" + appSettings["VERSAO"]; while (true) { GetFiles(); DirectoryInfo directoryInfo = new DirectoryInfo("temp"); FileInfo[] files = directoryInfo.GetFiles("*.csv"); if (files.Length > 0) { foreach (FileInfo file in files) { var reader = new StreamReader(file.FullName); var csvReader = new CsvReader(reader, CultureInfo.InvariantCulture); csvReader.Configuration.HasHeaderRecord = false; csvReader.Configuration.Delimiter = ","; List <Rlt> rlts = csvReader.GetRecords <Rlt>().ToList(); reader.Close(); File.Delete(file.FullName); foreach (Rlt rlt in rlts) { Fac fac = new Fac { Name = rlt.Matricula, Code = rlt.Senha, AuthorizationLevel = rlt.Categoria }; if (rlt.Acao.Equals("1")) { AddFac(fac); var writer = new StreamWriter($@"temp\{Path.GetFileNameWithoutExtension(file.Name)}_inseridos.csv", true); var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture); csvWriter.WriteRecord(rlt); csvWriter.NextRecord(); writer.Close(); } else if (rlt.Acao.Equals("2")) { RemoveFac(fac); var writer = new StreamWriter($@"temp\{Path.GetFileNameWithoutExtension(file.Name)}_excluidos.csv", true); var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture); csvWriter.WriteRecord(rlt); csvWriter.NextRecord(); writer.Close(); } else { UpdateFac(fac); var writer = new StreamWriter($@"temp\{Path.GetFileNameWithoutExtension(file.Name)}_alterados.csv", true); var csvWriter = new CsvWriter(writer, CultureInfo.InvariantCulture); csvWriter.WriteRecord(rlt); csvWriter.NextRecord(); writer.Close(); } } } PutFiles(); } Thread.Sleep(int.Parse(appSettings["sleep"])); } }