/// <summary> /// Generates an XML file (either generates the full XML or an incremental file). /// </summary> /// <param name="nextTransactionId">Indicates if a full XML file should be generated /// or just a partial incremental file.</param> /// <returns>Returns an XML stream of the file content.</returns> public ParsePollRequestResult GenerateRecordEnsemble(string nextTransactionId) { this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "Begin - SyncManager - GenerateRecordEnsemble transaction ID :" + nextTransactionId); ParsePollRequestResult pollResult = new ParsePollRequestResult(); XmlDocument xmldoc = null; // get data from azure tables NextTransactionID reqTransId = this.dalcDbSync.GetRequestorTransactionId(nextTransactionId); // Bad Request if (reqTransId == null) { pollResult.RTResponseCode = PollStatus.BadRequest; } else if (reqTransId.Timestamp.AddHours(72) >= DateTime.Now) { // Transaction ID not older than 72 hour - ok try { xmldoc = this.BuildRecordEnsumble(DbSyncScope.INC, reqTransId, "External"); } catch { throw; } xmldoc = XmlCryptography.SignXmlDcoument(Utils.GetFilePathForConfigKey("SignCertificate"), xmldoc); pollResult.ResponseData = xmldoc.OuterXml; XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmldoc.NameTable); namespaceManager.AddNamespace("ren", xmldoc.DocumentElement.NamespaceURI); XmlNodeList nodelist = xmldoc.SelectNodes("//ren:Registration", namespaceManager); if (nodelist != null && nodelist.Count > 0) { this.VerifyRecordEnsembleGenerated(xmldoc); pollResult.RTResponseCode = PollStatus.Success; pollResult.ResponseData = xmldoc.OuterXml; pollResult.NextTransactionId = xmldoc.SelectSingleNode("//ren:NextTransactionID", namespaceManager).InnerXml; } else { pollResult.RTResponseCode = PollStatus.NoNewRecords; pollResult.NextTransactionId = xmldoc.SelectSingleNode("//ren:NextTransactionID", namespaceManager).InnerXml; } } else if (reqTransId.Timestamp.AddHours(72) < DateTime.Now) { // Transaction ID Stale > 72 hours pollResult.RTResponseCode = PollStatus.TransactionIDStale; } this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "End - SyncManager - GenerateRecordEnsemble transaction ID :" + nextTransactionId); return(pollResult); }
/// <summary> /// Generates an XML file (either generates the full XML). /// </summary> /// <param name="scope">Indicates if a full XML file should be generated /// or just a partial incremental file.</param> /// <returns>Returns an XML string of the file content.</returns> public string GenerateRecordEnsemble(DbSyncScope scope) { string wsdba = Utils.Configuration[Constants.ConfigSettingWSDBAName]; this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "Begin - SyncManager - GenerateRecordEnsemble scope :" + scope); XmlDocument xmlDocAll = new XmlDocument(); string signedOutputFilePath = null; try { NextTransactionID reqTransId = this.dalcDbSync.GetRequestorTransactionId(wsdba, scope); // generating xml Doc xmlDocAll = this.BuildRecordEnsumble(scope, reqTransId, wsdba); // Registrations count check if (this.registrationExist) { // Signing the XML xmlDocAll = XmlCryptography.SignXmlDcoument(Utils.GetFilePathForConfigKey("SignCertificate"), xmlDocAll); this.VerifyRecordEnsembleGenerated(xmlDocAll); // <n1:NextTransactionID/> string timeStamp = "F" + DateTime.Now.ToFileTime() + "\\"; string signedOutPutFileName = Utils.Configuration["Registrar"] + ".V" + Utils.Configuration["DBSyncVersionNo"] + "." + scope.ToString() + "." + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "T" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "Z"; if (!Directory.Exists(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp)) { Directory.CreateDirectory(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp); } signedOutputFilePath = Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".xml"; XmlTextWriter writer = null; // Saving signed xml to file using (writer = new XmlTextWriter(signedOutputFilePath, null)) { writer.Formatting = Formatting.Indented; xmlDocAll.Save(writer); } // compressing the xml file this.CreateZipFile(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".xml", Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".zip", signedOutPutFileName + ".xml"); if (scope == DbSyncScope.ALL) { this.dalcDbSync.UploadAllRegistrationsFile(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".zip", Utils.Configuration["ALLFileBlobContainer"], signedOutPutFileName + ".zip"); } else { this.dalcDbSync.UploadINCRegistrationsFile(Utils.GetOutputDirPathForConfigKey("SignedOutputFilePath") + timeStamp + signedOutPutFileName + ".zip", Utils.Configuration["INCFileBlobContainer"], signedOutPutFileName + ".zip"); } } else { // No Records found case. this.auditor.Audit(AuditId.DBSyncFileGenerated, AuditStatus.Success, 0, "File Service : No Records Found"); return("No Records Found"); } } catch { throw; } this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "End - SyncManager - GenerateRecordEnsemble scope :" + scope); return(signedOutputFilePath); }