SPLogTransportLayer CLogTransportFactory::GetTransportLayer(const tstring& name, CNetworkLog& netLog, tstring& errorString)
{
	HRESULT hResult = S_OK;
	try
	{
		errorString.clear();
		IComUDPListenerPtr comUDPListener; 
		hResult = comUDPListener.CreateInstance(__uuidof(CComUDPListener), 0, CLSCTX_LOCAL_SERVER);
		if ( S_OK == hResult )
		{
			comUDPListener->AddWatch(GetCurrentProcessId());
			return SPLogTransportLayer(new CLocalNetworkComLogTransport(comUDPListener, name, netLog));
		}
		else
		{
			return SPLogTransportLayer(new CLocalNetworkLogTransport(name, netLog));
		}
	}
	catch(CExceptionBase &e)
	{
		errorString = Format(_T("\nComError:\n%d\nSockError:\n%s"),hResult, e.m_strWhat.c_str());
		return SPLogTransportLayer();
	}
	catch(...)
	{
		errorString = Format(_T("\nComError:\n%d\nSockError:\n%s"),hResult, _T("Unkwnown exception"));
		return SPLogTransportLayer();
	}
}
Beispiel #2
0
void PathX::GetExtension(const tstring& path, tstring& outExtension)
{
	tstring::size_type pos = path.find_last_of(extension);
	if (pos == tstring::size_type(-1))
	{
		outExtension.clear();
		return;
	}
	else if(pos == tstring::size_type(path.length()-1))
	{
		outExtension.clear();
		return;
	}
	else
	{
		outExtension = path.substr(pos+1, path.length());
		return;
	}
}
Beispiel #3
0
void onEndTestCase()
{
	ASSERT(!s_currentTestCase.empty());

	if (s_teardown != nullptr)
	{
		try
		{
			s_teardown();
		}
		catch(const Core::Exception& e)
		{
			processSetupTeardownException(TXT("TearDown"), e.twhat());
		}
		catch (...)
		{
			processSetupTeardownException(TXT("TearDown"), TXT("UNKNOWN"));
		}
	}

	s_executed.push_back(s_currentTestCase);

	// Update statistics.
	if (s_currentResult == SUCCEEDED)
	{
		++s_numPassed;

		if (!s_verbose)
			tcout << TXT(".");
	}
	else if (s_currentResult == FAILED)
	{
		++s_numFailed;

		s_failures.push_back(s_currentTestCase);
		s_failuresAsserts.push_back(s_currentTestCaseAsserts);

		if (!s_verbose)
			tcout << TXT("F");
	}
	else
	{
		ASSERT_FALSE();
		ASSERT(s_currentResult == UNKNOWN);

		++s_numUnknown;

		if (!s_verbose)
			tcout << TXT("?");
	}

	s_currentResult = UNKNOWN;
	s_currentTestCase.clear();
	s_currentTestCaseAsserts.clear();
}
const tstring& CDBTableInfoRecord::GetField(unsigned int idx) const
{
	static tstring str;

	if(!TblPtr)
	{
		_ASSERT(false);
		str.clear();
		return str;
	}

	switch (idx)
	{
	case Name:
		return TblPtr->GetName();
		break;
	case DBName:
		return TblPtr->GetDBName();
		break;
	case Buildin:
		str = TblPtr->GetSchema().IsBuildin() ? TEXT("1") : TEXT("0");
		return str;
		break;
	case DBExist:
		str = TblPtr->GetSchema().IsDBExist() ? TEXT("1") : TEXT("0");
		return str;
		break;
	case State:
		str = IsStateNormal() ? TEXT("") : TEXT("!");
		break;
	default:
		_ASSERT(false);
		str.clear();
		return str;
		break;
	}

	return str;
}
Beispiel #5
0
bool Control::ReadStringData(tstring& str) const
{
    StringDataBinding* data = CastDataBinding<StringDataBinding, DataBindingTypes::String>( m_DataBinding );
    if (data)
    {
        str.clear();
        data->Get( str );
        return true;
    }

    HELIUM_BREAK(); // you should not call this, your control is using custom data
    return false;
}
Beispiel #6
0
void PathX::GetDirectory(const tstring& path, tstring& outDirectory)
{
	tstring::size_type pos = path.find_last_of(separator);
	if (pos == tstring::size_type(-1))
	{
		outDirectory.clear();
		return;
	}
	else
	{
		outDirectory = path.substr(0, pos);
		return;
	}
}
Beispiel #7
0
    void set_text(const TCHAR *_text) {
        assert_none_locked();
        assert_thread();

#ifndef USE_GDI
        if (_text != NULL)
            text = _text;
        else
            text.clear();
        invalidate();
#else /* USE_GDI */
        ::SetWindowText(hWnd, _text);
#endif /* USE_GDI */
    }
Beispiel #8
0
  void set_text(const TCHAR *_text) {
    AssertNoneLocked();
    AssertThread();

#ifndef USE_GDI
    if (_text != nullptr)
      text = _text;
    else
      text.clear();
    Invalidate();
#else /* USE_GDI */
    ::SetWindowText(hWnd, _text);
#endif /* USE_GDI */
  }
Beispiel #9
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// распарсить путь в котором указана переменная среды
// возможные варианты: "VarName", "%VarName", "%VarName%", "%VarName%LocalPath", "VarName%"
// возвращает true, если название VarName задано не точно (варианты 1, 2)
bool nf::Parser::ParseEnvVarPath(tstring const& Src
								 , tstring& VarName
								 , tstring& LocalPath)
{
	LocalPath.clear();
	tsmatch what;
	if (! boost::regex_search(Src, what, tregex(re::RE_EV))) 
	{
		VarName = Src;
		return false;
	}
	VarName = what[1];
	LocalPath = what[3];
	return ! tstring(what[2]).empty();
}
Beispiel #10
0
void CmdDlg::prettify(tstring &text)
{
	try {
		const tstring search(_T("\n")), replace(_T("\r\n"));

		// http://stackoverflow.com/a/14678800/98528
		tstring::size_type pos = 0;
		while ((pos = text.find(search, pos)) != tstring::npos) {
			text.replace(pos, search.length(), replace);
			pos += replace.length();
		}
		text += replace;
	} catch (...) {
		text.clear();
	}
}
Beispiel #11
0
void PathX::GetFileName(const tstring& path, tstring& outFileName)
{
	tstring::size_type pos = path.find_last_of(separator);
	if (pos == tstring::size_type(-1))
	{
		outFileName = path;
		return;
	}
	else if(pos == tstring::size_type(path.length()-1))
	{
		outFileName.clear();
		return;
	}
	else
	{
		outFileName = path.substr(pos+1, path.length());
		return;
	}
}
Beispiel #12
0
void onEndTestSet()
{
	ASSERT(s_currentTestCase.empty());
	ASSERT(s_currentTestCaseAsserts.empty());

	if (!s_quiet && !s_verbose)
	{
		tcout << std::endl;
	}

	if (!s_failures.empty())
	{
		const tstring failureCount = (s_quiet) ? Core::fmt(TXT(" %s: %u failure(s)"), s_currentTestSet.c_str(), s_failures.size())
											   : Core::fmt(TXT(" %u failure(s)"), s_failures.size());

		tcout << std::endl;
		tcout << failureCount << std::endl;

		for (size_t i = 0; i != s_failures.size(); ++i)
		{
			debugWrite(TXT(" > %s\n"), s_failures[i].c_str());
			tcout << TXT(" > ") << s_failures[i] << std::endl;

			for (size_t j = 0; j != s_failuresAsserts[i].size(); ++j)
			{
				debugWrite(TXT("  %s\n"), s_failuresAsserts[i][j].c_str());
				tcout << TXT("  ") << s_failuresAsserts[i][j] << std::endl;
			}
		}
	}

	if (!s_quiet)
	{
		tcout << std::endl;
	}

	s_currentTestSet.clear();
	s_failures.clear();
	s_failuresAsserts.clear();
	s_executed.clear();
	s_setup = nullptr;
	s_teardown = nullptr;
}
Beispiel #13
0
BOOL CSocketObj::GetLocalAddr(tstring &Address, WORD &Port)
{
	SOCKADDR_STORAGE name;
	int namelen;
	char addrbuf[NI_MAXHOST];
	char portbuf[NI_MAXSERV];

	Address.clear();
	Port = 0;

	namelen = sizeof(name);
	if (getsockname(mSock, (PSOCKADDR)&name, &namelen) == 0) {
		if (getnameinfo((PSOCKADDR)&name, namelen, addrbuf, NI_MAXHOST, portbuf, NI_MAXSERV, NI_NUMERICHOST || NI_NUMERICSERV) == 0) {
			Address = string_to_tstring(string(addrbuf));
			Port = stoi(portbuf);
		}
		return TRUE;
	}
	return FALSE;
}
Beispiel #14
0
void PathX::GetFileNameNoExtension(const tstring& path, tstring& outFileName)
{
	tstring fileName;
	GetFileName(path, fileName);
	tstring::size_type pos = fileName.find_last_of(extension);
	if (pos == tstring::size_type(-1))
	{
		outFileName = path;
		return;
	}
	else if(pos == tstring::size_type(0))
	{
		outFileName.clear();
		return;
	}
	else
	{
		outFileName = fileName.substr(0, pos);
		return;
	}
}
const tstring& CDBColumnInfoRecord::GetField(unsigned int idx) const
{
	static tstring str;

	if(!ColPtr)
	{
		_ASSERT(false);
		str.clear();
		return str;
	}

	switch (idx)
	{
	case Name:
		return ColPtr->Name;
		break;
	case DBName:
		return ColPtr->DBName;
		break;
	case Buildin:
		str = ColPtr->IsBuildin() ? TEXT("1") : TEXT("0");
		return str;
		break;
	case DBExist:
		str = ColPtr->IsDBExist() ? TEXT("1") : TEXT("0");
		return str;
		break;
	case KeyCol:
		str = ColPtr->IsKeyColumn() ? TEXT("1") : TEXT("0");
		return str;
		break;
	case DBPK:
		str = ColPtr->IsDBPrimaryKey() ? TEXT("1") : TEXT("0");
		return str;
		break;
	case DBUnnull:
		str = ColPtr->IsDBUnnull() ? TEXT("1") : TEXT("0");
		return str;
		break;
	case Type:
		str = EnumEntityOfCppDataType()[ColPtr->Type].ValueStr; // str.clear(); //
		return str;
		break;
	case DBType:
		str = ColPtr->DBType->ToString();
		return str;
		break;
	case State:
		str = IsStateNormal() ? TEXT("") : TEXT("!");
		break;
	case RelyTbl:
		str = boost::lexical_cast<tstring>(ColPtr->RelyTblID);
		break;
	case RelyCol:
		str = boost::lexical_cast<tstring>(ColPtr->RelyColID);
		break;
	case VisiCol:
		str = boost::lexical_cast<tstring>(ColPtr->VisiColID);
		break;
	case Index:
		str = boost::lexical_cast<tstring>(ColPtr->Index);
		break; 
	default:
		_ASSERT(false);
		str.clear();
		return str;
		break;
	}

	return str;
}
Beispiel #16
0
/// Get the symbol for the specified address.
///
/// @param[out] rSymbol   Address symbol.
/// @param[in]  pAddress  Address to translate.
///
/// @return  True if the address was successfully resolved, false if not.
void Helium::GetAddressSymbol( tstring& rSymbol, void* pAddress )
{
    HELIUM_ASSERT( pAddress );

    MutexScopeLock scopeLock( GetStackWalkMutex() );
    ConditionalSymInitialize();

//    rSymbol.Remove( 0, rSymbol.GetSize() );
    rSymbol.clear();

    HANDLE hProcess = GetCurrentProcess();
    HELIUM_ASSERT( hProcess );

    bool bAddedModuleName = false;

    DWORD64 moduleBase = SymGetModuleBase64( hProcess, reinterpret_cast< uintptr_t >( pAddress ) );
    if( moduleBase )
    {
        IMAGEHLP_MODULE64 moduleInfo;
        MemoryZero( &moduleInfo, sizeof( moduleInfo ) );
        moduleInfo.SizeOfStruct = sizeof( moduleInfo );
        if( SymGetModuleInfo64( hProcess, moduleBase, &moduleInfo ) )
        {
            rSymbol += TXT( "(" );
            rSymbol += moduleInfo.ModuleName;
            rSymbol += TXT( ") " );

            bAddedModuleName = true;
        }
    }

    if( !bAddedModuleName )
    {
        rSymbol += TXT( "(???) " );
    }

    uint64_t symbolInfoBuffer[
        ( sizeof( SYMBOL_INFO ) + sizeof( tchar_t ) * ( MAX_SYM_NAME - 1 ) + sizeof( uint64_t ) - 1 ) /
        sizeof( uint64_t ) ];
    MemoryZero( symbolInfoBuffer, sizeof( symbolInfoBuffer ) );

    SYMBOL_INFO& rSymbolInfo = *reinterpret_cast< SYMBOL_INFO* >( &symbolInfoBuffer[ 0 ] );
    rSymbolInfo.SizeOfStruct = sizeof( SYMBOL_INFO );
    rSymbolInfo.MaxNameLen = MAX_SYM_NAME;
    if( SymFromAddr( hProcess, reinterpret_cast< uintptr_t >( pAddress ), NULL, &rSymbolInfo ) )
    {
        rSymbolInfo.Name[ MAX_SYM_NAME - 1 ] = TXT( '\0' );
        rSymbol += rSymbolInfo.Name;
        rSymbol += TXT( " " );
    }
    else
    {
        rSymbol += TXT( "??? " );
    }

    DWORD displacement = 0;
    IMAGEHLP_LINE64 lineInfo;
    MemoryZero( &lineInfo, sizeof( lineInfo ) );
    lineInfo.SizeOfStruct = sizeof( lineInfo );
    if( SymGetLineFromAddr64( hProcess, reinterpret_cast< uintptr_t >( pAddress ), &displacement, &lineInfo ) )
    {
        tchar_t lineNumberBuffer[ 32 ];
        StringFormat( lineNumberBuffer, HELIUM_ARRAY_COUNT( lineNumberBuffer ), TXT( "%u" ), lineInfo.LineNumber );
        lineNumberBuffer[ HELIUM_ARRAY_COUNT( lineNumberBuffer ) - 1 ] = TXT( '\0' );

        rSymbol += TXT( "(" );
        rSymbol += lineInfo.FileName;
        rSymbol += TXT( ", line " );
        rSymbol += lineNumberBuffer;
        rSymbol += TXT( ")" );
    }
    else
    {
        rSymbol += TXT( "(???, line ?)" );
    }
}