Ejemplo n.º 1
0
void AOSOutputExecutor::execute(AOSContext& context)
{
  AString command;
  if (
    context.useRequestParameterPairs().exists(OVERRIDE_OUTPUT)
    && m_Services.useConfiguration().isOutputOverrideAllowed()
  )
  {
    //a_Override requested and allowed
    context.useRequestParameterPairs().get(OVERRIDE_OUTPUT, command);
  }
  else
  {
    command = context.getOutputCommand();
    if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
    {
      ARope rope("Default output generator overridden to: ",40);
      rope.append(command);
      context.useEventVisitor().startEvent(rope, AEventVisitor::EL_DEBUG);
    }
  }

  if (command.equals("NOP"))
  {
    //a_If NOP was used force XML
    m_Services.useConfiguration().setMimeTypeFromExt(ASW("xml",3), context);
    if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
      context.useEventVisitor().startEvent(ASWNL("NOP detected, defaulting to XML output"), AEventVisitor::EL_DEBUG);
  }

  if (command.isEmpty())
  {
    if (!m_Services.useConfiguration().getAosDefaultOutputGenerator().isEmpty())
    {
      command.assign(m_Services.useConfiguration().getAosDefaultOutputGenerator());
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
      {
        ARope rope("No output generator specified, defaulting to: ",46);
        rope.append(command);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_DEBUG);
      }
    }
    else
    {
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
        context.useEventVisitor().startEvent(ASW("No output generator, defaulting to XML",38), AEventVisitor::EL_DEBUG);
      return;
    }
  }

  try
  {
    //a_Find input command, if not found execute the default
    OutputGeneratorContainer::iterator it = m_OutputGenerators.find(command);
    if (it == m_OutputGenerators.end())
    {
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_WARN))
      {
        ARope rope("Skipping unknown output generator: ",35);
        rope.append(command);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_WARN);
      }
    }
    else
    {
      ATimer timer(true);

      //a_Generate output
      if (context.useEventVisitor().isLogging(AEventVisitor::EL_INFO))
      {
        ARope rope("Generating output: ",19);
        rope.append((*it).first);
        context.useEventVisitor().startEvent(rope, AEventVisitor::EL_INFO);
      }

      if (context.useContextFlags().isClear(AOSContext::CTXFLAG_IS_AJAX))
      {
        context.useModel().overwriteElement(ASW("execute/output", 14)).addData(command);

        //a_Publish timers
        context.getRequestTimer().emitXml(context.useModel().overwriteElement(ASW("request_time",12)));
        context.getContextTimer().emitXml(context.useModel().overwriteElement(ASW("context_time",12)));
      }

      //a_Generate output
      AOSContext::ReturnCode ret = (*it).second->execute(context);
      switch (ret)
      {
        case AOSContext::RETURN_OK:
        break;

        case AOSContext::RETURN_REDIRECT:
          if (context.useEventVisitor().isLogging(AEventVisitor::EL_INFO))
          {
            context.useEventVisitor().startEvent(ASWNL("Output generator has done a redirect"), AEventVisitor::EL_DEBUG);
          }
        break;
      
        default:
          context.addError((*it).second->getClass(), ASWNL("Output generator returned neither OK nor REDIRECT"));
        return;
      }

      //a_Event over
      context.useEventVisitor().endEvent();

      //a_Add execution time
      (*it).second->addExecutionTimeSample(timer.getInterval());
    }
  }
  catch(AException& ex)
  {
    AString strWhere("AOSOutputExecutor::execute(", 27);
    strWhere.append(command);
    strWhere.append(')');
    context.addError(strWhere, ex.what());

    AXmlElement& element = context.useModel().addElement("output_error");
    element.addElement("where", strWhere);
    element.addElement("exception", ex);
  }
  catch(...)
  {
    AString strWhere("AOSOutputExecutor::execute(", 27);
    strWhere.append(command);
    strWhere.append(')');
    context.addError(strWhere, ASWNL("Unknown Exception"));

    context.useModel().addElement("output_error").addData("Unknown Exception");
  }
}
Ejemplo n.º 2
0
//	リストア処理実行ボタン
void CBackupDialog::OnBtnRestore() 
{
	UpdateData(TRUE);	// DDX更新

	CString str;
	CFileFind finder;

	// リストアデータフォルダ
	BOOL blFind = FALSE;
	CString strFolder;
	m_edtRestorePath.GetWindowText(strFolder);
	if (strFolder.IsEmpty()) return;
	CFileSpec fs(strFolder);
	if (fs.Exist()) {
		if (fs.GetFileName() == _T("tapur.backup")) {
			blFind = TRUE;
		} else {
			fs.SetFullSpec(strFolder + _T("\\tapur.backup"));
			if (fs.Exist()) {
				strFolder += _T("\\tapur.backup");
				blFind = TRUE;
			}
		}
	}
	if (!blFind) {
		str.LoadString(IDS_MSGBOX913);
		AfxMessageBox(str, MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
		return;
	}

	str.LoadString(IDS_MSGBOX912);
	if (AfxMessageBox(str, MB_YESNO | MB_APPLMODAL | MB_ICONQUESTION ) != IDYES) return;

	// リストア処理
	CFileSpec fs_out(theApp.m_strDataFolder);	// user data folder
	CString strOrgFolder = fs_out.GetFolder();	// data folder
	fs_out.SetFullSpec(strOrgFolder);
	if (fs_out.Exist()) {
		if (!fs_out.FileDelete(TRUE, this->m_hWnd)) goto PROC_CANCEL;
	}
	if (!fs.FileCopy(strOrgFolder, TRUE, TRUE, this->m_hWnd)) goto PROC_CANCEL;

	// データベースの書き換え
	BOOL bWorking = finder.FindFile(strOrgFolder + _T("\\*"));
	while (bWorking)
	{
		bWorking = finder.FindNextFile();
		if (!finder.IsDirectory()) continue;
		str = finder.GetFileName();
		if (str == _T(".") || str == _T("..")) continue;

		CString strTbl = finder.GetFilePath() + _T("\\") + _T(DBFILE_NAME);
		CTblRdfl tbl(strTbl);
		CString strWhere(_T("lngSystemFlag>=0"));
		long lngCnt = tbl.CountRec(strWhere);	// all
		if (lngCnt == 0) continue;

		CString strSet = _T("strRemarks1='") + finder.GetFilePath() + _T("'");
		if (!tbl.UpdateRec(strSet, strWhere)) goto PROC_CANCEL;
	} 

	str.LoadString(IDS_MSGBOX918);
	AfxMessageBox(str, MB_OK | MB_APPLMODAL | MB_ICONINFORMATION);
	return;
PROC_CANCEL:
	str.LoadString(IDS_MSGBOX920);
	AfxMessageBox(str, MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
}