public static AddIn Load(string fileName) { AddIn result; try { using (System.IO.TextReader textReader = System.IO.File.OpenText(fileName)) { AddIn addIn = AddIn.Load(textReader, System.IO.Path.GetDirectoryName(fileName)); addIn.addInFileName = fileName; result = addIn; } } catch (System.Exception innerException) { throw new System.NotSupportedException("Can't load " + fileName, innerException); } return(result); }
/// <summary> /// Loads a list of .addin files, ensuring that dependencies are satisfied. /// This method is normally called by <see cref="CoreStartup.RunInitialization"/>. /// </summary> /// <param name="addInFiles"> /// The list of .addin file names to load. /// </param> /// <param name="disabledAddIns"> /// The list of disabled AddIn identity names. /// </param> public static void Load(List <string> addInFiles, List <string> disabledAddIns) { List <AddIn> list = new List <AddIn>(); Dictionary <string, Version> dict = new Dictionary <string, Version>(); Dictionary <string, AddIn> addInDict = new Dictionary <string, AddIn>(); foreach (string fileName in addInFiles) { AddIn addIn; try { addIn = AddIn.Load(fileName); } catch (AddInLoadException ex) { LoggingService.Error(ex); if (ex.InnerException != null) { MessageService.ShowError("Error loading AddIn " + fileName + ":\n" + ex.InnerException.Message); } else { MessageService.ShowError("Error loading AddIn " + fileName + ":\n" + ex.Message); } addIn = new AddIn(); addIn.addInFileName = fileName; addIn.CustomErrorMessage = ex.Message; } if (addIn.Action == AddInAction.CustomError) { list.Add(addIn); continue; } addIn.Enabled = true; if (disabledAddIns != null && disabledAddIns.Count > 0) { foreach (string name in addIn.Manifest.Identities.Keys) { if (disabledAddIns.Contains(name)) { addIn.Enabled = false; break; } } } if (addIn.Enabled) { foreach (KeyValuePair <string, Version> pair in addIn.Manifest.Identities) { if (dict.ContainsKey(pair.Key)) { MessageService.ShowError("Name '" + pair.Key + "' is used by " + "'" + addInDict[pair.Key].FileName + "' and '" + fileName + "'"); addIn.Enabled = false; addIn.Action = AddInAction.InstalledTwice; break; } else { dict.Add(pair.Key, pair.Value); addInDict.Add(pair.Key, addIn); } } } list.Add(addIn); } checkDependencies: for (int i = 0; i < list.Count; i++) { AddIn addIn = list[i]; if (!addIn.Enabled) { continue; } Version versionFound; foreach (AddInReference reference in addIn.Manifest.Conflicts) { if (reference.Check(dict, out versionFound)) { MessageService.ShowError(addIn.Name + " conflicts with " + reference.ToString() + " and has been disabled."); DisableAddin(addIn, dict, addInDict); goto checkDependencies; // after removing one addin, others could break } } foreach (AddInReference reference in addIn.Manifest.Dependencies) { if (!reference.Check(dict, out versionFound)) { if (versionFound != null) { MessageService.ShowError(addIn.Name + " has not been loaded because it requires " + reference.ToString() + ", but version " + versionFound.ToString() + " is installed."); } else { MessageService.ShowError(addIn.Name + " has not been loaded because it requires " + reference.ToString() + "."); } DisableAddin(addIn, dict, addInDict); goto checkDependencies; // after removing one addin, others could break } } } foreach (AddIn addIn in list) { try { InsertAddIn(addIn); } catch (AddInLoadException ex) { LoggingService.Error(ex); MessageService.ShowError("Error loading AddIn " + addIn.FileName + ":\n" + ex.Message); } } }
public static void Load(List <string> addInFiles, List <string> disabledAddIns) { _loadErrors.Clear(); int errCnt = 1; List <AddIn> list = new List <AddIn>(); Dictionary <string, Version> dict = new Dictionary <string, Version>(); Dictionary <string, AddIn> addInDict = new Dictionary <string, AddIn>(); foreach (string fileName in addInFiles) { // Revision: Added by Ali Özgür on 15.05.2007 if (!File.Exists(fileName)) { _loadErrors.Add(String.Format("AddIn Load Error {0}: File does not exist! \"{1}\".", errCnt, fileName)); errCnt++; continue; } AddIn addIn = AddIn.Load(fileName); if (addIn.Action == AddInAction.CustomError) { list.Add(addIn); continue; } addIn.Enabled = true; if (disabledAddIns != null && disabledAddIns.Count > 0) { foreach (string name in addIn.Manifest.Identities.Keys) { if (disabledAddIns.Contains(name)) { addIn.Enabled = false; break; } } } if (addIn.Enabled) { foreach (KeyValuePair <string, Version> pair in addIn.Manifest.Identities) { if (dict.ContainsKey(pair.Key)) { MessageService.ShowError("Name '" + pair.Key + "' is used by " + "'" + addInDict[pair.Key].FileName + "' and '" + fileName + "'"); addIn.Enabled = false; addIn.Action = AddInAction.InstalledTwice; break; } else { dict.Add(pair.Key, pair.Value); addInDict.Add(pair.Key, addIn); } } } list.Add(addIn); } checkDependencies: for (int i = 0; i < list.Count; i++) { AddIn addIn = list[i]; if (!addIn.Enabled) { continue; } Version versionFound; foreach (AddInReference reference in addIn.Manifest.Conflicts) { if (reference.Check(dict, out versionFound)) { MessageService.ShowError(addIn.Name + " conflicts with " + reference.ToString() + " and has been disabled."); DisableAddin(addIn, dict, addInDict); goto checkDependencies; // after removing one addin, others could break } } foreach (AddInReference reference in addIn.Manifest.Dependencies) { if (!reference.Check(dict, out versionFound)) { if (versionFound != null) { MessageService.ShowError(addIn.Name + " has not been loaded because it requires " + reference.ToString() + ", but version " + versionFound.ToString() + " is installed."); } else { MessageService.ShowError(addIn.Name + " has not been loaded because it requires " + reference.ToString() + "."); } DisableAddin(addIn, dict, addInDict); goto checkDependencies; // after removing one addin, others could break } } } foreach (AddIn addIn in list) { InsertAddIn(addIn); } }
public static AddIn Load(System.IO.TextReader textReader) { return(AddIn.Load(textReader, null)); }
public static void Load(System.Collections.Generic.List <string> addInFiles, List <string> disabledAddIns) { System.Collections.Generic.List <AddIn> list = new System.Collections.Generic.List <AddIn>(); System.Collections.Generic.Dictionary <string, System.Version> dictionary = new System.Collections.Generic.Dictionary <string, System.Version>(); System.Collections.Generic.Dictionary <string, AddIn> dictionary2 = new System.Collections.Generic.Dictionary <string, AddIn>(); foreach (string current in addInFiles) { AddIn addIn; try { addIn = AddIn.Load(current); } catch (System.Exception ex) { addIn = new AddIn(); addIn.addInFileName = current; addIn.CustomErrorMessage = ex.Message; } if (addIn.Action == AddInAction.CustomError) { list.Add(addIn); } else { addIn.Enabled = true; if (disabledAddIns != null && disabledAddIns.Count > 0) { foreach (string current2 in addIn.Manifest.Identities.Keys) { if (disabledAddIns.Contains(current2)) { addIn.Enabled = false; break; } } } if (addIn.Enabled) { foreach (System.Collections.Generic.KeyValuePair <string, System.Version> current3 in addIn.Manifest.Identities) { if (dictionary.ContainsKey(current3.Key)) { addIn.Enabled = false; addIn.Action = AddInAction.InstalledTwice; break; } dictionary.Add(current3.Key, current3.Value); dictionary2.Add(current3.Key, addIn); } } list.Add(addIn); } } while (true) { IL_175: for (int i = 0; i < list.Count; i++) { AddIn addIn2 = list[i]; if (addIn2.Enabled) { foreach (AddInReference current4 in addIn2.Manifest.Conflicts) { System.Version version; if (current4.Check(dictionary, out version)) { AddInTree.DisableAddin(addIn2, dictionary, dictionary2); goto IL_175; } } foreach (AddInReference current5 in addIn2.Manifest.Dependencies) { System.Version version; if (!current5.Check(dictionary, out version)) { AddInTree.DisableAddin(addIn2, dictionary, dictionary2); goto IL_175; } } } } break; } foreach (AddIn current6 in list) { try { AddInTree.InsertAddIn(current6); } catch (System.Exception ex2) { MessageBox.Show(ex2.Message); } } }