Exemplo n.º 1
0
        /// <summary>
        /// Generate the XML file of Registrations
        /// </summary>
        /// <param name="scope">Scope of the registration (All/Increment)</param>
        /// <param name="requestedTransactionId">Next Transaction ID</param>
        ///  <param name="requester"> DB Sync requester component</param>
        /// <returns>Xml Document</returns>
        private XmlDocument BuildRecordEnsumble(DbSyncScope scope, NextTransactionID requestedTransactionId, string requester)
        {
            FixedTVBDRegistration[]     fixedTVBDRegistrations     = null;
            LPAuxRegistration[]         lpauxRegistrations         = null;
            MVPDRegistration[]          mvpdRegistrations          = null;
            TempBASRegistration[]       tempBasRegistrations       = null;
            TVReceiveSiteRegistration[] tvreceiveSiteRegistrations = null;
            string wsdbaNameForFile   = Utils.Configuration[Constants.ConfigSettingWSDBAName];
            string generationDateTime = null;
            string recordsFrom        = null;
            string recordsTo          = null;

            DateTime dt = DateTime.Now;

            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager BuildRecordEnsumble() Retrieving data Scope:" + scope + ", RequestedTransactionID:" + requestedTransactionId);
            if (scope == DbSyncScope.ALL)
            {
                // All File
                this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager get all registrations from Azure table");
                fixedTVBDRegistrations     = this.dalcDbSync.GetFixedTVBDRegistration(wsdbaNameForFile, null);
                mvpdRegistrations          = this.dalcDbSync.GetMVPDRegistration(wsdbaNameForFile, null);
                lpauxRegistrations         = this.dalcDbSync.GetLPAuxRegistration(wsdbaNameForFile, null);
                tempBasRegistrations       = this.dalcDbSync.GetTempBASRegistration(wsdbaNameForFile, null);
                tvreceiveSiteRegistrations = this.dalcDbSync.GetTVReceiveSiteRegistration(wsdbaNameForFile, null);
            }
            else
            {
                if (requestedTransactionId != null)
                {
                    this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager get Incrimental registrations from Azure table");
                    recordsFrom = this.BuildDateZ(requestedTransactionId.NextTransactionIdDateTime);
                    DateTime dtfrom = Convert.ToDateTime(requestedTransactionId.NextTransactionIdDateTime);
                    fixedTVBDRegistrations     = this.dalcDbSync.GetFixedTVBDRegistration(wsdbaNameForFile, dtfrom, dt);
                    mvpdRegistrations          = this.dalcDbSync.GetMVPDRegistration(wsdbaNameForFile, dtfrom, dt);
                    lpauxRegistrations         = this.dalcDbSync.GetLPAuxRegistration(wsdbaNameForFile, dtfrom, dt);
                    tempBasRegistrations       = this.dalcDbSync.GetTempBASRegistration(wsdbaNameForFile, dtfrom, dt);
                    tvreceiveSiteRegistrations = this.dalcDbSync.GetTVReceiveSiteRegistration(wsdbaNameForFile, dtfrom, dt);
                }
            }

            NextTransactionID nextTransactionId = new NextTransactionID();

            //// updating existing transactionid for file incemental update when called from Incremental File
            if ((scope == DbSyncScope.INC) && (requester == wsdbaNameForFile))
            {
                nextTransactionId = requestedTransactionId;
                requestedTransactionId.Timestamp                 = dt;
                requestedTransactionId.NextTransactionId         = Guid.NewGuid().ToString();
                requestedTransactionId.NextTransactionIdDateTime = dt;
                this.dalcDbSync.SaveNextTransactionIdInfo(nextTransactionId);
            }
            else
            {
                ////  create new transaction ID remaining cases like File All, Incremental Web Service.
                nextTransactionId.PartitionKey              = scope.ToString();
                nextTransactionId.RowKey                    = Guid.NewGuid().ToString();
                nextTransactionId.Timestamp                 = dt;
                nextTransactionId.NextTransactionId         = Guid.NewGuid().ToString();
                nextTransactionId.NextTransactionIdDateTime = dt;

                if (requester == wsdbaNameForFile)
                {
                    nextTransactionId.WSDBA = wsdbaNameForFile;
                }
                else
                {
                    nextTransactionId.WSDBA = string.Empty;
                }

                this.dalcDbSync.SaveNextTransactionIdInfo(nextTransactionId);
            }

            // ToDo: save value to azure table.
            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager:BuildRecordEnsumble generating XML file.");

            // loading out bound XML template
            XmlDocument xmlDocTemplate = new XmlDocument();

            xmlDocTemplate.Load(Utils.GetFilePathForConfigKey("OutBoundXMLTemplate"));

            // Actual File to be generated with default root node
            XmlDocument xmlDocAll = new XmlDocument();

            xmlDocAll.Load(Utils.GetFilePathForConfigKey("RegistrationRecordEnsembleFile"));

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDocTemplate.NameTable);

            namespaceManager.AddNamespace("vcard", Constants.VCardXmlns);
            namespaceManager.AddNamespace("ical", Constants.ICalXmlns);
            namespaceManager.AddNamespace("gml", Constants.GMLXmlns);
            namespaceManager.AddNamespace("ren", xmlDocTemplate.DocumentElement.NamespaceURI);
            generationDateTime = this.BuildDateZ(DateTime.Now);

            if (scope == DbSyncScope.ALL)
            {
                recordsFrom = Utils.Configuration["RegistrationsStartDate"];
            }

            recordsTo = generationDateTime;

            // setting the Ensemble details
            XmlNode node = xmlDocAll.SelectSingleNode("//ren:EnsembleDescription", namespaceManager);

            node.SelectSingleNode("//ren:Registrar", namespaceManager).InnerText      = Utils.Configuration["Registrar"];
            node.SelectSingleNode("//ren:GenerationDate", namespaceManager).InnerText = generationDateTime;
            node.SelectSingleNode("//ren:Scope", namespaceManager).InnerText          = scope.ToString();
            node.SelectSingleNode("//ren:RecordsFrom", namespaceManager).InnerText    = recordsFrom;
            node.SelectSingleNode("//ren:RecordsTo", namespaceManager).InnerText      = recordsTo;

            // fixed tvbd registrations
            XmlNode xnode = null;

            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager:BuildRecordEnsumble add Fixed_TVBD registration information to XML file.");
            for (int index = 0; index < fixedTVBDRegistrations.Length; index++)
            {
                this.registrationExist = true;
                node = xmlDocTemplate.SelectSingleNode("//ren:Registration[ren:registrationType='Fixed_TVBD_Registration']", namespaceManager).CloneNode(true);
                RegistrationXmlNodeBuilder.BuildFixedTVBDRegistrationXmlNode(node, fixedTVBDRegistrations[index], namespaceManager);
                xnode          = xmlDocAll.CreateNode(XmlNodeType.Element, "n1:Registration", xmlDocAll.DocumentElement.NamespaceURI);
                xnode.InnerXml = node.InnerXml;
                xmlDocAll.DocumentElement.AppendChild(xnode);
            }

            // LPAux registrations
            xnode = null;
            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager:BuildRecordEnsumble add LP-Aux registration information to XML file.");
            for (int index = 0; index < lpauxRegistrations.Length; index++)
            {
                this.registrationExist = true;
                node = xmlDocTemplate.SelectSingleNode("//ren:Registration[ren:registrationType='LP-Aux_Registration']", namespaceManager).CloneNode(true);
                RegistrationXmlNodeBuilder.BuildLPAUXRegistrationXmlNode(node, lpauxRegistrations[index], namespaceManager);
                xnode          = xmlDocAll.CreateNode(XmlNodeType.Element, "n1:Registration", xmlDocAll.DocumentElement.NamespaceURI);
                xnode.InnerXml = node.InnerXml;
                xmlDocAll.DocumentElement.AppendChild(xnode);
            }

            // MVPD registrations
            xnode = null;
            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager:BuildRecordEnsumble add MVPD registration information to XML file.");
            for (int index = 0; index < mvpdRegistrations.Length; index++)
            {
                this.registrationExist = true;
                node = xmlDocTemplate.SelectSingleNode("//ren:Registration[ren:registrationType='MVPD_Registration']", namespaceManager).CloneNode(true);
                RegistrationXmlNodeBuilder.BuildMVPDRegistrationXmlNode(node, mvpdRegistrations[index], namespaceManager);
                xnode          = xmlDocAll.CreateNode(XmlNodeType.Element, "n1:Registration", xmlDocAll.DocumentElement.NamespaceURI);
                xnode.InnerXml = node.InnerXml;
                xmlDocAll.DocumentElement.AppendChild(xnode);
            }

            // Temp Bas registrations
            xnode = null;
            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager:BuildRecordEnsumble add Temp_BAS registration information to XML file.");
            for (int index = 0; index < tempBasRegistrations.Length; index++)
            {
                this.registrationExist = true;
                node = xmlDocTemplate.SelectSingleNode("//ren:Registration[ren:registrationType='Temp_BAS_Registration']", namespaceManager).CloneNode(true);
                RegistrationXmlNodeBuilder.BuildTBasRegistrationXmlNode(node, tempBasRegistrations[index], namespaceManager);
                xnode          = xmlDocAll.CreateNode(XmlNodeType.Element, "n1:Registration", xmlDocAll.DocumentElement.NamespaceURI);
                xnode.InnerXml = node.InnerXml;
                xmlDocAll.DocumentElement.AppendChild(xnode);
            }

            // TV Receive Site registrations
            xnode = null;
            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", Begin - dbSyncManager:BuildRecordEnsumble add TV_Receive_Site registration information to XML file.");
            for (int index = 0; index < tvreceiveSiteRegistrations.Length; index++)
            {
                this.registrationExist = true;
                node = xmlDocTemplate.SelectSingleNode("//ren:Registration[ren:registrationType='TV_Receive_Site_Registration']", namespaceManager).CloneNode(true);
                RegistrationXmlNodeBuilder.BuildTVReceiveSiteRegistrationXmlNode(node, tvreceiveSiteRegistrations[index], namespaceManager);
                xnode          = xmlDocAll.CreateNode(XmlNodeType.Element, "n1:Registration", xmlDocAll.DocumentElement.NamespaceURI);
                xnode.InnerXml = node.InnerXml;
                xmlDocAll.DocumentElement.AppendChild(xnode);
            }

            xnode          = xmlDocAll.CreateNode(XmlNodeType.Element, "n1:NextTransactionID", xmlDocAll.DocumentElement.NamespaceURI);
            xnode.InnerXml = nextTransactionId.NextTransactionId;
            xmlDocAll.DocumentElement.AppendChild(xnode);
            this.logger.Log(TraceEventType.Information, LoggingMessageId.DBSyncPollerGenericMessage, "WSDBA:" + wsdbaNameForFile + ", End - dbSyncManager BuildRecordEnsumble()");

            return(xmlDocAll);
        }
Exemplo n.º 2
0
        /// <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);
        }