コード例 #1
0
ファイル: ExtCommon.cs プロジェクト: xzoth/ACMESharp
        public static TExtConfig InitExtConfig <TExtConfig>() where TExtConfig : new()
        {
            var aggCat = new AggregateCatalog();

            // Add the assembly that contains the current Component/Provider Scaffold
            var thisAsm = Assembly.GetExecutingAssembly();

            aggCat.Catalogs.Add(new AssemblyCatalog(thisAsm));

            // Add assemblies in the current apps path and runtime
            aggCat.Catalogs.Add(new AppCatalog(BaseDirectoryOverride, RelativeSearchPathOverride));

            // Add the local extension folder if it exists
            var thisExt = ExtCommon.GetExtPath();

            if (Directory.Exists(thisExt))
            {
                aggCat.Catalogs.Add(new DirectoryCatalog(thisExt));
            }

            // Other possible folders to include:
            //    * Application CWD
            //    * PATH
            //    * User-specific ext folder
            //    * System-wide ext folder

            var config = new TExtConfig();

            // Guard this with a try-catch if we want to do something
            // in an error situation other than let it throw up
            var cc = new CompositionContainer(aggCat);

            cc.ComposeParts(config);

            if (config is IExtDetail)
            {
                ((IExtDetail)config).CompositionContainer = cc;
            }
            else
            {
                cc.Dispose();
            }

            return(config);
        }
コード例 #2
0
        public static TExtConfig InitExtConfig <TExtConfig>() where TExtConfig : new()
        {
            var aggCat = new AggregateCatalog();

            // Add the assembly that contains the current Component/Provider Scaffold
            var thisAsm = Assembly.GetExecutingAssembly();

            aggCat.Catalogs.Add(new AssemblyCatalog(thisAsm));

            // Add assemblies in the current apps path and runtime
            aggCat.Catalogs.Add(new AppCatalog(BaseDirectoryOverride, RelativeSearchPathOverride));

            // Add the local extension folder if it exists
            var thisExt = ExtCommon.GetExtPath();

            if (Directory.Exists(thisExt))
            {
                aggCat.Catalogs.Add(new DirectoryCatalog(thisExt));

                if (IncludeExtPathFolders)
                {
                    // Add each immediate child directory as well
                    foreach (var d in Directory.GetDirectories(thisExt))
                    {
                        aggCat.Catalogs.Add(new DirectoryCatalog(d));
                    }
                }

                if (IncludeExtPathLinks)
                {
                    // Add each folder that's defined in ExtPathLink definition file
                    foreach (var f in Directory.GetFiles(thisExt, "*.extlnk"))
                    {
                        try
                        {
                            var epl = JsonHelper.Load <ExtPathLink>(File.ReadAllText(f));
                            aggCat.Catalogs.Add(new DirectoryCatalog(epl.Path));
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("failed to resolve extension link", ex)
                                  .With(nameof(ExtPathLink), f);
                        }
                    }
                }
            }

            // Other possible folders to include:
            //    * Application CWD
            //    * PATH
            //    * User-specific ext folder
            //    * System-wide ext folder

            var config = new TExtConfig();

            // Guard this with a try-catch if we want to do something
            // in an error situation other than let it throw up
            var cc = new CompositionContainer(aggCat);

            cc.ComposeParts(config);

            if (config is IExtDetail)
            {
                ((IExtDetail)config).CompositionContainer = cc;
            }
            else
            {
                cc.Dispose();
            }

            return(config);
        }