//static public int GetEnumValueIndex(System.Type enumType, string valueName) //{ // string[] names = System.Enum.GetNames(enumType); // for (int i = 0; i < names.Length; i++) // { // if (names[i] == valueName) // { // return i; // } // } // throw new Exception("Invalid enum value name passed in."); //} /// <summary> /// Loads all the assemblies in the directory of the executing (entry) assembly and searches /// them for inheritors of the given type. SLOW! /// </summary> /// <returns></returns> //static public List<Type> GetCollectTypeChildrenTypesFromRelatedAssemblies(Type typeSearched) //{ // List<Type> result = new List<Type>(); // // Load all the assemblies in the directory of the current application and try to find // // inheritors of AIndividual in them, then gather those in the list. // string path = Assembly.GetEntryAssembly().Location; // path = path.Remove(path.LastIndexOf('\\')); // string[] dllFiles = System.IO.Directory.GetFiles(path, "*.dll"); // foreach (string file in dllFiles) // { // Assembly assembly; // try // { // assembly = Assembly.LoadFile(file); // } // catch (Exception) // {// This DLL was not a proper assembly, disregard. // continue; // } // // Try to find typeSearched inheritors in this assembly. // result.AddRange(ReflectionSupport.GetTypeChildrenTypes(typeSearched, assembly)); // } // return result; //} /// <summary> /// Helper method allows to retrieve application entry assembly referenced (static and runtime) assemblies. /// </summary> static public List <Assembly> GetAssemblies(bool entryAssembly, bool entryReferencedAssemblies) { Assembly startAssembly = Assembly.GetEntryAssembly(); if (startAssembly == null) { startAssembly = Assembly.GetCallingAssembly(); CoreSystemMonitor.OperationWarning("Failed to find application entry assembly, operating with reduced set."); } return(GetReferencedAndInitialAssembly(startAssembly)); }
/// <summary> /// Helper. /// </summary> /// <param name="dateTime"></param> /// <param name="timeZoneId"></param> /// <returns></returns> private static DateTime ConvertToLocalDateTime(string dateTime, string timeZoneId) { // Strip the time zone ID from the end of the dateTime string. dateTime = dateTime.Replace(timeZoneId, "").Trim(); // Convert the timeZoneId to a TimeSpan. // (Leading + signs aren't allowed in the TimeSpan.Parse // parameter, although leading - signs are. // The purpose of the [+]*? at the beginning of the // regex is to account for, and ignore, any leading + sign). string ts = Regex.Replace(GetTimeZoneOffset(timeZoneId), @"^[+]*?(?<hours>[-]?\d\d)(?<minutes>\d\d)$", "${hours}:${minutes}:00"); TimeSpan timeZoneOffset = TimeSpan.Parse(ts); TimeSpan localUtcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); // Get the absolute time difference between the given // datetime's time zone and the local datetime's time zone. TimeSpan absoluteOffset = timeZoneOffset - localUtcOffset; absoluteOffset = absoluteOffset.Duration(); // Now that the absolute time difference is known, // determine whether to add or subtract it from the // given dateTime, and then return the result. try { if (timeZoneOffset < localUtcOffset) { return(DateTime.Parse(dateTime) + absoluteOffset); } else { return(DateTime.Parse(dateTime) - absoluteOffset); } } catch { CoreSystemMonitor.OperationWarning("Parsing of date time [" + dateTime + "] failed."); return(DateTime.MinValue); } }