예제 #1
0
bool CEOSSDbAccess::OpenTheDatabase(short sFacNum, CString* pstrErrorMsg,const CString& csFacDir)
{
	CString strFacilityDirectory = csFacDir;// ((BSTR) g_pIFacMgr->GetFacilityDirectory(sFacNum));
	mstrDatabaseRootPath = csFacDir;/*strFacilityDirectory;*/
	strFacilityDirectory = m_Dir.AppendPath(strFacilityDirectory, mstrComponentName);
	msFacNum = sFacNum;

	BOOL bStatus = false;
	CString strErrorMsg;
	
	//If the datastore doesn't exist, create it and try again. 
	if (!m_Dir.FileExists (strFacilityDirectory, mstrDatabaseName)) {
		//Create the data store if it doesn't exist.
		if (!CreateDataStore (sFacNum))
		{
			//We still didn't create the datastore.
			bStatus = false;
			strErrorMsg.Format("Database could not be created at %s.", strFacilityDirectory);
			MessageBox(NULL, strErrorMsg, "Database Creation Error", MB_OK|MB_ICONWARNING);
			pstrErrorMsg->Format("%s", strErrorMsg);
		}
		else
		{
			bStatus = true;
		}
	}

	return(OpenDatabase(strFacilityDirectory, mstrDatabaseName));
	return true;
}
예제 #2
0
void MgdCreateFileFeatureSource::CreateFeatureSource(bool bCheckFeatureClass, bool bCheckSpatialContext)
{
    MG_FEATURE_SERVICE_TRY()

    //Some basic schema validation:
    //  A schema must be supplied
    //  The schema must define at least one class
    //  Each class must have an identity property
    //  A coordinate system must be defined
    //
    Ptr<MgFeatureSchema> schema = m_params->GetFeatureSchema();
    if(schema == NULL)
        throw new MgInvalidArgumentException(L"MgdCreateFileFeatureSource.CreateFeatureSource", __LINE__, __WFILE__, NULL, L"MgMissingSchema", NULL);

    if (bCheckFeatureClass)
    {
        Ptr<MgClassDefinitionCollection> classes = schema->GetClasses();
        if(classes == NULL || classes->GetCount() == 0)
            throw new MgInvalidArgumentException(L"MgdCreateFileFeatureSource.CreateFeatureSource", __LINE__, __WFILE__, NULL, L"MgMissingClassDef", NULL);

        for(INT32 ci = 0; ci < classes->GetCount(); ci++)
        {
            Ptr<MgClassDefinition> classDef = classes->GetItem(ci);
            Ptr<MgPropertyDefinitionCollection> idProps = classDef->GetIdentityProperties();
            if(idProps == NULL || idProps->GetCount() == 0)
                throw new MgInvalidArgumentException(L"MgdCreateFileFeatureSource.CreateFeatureSource", __LINE__, __WFILE__, NULL, L"MgClassWOIdentity", NULL);
        }
    }

    if (bCheckSpatialContext)
    {
        // A coordinate system must be defined
        if(m_params->GetCoordinateSystemWkt().empty())
            throw new MgInvalidArgumentException(L"MgdCreateFileFeatureSource.CreateFeatureSource", __LINE__, __WFILE__, NULL, L"MgMissingSrs", NULL);
    }

    // Connect to provider
    STRING connString = GetFirstConnectionString();
    STRING providerName = m_params->GetProviderName();
    
    
    Ptr<MgdFeatureConnection> connWrap = new MgdFeatureConnection(providerName, connString);
    {
        if(NULL == connWrap.p)
        {
            throw new MgdConnectionFailedException(L"MgdCreateFileFeatureSource.CreateFeatureSource", __LINE__, __WFILE__, NULL, L"", NULL);
        }

        FdoPtr<FdoIConnection> conn = connWrap->GetConnection();
        if (conn == NULL)
        {
            throw new MgdConnectionFailedException(L"MgdCreateFileFeatureSource.CreateFeatureSource", __LINE__, __WFILE__, NULL, L"", NULL);
        }

        CreateDataStore(conn);
        ApplySchemaAndCreateSpatialContext(conn);

        MgdFdoConnectionUtil::CloseConnection(conn);

        Ptr<MgResourceService> resourceService = GetResourceService();
        if (NULL != (MgResourceService*)resourceService)
        {
            SetFeatureSourceDefinition(resourceService);
            SetResourceData(resourceService);
        }
    }

    MG_FEATURE_SERVICE_CATCH_AND_THROW(L"MgdCreateFileFeatureSource::CreateFeatureSource")
}