private HLPlatforms GetPlatforms() { var platforms = new HLPlatforms(); try { platforms = HLPlatforms.GetPlatforms(); } catch (Exception ex) { Trace.TraceError(ex.Message, "ConfigManager"); } finally { if (platforms.Platforms.Count == 0 || platforms.Platforms.Count(p => p.Active) == 0) { Trace.TraceError( "No Platforms marked Active were found in MyHLPlatforms.xml - or the file could not ge found. Creating default MyHL Platform", "ConfigManager"); platforms.Platforms.Clear(); var myHL = new Platform(); myHL.Name = "MyHL"; myHL.Active = true; myHL.Default = true; platforms.Platforms.Add(myHL); } } return(platforms); }
private static HLPlatforms createPlatforms() { HLPlatforms result = new HLPlatforms(); Platform pl = new Platform(); pl.Active = true; pl.Default = true; pl.Name = "MyHL"; result.Platforms.Add(pl); return(result); }
public static HLPlatforms GetPlatforms() { HLPlatforms result = null; string filePath = Settings.GetRequiredAppSetting("PlatformConfigFile", @"App_Data\MyHLPlatforms.xml"); string platformFilePath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath ?? ".\\", filePath); if (!File.Exists(platformFilePath)) { return(createPlatforms()); } if (File.Exists(platformFilePath)) { FileStream f = null; try { var serial = new XmlSerializer(typeof(HLPlatforms)); f = File.OpenRead(platformFilePath); result = serial.Deserialize(f) as HLPlatforms; } catch (Exception ex) { string errorMessage = "Could not find or open the HL Platfoms list"; LoggerHelper.Exception("ConfigManager", ex, string.Format("{0},\r\nException: {1}", errorMessage, ex.Message)); throw new ApplicationException(errorMessage, ex); } finally { if (null != f) { f.Close(); } } } if (null == result) { string errorMessage = "ConfigManager - Could not find or open the HL Platfoms list"; LoggerHelper.Error(errorMessage); throw new ApplicationException(errorMessage); } return(result); }