コード例 #1
0
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (document.IsZipFile)
                {
                    _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath);
                }
                else
                {
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                _headerDocumentHelper.Load(tempXmlFilePath);
                _organizationIdentifier = _headerDocumentHelper.GetProperty(ORG_ID_PROP_NAME);
                if (string.IsNullOrEmpty(_organizationIdentifier))
                {
                    throw new ArgumentException(string.Format("Submission document is missing a \"{0}\" property.",
                                                              ORG_ID_PROP_NAME));
                }
                string     operation;
                XmlElement xmlPayload = _headerDocumentHelper.GetFirstPayload(out operation);
                if (xmlPayload == null)
                {
                    throw new ArgumentException("Submission document is missing a payload.");
                }
                if (operation != FULL_REPLACE_OPERATION)
                {
                    if (!operation.StartsWith(YEAR_OPERATION) || (operation.Length != (YEAR_OPERATION.Length + 4)) ||
                        !int.TryParse(operation.Substring(YEAR_OPERATION.Length), out _year) || (_year < MIN_YEAR) ||
                        (_year > MAX_YEAR))
                    {
                        throw new ArgumentException(string.Format("Invalid payload operation specified: \"{0}\"", operation));
                    }
                }

                ProgramListType payloadData = _serializationHelper.Deserialize <ProgramListType>(xmlPayload);

                if (_year == 0)
                {
                    ReplaceAll(_organizationIdentifier, payloadData);
                }
                else
                {
                    ReplaceYear(_organizationIdentifier, _year, payloadData);
                }
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
コード例 #2
0
 protected void ReplaceYear(string orgId, int year, ProgramListType payloadData)
 {
     payloadData.ProgramDetails = FilterProgramDetailsListByYear(year, payloadData.ProgramDetails);
     _baseDao.TransactionTemplate.Execute(delegate
     {
         if (_baseDao.RowExistsSimple(Tables.P2R_ORG.ToString(), "ORG_ID", orgId))
         {
             AppendAuditLogEvent("Deleting all projects in database where ORG_ID = \"{0}\" and year = \"{1}\"", orgId, year);
             string query =
                 string.Format("PROJECT_DETAILS_ID IN " +
                               "(SELECT project.PROJECT_DETAILS_ID FROM P2R_PROJECT_DETAILS project, P2R_PROGRAM_DETAILS program WHERE " +
                               "program.ORG_ID = '{0}' AND project.PROGRAM_DETAILS_ID = program.PROGRAM_DETAILS_ID AND " +
                               "project.PROJECT_START_DATE >= '{1}' AND project.PROJECT_START_DATE < '{2}')",
                               orgId, new DateTime(year, 1, 1, 0, 0, 0).ToString(), new DateTime(year + 1, 1, 1, 0, 0, 0).ToString());
             _baseDao.DoSimpleDelete(Tables.P2R_PROJECT_DETAILS.ToString(), query, null);
             UpdateProgramDetails(orgId, payloadData.ProgramDetails);
         }
         else
         {
             // ORG id does not exist, this reverts to a full replace for the org
             AppendAuditLogEvent("Adding new entries in database for ORG_ID = \"{0}\" and year = \"{1}\"", orgId, year);
             _baseDao.DoInsert(Tables.P2R_ORG.ToString(), "ORG_ID", orgId);
             InsertProgramDetails(orgId, payloadData.ProgramDetails);
         }
         AppendAuditLogEvent("Finished updating database for ORG_ID = \"{0}\"", orgId);
         return(null);
     });
 }
コード例 #3
0
        protected virtual ProgramListType GetProgramListData()
        {
            ProgramListType programList = new ProgramListType();

            programList.ProgramDetails = GetProgramDetails();

            return(programList);
        }
コード例 #4
0
        public void ProcessSolicit(string requestId)
        {
            LazyInit();

            ValidateRequest(requestId);

            ValidateOrganization();

            ProgramListType data = GetProgramListData();

            GenerateSubmissionFileAndAddToTransaction(data);
        }
コード例 #5
0
 protected void ReplaceAll(string orgId, ProgramListType payloadData)
 {
     _baseDao.TransactionTemplate.Execute(delegate
     {
         AppendAuditLogEvent("Deleting all entries in database where ORG_ID = \"{0}\"", orgId);
         _baseDao.DoSimpleDelete(Tables.P2R_ORG.ToString(), "ORG_ID", new object[] { orgId });
         AppendAuditLogEvent("Adding new entries in database for ORG_ID = \"{0}\"", orgId);
         _baseDao.DoInsert(Tables.P2R_ORG.ToString(), "ORG_ID", orgId);
         InsertProgramDetails(orgId, payloadData.ProgramDetails);
         AppendAuditLogEvent("Finished updating database for ORG_ID = \"{0}\"", orgId);
         return(null);
     });
 }
コード例 #6
0
        protected virtual void GenerateSubmissionFileAndAddToTransaction(ProgramListType data)
        {
            string submitFile = GenerateSubmissionFile(_year, data);

            try
            {
                try
                {
                    _documentManager.AddDocument(_dataRequest.TransactionId, CommonTransactionStatusCode.Completed,
                                                 null, submitFile);
                }
                catch (Exception e)
                {
                    AppendAuditLogEvent("Failed to attach submission document \"{0}\" to transaction \"{1}\" with exception: {2}",
                                        submitFile, _dataRequest.TransactionId, ExceptionUtils.ToShortString(e));
                    throw;
                }
            }
            finally
            {
                FileUtils.SafeDeleteFile(submitFile);
            }
        }
コード例 #7
0
        protected virtual string GenerateSubmissionFile(int year, ProgramListType data)
        {
            AppendAuditLogEvent("Generating submission file from results");

            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            tempXmlFilePath = Path.ChangeExtension(tempXmlFilePath, ".xml");
            string tempXmlFilePath2 = _settingsProvider.NewTempFilePath();

            tempXmlFilePath2 = Path.ChangeExtension(tempXmlFilePath, ".xml");

            string tempZipFilePath = _settingsProvider.NewTempFilePath();

            tempZipFilePath = Path.ChangeExtension(tempZipFilePath, ".zip");

            try
            {
                _serializationHelper.Serialize(data, tempXmlFilePath);

                if (_addHeader)
                {
                    // Configure the submission header helper
                    _headerDocumentHelper.Configure(ValidateNonEmptyConfigParameter(CONFIG_AUTHOR),
                                                    ValidateNonEmptyConfigParameter(CONFIG_ORGANIZATION),
                                                    P2R_FLOW_NAME, null,
                                                    ValidateNonEmptyConfigParameter(CONFIG_CONTACT_INFO),
                                                    null);
                    _headerDocumentHelper.AddPropery(ORG_ID_PROP_NAME, _organizationIdentifier);

                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempXmlFilePath);

                    string operation;
                    if (year == 0)
                    {
                        operation = FULL_REPLACE_OPERATION;
                    }
                    else
                    {
                        operation = YEAR_OPERATION + year.ToString();
                    }
                    _headerDocumentHelper.AddPayload(operation, doc.DocumentElement);

                    _headerDocumentHelper.Serialize(tempXmlFilePath2);

                    _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath);
                }
                else
                {
                    _compressionHelper.CompressFile(tempXmlFilePath, tempZipFilePath);
                }
                return(tempZipFilePath);
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
                FileUtils.SafeDeleteFile(tempXmlFilePath2);
            }
        }