Exemple #1
0
 public string GetBuildNumber()
 {
     return(StartupAssembly.GetCustomAttribute <AssemblyFileVersionAttribute>()?.Version ??
            StartupAssembly.GetCustomAttribute <AssemblyVersionAttribute>()?.Version ??
            StartupAssembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion ??
            "unknown");
 }
 public CommonOptions Value()
 => new CommonOptions
 {
     Assembly         = Assembly.Value(),
     StartupAssembly  = StartupAssembly.Value(),
     DataDirectory    = DataDirectory.Value(),
     ProjectDirectory = ProjectDirectory.Value(),
     ContentRootPath  = ContentRootPath.Value(),
     RootNamespace    = RootNamespace.Value()
 };
Exemple #3
0
        protected IOperationExecutor CreateExecutor(string[] remainingArguments)
        {
            try
            {
#if NET461
                try
                {
                    return(new AppDomainOperationExecutor(
                               Assembly !.Value() !,
                               StartupAssembly !.Value(),
                               _projectDir !.Value(),
                               _dataDir !.Value(),
                               _rootNamespace !.Value(),
                               _language !.Value(),
                               _nullable !.HasValue(),
                               remainingArguments));
                }
                catch (MissingMethodException) // NB: Thrown with EF Core 3.1
                {
                    var configurationFile = (StartupAssembly !.Value() ?? Assembly !.Value() !) + ".config";
                    if (File.Exists(configurationFile))
                    {
                        AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configurationFile);
                        try
                        {
                            typeof(ConfigurationManager)
                            .GetField("s_initState", BindingFlags.Static | BindingFlags.NonPublic)
                            .SetValue(null, 0);
                            typeof(ConfigurationManager)
                            .GetField("s_configSystem", BindingFlags.Static | BindingFlags.NonPublic)
                            .SetValue(null, null);
                            typeof(ConfigurationManager).Assembly
                            .GetType("System.Configuration.ClientConfigPaths")
                            .GetField("s_current", BindingFlags.Static | BindingFlags.NonPublic)
                            .SetValue(null, null);
                        }
                        catch
                        {
                        }
                    }
                }
#elif !NETCOREAPP2_0
#error target frameworks need to be updated.
#endif
                return(new ReflectionOperationExecutor(
                           Assembly !.Value() !,
                           StartupAssembly !.Value(),
                           _projectDir !.Value(),
                           _dataDir !.Value(),
                           _rootNamespace !.Value(),
                           _language !.Value(),
                           _nullable !.HasValue(),
                           remainingArguments));
            }
            catch (FileNotFoundException ex)
                when(ex.FileName != null &&
                     new AssemblyName(ex.FileName).Name == OperationExecutorBase.DesignAssemblyName)
                {
                    throw new CommandException(
                              Resources.DesignNotFound(
                                  Path.GetFileNameWithoutExtension(
                                      StartupAssembly !.HasValue() ? StartupAssembly.Value() : Assembly !.Value())),
                              ex);
                }
        }
Exemple #4
0
        /// <summary>
        /// Load up Lynicon modules and initialise the Lynicon data API after having loaded outputs from the current Visual Studio project
        /// which references Lynicon
        /// </summary>
        /// <param name="sendMessage"></param>
        public static void InitialiseDataApi(Action <MessageEventArgs> sendMessage)
        {
            if (DataApiInitialised)
            {
                return;
            }

            EnsureLoaded(sendMessage);

            using (AppConfig.Change(WebConfigPath))
            {
                string lyniconConfigName = DefaultNs + ".LyniconConfig";

                if (sendMessage != null)
                {
                    sendMessage(new MessageEventArgs("Initializing Project Context", "Trying to load type: " + lyniconConfigName));
                }
                Type lyniconConfig = StartupAssembly.GetType(lyniconConfigName);
                if (lyniconConfig == null)
                {
                    sendMessage(new MessageEventArgs(new Exception("Cannot load type LyniconConfig: you may not have built the solution after installing the Lynicon package")));
                }


                if (sendMessage != null)
                {
                    sendMessage(new MessageEventArgs("Initializing Project Context", "Type loaded"));
                }

                var registerModulesMethod   = lyniconConfig.GetMethod("RegisterModules", BindingFlags.Static | BindingFlags.Public);
                var initialiseDataApiMethod = lyniconConfig.GetMethod("InitialiseDataApi", BindingFlags.Static | BindingFlags.Public);
                if ((registerModulesMethod == null || initialiseDataApiMethod == null) && sendMessage != null)
                {
                    sendMessage(new MessageEventArgs(new Exception("Cannot find 'RegisterModules' and 'InitialiseDataApi' methods on LyniconConfig")));
                }

                if (sendMessage != null)
                {
                    sendMessage(new MessageEventArgs("Initializing Project Context", "Initializing Data Api"));
                }
                try
                {
                    registerModulesMethod.Invoke(null, new object[0]);
                    initialiseDataApiMethod.Invoke(null, new object[0]);
                }
                catch (Exception ex)
                {
                    if (sendMessage != null)
                    {
                        sendMessage(new MessageEventArgs(ex));
                    }
                }

                if (sendMessage != null)
                {
                    sendMessage(new MessageEventArgs("Initializing Project Context", "Lynicon initialized"));
                }
            }

            DataApiInitialised = true;
        }
Exemple #5
0
        /// <summary>
        /// Set up environment parameters and load assemblies from the output of the currently running
        /// Visual Studio project
        /// </summary>
        /// <param name="sendMessage"></param>
        public static void EnsureLoaded(Action <MessageEventArgs> sendMessage)
        {
            if (ContextLoaded)
            {
                return;
            }

            EnsureDTE(sendMessage);

            if (sendMessage != null)
            {
                sendMessage(new MessageEventArgs("Initializing Project Context", "Loading assembly: " + AssPath));
            }

            System.AppDomain.CurrentDomain.SetData("APPBASE", RootPath);
            System.AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "bin");
            System.AppDomain.CurrentDomain.SetData("DataDirectory", RootPath + "\\App_Data");

            DllPath = RootPath + "\\bin\\";

            // Use the web config of the website project as config for this appdomain
            using (AppConfig.Change(WebConfigPath))
            {
                StartupAssembly = null;
                try
                {
                    StartupAssembly = Assembly.LoadFrom(AssPath);
                    var x = StartupAssembly.GetType("log4net.Config.Log4NetConfigurationSectionHandler");
                }
                catch (Exception ex)
                {
                    if (sendMessage != null)
                    {
                        if (ex is FileNotFoundException && ex.Message.StartsWith("Could not load"))
                        {
                            sendMessage(new MessageEventArgs(new Exception("Couldn't load the project assembly: you may not have compiled it", ex)));
                        }
                        else
                        {
                            sendMessage(new MessageEventArgs(ex));
                        }
                    }
                }

                Assembly efSqlAss = null;
                try
                {
                    // Load this manually as it will generally not be referenced but is referenced by Lynicon
                    efSqlAss = Assembly.LoadFrom(RootPath + "\\bin\\EntityFramework.SqlServer.dll");
                    var x = efSqlAss.GetType("System.Data.Entity.SqlServer.SqlProviderServices");
                }
                catch { }

                if (sendMessage != null)
                {
                    sendMessage(new MessageEventArgs("Initializing Project Context", "Assembly loaded"));
                }
            }

            ContextLoaded = true;
        }
 public override void SetupSwaggerGen(SwaggerGenOptions options, string xmlPath = null)
 {
     base.SetupSwaggerGen(options, StartupAssembly.GetXmlCommentsFile());
 }