in apps/samplecode/automotive/apisamples/Microsoft.Dynamics.Automotive.Samples/helpercode/CrmServiceHelpers.cs [382:444]
public Boolean ReadConfigurations()
{
Boolean isConfigExist = false;
if (configurations == null)
configurations = new List<Configuration>();
if (File.Exists(CrmServiceHelperConstants.ServerCredentialsFile))
{
XElement configurationsFromFile =
XElement.Load(CrmServiceHelperConstants.ServerCredentialsFile);
foreach (XElement config in configurationsFromFile.Nodes())
{
Configuration newConfig = new Configuration();
var serverAddress = config.Element("ServerAddress");
if (serverAddress != null)
if (!String.IsNullOrEmpty(serverAddress.Value))
newConfig.ServerAddress = serverAddress.Value;
var organizationName = config.Element("OrganizationName");
if (organizationName != null)
if (!String.IsNullOrEmpty(organizationName.Value))
newConfig.OrganizationName = organizationName.Value;
var discoveryUri = config.Element("DiscoveryUri");
if (discoveryUri != null)
if (!String.IsNullOrEmpty(discoveryUri.Value))
newConfig.DiscoveryUri = new Uri(discoveryUri.Value);
var organizationUri = config.Element("OrganizationUri");
if (organizationUri != null)
if (!String.IsNullOrEmpty(organizationUri.Value))
newConfig.OrganizationUri = new Uri(organizationUri.Value);
var homeRealmUri = config.Element("HomeRealmUri");
if (homeRealmUri != null)
if (!String.IsNullOrEmpty(homeRealmUri.Value))
newConfig.HomeRealmUri = new Uri(homeRealmUri.Value);
var vendpointType = config.Element("EndpointType");
if (vendpointType != null)
newConfig.EndpointType =
RetrieveAuthenticationType(vendpointType.Value);
if (config.Element("Credentials").HasElements)
{
newConfig.Credentials =
ParseInCredentials(config.Element("Credentials"),
newConfig.EndpointType,
newConfig.ServerAddress + ":" + newConfig.OrganizationName + ":" + config.Element("Credentials").Element("UserName").Value);
}
if (newConfig.EndpointType == AuthenticationProviderType.LiveId)
{
newConfig.DeviceCredentials = GetDeviceCredentials();
}
var userPrincipalName = config.Element("UserPrincipalName");
if (userPrincipalName != null)
if (!String.IsNullOrWhiteSpace(userPrincipalName.Value))
newConfig.UserPrincipalName = userPrincipalName.Value;
configurations.Add(newConfig);
}
}
if (configurations.Count > 0)
isConfigExist = true;
return isConfigExist;
}