/// <summary> /// Register the current application and ensure that the local ApiKeyInfo is set and /// written to ApiKeyFilePath /// </summary> /// <returns></returns> protected internal bool RegisterApplicationProcess() { lock (_registerLock) { if (!IsInitialized) { FireEvent(Initializing); CoreServiceResponse response = ApplicationRegistryService.RegisterApplicationProcess(ProcessDescriptor); ApplicationRegistrationResult appRegistrationResult = response.Data.FromJObject <ApplicationRegistrationResult>(); if (response.Success) { IsInitialized = true; FireEvent(Initialized); ApiKeyInfo keyInfo = new ApiKeyInfo { ApiKey = appRegistrationResult.ApiKey, ApplicationClientId = appRegistrationResult.ClientId, ApplicationName = GetApplicationName() }; EnsureApiKeyFileDirectory(); keyInfo.ToJsonFile(ApiKeyFilePath); FireEvent(ApiKeyFileSaved); } else { Message = response.Message; FireEvent(InitializationFailed); } } return(IsInitialized); } }
public ApiKeyInfo GetApiKeyInfo(IApplicationNameProvider nameProvider) { if (_apiKeyInfo == null) { if (File.Exists(ApiKeyFilePath)) { _apiKeyInfo = ApiKeyFilePath.FromJsonFile <ApiKeyInfo>(); } else { FireEvent(ApiKeyFileNotFound); _apiKeyInfo = ApplicationRegistryService.GetClientApiKeyInfo(); _apiKeyInfo.ApplicationName = nameProvider.GetApplicationName(); EnsureApiKeyFileDirectory(); _apiKeyInfo.ToJsonFile(ApiKeyFilePath); } } return(_apiKeyInfo); }