/// <summary> /// Constructs App from the manifest /// </summary> /// <param name="root">Root of the manifest xml</param> /// <returns>App object</returns> public static App Parse(XmlDocument root) { #region argument if (root == null) { throw new ArgumentNullException("root"); } #endregion XmlNode manifest = root.SelectSingleNode("manifest"); App app = new App(); try { app.Name = manifest.SelectSingleNode("name").InnerText; app.Publisher = manifest.SelectSingleNode("publisher").InnerText; app.Description = manifest.SelectSingleNode("description").InnerText; app.UniqueId = new Guid(manifest.SelectSingleNode("uniqueid").InnerText); app.Version = Version.Parse(manifest.SelectSingleNode("version").InnerText); app.Scope = (AppScope)Enum.Parse(typeof(AppScope), manifest.SelectSingleNode("scope").InnerText, true); app.File = manifest.SelectSingleNode("file").Attributes["name"].Value; } catch (NullReferenceException) { throw new MessageException(ResourceManager.GetMessage(AppsMessages.ManadatoryFieldsMissing)); } // for abstract apps, file entry must be defined. if (app.IsAbstractApp()) { try { app.FileEntry = manifest.SelectSingleNode("file").Attributes["entry"].Value; } catch (NullReferenceException) { throw new MessageException(ResourceManager.GetMessage(AppsMessages.ManadatoryFieldsMissing)); } // make sure the file is an assembly extension. if (!app.File.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) { throw new MessageException(ResourceManager.GetMessage(AppsMessages.FileNameMustBeAssembly)); } } XmlNode node = manifest.SelectSingleNode("url"); if (node != null) { app.Url = node.InnerText; } //icon node = manifest.SelectSingleNode("icon"); if (node != null) { app.IconUrl = node.InnerText; } //add fields AddFields(app, manifest); //add references to the app. AddReferences(app, manifest); return app; }
private static AbstractApp GetDefinedApp(App app) { if (app == null) { throw new ArgumentNullException("app"); } AbstractApp definedApp = null; if (app.IsAbstractApp()) { // get the app file and entry. string file = app.File; string entry = app.FileEntry; // load the assembly, it will throw exception if needed. Assembly assembly = AssemblyUtility.Load( HttpContext.Current.Server.MapPath(string.Format("{0}/{1}/{2}", SitePaths.App, app.Location, app.File)) ); // load the app from the assembly Type type = assembly.GetType(entry, false); if (type == null) { // unable to load the class from the assembly throw new MessageException( string.Format(ResourceManager.GetLiteral("Admin.Apps.AppEntryNotFound"), entry, app.File) ); } // create the abstractapp try { definedApp = Activator.CreateInstance(type) as AbstractApp; definedApp.InvokedApp = app; } catch (Exception exception) { // not a valid type for abstractapp logger.Log(LogLevel.Warn, "Unable to create abstractapp of type : {0}. Exception - {1}", type, exception); } if (definedApp == null) { // unable to create app throw new MessageException( string.Format(ResourceManager.GetLiteral("Admin.Apps.InvalidAppEntry"), app.FileEntry) ); } } else { // throw as the app is not of the scope // that can be translated into AbstractApp. throw new InvalidOperationException("app"); } #if DEBUG if (definedApp == null) { //something went wrong throw new InvalidOperationException("definedApp should not be null now"); } #endif return definedApp; }