示例#1
0
        /// <summary>
        ///Create a Header
        /// </summary>
        private void InitialiseHeader()
        {
            try
            {
                IList <ITextTypeWrapper> name = new List <ITextTypeWrapper>();
                name.Add(new TextTypeWrapperImpl(FindHeaderSetting("lang"), FindHeaderSetting("name"), null));

                IList <ITextTypeWrapper> textTypeWrapperSender = new List <ITextTypeWrapper>();
                textTypeWrapperSender.Add(new TextTypeWrapperImpl(FindHeaderSetting("lang"), FindHeaderSetting("sendername"), null));

                IContactMutableObject senderContact = new ContactMutableObjectCore();
                senderContact.AddName(new TextTypeWrapperMutableCore(FindHeaderSetting("lang"), FindHeaderSetting("sendercontactname")));
                senderContact.AddDepartment(new TextTypeWrapperMutableCore(FindHeaderSetting("lang"), FindHeaderSetting("sendercontactdepartment")));
                senderContact.AddRole(new TextTypeWrapperMutableCore(FindHeaderSetting("lang"), FindHeaderSetting("sendercontactrole")));

                if (!string.IsNullOrEmpty(FindHeaderSetting("sendercontacttelephone")))
                {
                    senderContact.AddTelephone(FindHeaderSetting("sendercontacttelephone"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("sendercontactfax")))
                {
                    senderContact.AddFax(FindHeaderSetting("sendercontactfax"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("sendercontactx400")))
                {
                    senderContact.AddX400(FindHeaderSetting("sendercontactx400"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("sendercontacturi")))
                {
                    senderContact.AddUri(FindHeaderSetting("sendercontacturi"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("sendercontactemail")))
                {
                    senderContact.AddEmail(FindHeaderSetting("sendercontactemail"));
                }

                // SENDER
                IContact         contactImmutableSender = new ContactCore(senderContact);
                IList <IContact> contactsSender         = new List <IContact>();
                contactsSender.Add(contactImmutableSender);
                IParty sender = new PartyCore(textTypeWrapperSender, FindHeaderSetting("senderid"), contactsSender, null);

                IList <ITextTypeWrapper> textTypeWrapperReceiver = new List <ITextTypeWrapper>();
                textTypeWrapperReceiver.Add(new TextTypeWrapperImpl(FindHeaderSetting("lang"), FindHeaderSetting("receivername"), null));

                IContactMutableObject receiverContact = new ContactMutableObjectCore();

                receiverContact.AddName(new TextTypeWrapperMutableCore(FindHeaderSetting("lang"), FindHeaderSetting("receivercontactname")));
                receiverContact.AddDepartment(new TextTypeWrapperMutableCore(FindHeaderSetting("lang"), FindHeaderSetting("receivercontactdepartment")));
                receiverContact.AddRole(new TextTypeWrapperMutableCore(FindHeaderSetting("lang"), FindHeaderSetting("receivercontactrole")));

                if (!string.IsNullOrEmpty(FindHeaderSetting("receivercontacttelephone")))
                {
                    receiverContact.AddTelephone(FindHeaderSetting("receivercontacttelephone"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("receivercontactfax")))
                {
                    receiverContact.AddFax(FindHeaderSetting("receivercontactfax"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("receivercontactx400")))
                {
                    receiverContact.AddX400(FindHeaderSetting("receivercontactx400"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("receivercontacturi")))
                {
                    receiverContact.AddUri(FindHeaderSetting("receivercontacturi"));
                }

                if (!string.IsNullOrEmpty(FindHeaderSetting("receivercontactemail")))
                {
                    receiverContact.AddEmail(FindHeaderSetting("receivercontactemail"));
                }

                // RECEIVER
                IContact         contactImmutableReceiver = new ContactCore(receiverContact);
                IList <IContact> contactsReceiver         = new List <IContact>();
                contactsReceiver.Add(contactImmutableReceiver);
                IParty         receiver     = new PartyCore(textTypeWrapperReceiver, FindHeaderSetting("receiverid"), contactsReceiver, null);
                IList <IParty> receiverList = new List <IParty>();
                receiverList.Add(receiver);

                IDictionary <string, string> additionalAttributes = new Dictionary <string, string>();
                additionalAttributes.Add(NameTableCache.GetElementName(ElementNameTable.KeyFamilyRef), FindHeaderSetting("keyfamilyref"));
                additionalAttributes.Add(NameTableCache.GetElementName(ElementNameTable.KeyFamilyAgency), FindHeaderSetting("keyfamilyagency"));
                additionalAttributes.Add(NameTableCache.GetElementName(ElementNameTable.DataSetAgency), FindHeaderSetting("datasetagency"));

                DateTime extracted, prepared, reportingBegin, reportingEnd;
                bool     isValid = DateTime.TryParse(FindHeaderSetting("extracted"), out extracted);
                if (!isValid)
                {
                    extracted = DateTime.Now;
                }

                isValid = DateTime.TryParse(FindHeaderSetting("reportingbegin"), out reportingBegin);
                if (!isValid)
                {
                    reportingBegin = DateTime.Now;
                }

                isValid = DateTime.TryParse(FindHeaderSetting("reportingend"), out reportingEnd);
                if (!isValid)
                {
                    reportingEnd = DateTime.Now;
                }

                isValid = DateTime.TryParse(FindHeaderSetting("prepared"), out prepared);
                if (!isValid)
                {
                    prepared = DateTime.Now;
                }

                IList <ITextTypeWrapper> source = new List <ITextTypeWrapper>();
                if (!string.IsNullOrEmpty(FindHeaderSetting("source")))
                {
                    source.Add(new TextTypeWrapperImpl(FindHeaderSetting("lang"), FindHeaderSetting("source"), null));
                }

                this._header = new HeaderImpl(
                    additionalAttributes,
                    null,
                    null,
                    DatasetAction.GetAction(FindHeaderSetting("datasetaction")),
                    FindHeaderSetting("id"),
                    FindHeaderSetting("datasetid"),
                    null,
                    extracted,
                    prepared,
                    reportingBegin,
                    reportingEnd,
                    name,
                    source,
                    receiverList,
                    sender,
                    bool.Parse(FindHeaderSetting("test")));
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.CreateHeader, ex);
            }
        }
示例#2
0
        /// <summary>
        /// This method queries the mapping store for header information for a specific dataflow
        /// </summary>
        /// <param name="beginDate">For ReportingBegin element</param>
        /// <param name="endDate">For ReportingEnd element</param>
        /// <param name="dataflowReference">The dataflow reference.</param>
        /// <returns>
        /// A <see cref="IHeader" /> object. Otherwise null
        /// </returns>
        private IHeader GetHeader(DateTime?beginDate, DateTime?endDate, IMaintainableRefObject dataflowReference)
        {
            long   headerSysId;
            string paramId  = this._mappingStoreDb.BuildParameterName(ParameterNameConstants.IdParameter);
            string version1 = this._mappingStoreDb.BuildParameterName(ParameterNameConstants.VersionParameter1);
            string version2 = this._mappingStoreDb.BuildParameterName(ParameterNameConstants.VersionParameter2);
            string version3 = this._mappingStoreDb.BuildParameterName(ParameterNameConstants.VersionParameter3);
            string agency   = this._mappingStoreDb.BuildParameterName(ParameterNameConstants.AgencyParameter);

            var sqlCommand = new StringBuilder();

            sqlCommand.Append("SELECT HD.HEADER_ID, HD.TEST, HD.DATASET_AGENCY, HD.DF_ID ");
            sqlCommand.Append("FROM HEADER HD, DATAFLOW DF, ARTEFACT ART ");
            sqlCommand.Append("WHERE HD.DF_ID = DF.DF_ID ");
            sqlCommand.Append("AND DF.DF_ID = ART.ART_ID ");
            sqlCommand.AppendFormat("AND ART.ID = {0} ", paramId);
            sqlCommand.AppendFormat("AND dbo.isEqualVersion(ART.VERSION1,ART.VERSION2,ART.VERSION3,{0},{1},{2})=1 ", version1, version2, version3);
            sqlCommand.AppendFormat("AND ART.AGENCY = {0} ", agency);

            IDictionary <string, string> additionalAttributes = new Dictionary <string, string>(StringComparer.Ordinal);
            bool     test;
            DateTime currentDate    = DateTime.Now;
            var      dataflowId     = dataflowReference.MaintainableId;
            var      dataflowAgency = dataflowReference.AgencyId;
            var      version        = dataflowReference.SplitVersion(3);

            using (DbCommand command = this._mappingStoreDb.GetSqlStringCommand(sqlCommand.ToString()))
            {
                this._mappingStoreDb.AddInParameter(command, ParameterNameConstants.IdParameter, DbType.String, dataflowId);
                this._mappingStoreDb.AddInParameter(command, ParameterNameConstants.VersionParameter1, DbType.Int64, version[0].HasValue ? version[0].Value : 0);
                this._mappingStoreDb.AddInParameter(command, ParameterNameConstants.VersionParameter2, DbType.Int64, version[1].HasValue ? version[1].Value : 0);
                this._mappingStoreDb.AddInParameter(command, ParameterNameConstants.VersionParameter3, DbType.Int64, version[2].HasValue ? (object)version[2].Value : null);
                this._mappingStoreDb.AddInParameter(command, ParameterNameConstants.AgencyParameter, DbType.String, dataflowAgency);

                using (IDataReader dataReader = this._mappingStoreDb.ExecuteReader(command))
                {
                    // we expect only 1 record here
                    if (dataReader.Read())
                    {
                        headerSysId = DataReaderHelper.GetInt64(dataReader, "HEADER_ID");
                        test        = DataReaderHelper.GetBoolean(dataReader, "TEST");
                        additionalAttributes.Add("DataSetAgency", DataReaderHelper.GetString(dataReader, "DATASET_AGENCY"));
                        _log.DebugFormat(CultureInfo.InvariantCulture, "Found header information in mapping store for Dataflow {0}", dataflowId);
                    }
                    else
                    {
                        _log.DebugFormat(CultureInfo.InvariantCulture, "No header information found in mapping store for Dataflow {0}", dataflowId);
                        return(null);
                    }
                }
            }

            string datasetId = BuildDatasetId(dataflowId, currentDate);

            // DatasetAction: Information (case that is response to a query)
            DatasetAction datasetAction = DatasetAction.GetAction("Information");

            IHeader ret = new HeaderImpl(additionalAttributes, null, null, datasetAction, dataflowId, datasetId, null, currentDate, currentDate, beginDate, endDate, null, null, null, null, test);

            PopulateHeaderLocalisedStrings(this._mappingStoreDb, headerSysId, ret);
            PoulateHeaderSendersAndReceivers(this._mappingStoreDb, headerSysId, ret);
            if (ret.Sender != null)
            {
                DateTime extracted = ret.Extracted.HasValue ? ret.Extracted.Value : currentDate;

                ret.DatasetId = BuildDatasetId(ret.Id, extracted, ret.Sender.Id);
            }

            return(ret);
        }
示例#3
0
        /// <summary>
        ///     This method initializes the log file name.
        ///     The value for this property is configured in the web.config file in the "appSettings" section
        ///     under the "logFileName" key.
        /// </summary>
        private void InitialiseHeader()
        {
            IList <ITextTypeWrapper> name = new List <ITextTypeWrapper>();

            name.Add(new TextTypeWrapperImpl(HeaderSettings.Default.lang, HeaderSettings.Default.name, null));

            IList <ITextTypeWrapper> textTypeWrapperSender = new List <ITextTypeWrapper>();

            textTypeWrapperSender.Add(new TextTypeWrapperImpl(HeaderSettings.Default.lang, HeaderSettings.Default.sendername, null));

            IContactMutableObject senderContact = new ContactMutableObjectCore();

            senderContact.AddName(new TextTypeWrapperMutableCore(HeaderSettings.Default.lang, HeaderSettings.Default.sendercontactname));
            senderContact.AddDepartment(new TextTypeWrapperMutableCore(HeaderSettings.Default.lang, HeaderSettings.Default.sendercontactdepartment));
            senderContact.AddRole(new TextTypeWrapperMutableCore(HeaderSettings.Default.lang, HeaderSettings.Default.sendercontactrole));

            if (!string.IsNullOrEmpty(HeaderSettings.Default.sendercontacttelephone))
            {
                senderContact.AddTelephone(HeaderSettings.Default.sendercontacttelephone);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.sendercontactfax))
            {
                senderContact.AddFax(HeaderSettings.Default.sendercontactfax);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.sendercontactx400))
            {
                senderContact.AddX400(HeaderSettings.Default.sendercontactx400);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.sendercontacturi))
            {
                senderContact.AddUri(HeaderSettings.Default.sendercontacturi);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.sendercontactemail))
            {
                senderContact.AddEmail(HeaderSettings.Default.sendercontactemail);
            }

            // SENDER
            IContact         contactImmutableSender = new ContactCore(senderContact);
            IList <IContact> contactsSender         = new List <IContact>();

            contactsSender.Add(contactImmutableSender);
            IParty sender = new PartyCore(textTypeWrapperSender, HeaderSettings.Default.senderid, contactsSender, null);

            IList <ITextTypeWrapper> textTypeWrapperReceiver = new List <ITextTypeWrapper>();

            textTypeWrapperReceiver.Add(new TextTypeWrapperImpl(HeaderSettings.Default.lang, HeaderSettings.Default.receivername, null));

            IContactMutableObject receiverContact = new ContactMutableObjectCore();

            receiverContact.AddName(new TextTypeWrapperMutableCore(HeaderSettings.Default.lang, HeaderSettings.Default.receivercontactname));
            receiverContact.AddDepartment(new TextTypeWrapperMutableCore(HeaderSettings.Default.lang, HeaderSettings.Default.receivercontactdepartment));
            receiverContact.AddRole(new TextTypeWrapperMutableCore(HeaderSettings.Default.lang, HeaderSettings.Default.receivercontactrole));

            if (!string.IsNullOrEmpty(HeaderSettings.Default.receivercontacttelephone))
            {
                receiverContact.AddTelephone(HeaderSettings.Default.receivercontacttelephone);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.receivercontactfax))
            {
                receiverContact.AddFax(HeaderSettings.Default.receivercontactfax);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.receivercontactx400))
            {
                receiverContact.AddX400(HeaderSettings.Default.receivercontactx400);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.receivercontacturi))
            {
                receiverContact.AddUri(HeaderSettings.Default.receivercontacturi);
            }

            if (!string.IsNullOrEmpty(HeaderSettings.Default.receivercontactemail))
            {
                receiverContact.AddEmail(HeaderSettings.Default.receivercontactemail);
            }

            // RECEIVER
            IContact         contactImmutableReceiver = new ContactCore(receiverContact);
            IList <IContact> contactsReceiver         = new List <IContact>();

            contactsReceiver.Add(contactImmutableReceiver);
            IParty         receiver     = new PartyCore(textTypeWrapperReceiver, HeaderSettings.Default.receiverid, contactsReceiver, null);
            IList <IParty> receiverList = new List <IParty>();

            receiverList.Add(receiver);

            IDictionary <string, string> additionalAttributes = new Dictionary <string, string>();

            additionalAttributes.Add(NameTableCache.GetElementName(ElementNameTable.KeyFamilyRef), HeaderSettings.Default.keyfamilyref);
            additionalAttributes.Add(NameTableCache.GetElementName(ElementNameTable.KeyFamilyAgency), HeaderSettings.Default.keyfamilyagency);
            additionalAttributes.Add(NameTableCache.GetElementName(ElementNameTable.DataSetAgency), HeaderSettings.Default.datasetagency);

            DateTime extracted, prepared, reportingBegin, reportingEnd;
            bool     isValid = DateTime.TryParse(HeaderSettings.Default.extracted, out extracted);

            if (!isValid)
            {
                extracted = DateTime.Now;
            }

            isValid = DateTime.TryParse(HeaderSettings.Default.reportingbegin, out reportingBegin);
            if (!isValid)
            {
                reportingBegin = DateTime.Now;
            }

            isValid = DateTime.TryParse(HeaderSettings.Default.reportingend, out reportingEnd);
            if (!isValid)
            {
                reportingEnd = DateTime.Now;
            }

            isValid = DateTime.TryParse(HeaderSettings.Default.prepared, out prepared);
            if (!isValid)
            {
                prepared = DateTime.Now;
            }

            IList <ITextTypeWrapper> source = new List <ITextTypeWrapper>();

            if (!string.IsNullOrEmpty(HeaderSettings.Default.source))
            {
                source.Add(new TextTypeWrapperImpl(HeaderSettings.Default.lang, HeaderSettings.Default.source, null));
            }

            this._header = new HeaderImpl(
                additionalAttributes,
                null,
                null,
                DatasetAction.GetAction(HeaderSettings.Default.datasetaction),
                HeaderSettings.Default.id,
                HeaderSettings.Default.datasetid,
                null,
                extracted,
                prepared,
                reportingBegin,
                reportingEnd,
                name,
                source,
                receiverList,
                sender,
                bool.Parse(HeaderSettings.Default.test));
        }