public void ReadXml() { string xml = "<extension name=\"test\" version=\"1.0.0\"><class></class></extension>"; ExtensionInfo info = new ExtensionInfo(); XmlReader reader = XmlReader.Create(new System.IO.StringReader(xml)); while (!reader.IsStartElement()) { reader.Read(); } info.ReadXml(reader); Assert.AreEqual("test", info.Name); Assert.AreEqual(new Version("1.0.0"), info.Version); Assert.IsNull(info.Author); Assert.IsNull(info.Description); Assert.IsNull(info.Dependencies); Assert.IsEmpty(info.Class); xml = "<extension version=\"1.0\" name=\"My displayed name\"><class>the full qualified name of the class implementing the extension</class><author>Someone</author><dependencies><dependency>a fullname to the extension</dependency><dependency>a second extension</dependency></dependencies></extension>"; reader = XmlReader.Create(new System.IO.StringReader(xml)); while (!reader.IsStartElement()) { reader.Read(); } info = new ExtensionInfo(); info.ReadXml(reader); Assert.AreEqual("My displayed name", info.Name); Assert.AreEqual(new Version("1.0"), info.Version); Assert.IsNull(info.Description); Assert.AreEqual("a fullname to the extension", info.Dependencies[0]); Assert.AreEqual("a second extension", info.Dependencies[1]); Assert.AreEqual(info.Class, "the full qualified name of the class implementing the extension"); }
public LoggingExtension(IrcSharkApplication app, ExtensionInfo info) : base("Logging", info) { this.app = app; IrcShark.Connections.Added += new IrcSharp.Extended.AddedEventHandler<IrcSharp.Extended.IrcConnection>(Connections_Added); IrcShark.Connections.Removed += new IrcSharp.Extended.RemovedEventHandler<IrcSharp.Extended.IrcConnection>(Connections_Removed); }
public ExtensionInfo(ExtensionInfo baseInfo) { SourceAssemblyValue = baseInfo.SourceAssembly; AssemblyGUIDValue = baseInfo.AssemblyGuid; SourceFileValue = baseInfo.SourceFile; TypeNameValue = baseInfo.TypeName; }
/// <summary> /// Initializes a new instance of the ExtensionInfoBuilder class for the given assembly. /// </summary> /// <param name="fileName">The file name and path to the assembly to check.</param> public ExtensionInfoBuilder(string fileName) { ExtensionInfo ei; Type[] types; resultExtensions = new ExtensionInfoCollection(); Type ropt = typeof(Extension); sourceAssembly = Assembly.ReflectionOnlyLoadFrom(fileName); ropt = ReflectionOnlyTypeFromAssembly(sourceAssembly, ropt); try { types = sourceAssembly.GetExportedTypes(); foreach (Type t in types) { try { if (t.IsSubclassOf(ropt) && !t.IsAbstract) { ei = new ExtensionInfo(t); resultExtensions.Add(ei); } } catch (ArgumentOutOfRangeException) { ei = null; } } } catch (ReflectionTypeLoadException) { return; } }
public IrcCloneSharkExtension(IrcSharkApplication sharkApp, ExtensionInfo myInfo) : base("IrcShark GUI (mIRC-Clone)", myInfo) { IrcSharkApp = sharkApp; IrcSharkApp.ShowGUI = false; Console.Out.WriteLine("IrcCloneShark loaded!"); MainFormValue = new MainForm(this); MainFormValue.Show(); }
public ExtensionInfoBuilder(String fileName) { ExtensionInfo ei; Type[] types; AssemblyName AsmName; Type ropt = typeof(Extension); ResultExtensions = new List<ExtensionInfo>(); AsmName = AssemblyName.GetAssemblyName(fileName); SourceAssembly = Assembly.ReflectionOnlyLoadFrom(fileName); foreach (AssemblyName asm in SourceAssembly.GetReferencedAssemblies()) { if (asm.FullName == typeof(Extension).Assembly.FullName) { foreach(Type t in Assembly.ReflectionOnlyLoad(asm.FullName).GetExportedTypes()) { if (t.Name == "Extension") { ropt = t; } } } else Assembly.ReflectionOnlyLoad(asm.FullName); } try { types = SourceAssembly.GetExportedTypes(); foreach (Type t in types) { try { if (t.IsSubclassOf(ropt)) { ei = new ExtensionInfo(t); ResultExtensions.Add(ei); } } catch(ArgumentOutOfRangeException) { ei = null; } } } catch (ReflectionTypeLoadException) { } }
/// <summary> /// Initializes a new instance of the ExtensionContext class. /// </summary> internal ExtensionContext(IrcSharkApplication app, ExtensionInfo info) { this.app = app; this.info = info; foreach (string path in app.SettingsDirectorys) { if (Directory.Exists(Path.Combine(path, info.Class))) { this.settingPath = Path.Combine(path, info.Class); } } if (this.settingPath == null) { this.settingPath = Path.Combine(app.SettingsDirectorys.Default, info.Class); Directory.CreateDirectory(this.settingPath); } }
public Extension(String Name, ExtensionInfo ownInfo) { NameValue = Name; }
public StatusChangedEventArgs(ExtensionInfo ext, ExtensionStates status) { ExtensionValue = ext; StatusValue = status; }
public void Constructor() { ExtensionInfo info = new ExtensionInfo(); Assert.IsNotNull(info); }
/// <summary> /// Checks if the current ExtensionInfo is compatible to the given one. /// </summary> /// <param name="info"> /// The ExtensionInfo to check for compatiblity. /// </param> /// <returns> /// Returns true if the given ExtensionInfo describes the same extension /// with the same or a newer version number. /// </returns> public bool CompatibleWith(ExtensionInfo info) { if (info == null) { return false; } if (!info.Class.Equals(Class)) { return false; } if (info.Version.CompareTo(Version) < 0) { return false; } return true; }
/// <summary> /// Initializes a new instance of the ExtensionException class for the given extension with the given message. /// </summary> /// <param name="info"> /// The <see cref="ExtensionInfo"/> for the extension causing the exception. /// </param> /// <param name="msg"> /// The message of the exception. /// </param> public ExtensionException(ExtensionInfo info, string msg) : base(msg) { this.info = info; }
/// <summary> /// Give information about if the given extension will be unloaded next time IrcShark starts. /// </summary> /// <returns>true, if the extension will be unloaded, else false</returns> public bool IsMarkedForUnload(ExtensionInfo ext) { if (!IsLoaded(ext)) return true; foreach (ExtensionManagerSettings.EditableExtensionInfo enabledExt in Settings.EnabledExtensions) { if (enabledExt.Equals(ext)) return false; } return true; }
/// <summary> /// Checks if the given extension is loaded or not. /// </summary> /// <returns>true, if the extension is loaded, else false</returns> public bool IsLoaded(ExtensionInfo info) { return Extensions.ContainsKey(info); }
public bool Equals(ExtensionInfo info) { //return AssemblyGuid == info.AssemblyGuid; return TypeName == info.TypeName; }
private static void WriteLoadedExtensions(XmlWriter writer, ExtensionInfo[] loaded) { if (loaded.Length > 0) { writer.WriteStartElement("loaded"); foreach (ExtensionInfo ext in loaded) { ext.WriteXml(writer); } writer.WriteEndElement(); } }
/// <summary> /// Reads the list of loaded extensions. /// </summary> /// <param name="reader">The reader to read from.</param> private void ReadLoadedExtensions(XmlReader reader) { reader.Read(); while (true) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "extension": try { ExtensionInfo info = new ExtensionInfo(); info.ReadXml(reader); loadedExtensions.Add(info); } catch (Exception ex) { throw new ConfigurationException("couldn't load extension info", ex); } break; default: reader.Skip(); break; } break; case XmlNodeType.EndElement: reader.Read(); return; default: if (!reader.Read()) { return; } break; } } }
/// <summary> /// Loads the given extension. /// </summary> public void Load(ExtensionInfo ext) { if (IsLoaded(ext)) { if (IsMarkedForUnload(ext)) { Settings.EnabledExtensions.Add(new ExtensionManagerSettings.EditableExtensionInfo(ext)); if (StatusChanged != null) StatusChanged(this, new StatusChangedEventArgs(ext, ExtensionStates.Loaded)); } return; } if (HiddenLoad(ext)) Settings.EnabledExtensions.Add(new ExtensionManagerSettings.EditableExtensionInfo(ext)); }
/// <summary> /// Initializes a new instance of the ExtensionException class for the given extension. /// </summary> /// <param name="info"> /// The <see cref="ExtensionInfo"/> for the extension causing the exception. /// </param> public ExtensionException(ExtensionInfo info) : base(String.Format("Exception caused by extension {0} ", info.Name)) { this.info = info; }
/// <summary> /// Marks the given extension to be unladed next time IrcShark starts. /// </summary> public void Unload(ExtensionInfo ext) { if (!IsLoaded(ext)) return; List<ExtensionManagerSettings.EditableExtensionInfo> toRemove = new List<ExtensionManagerSettings.EditableExtensionInfo>(); foreach (ExtensionManagerSettings.EditableExtensionInfo enabledExt in Settings.EnabledExtensions) { if (enabledExt.Equals(ext)) { toRemove.Add(enabledExt); } } foreach (ExtensionManagerSettings.EditableExtensionInfo toDel in toRemove) { Settings.EnabledExtensions.Remove(toDel); } if (StatusChanged != null) StatusChanged(this, new StatusChangedEventArgs(ext, ExtensionStates.MarkedForUnload)); }
bool HiddenLoad(ExtensionInfo ext) { Extension newExtension; if (IsLoaded(ext)) return false; newExtension = (Extension)AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(ext.SourceFile, ext.TypeName, false, System.Reflection.BindingFlags.CreateInstance, null, new Object[] { AppValue, ext }, null, null, null); ExtensionsValue.Add(ext, newExtension); if (StatusChanged != null) StatusChanged(this, new StatusChangedEventArgs(ext, ExtensionStates.Loaded)); return true; }
/// <summary> /// Compares this ExtensionInfo with another one. /// </summary> /// <param name="info">The ExtensionInfo to compare with.</param> /// <returns>Returns true, if the objects are equal, false otherwise.</returns> public bool CompareTo(ExtensionInfo info) { if (info == null) { return false; } if (!info.AssemblyGuid.Equals(AssemblyGuid)) { return false; } if (!info.Class.Equals(Class)) { return false; } return true; }