Example #1
0
        public ModuleLoader(IAuthentication authentication, IDataService dataService, ILogger logger)
        {
            _authentication = authentication;
            _dataService    = dataService;
            _logger         = logger;

            BinPath  = Assembly.GetExecutingAssembly().Location;
            BinPath  = BinPath.Substring(0, BinPath.LastIndexOf('\\'));
            DataPath = CoreExtensionApplication._current.Configuration.AppData;

            _loadedModules = new Dictionary <string, Module>();

            _logger.Entry($"Loading modules from {BinPath} and {DataPath}.", Severity.Debug);
            if (CoreExtensionApplication._current.Configuration.EnableModuleUpdate)
            {
                ProcessManifest();
            }
        }
Example #2
0
        internal Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            Logger.Trace(m => m("OnAssemblyResolve, args.Name = '{0}', args.RequestingAssembly = '{1}'", args.Name, args.RequestingAssembly != null ? args.RequestingAssembly.FullName : string.Empty));
            if (File.Exists(args.Name))
            {
                Logger.Trace(m => m("Requested name '{0}' is an existing file, will try to load it", args.Name));
                return(Assembly.LoadFrom(args.Name));
            }

            string fileName = GetFileName(args.Name);

            foreach (Assembly assembly in BinPath.Select(binFolder => LoadAssemblyFromFolder(args.Name, fileName, binFolder)).Where(assembly => assembly != null))
            {
                return(assembly);
            }

            Logger.Warn(m => m("Assembly not found: '{0}'", args.Name));
            return(null);
        }
Example #3
0
        public ModuleLoader(IAuthentication authentication, ILogger <CoreExtensionApplication> logger, IConfiguration config)
        {
            _authentication = authentication;
            _logger         = logger;
            _config         = config;

            BinPath  = Assembly.GetExecutingAssembly().Location;
            BinPath  = BinPath.Substring(0, BinPath.LastIndexOf('\\'));
            DataPath = _config["AppData"];

            _loadedModules = new Dictionary <string, Module>();

            _logger.LogDebug($"Loading modules from {BinPath} and {DataPath}.");

            /*if (_config.EnableModuleUpdate)
             * {
             *  ProcessManifest();
             * }*/
        }
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            try
            {
                var        binRelative   = BinPath.Replace(ProjectDir + "\\", "");
                var        hooksRelative = HooksPath.Replace(ProjectDir + "\\", "");
                var        fileRelative  = FilePath.Replace(ProjectDir + "\\", "");
                XDocument  document      = XDocument.Load(ProjectPath);
                XNamespace ns            = "http://schemas.microsoft.com/developer/msbuild/2003";

                bool     foundBin   = false;
                bool     foundHooks = false;
                bool     foundFile  = false;
                XElement itemGroup  = null;
                foreach (XElement el in document.Descendants(ns + "ItemGroup"))
                {
                    foreach (XElement item in el.Descendants(ns + "Compile"))
                    {
                        itemGroup = el;
                        if (item.Attribute("Include").Value.Contains(binRelative))
                        {
                            foundBin = true;
                            Log.LogMessage(MessageImportance.Low, "FoundBin: {0}", foundBin);
                        }
                        else if (item.Attribute("Include").Value.Contains(hooksRelative))
                        {
                            foundHooks = true;
                            Log.LogMessage(MessageImportance.Low, "FoundHooks: {0}", foundHooks);
                        }
                        else if (item.Attribute("Include").Value.Contains(fileRelative))
                        {
                            foundFile = true;
                            Log.LogMessage(MessageImportance.Low, "FoundFile: {0}", foundFile);
                        }
                    }
                }

                if (!foundBin)
                {
                    XElement item = new XElement(ns + "Compile");
                    item.SetAttributeValue("Include", binRelative);
                    if (itemGroup != null)
                    {
                        itemGroup.Add(item);
                    }
                }
                if (!foundHooks)
                {
                    XElement item = new XElement(ns + "Compile");
                    item.SetAttributeValue("Include", hooksRelative);
                    if (itemGroup != null)
                    {
                        itemGroup.Add(item);
                    }
                }
                if (!foundFile)
                {
                    XElement item = new XElement(ns + "Compile");
                    item.SetAttributeValue("Include", fileRelative);
                    if (itemGroup != null)
                    {
                        itemGroup.Add(item);
                    }
                }
                if (!foundBin || !foundHooks || !foundFile)
                {
                    document.Save(ProjectPath);
                }
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }

            return(!Log.HasLoggedErrors);
        }