/// <summary> /// Get DIAdaptation instance for collection based on adaptation name /// </summary> /// <param name="diAdaptations"></param> /// <param name="adaptationName"></param> /// <returns></returns> private static DIAdaptation GetDIAdaptation(DIAdaptations diAdaptations, string adaptationName) { DIAdaptation RetVal = null; foreach (DIAdaptation diAdaptation in diAdaptations.Adaptations) { if (string.Compare(adaptationName, diAdaptation.AdaptationName, true) == 0) { RetVal = diAdaptation; break; } } return RetVal; }
/// <summary> /// Set the Last used adaptation in DIAdaptations.xml. If file does not exists then create one /// </summary> /// <param name="adaptationName"></param> /// <param name="adaptationFolder"></param> public static void SetDIAdaptations(string executableFolder, string adaptationName, string adaptationVersion, string adaptationFolder) { try { string DIAdaptationsPath = Path.Combine(executableFolder, DIAdaptations.DI_ADAPTATIONS_FILENAME); DIAdaptations oDIAdaptations = null; DIAdaptation oDIAdaptation = null; //-- Check for existance of C:\DevInfo\DevInfo 6.0\DIAdaptations.xml //-- If DIAdaptation.xml doesn't exist then create one if (File.Exists(DIAdaptationsPath)) { //-- Load serialised DIAdaptation.xml oDIAdaptations = DIAdaptations.Load(DIAdaptationsPath); //-- Get current adaption in collection oDIAdaptation = DIAdaptations.GetDIAdaptation(oDIAdaptations, adaptationName); } else { oDIAdaptations = new DIAdaptations(); } //-- If current adaptation doesnt exists in collection then add it to collection if ((oDIAdaptation == null)) { oDIAdaptation = new DIAdaptation(adaptationName,adaptationVersion, adaptationFolder); oDIAdaptations.Adaptations.Add(oDIAdaptation); } oDIAdaptations.LastUsedAdaptation = oDIAdaptation; oDIAdaptations.Save(DIAdaptationsPath); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); } }