/// <summary> /// Polling of SFTP server to get the all registrations file. /// </summary> /// <param name="adminInfo"> DB Admin info</param> private void PollSFTPServer(DBAdminInfo adminInfo) { // call to sftp server for getting all regisrations file string filename = null; SFTPHelper sftpClient = new SFTPHelper(this.Logger); XmlNamespaceManager namespacemanager; try { this.Logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "Begin FCCDBSyncPoller - Poll() - making SFTPClint Call "); filename = sftpClient.GetAllXMLfileFromSFTP(adminInfo.FtpServerUrl, adminInfo.SFTPPath, adminInfo.FtpServerUserId, adminInfo.FtpServerPwd, Utils.GetOutputDirPathForConfigKey("FTPFileDownloadPath")); this.Logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "End FCCDBSyncPoller - Poll() - making SFTPClint Call "); XmlDocument xmlDocAll = new XmlDocument(); xmlDocAll.PreserveWhitespace = true; xmlDocAll.Load(filename); namespacemanager = new XmlNamespaceManager(xmlDocAll.NameTable); namespacemanager.AddNamespace("m", xmlDocAll.DocumentElement.NamespaceURI); this.SyncManager.ParsePollResponse(adminInfo.Name, xmlDocAll.OuterXml, adminInfo.PublicKey); // Update Next Trasaction ID adminInfo.NextTransactionID = xmlDocAll.SelectSingleNode("//m:NextTransactionID", namespacemanager).InnerText; this.SyncManager.UpdateDBAdminInfo(adminInfo); } catch (Exception e) { this.Auditor.Audit(AuditId.DBSyncPollRequest, AuditStatus.Failure, 0, "FCCDBSyncPoller - Poll() - SFP file get Exception :" + e.ToString()); this.Logger.Log(TraceEventType.Error, LoggingMessageId.DBSyncPollerGenericMessage, "FCCDBSyncPoller - Poll() - SFTP file get Exception :" + e.ToString()); } }
/// <summary> /// Send Poll request /// </summary> /// <param name="dbadmin">DB admin info</param> /// <returns>string response</returns> private string SendPollRequest(DBAdminInfo dbadmin) { string reponseXml = string.Empty; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Stream requestStream = null; HttpWebRequest httpWebRequest = null; HttpWebResponse wr = null; this.Logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "Begin FCCDBSyncPoller - SendPollRequest() - Calling WiteSpace DBA web service URL:" + dbadmin.WebServiceUrl); try { httpWebRequest = WebRequest.Create(dbadmin.WebServiceUrl) as HttpWebRequest; httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "text/xml; charset=utf-8"; // "application/xml"; httpWebRequest.Headers.Add("SOAPAction", "http://www.whitespace-db-providers.org/2011//InterDB/ws/RealTimePoll"); using (requestStream = httpWebRequest.GetRequestStream()) { requestStream = this.SyncManager.GeneratePollRequest(requestStream, dbadmin.NextTransactionID); using (wr = (HttpWebResponse)httpWebRequest.GetResponse()) { if (wr.StatusCode != HttpStatusCode.OK) { stopWatch.Stop(); this.Auditor.Audit(AuditId.DBSyncPollRequest, AuditStatus.Failure, stopWatch.Elapsed.Ticks, "FCCDBSyncPoller - SendPollRequest - Response Status code :" + wr.StatusCode.ToString()); this.Logger.Log(TraceEventType.Error, LoggingMessageId.DBSyncPollerGenericMessage, "FCCDBSyncPoller - SendPollRequest - Response Status code :" + wr.StatusCode.ToString()); } else { using (StreamReader srd = new StreamReader(wr.GetResponseStream())) { reponseXml = srd.ReadToEnd(); } } } } } catch (WebException e) { stopWatch.Stop(); this.Auditor.Audit(AuditId.DBSyncPollRequest, AuditStatus.Failure, stopWatch.Elapsed.Ticks, e.ToString()); this.Logger.Log(TraceEventType.Error, LoggingMessageId.DBSyncPollerGenericMessage, "FCCDBSyncPoller - SendPollRequest - " + e.ToString()); } this.Logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "End FCCDBSyncPoller - SendPollRequest() - Calling WiteSpace DBA web service URL"); reponseXml = HttpUtility.HtmlDecode(reponseXml); return(reponseXml); }
/// <summary> /// parses the response xml received as poll response. /// </summary> /// <param name="adminInfo"> Admin Info </param> public void UpdateDBAdminInfo(DBAdminInfo adminInfo) { this.dalcDbSync.UpdateDBAdminInfo(adminInfo); }