Example #1
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Return currently defined locale for user, or default locale.
///
STRING MgException::GetLocale() throw()
{
    STRING locale;

    MG_TRY()

    if (NULL != sm_localeCallbackFunc)
    {
        locale = (*sm_localeCallbackFunc)();
    }

    MG_CATCH_AND_RELEASE()

    if (locale.empty())
    {
        MG_TRY()

        MgConfiguration* configuration = MgConfiguration::GetInstance();

        if (NULL != configuration && configuration->IsFileLoaded())
        {
            configuration->GetStringValue(
                MgFoundationConfigProperties::GeneralPropertiesSection,
                MgFoundationConfigProperties::GeneralPropertyDefaultMessageLocale,
                locale,
                MgFoundationConfigProperties::DefaultGeneralPropertyDefaultMessageLocale);
        }

        MG_CATCH_AND_RELEASE()

        if (locale.empty())
        {
            locale = MgResources::DefaultMessageLocale;
        }
    }
Example #2
0
/// <summary>
/// Initializes the common parameters and parameters specific to this request.
/// </summary>
/// <param name="name">Input
/// MgHttpRequest
/// This contains all the parameters of the request.
/// </param>
/// <returns>
/// nothing
/// </returns>
MgHttpMoveResource::MgHttpMoveResource(MgHttpRequest *hRequest)
{
    InitializeCommonParameters(hRequest);

    Ptr<MgHttpRequestParam> hrParam = m_hRequest->GetRequestParam();
    assert(hrParam != 0);

    // Get Source Resource Id name
    m_sourceResourceId = hrParam->GetParameterValue(MgHttpResourceStrings::reqSourceResourceId);

    // Get Destination Resource Id name
    m_destResourceId = hrParam->GetParameterValue(MgHttpResourceStrings::reqDestinationResourceId);

    // Get the flag to determine whether or not the destination resource
    // should be overwritten if it exists.
    m_overwrite = ::atoi(MgUtil::WideCharToMultiByte(
        hrParam->GetParameterValue(
        MgHttpResourceStrings::reqOverwrite)).c_str()) != 0;

    // In order to maintain backward compatibility, the Cascade flag
    // will be set to false by default if it is not specified.
    STRING cascadeParam = hrParam->GetParameterValue(MgHttpResourceStrings::reqCascade);

    m_cascade = (!cascadeParam.empty() && 0 != MgUtil::StringToInt32(cascadeParam));
}
Example #3
0
void MgServerSiteService::ValidateAuthorOrSelf(CREFSTRING user, CREFSTRING group)
{
    bool bAllowed = false;

    Ptr<MgUserInformation> userInfo = MgUserInformation::GetCurrentUserInfo();
    STRING currUser = userInfo->GetUserName();
    if (currUser.empty())
    {
        currUser = GetUserForSession();
    }

    // Is user an Author or Admin?
    Ptr<MgSecurityCache> securityCache = GetResourceService().CreateSecurityCache();

    Ptr<MgStringCollection> roles = new MgStringCollection;
    roles->Add(MgRole::Administrator);
    roles->Add(MgRole::Author);
    if (securityCache->IsUserInRoles(currUser, roles))
    {
        bAllowed = true;
    }

    // Are we looking ourselves up?
    if (group.empty() && currUser == user)
    {
        bAllowed = true;
    }

    if (!bAllowed)
    {
        throw new MgUnauthorizedAccessException(L"MgServerSiteService.ValidateAuthorOrSelf",
                __LINE__, __WFILE__, NULL, L"", NULL);
    }
}
Example #4
0
void UnescapeHex(const STRING& str, size_t& i, STRING& Ret, BOOL Unicode)
{
    STRING Num;

    // hexadecimal
    if (iswxdigit(str[i]))
    {
        Num += str[i];
        ++i;
        if (iswxdigit(str[i]))
        {
            Num += str[i];
            ++i;
            if (Unicode)
            {
                if (iswxdigit(str[i]))
                {
                    Num += str[i];
                    ++i;
                    if (iswxdigit(str[i]))
                    {
                        Num += str[i];
                        ++i;
                    }
                }
            }
        }
    }
    if (!Num.empty())
    {
        Ret += (WCHAR)wcstoul(&Num[0], NULL, 16);
    }
}
Example #5
0
STRING MgServerSiteService::GetUserForSession()
{
    STRING session;
    STRING userId;
    Ptr<MgUserInformation> currUserInfo = MgUserInformation::GetCurrentUserInfo();
    assert(NULL != currUserInfo);

    MG_SITE_SERVICE_TRY()

    MG_LOG_TRACE_ENTRY(L"MgServerSiteService::GetUserForSession()");

    session = currUserInfo->GetMgSessionId();

    if (!session.empty())
    {
        userId = MgSessionManager::GetUserName(session);
    }
    else
    {
        MgStringCollection arguments;
        arguments.Add(L"1");
        arguments.Add(session);

        throw new MgInvalidArgumentException(L"MgServerSiteService.GetUserForSession()",
            __LINE__, __WFILE__, &arguments, L"MgInvalidSessionsId", NULL);
    }

    MG_SITE_SERVICE_CATCH_AND_THROW(L"MgServerSiteService.GetUserForSession")

    return userId;
}
Example #6
0
/*
 * Constructor.
 */
CAnimation::CAnimation(const STRING file):
m_users(1) 
{
	extern STRING g_projectPath;

	renderFrame = &CAnimation::renderAnmFrame;

	if (!file.empty())
	{
		const STRING ext = getExtension(file);
	    
		if (_ftcsicmp(ext.c_str(), _T("anm")) == 0)
		{
			m_data.open(g_projectPath + MISC_PATH + file);
		}
		else if (_ftcsicmp(ext.c_str(), _T("gif")) == 0)
		{
			m_data.loadFromGif(resolve(g_projectPath + MISC_PATH + file));
			renderFrame = &CAnimation::renderFileFrame;
			m_data.filename = file;
		}
	}

	freeCanvases();
	m_canvases.resize(m_data.frameCount, NULL);
}
Example #7
0
void UnescapeOther(const STRING& str, size_t& i, STRING& Ret)
{
    STRING Num;

    // check octal
    if (L'0' <= str[i] && str[i] < L'8')
    {
        Num += str[i];
        ++i;
        if (L'0' <= str[i] && str[i] < L'8')
        {
            Num += str[i];
            ++i;
            if (L'0' <= str[i] && str[i] < L'8')
            {
                Num += str[i];
                ++i;
            }
        }
    }
    if (Num.empty())
    {
        Ret += str[i];
        ++i;
    }
    else
    {
        // octal
        Ret += (WCHAR)wcstoul(&Num[0], NULL, 8);
    }
}
VOID CActionItem_ChatMood::DoAction()
{
	STRING strKey = SCRIPT_SANDBOX::Talk::s_Talk.FindTalkActKey(GetPosIndex());
	if(!strKey.empty())
	{
		CEventSystem::GetMe()->PushEvent(GE_CHAT_ACTSET, strKey.c_str());
	}
}
Example #9
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Appends a slash to non-empty string
///
STRING MgUnmanagedDataManager::FormatSubdir(CREFSTRING subdir)
{
    STRING result = subdir;
    if (!result.empty())
    {
        MgFileUtil::AppendSlashToEndOfPath(result);
    }

    return result;
}
Example #10
0
// clears the tile cache for the given map
void MgdTileCache::Clear(MgMapBase* map)
{
    if (map != NULL)
    {
        STRING basePath = GetBasePath(map);

        // delete main map directory
        if (!basePath.empty())
            MgFileUtil::DeleteDirectory(basePath, true, false);
    }
}
Example #11
0
void PolyObjectBuffer::EnableObjectVerticesTrace(BOOL enableTrace,
    STRING traceFile)
{
    traceVertices = enableTrace;

    if (traceVertices) {
        assert(!traceFile.empty());
        traceFileName = traceFile;
    }

} // end: EnableBoundaryTraversalTrace()
Example #12
0
void IntersectionList::EnableIntersectionTrace(BOOL enableTrace,
    STRING traceFile)
{
    traceIntersections = enableTrace;

    if (traceIntersections) {
        assert(!traceFile.empty());
        intersectionTraceFileName = traceFile;
    }

} // end: EnableIntersectionTrace()
Example #13
0
/// <summary>
/// Initializes the common parameters and parameters specific to this request.
/// </summary>
/// <param name="name">Input
/// MgHttpRequest
/// This contains all the parameters of the request.
/// </param>
/// <returns>
/// nothing
/// </returns>
MgHttpKmlGetLayer::MgHttpKmlGetLayer(MgHttpRequest *hRequest)
{
    InitializeCommonParameters(hRequest);

    Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();

    // Get the layer definition
    m_layerDefinition = params->GetParameterValue(MgHttpResourceStrings::reqKmlLayerDefinition);

    // Get the map agent Uri
    m_agentUri = hRequest->GetAgentUri();

    // Get the bounding box
    m_boundingBox = params->GetParameterValue(MgHttpResourceStrings::reqKmlBoundingBox);

    // Get the requested format
    m_format = params->GetParameterValue(MgHttpResourceStrings::reqKmlFormat);

    // Get the map image width
    STRING width = params->GetParameterValue(MgHttpResourceStrings::reqKmlWidth);
    m_width = MgUtil::StringToInt32(width);

    // Get the map image height
    STRING height = params->GetParameterValue(MgHttpResourceStrings::reqKmlHeight);
    m_height = MgUtil::StringToInt32(height);

    // Get the map resolution
    STRING dpi = params->GetParameterValue(MgHttpResourceStrings::reqKmlDpi);
    if(!dpi.empty())
    {
        m_dpi = MgUtil::StringToDouble(dpi);
    }
    else
    {
        m_dpi = 96; // default
    }

    // Get the draw order
    STRING drawOrder = params->GetParameterValue(MgHttpResourceStrings::reqKmlDrawOrder);
    m_drawOrder = drawOrder.empty() ? 0 : MgUtil::StringToInt32(drawOrder);
}
Example #14
0
// clears the tile cache for the given map
void MgdTileCache::Clear(MgResourceIdentifier* mapDef)
{
    // the resource must be a map definition
    if (mapDef != NULL && mapDef->GetResourceType() == MgResourceType::MapDefinition)
    {
        STRING basePath = GetBasePath(mapDef);

        // delete main map directory
        if (!basePath.empty())
            MgFileUtil::DeleteDirectory(basePath, true, false);
    }
}
VOID CGameInterface::PacketItem_UserItem(tActionItem* pActionItem, int targetServerID, fVector2& fvPos)
{
	//空物品
	if(!pActionItem || pActionItem->GetType() != AOT_ITEM) return;
	CObject_Item* pItem = (CObject_Item*)(((CActionItem_Item*)pActionItem)->GetItemImpl());
	if(!pItem) return;
	//必须是能够使用的物品
	if(pItem->GetItemClass()!=ICLASS_COMITEM && pItem->GetItemClass()!=ICLASS_TASKITEM) return;
	//特殊物品不能在背包中直接使用,例如,宠物技能书
	STRING strTemp;
	if(!CObject_Item::CheckUseInPackage(pItem, strTemp))
	{
		if(!strTemp.empty()) CGameProcedure::s_pEventSystem->PushEvent(GE_NEW_DEBUGMESSAGE, strTemp.c_str());
		return;
	}
	//组队跟随中...
	if(CObjectManager::GetMe()->GetMySelf()->GetCharacterData()->Get_TeamFollowFlag()) return;

	//检查目前选中的目标
	CObject* pObj = (CObject*)CObjectManager::GetMe()->FindServerObject(targetServerID);
	
	//检查物品是否能够直接使用
	int objID;
	PET_GUID_t petID;
	bool bCanuseDir = ((CObject_Item_Medicine*)pItem)->IsValidTarget(pObj, fvPos, objID, petID);

	if(bCanuseDir)
	{
		WORLD_POS posTarget(fvPos.x, fvPos.y);

		//能够直接使用
		CGUseItem msg;
		msg.SetBagIndex( pItem->GetPosIndex() );
		msg.SetTargetObjID(objID);
		msg.SetTargetPetGUID(petID);
		msg.SetTargetPos(&posTarget);

		CNetManager::GetMe()->SendPacket( &msg );
		return;
	}

	//如果已经选中目标,说明目标不合适,如果是用在自己宠物上的物品,说明宠物没有释放
	if(pObj || ((CObject_Item_Medicine*)pItem)->IsTargetOne())
	{
		CGameProcedure::s_pEventSystem->PushEvent(GE_NEW_DEBUGMESSAGE, "无效目标");
		return;
	}

	//需要选中目标,在鼠标上挂上物品
	CActionSystem::GetMe()->SetDefaultAction(pActionItem);
}
Example #16
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Provides the long transaction name associated with the specified
/// resource.  Returns false if no session was active for the current
/// request, or if no long transaction name was found.
///
bool MgLongTransactionManager::GetLongTransactionName(MgResourceIdentifier* featureSourceId, REFSTRING longTransactionName)
{
    ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, false));

    STRING sessionId;
    Ptr<MgUserInformation> userInfo = MgUserInformation::GetCurrentUserInfo();
    if (userInfo != NULL)
        sessionId = userInfo->GetMgSessionId();

    if (sessionId.empty())
        return false;

    return MgLongTransactionManager::GetLongTransactionName(sessionId, featureSourceId, longTransactionName);
}
Example #17
0
void uninitialisePakFile()
{
	// Return if this isn't a pak file.
	if (g_pakTempPath.empty()) return;

	deleteTree(g_pakTempPath);
	ZIPClose();

	// If we are a standalone game, also delete the tag on archive.
	if (g_bStandalone)
	{
		unlink(g_pakFile.c_str());
	}
}
Example #18
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Initializes the package status information.
///
void MgResourcePackageHandler::InitializeStatus(CREFSTRING packageApiName,
    CREFSTRING packagePathname, bool logActivities)
{
    m_packagePathname = packagePathname;

    // Create the package log writer.
    if (logActivities)
    {
        m_packageLogWriter = new MgPackageLogWriter(packageApiName,
            m_packagePathname);
    }

    if (m_packageLogWriter != NULL)
    {
        m_opsSucceeded = 0;
        m_opsReceived = 0;

        MgServerManager* serverManager = MgServerManager::GetInstance();
        ACE_ASSERT(NULL != serverManager && serverManager->IsSiteServer());

        MgPackageStatusInformation& statusInfo = m_packageLogWriter->GetStatusInfo();

        Ptr<MgDateTime> startTime = new MgDateTime();
        statusInfo.SetEndTime(startTime);

        Ptr<MgUserInformation> currUserInfo = m_repositoryManager.GetCurrentUserInfo();
        ACE_ASSERT(NULL != currUserInfo.p);

        if (NULL != currUserInfo)
        {
            statusInfo.SetUserName(currUserInfo->GetUserName());
        }

        STRING serverName = serverManager->GetServerName();
        STRING serverAddress = serverManager->GetLocalServerAddress();

        if (serverName.empty())
        {
            MgIpUtil::HostAddressToName(serverAddress, serverName, false);
        }

        statusInfo.SetServerName(serverName);
        statusInfo.SetServerAddress(serverAddress);

        // Write the log file.
        m_packageLogWriter->UpdateLog();
    }
}
Example #19
0
void MgWmsFeatureInfo::GenerateDefinitions(MgUtilDictionary& dictionary)
{
    if(m_propertyCollection != NULL && m_index >= 0 && m_index < m_propertyCollection->GetCount())
    {
        Ptr<MgPropertyCollection> props = m_propertyCollection->GetItem(m_index);
        if(props->Contains(kpszLayerNameProperty))
        {
            Ptr<MgStringProperty> layerNameProp = (MgStringProperty*)props->GetItem(kpszLayerNameProperty);
            STRING value = MgUtil::ReplaceEscapeCharInXml(layerNameProp->GetValue());
            if(!value.empty())
            {
                dictionary.AddDefinition(kpszDefinitionFeatureInfoLayerName, value);
            }
        }
    }
}
Example #20
0
// gets the base path to use with the tile cache for the given map definition resource
STRING MgdTileCache::GetBasePath(MgResourceIdentifier* mapDef)
{
    assert(mapDef != NULL);
    assert(mapDef->GetResourceType() == MgResourceType::MapDefinition);
    STRING mapPath;

    if (mapDef->GetRepositoryType() == MgRepositoryType::Library)
    {
        // for maps in the library repository the path+name is unique
        mapPath  = mapDef->GetPath();
        mapPath += L"_";
        mapPath += mapDef->GetName();
    }
    else if (mapDef->GetRepositoryType() == MgRepositoryType::Session)
    {
        // for maps in the session repository we use the session + path + map name
        mapPath  = mapDef->GetRepositoryName();
        mapPath += L"_";

        STRING resourcePath  = mapDef->GetPath();

        if (!resourcePath.empty())
        {
            mapPath += resourcePath;
            mapPath += L"_";
        }

        mapPath += mapDef->GetName();
    }
    else
    {
        // shouldn't get here
        assert(false);
        return mapPath;
    }

    // for safety
    mapPath = MgUtil::ReplaceString(mapPath, L"/", L"_");
    mapPath = MgUtil::ReplaceString(mapPath, L":", L"_");

    // Build the base path using format "%ls%ls":
    //     <basePath> = <tileCachePath><mapPath>
    STRING basePath = sm_path;
    basePath += mapPath;

    return basePath;
}
Example #21
0
Handle ResourceManager::NewResource(BaseResource* r, char tag)
{
  assert(r);

  STRING filename = r->GetFilename();

  if(!filename.empty() &&
     g_nameHandleTable.find(filename) != g_nameHandleTable.end())
  {
    return Handle(g_nameHandleTable[filename]);
  }

  Handle h;
  h.Init(r->GetHash(), tag);
  g_nameHandleTable[filename] = h.GetHandle();
  g_handleResTable[h.GetHandle()] = r;

  return h;
}
Example #22
0
void EditDlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
    WCHAR szValue[MAX_STRING];
    STRING str;
    INT i;

    switch (id)
    {
        case IDOK:
            GetDlgItemTextW(hwnd, cmb2, szValue, _countof(szValue));
            str = szValue;
            trim(str);
            if (str.empty())
            {
                WCHAR sz[MAX_STRING];
                SendDlgItemMessageW(hwnd, cmb2, CB_SETEDITSEL, 0, MAKELPARAM(0, -1));
                SetFocus(GetDlgItem(hwnd, cmb2));
                LoadStringW(g_hInstance, IDS_ENTERNAME2, sz, _countof(sz));
                MessageBoxW(hwnd, sz, NULL, MB_ICONERROR);
                return;
            }

            g_Items[g_iItem].m_CharSet2 = DEFAULT_CHARSET;
            i = SendDlgItemMessageW(hwnd, cmb4, CB_GETCURSEL, 0, 0);
            if (i != CB_ERR)
            {
                g_Items[g_iItem].m_CharSet2 = g_CharSetList[i].CharSet;
            }
            g_Items[g_iItem].m_Substitute = str;

            g_bModified = TRUE;
            EndDialog(hwnd, IDOK);
            break;
        case IDCANCEL:
            EndDialog(hwnd, IDCANCEL);
            break;
        case psh1:
            LV_OnDelete(g_hListView, g_iItem);
            EndDialog(hwnd, psh1);
            break;
    }
}
void MgResourceDefinitionManager::ValidateDocument(XmlDocument& xmlDoc)
{
    MG_RESOURCE_SERVICE_TRY()

    MgResourceIdentifier resource(MgUtil::MultiByteToWideChar(xmlDoc.getName()));

    // Skip XML schema validation on runtime resources.

    if (!resource.IsRuntimeResource())
    {
        std::string xmlContent;
        MgXmlUtil xmlUtil(xmlDoc.getContent(xmlContent));

        DOMElement* rootNode = xmlUtil.GetRootNode();
        if(NULL != rootNode)
        {
            assert(NULL != rootNode);

            STRING rootName;
            const XMLCh* tag = rootNode->getTagName();

            if (NULL != tag)
            {
                rootName = X2W(tag);
                assert(!rootName.empty());
            }

            STRING schemaName;
            const XMLCh* attr = rootNode->getAttribute(X("xsi:noNamespaceSchemaLocation"));

            if (NULL != attr)
            {
                schemaName = X2W(attr);
            }

            ValidateDocument(resource, rootName, schemaName);
        }
    }

    MG_RESOURCE_CONTAINER_CATCH_AND_THROW(L"MgResourceDefinitionManager.ValidateDocument")
}
Example #24
0
/// <summary>
/// Initializes the common parameters and parameters specific to this request.
/// </summary>
/// <param name="name">Input
/// MgHttpRequest
/// This contains all the parameters of the request.
/// </param>
/// <returns>
/// nothing
/// </returns>
MgHttpEnumerateResources::MgHttpEnumerateResources(MgHttpRequest *hRequest)
{
    InitializeCommonParameters(hRequest);

    Ptr<MgHttpRequestParam> hrParam = m_hRequest->GetRequestParam();

    // Get resource id
    m_resourceId = hrParam->GetParameterValue(MgHttpResourceStrings::reqResourceId);

    // Get depth
    m_depth = MgUtil::StringToInt32(hrParam->GetParameterValue(MgHttpResourceStrings::reqDepth));

    // Get type
    m_type = hrParam->GetParameterValue(MgHttpResourceStrings::reqType);

    // In order to maintain backward compatibility, the Compute Children flag
    // will be set to true by default if it is not specified.
    STRING computeChildrenParam = hrParam->GetParameterValue(MgHttpResourceStrings::reqComputeChildren);

    m_computeChildren = (computeChildrenParam.empty() || 0 != MgUtil::StringToInt32(computeChildrenParam));
}
Example #25
0
STRING MgServerSiteService::CreateSession()
{
    STRING session;
    Ptr<MgUserInformation> currUserInfo = MgUserInformation::GetCurrentUserInfo();
    assert(NULL != currUserInfo);

    MG_SITE_SERVICE_TRY()

    MG_LOG_TRACE_ENTRY(L"MgServerSiteService::CreateSession()");

    session = currUserInfo->GetMgSessionId();

    if (session.empty())
    {
        MgSiteManager* siteManager = MgSiteManager::GetInstance();
        Ptr<MgSiteInfo> siteInfo = siteManager->GetSiteInfo(0);
        session = currUserInfo->CreateMgSessionId(siteInfo);
        currUserInfo->SetMgSessionId(session);
    }
    else
    {
        throw new MgDuplicateSessionException(
            L"MgServerSiteService.CreateSession", __LINE__, __WFILE__, NULL, L"", NULL);
    }

    // Note that if an error occurs, the abandoned session repositry will
    // be eventually deleted by the internal session cleanup event timer.

    MgResourceIdentifier resource(MgRepositoryType::Session, session,
        L"", L"", MgResourceType::Folder);

    MgSessionManager::AddSession(session, currUserInfo->GetUserName());
    GetResourceService().CreateRepository(&resource, NULL, NULL);

    MG_SITE_SERVICE_CATCH_AND_THROW(L"MgServerSiteService.CreateSession")

    return session;
}
Example #26
0
//////////////////////////////////////////////////////////////////
// Processes a GetMap request from the Viewer and returns
// a DWF containing an EMap that fully describes the map
// but does not yet contain any layer graphics
//
MgByteReader* MgDwfController::GetMap(MgResourceIdentifier* mapDefinition,
    CREFSTRING dwfVersion, CREFSTRING eMapVersion, MgPropertyCollection* mapViewCommands)
{
    //create a session id to associate with this map
    STRING sessionId;
    Ptr<MgUserInformation> userInfo = m_siteConn->GetUserInfo();
    if (userInfo.p != NULL) sessionId = userInfo->GetMgSessionId();
    if (sessionId.empty())
    {
        Ptr<MgSite> site = m_siteConn->GetSite();
        sessionId = site->CreateSession();
        userInfo->SetMgSessionId(sessionId);
    }

    //get an instance of the resource service
    Ptr<MgResourceService> resourceService = (MgResourceService*)GetService(MgServiceType::ResourceService);

    //instantiate a map object and let it load itself from the map definition in the resource repository
    Ptr<MgMap> map = new MgMap();
    map->Create(resourceService, mapDefinition, mapDefinition->GetName());

    m_operation = get;

    //apply commands
    ApplyMapViewCommands(map, mapViewCommands);

    //save the map state in the session repository
    Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Session:" + sessionId + L"//" + mapDefinition->GetName() + L"." + MgResourceType::Map);
    map->Save(resourceService.p, resId.p);

    Ptr<MgDwfVersion> dwfv = new MgDwfVersion(dwfVersion, eMapVersion);

    //get an instance of the mapping service and call the GetMap API
    Ptr<MgMappingService> mappingService = (MgMappingService*)GetService(MgServiceType::MappingService);
    return mappingService->GenerateMap(map, sessionId, m_mapAgentUri, dwfv);
}
Example #27
0
TestProfilingService::TestProfilingService()
{
    // Initialize service objects.
    MgServiceManager* serviceManager = MgServiceManager::GetInstance();

    m_svcResource = dynamic_cast<MgResourceService*>(
        serviceManager->RequestService(MgServiceType::ResourceService));
    assert(m_svcResource != NULL);

    m_svcProfiling = dynamic_cast<MgProfilingService*>(
        serviceManager->RequestService(MgServiceType::ProfilingService));
    assert(m_svcProfiling != NULL);

    // Initialize a site connection.
    Ptr<MgServerSiteService> svcSite = dynamic_cast<MgServerSiteService*>(
        serviceManager->RequestService(MgServiceType::SiteService));
    assert(svcSite != NULL);

    Ptr<MgUserInformation> userInfo = new MgUserInformation(
        L"Administrator", L"admin");
    userInfo->SetLocale(TEST_LOCALE);

    // Set the current MgUserInformation
    // This must be done before calling CreateSession()
    MgUserInformation::SetCurrentUserInfo(userInfo);

    STRING session = svcSite->CreateSession();
    assert(!session.empty());
    userInfo->SetMgSessionId(session);

    // Set the current MgUserInformation
    MgUserInformation::SetCurrentUserInfo(userInfo);

    m_siteConnection = new MgSiteConnection();
    m_siteConnection->Open(userInfo);
}
Example #28
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Returns unmanaged data
///
MgByteReader* MgUnmanagedDataManager::EnumerateUnmanagedData(CREFSTRING path, bool recursive, CREFSTRING type, CREFSTRING filter)
{
    Ptr<MgByteReader> byteReader;

    MG_TRY()

    ACE_TRACE("MgUnmanagedDataManager::EnumerateUnmanagedData");

    Ptr<MgPropertyCollection> unmanagedDataMappings = GetUnmanagedDataMappings();

    if (NULL != unmanagedDataMappings.p)
    {
        // this XML follows the ResourceList-1.0.0.xsd schema
        string list = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        list += "<UnmanagedDataList xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"UnmanagedDataList-1.0.0.xsd\">\n";

        // check arguments...

        // pull out the mapping name from the path
        // path must be in the form of:
        //      ""
        //      "[alias1]"
        //      "[alias1]subfolder1"
        //      "[alias1]subfolder1/"
        //      "[alias1]subfolder1/subfolder2/"

        STRING mappingName = L"", subfolder = L"";
        if (!MgUnmanagedDataManager::ParsePath(path, mappingName, subfolder))
        {
            MgStringCollection arguments;
            arguments.Add(L"1");
            arguments.Add(path);

            throw new MgInvalidArgumentException(L"MgUnmanagedDataManager.EnumerateUnmanagedData",
                __LINE__, __WFILE__, &arguments, L"", NULL);
        }

        // type must be:
        //      "FOLDERS"
        //      "FILES"
        //      "BOTH"

        bool storeFolders = ACE_OS::strcasecmp(type.c_str(), MgResourceUnmanagedDataType::Folders.c_str()) == 0
            || ACE_OS::strcasecmp(type.c_str(), MgResourceUnmanagedDataType::Both.c_str()) == 0;

        bool storeFiles = ACE_OS::strcasecmp(type.c_str(), MgResourceUnmanagedDataType::Files.c_str()) == 0
            || ACE_OS::strcasecmp(type.c_str(), MgResourceUnmanagedDataType::Both.c_str()) == 0;

        ACE_ASSERT(storeFolders || storeFiles);

        // filter is ignored if type = "FOLDERS"
        // filter can be:
        //      ""
        //      ".sdf"
        //      ".sdf;.pdf;.shp"
        //      "sdf"
        //      "sdf;dwf;png"

        MgStringCollection filters;
        if (storeFiles)
            ParseFilter(filter, &filters);

        // are we looking in a specific path?
        if (!mappingName.empty())
        {
            Ptr<MgStringProperty> stringProp = dynamic_cast<MgStringProperty*>(unmanagedDataMappings->FindItem(mappingName));
            if (stringProp != NULL)
            {
                // we have a match!
                STRING mappingDir = stringProp->GetValue();

                // get the files and/or folders from that folder and subfolder (recursive)
                GetFilesAndFolders(list, mappingName, mappingDir, subfolder, &filters, storeFolders, storeFiles, recursive);
            }
            else
            {
                MgStringCollection arguments;
                arguments.Add(L"1");
                arguments.Add(path);

                throw new MgInvalidArgumentException(L"MgUnmanagedDataManager.EnumerateUnmanagedData",
                    __LINE__, __WFILE__, &arguments, L"", NULL);
            }
        }
        else
        {
            // getting files starting from virtual root (all mappings)
            // iterate thru mappings
            for (int i = 0; i < unmanagedDataMappings->GetCount(); i++)
            {
                Ptr<MgStringProperty> stringProp = dynamic_cast<MgStringProperty*>(unmanagedDataMappings->GetItem(i));

                STRING mapName = stringProp->GetName();
                STRING mapDir = stringProp->GetValue();

                if (MgFileUtil::IsDirectory(mapDir))
                {
                    if (storeFolders)
                    {
                        MgDateTime createdDate = MgFileUtil::GetFileCreationTime(mapDir);
                        MgDateTime modifiedDate = MgFileUtil::GetFileModificationTime(mapDir);

                        INT32 numFolders = 0;
                        INT32 numFiles = 0;

                        GetNumberOfFilesAndSubfolders(mapDir, numFolders, numFiles);

                        // add top-level mappings
                        AddFolder(list, mapName, L"", L"", numFolders, numFiles, createdDate, modifiedDate);
                    }

                    if (recursive)
                        GetFilesAndFolders(list, mapName, mapDir, L"", &filters, storeFolders, storeFiles, recursive);
                }
            }
        }

        list += "</UnmanagedDataList>";

        Ptr<MgByteSource> byteSource = new MgByteSource(
        (unsigned char*)list.c_str(), (INT32)list.length());

        byteSource->SetMimeType(MgMimeType::Xml);
        byteReader = byteSource->GetReader();
    }

    MG_CATCH_AND_THROW(L"MgUnmanagedDataManager.EnumerateUnmanagedData")

    return byteReader.Detach();
}
Example #29
0
MgByteReader* MgHtmlController::CollectQueryMapFeaturesResult(MgResourceService* resourceService,
                                                              INT32 requestData,
                                                              MgFeatureInformation* featInfo,
                                                              MgSelection* selectionSet,
                                                              MgBatchPropertyCollection* attributes, 
                                                              MgByteReader* inlineSelection)
{
    STRING xml;
    STRING tooltip;
    STRING hyperlink;
    STRING xmlSelection = selectionSet? selectionSet->ToXml(false): L"";

    if (NULL != featInfo)
    {
        tooltip = featInfo->GetTooltip();
        hyperlink = featInfo->GetHyperlink();
    }

    // TODO: Stil haven't defined a schema for v2.6. Should we?
    xml.append(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<FeatureInformation>\n");

    size_t len = xmlSelection.length();
    if(len > 0)
    {
        xml.reserve(len + 2048);
        xml.append(xmlSelection);
    }
    else
    {
        xml.reserve(2048);
        xml.append(L"<FeatureSet />\n");
    }

    if (((requestData & REQUEST_TOOLTIP) == REQUEST_TOOLTIP) && !tooltip.empty())
    {
        xml.append(L"<Tooltip>");
        xml.append(MgUtil::ReplaceEscapeCharInXml(tooltip));
        xml.append(L"</Tooltip>\n");
    }
    else
        xml.append(L"<Tooltip />\n");

    if (((requestData & REQUEST_HYPERLINK) == REQUEST_HYPERLINK) && !hyperlink.empty())
    {
        xml.append(L"<Hyperlink>");
        xml.append(MgUtil::ReplaceEscapeCharInXml(hyperlink));
        xml.append(L"</Hyperlink>\n");
    }
    else
        xml.append(L"<Hyperlink />\n");

    if (((requestData & REQUEST_INLINE_SELECTION) == REQUEST_INLINE_SELECTION) && NULL != inlineSelection)
    {
        xml.append(L"<InlineSelectionImage>\n");
        xml.append(L"<MimeType>");
        xml.append(inlineSelection->GetMimeType());
        xml.append(L"</MimeType>\n");
        xml.append(L"<Content>");
        MgByteSink sink(inlineSelection);
        Ptr<MgByte> bytes = sink.ToBuffer();
        Ptr<MgMemoryStreamHelper> streamHelper = new MgMemoryStreamHelper((INT8*) bytes->Bytes(), bytes->GetLength(), false);
        std::string b64 = streamHelper->ToBase64();
        STRING wb64 = MgUtil::MultiByteToWideChar(b64);
        xml.append(wb64);
        xml.append(L"</Content>\n");
        xml.append(L"</InlineSelectionImage>\n");
    }
    else
        xml.append(L"<InlineSelectionImage />\n");

    if (((requestData & REQUEST_ATTRIBUTES) == REQUEST_ATTRIBUTES) && NULL != attributes)
    {
        xml.append(L"<SelectedFeatures>\n");
        WriteSelectedFeatureAttributes(resourceService, selectionSet, attributes, xml);
        xml.append(L"</SelectedFeatures>\n");
    }
    else
        xml.append(L"<SelectedFeatures />\n");

    xml.append(L"</FeatureInformation>\n");

    string xmlDoc = MgUtil::WideCharToMultiByte(xml);
    STRING mimeType = L"text/xml";
    return MgUtil::GetByteReader(xmlDoc, &mimeType);
}
Example #30
0
MgSpatialContextData* MgServerGetSpatialContexts::GetSpatialContextData(
    FdoISpatialContextReader* spatialReader, MgSpatialContextInfo* spatialContextInfo)
{
    Ptr<MgSpatialContextData> spatialData = new MgSpatialContextData();

    // Name must exist
    FdoString* name = spatialReader->GetName();
    CHECKNULL((FdoString*)name, L"MgServerGetSpatialContexts.GetSpatialContexts");
    spatialData->SetName(STRING(name));

    STRING coordSysName = L"";
    FdoString* csName = spatialReader->GetCoordinateSystem();

    Ptr<MgCoordinateSystemFactory> csFactory;
    // WKT for co-ordinate system
    FdoString* csWkt = NULL;
    STRING srsWkt = L"";

    bool haveValidCoordSys = false;
    if(NULL != csName && *csName != '\0')
    {
        coordSysName = STRING(csName);
    }
    else
    {
        csWkt = spatialReader->GetCoordinateSystemWkt();
        if (csWkt != NULL && *csWkt != '\0')
        {
            srsWkt = csWkt;
            try
            {
                csFactory = new MgCoordinateSystemFactory();
                coordSysName = csFactory->ConvertWktToCoordinateSystemCode(srsWkt);
                haveValidCoordSys = (coordSysName.size() != 0);
            }
            catch (MgException* e)
            {
                SAFE_RELEASE(e);
            }
            catch(...)
            {
            }
        }
    }

    bool spatialContextDefined = !coordSysName.empty();
    bool coordSysOverridden = false;

    // look for coordinate system override
    if (NULL != spatialContextInfo)
    {
        // Perform substitution of missing coordinate system with
        // the spatial context mapping defined in feature source document
        MgSpatialContextInfo::const_iterator iter = spatialContextInfo->find(name);

        if (spatialContextInfo->end() != iter)
        {
            csName = (iter->second).c_str();
            coordSysOverridden = true;
        }
    }

    if (csName != NULL && *csName != '\0')
    {
        spatialData->SetCoordinateSystem(STRING(csName));
    }

    // Desc for spatial context
    STRING desc = L"";

    // This flag is obsolete and will be deprecated.
    bool isActive = spatialReader->IsActive();

    if (coordSysOverridden)
    {
        srsWkt = csName;
        desc = MgServerFeatureUtil::GetMessage(L"MgCoordinateSystemOverridden");
    }
    else if (spatialContextDefined && !coordSysOverridden)
    {
        // avoid looking one more time after CS in case we have a valid one...
        if (!haveValidCoordSys)
        {
            csWkt = spatialReader->GetCoordinateSystemWkt();
            if(NULL != csWkt && *csWkt != '\0')
                srsWkt = csWkt;

            if (srsWkt.empty())
            {
                try
                {
                    if (csFactory == NULL)
                        csFactory = new MgCoordinateSystemFactory();

                    // Check if the spatial context coordinate system data represents an EPSG
                    // code. If this is the case the WKT data for the EPSG code has to be
                    // retrieved.
                    if (IsEpsgCodeRepresentation(csName))
                    {
                        // This is an EPSG code
                        FdoString* p = NULL;
                        if ((csName[0] == L'E') || (csName[0] == L'e'))
                            p = csName+5;
                        else
                            p = csName;

                        INT32 epsgCode = (INT32)wcstol(p, NULL, 10);

                        // Convert the EPSG numerical code to WKT
                        srsWkt = csFactory->ConvertEpsgCodeToWkt(epsgCode);
                    }
                    else
                    {
                        srsWkt = csFactory->ConvertCoordinateSystemCodeToWkt(STRING(csName));
                    }
                }
                catch (MgException* e)
                {
                    SAFE_RELEASE(e);
                }
                catch(...)
                {
                    // Just use the empty WKT.
                }
            }
        }
        FdoString* fdoDesc = spatialReader->GetDescription();
        if(NULL != fdoDesc)
            desc = STRING(fdoDesc);
    }

    // retrieve other values from spatialReader
    FdoSpatialContextExtentType extentType = spatialReader->GetExtentType();
    FdoPtr<FdoByteArray> byteArray = spatialReader->GetExtent();
    double xyTol = spatialReader->GetXYTolerance();
    double zTol = spatialReader->GetZTolerance();

    spatialData->SetCoordinateSystemWkt(srsWkt);
    spatialData->SetDescription(desc);
    spatialData->SetExtentType((INT32)extentType);

    if (byteArray.p != NULL)
    {
        INT32 size = (INT32)byteArray->GetCount();
        BYTE_ARRAY_IN bytes = (BYTE_ARRAY_IN)byteArray->GetData();
        Ptr<MgByte> extent = new MgByte(bytes, size);
        spatialData->SetExtent(extent);
    }

    // XY Tolerance
    spatialData->SetXYTolerance(xyTol);

    // Z Tolerance
    spatialData->SetZTolerance(zTol);

    // This flag is obsolete and will be deprecated.
    spatialData->SetActiveStatus(isActive);

    return spatialData.Detach();
}