public override object GetService(Type serviceType) { if (container.CanResolve(serviceType)) { return(container.Resolve(serviceType)); } return(base.GetService(serviceType)); }
public void ProcessOneQuery(Document queryDoc) { try { _ctx.InitForQuery(queryDoc); if (string.IsNullOrEmpty(_ctx.Config.DefaultConnection)) { _vsOutputWindow.Write(@"QueryFirst would like to help you, but you need to tell it where your DB is. Breaking change in 1.0.0: QueryFirst now has it's own config file. You need to create qfconfig.json beside or above your query or put --QfDefaultConnection=myConnectionString somewhere in your query file. See the Readme section at https://marketplace.visualstudio.com/items?itemName=bbsimonbb.QueryFirst "); return; // nothing to be done } if (!_tiny.CanResolve <IProvider>(_ctx.Config.Provider)) { _vsOutputWindow.Write(string.Format( @"No Implementation of IProvider for providerName {0}. The query {1} may not run and the wrapper has not been regenerated.", _ctx.Config.Provider, _ctx.BaseName )); return; } // also called in the bowels of schema fetching, for Postgres, because no notion of declarations. try { var undeclared = _ctx.Provider.FindUndeclaredParameters(_ctx.Query.Text, _ctx.Config.DefaultConnection); var newParamDeclarations = _ctx.Provider.ConstructParameterDeclarations(undeclared); if (!string.IsNullOrEmpty(newParamDeclarations)) { _ctx.Query.ReplacePattern("-- endDesignTime", newParamDeclarations + "-- endDesignTime"); } } catch (SqlException ex) { if (ex.Message.Contains("sp_describe_undeclared_parameters")) { _vsOutputWindow.Write("Unable to find undeclared parameters. You will have to do this yourself.\n"); } else { throw; } } _ctx.ResultFields = _ctx.SchemaFetcher.GetFields(_ctx.Config.DefaultConnection, _ctx.Config.Provider, _ctx.Query.Text); var code = new WrapperClassMaker() { CodeGenerationContext = _ctx, QueryFirstInterfaceType = Config?.QueryFirstInterfaceType }.TransformText(); _ctx.PutCodeHere.WriteAndFormat(code); } catch (Exception ex) { _vsOutputWindow.Write(ex.TellMeEverything()); } }
/// <summary> /// Registers a single service type. /// </summary> /// <typeparam name="TInterface">Service interface type</typeparam> /// <typeparam name="TConcrete">Concrete type implementing that interface.</typeparam> /// <param name="initializer">Optional type initializer for interface.</param> protected virtual void RegisterService <TInterface, TConcrete>(Func <TInterface, TInterface> initializer) where TInterface : class where TConcrete : class, TInterface { if (!typeof(TInterface).IsInterface) { throw new Exception("Service type must be an interface."); } if (typeof(TConcrete).IsInterface || typeof(TConcrete).IsAbstract) { throw new Exception("Implementation object must be concrete."); } if (_container.CanResolve <TInterface>()) { throw new Exception( "Interface already registered. Duplicate " + "resolution types are not allowed."); } _container.Register <TInterface, TConcrete>(); if (null != initializer) { _inits.Add(typeof(TInterface), initializer); } // END FUNCTION }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { container.Register<IEasyEvents, Core.EasyEvents>().AsSingleton(); container.Register<IEventHandler<AppStartedEvent>, AppStartedEventHandler>(); container.Register<IEventHandler<ThingHappenedEvent>, ThingHappenedEventHandler>(); container.Register<IEventHandler<PageViewedEvent>, PageViewedEventHandler>(); var events = container.Resolve<IEasyEvents>(); events.Configure(new EasyEventsConfiguration { Store = new FileSystemEventStore(), //Store = new SqlEventStore("server=.;database=test;Integrated Security=true;"), HandlerFactory = type => container.CanResolve(type) ? container.Resolve(type) : null }); events.AddProcessorForStream(new AppEvent().Stream, async (c, e) => { if (e is ThingHappenedEvent && ((ThingHappenedEvent)e).TheThing == "broke") { await events.RaiseEventAsync(new ThingHappenedEvent("Ooooh noooo!!")); } }); events.ReplayAllEventsAsync().Wait(); events.RaiseEventAsync(new AppStartedEvent()).Wait(); }
private bool OpenGenericCanResolve(TinyIoCContainer container, ILogger logger) { logger.WriteLine("OpenGenericCanResolve"); container.Register(typeof(IThing <>), typeof(DefaultThing <>)); return(container.CanResolve(typeof(IThing <int>))); }
public object GetService(Type serviceType) { object service = null; if (!_TinyIoCContainer.CanResolve(serviceType) || !_TinyIoCContainer.TryResolve(serviceType, out service)) { service = null; } return(service); }
//public void RegisterAllServices() //{ // _container.Register<ITaskFolderRepository, TaskFolderRepository>().AsMultiInstance(); // _container.Register<ITaskFolderService, TaskFolderService>().AsMultiInstance(); //} void IDependencyResolver.RegisterType(Type type) { //生命周期 var life = ParseLife(type); //实现注册 if (!_container.CanResolve(type)) { _container.Register(type).Life(life); } //接口注册 foreach (var interfaceType in type.GetInterfaces()) { if (!_container.CanResolve(interfaceType)) { _container.Register(interfaceType, type).Life(life); } } }
string GetLoaderType(SafeUri uri) { // check if GIO can find the file, which is not the case // with filenames with invalid encoding if (!fileSystem.File.Exists(uri)) { return(null); } string extension = uri.GetExtension().ToLower(); // Ignore video thumbnails if (extension == ".thm") { return(null); } // Ignore empty files if (fileSystem.File.GetSize(uri) == 0) { return(null); } var param = UriAsParameter(uri); // Get loader by mime-type string mime = fileSystem.File.GetMimeType(uri); if (container.CanResolve <IImageFile> (mime, param)) { return(mime); } // Get loader by extension return(container.CanResolve <IImageFile> (extension, param) ? extension : null); }
static void registerDefaultTypes(TinyIoCContainer kernel) { var toRegister = new[] { new { Interface = typeof(IErrorViewModel), Impl = typeof(ErrorViewModel) }, new { Interface = typeof(IWelcomeViewModel), Impl = typeof(WelcomeViewModel) }, new { Interface = typeof(IInstallingViewModel), Impl = typeof(InstallingViewModel) }, new { Interface = typeof(IUninstallingViewModel), Impl = typeof(UninstallingViewModel) }, new { Interface = typeof(IViewFor <ErrorViewModel>), Impl = typeof(ErrorView) }, new { Interface = typeof(IViewFor <WelcomeViewModel>), Impl = typeof(WelcomeView) }, new { Interface = typeof(IViewFor <InstallingViewModel>), Impl = typeof(InstallingView) }, new { Interface = typeof(IViewFor <UninstallingViewModel>), Impl = typeof(UninstallingView) }, }; foreach (var pair in toRegister.Where(pair => !kernel.CanResolve(pair.Interface))) { kernel.Register(pair.Interface, pair.Impl); } }
public TinyIoCContainer CreateContainerForAssembly(Assembly assembly) { IPackageManagerModule module = CreateModule(assembly); Type packageManagerType = module.PackageManagerType; Debug.Assert(PackageManagerType.IsAssignableFrom(packageManagerType)); var container = new TinyIoCContainer(); module.RegisterDependencies(container); if (container.CanResolve<IPackageManager>()) { throw new ConfigurationException("Package Manager should not be manually configured in the dependency injection container"); } container.Register(PackageManagerType, packageManagerType); container.Register<ILogger>((c, p) => new Logger(new Context(packageManagerType.ToString()), _log)); container.Register<IShellCommandRunner, ShellCommandRunner>(); return container; }
/* * Standard Get method */ public static TGet Get <TGet>() where TGet : class { //TODO: Look into inspecting constructor arguments var t = typeof(TGet); if (Instances.ContainsKey(typeof(TGet))) { return(Instances[typeof(TGet)] as TGet); } if (!Injector.CanResolve <TGet>()) { throw (new ArgumentException("Target type cannot be resolved: " + t.FullName)); } return(Injector.Resolve <TGet>()); }
public TinyIoCContainer CreateContainerForAssembly(Assembly assembly) { IPackageManagerModule module = CreateModule(assembly); Type packageManagerType = module.PackageManagerType; Debug.Assert(PackageManagerType.IsAssignableFrom(packageManagerType)); var container = new TinyIoCContainer(); module.RegisterDependencies(container); if (container.CanResolve <IPackageManager>()) { throw new ConfigurationException("Package Manager should not be manually configured in the dependency injection container"); } container.Register(PackageManagerType, packageManagerType); container.Register <ILogger>((c, p) => new Logger(new Context(packageManagerType.ToString()), _log)); container.Register <IShellCommandRunner, ShellCommandRunner>(); return(container); }
protected override void RequestStartup(TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines, NancyContext context) { base.RequestStartup(container, pipelines, context); var statelessAuthConfiguration = new StatelessAuthenticationConfiguration(ctx => { if (string.IsNullOrWhiteSpace(ctx.Request.Headers["access-token"].FirstOrDefault())) { return(null); } var accessToken = ctx.Request.Headers["access-token"].FirstOrDefault(); var canResolve = container.CanResolve <IDataStore>(); if (!canResolve) { return(null); } var dataStore = container.Resolve <IDataStore>(); var trackingUser = dataStore.Query <TrackingUser>() .FirstOrDefault( x => x.AccessToken.Token == accessToken && x.AccessToken.Expires > DateTime.Now); if (trackingUser == null) { return(null); } var identity = new UserIdentity(trackingUser.Username, trackingUser.Claims, trackingUser.AccessToken); identity.UserId = trackingUser.Id; return(identity); }); StatelessAuthentication.Enable(pipelines, statelessAuthConfiguration); }
public static void BuildUp(object input) { var properties = from property in input.GetType().GetProperties() where _registeredTypes.Any(x => x == property.PropertyType) select property; foreach (var property in properties) { var type = property.PropertyType; var canResolve = _container.CanResolve(type); if (canResolve && property.GetValue(input, null) == null) { try { property.SetValue(input, _container.Resolve(type)); } catch (Exception ex) { // Catch any resolution errors and ignore them } } } }
static void registerDefaultTypes(TinyIoCContainer kernel) { var toRegister = new[] { new { Interface = typeof(IProcessFactory), Impl = typeof(DefaultProcessFactory) }, new { Interface = typeof(IErrorViewModel), Impl = typeof(ErrorViewModel) }, new { Interface = typeof(IWelcomeViewModel), Impl = typeof(WelcomeViewModel) }, new { Interface = typeof(IInstallingViewModel), Impl = typeof(InstallingViewModel) }, new { Interface = typeof(IUninstallingViewModel), Impl = typeof(UninstallingViewModel) }, new { Interface = typeof(IViewFor<ErrorViewModel>), Impl = typeof(ErrorView) }, new { Interface = typeof(IViewFor<WelcomeViewModel>), Impl = typeof(WelcomeView) }, new { Interface = typeof(IViewFor<InstallingViewModel>), Impl = typeof(InstallingView) }, new { Interface = typeof(IViewFor<UninstallingViewModel>), Impl = typeof(UninstallingView) }, }; foreach (var pair in toRegister.Where(pair => !kernel.CanResolve(pair.Interface))) { kernel.Register(pair.Interface, pair.Impl); } }
public bool IsTypeRegistered(Type type) { return(_container.CanResolve(type)); }
public void ProcessOneQuery(Document queryDoc) { _tiny = TinyIoCContainer.Current; _ctx.InitForQuery(queryDoc); // Test this! If I can get source control exclusions working, team members won't get the generated file. if (!File.Exists(_ctx.GeneratedClassFullFilename)) { File.Create(_ctx.GeneratedClassFullFilename); } if (GetItemByFilename(queryDoc.ProjectItem, _ctx.GeneratedClassFullFilename) != null) { queryDoc.ProjectItem.Collection.AddFromFile(_ctx.GeneratedClassFullFilename); } // copy namespace of generated partial class from user partial class // backward compatible... var textDoc = ((TextDocument)_ctx.QueryDoc.Object()); textDoc.ReplacePattern("--designTime", "-- designTime"); textDoc.ReplacePattern("--endDesignTime", "-- endDesignTime"); try { if (string.IsNullOrEmpty(_ctx.Config.DefaultConnection)) { _vsOutputWindow.Write(@"QueryFirst would like to help you, but you need to tell it where your DB is. Breaking change in 1.0.0: QueryFirst now has it's own config file. You need to create qfconfig.json beside or above your query or put --QfDefaultConnection=myConnectionString somewhere in your query file. See the Readme section at https://marketplace.visualstudio.com/items?itemName=bbsimonbb.QueryFirst "); return; // nothing to be done } if (!_tiny.CanResolve <IProvider>(_ctx.Config.Provider)) { _vsOutputWindow.Write(string.Format( @"No Implementation of IProvider for providerName {0}. The query {1} may not run and the wrapper has not been regenerated.", _ctx.Config.Provider, _ctx.BaseName )); return; } // Use QueryFirst within QueryFirst ! // ToDo, to make this work with Postgres, store as ConnectionStringSettings with provider name. QfRuntimeConnection.CurrentConnectionString = _ctx.Config.DefaultConnection; var matchInsert = Regex.Match(_ctx.Query.Text, "^insert\\s+into\\s+(?<tableName>\\w+)\\.\\.\\.", RegexOptions.IgnoreCase | RegexOptions.Multiline); var matchUpdate = Regex.Match(_ctx.Query.Text, "^update\\s+(?<tableName>\\w+)\\.\\.\\.", RegexOptions.IgnoreCase | RegexOptions.Multiline); if (matchInsert.Success) { var statement = new ScaffoldInsert().ExecuteScalar(matchInsert.Groups["tableName"].Value); if (string.IsNullOrEmpty(statement)) { _vsOutputWindow.Write("Unknown problem generating insert.\n"); } else { var ep = textDoc.CreateEditPoint(); ep.ReplaceText(_ctx.Query.Text.Length, statement, 0); //ctx.QueryDoc.Save(); } } else if (matchUpdate.Success) { var statement = new ScaffoldUpdate().ExecuteScalar(matchUpdate.Groups["tableName"].Value); if (string.IsNullOrEmpty(statement)) { _vsOutputWindow.Write("Unknown problem generating update.\n"); } else { var ep = textDoc.CreateEditPoint(); ep.ReplaceText(_ctx.Query.Text.Length, statement, 0); //ctx.QueryDoc.Save(); } } else { // Execute query try { // also called in the bowels of schema fetching, for Postgres, because no notion of declarations. try { var undeclared = _ctx.Provider.FindUndeclaredParameters(_ctx.Query.Text, _ctx.Config.DefaultConnection); var newParamDeclarations = _ctx.Provider.ConstructParameterDeclarations(undeclared); if (!string.IsNullOrEmpty(newParamDeclarations)) { _ctx.Query.ReplacePattern("-- endDesignTime", newParamDeclarations + "-- endDesignTime"); } } catch (SqlException ex) { if (ex.Message.Contains("sp_describe_undeclared_parameters")) { _vsOutputWindow.Write("Unable to find undeclared parameters. You will have to do this yourself.\n"); } else { throw; } } _ctx.ResultFields = _ctx.SchemaFetcher.GetFields(_ctx.Config.DefaultConnection, _ctx.Config.Provider, _ctx.Query.Text); } catch (Exception ex) { StringBuilder bldr = new StringBuilder(); bldr.AppendLine("Error running query."); bldr.AppendLine(); bldr.AppendLine("/*The last attempt to run this query failed with the following error. This class is no longer synced with the query"); bldr.AppendLine("You can compile the class by deleting this error information, but it will likely generate runtime errors."); bldr.AppendLine("-----------------------------------------------------------"); bldr.AppendLine(ex.Message); bldr.AppendLine("-----------------------------------------------------------"); bldr.AppendLine(ex.StackTrace); bldr.AppendLine("*/"); File.AppendAllText(_ctx.GeneratedClassFullFilename, bldr.ToString()); throw; } _ctx.QueryHasRun = true; StringBuilder Code = new StringBuilder(); var wrapper = _tiny.Resolve <IWrapperClassMaker>(); var results = _tiny.Resolve <IResultClassMaker>(); Code.Append(wrapper.StartNamespace(_ctx)); Code.Append(wrapper.Usings(_ctx)); if (_ctx.Config.MakeSelfTest) { Code.Append(wrapper.SelfTestUsings(_ctx)); } if (_ctx.ResultFields != null && _ctx.ResultFields.Count > 0) { Code.Append(results.Usings()); } Code.Append(wrapper.MakeInterface(_ctx)); Code.Append(wrapper.StartClass(_ctx)); Code.Append(wrapper.MakeExecuteNonQueryWithoutConn(_ctx)); Code.Append(wrapper.MakeExecuteNonQueryWithConn(_ctx)); Code.Append(wrapper.MakeGetCommandTextMethod(_ctx)); Code.Append(_ctx.Provider.MakeAddAParameter(_ctx)); if (_ctx.Config.MakeSelfTest) { Code.Append(wrapper.MakeSelfTestMethod(_ctx)); } if (_ctx.ResultFields != null && _ctx.ResultFields.Count > 0) { Code.Append(wrapper.MakeExecuteWithoutConn(_ctx)); Code.Append(wrapper.MakeExecuteWithConn(_ctx)); Code.Append(wrapper.MakeGetOneWithoutConn(_ctx)); Code.Append(wrapper.MakeGetOneWithConn(_ctx)); Code.Append(wrapper.MakeExecuteScalarWithoutConn(_ctx)); Code.Append(wrapper.MakeExecuteScalarWithConn(_ctx)); Code.Append(wrapper.MakeCreateMethod(_ctx)); Code.Append(wrapper.MakeOtherMethods(_ctx)); Code.Append(wrapper.CloseClass(_ctx)); Code.Append(results.StartClass(_ctx)); foreach (var fld in _ctx.ResultFields) { Code.Append(results.MakeProperty(fld)); } } Code.Append(results.CloseClass()); // closes wrapper class if no results ! Code.Append(wrapper.CloseNamespace(_ctx)); //File.WriteAllText(ctx.GeneratedClassFullFilename, Code.ToString()); _ctx.PutCodeHere.WriteAndFormat(Code.ToString()); var partialClassFile = GetItemByFilename(_ctx.QueryDoc.ProjectItem, _ctx.CurrDir + _ctx.BaseName + "Results.cs"); new BackwardCompatibility().InjectPOCOFactory(_ctx, partialClassFile); _vsOutputWindow.Write(Environment.NewLine + "QueryFirst generated wrapper class for " + _ctx.BaseName + ".sql"); } } catch (Exception ex) { _vsOutputWindow.Write(ex.TellMeEverything()); } }
public static bool CanResolve <TClassToInject> () where TClassToInject : class { return(Injector.CanResolve <TClassToInject> ()); }
public void ProcessOneQuery(Document queryDoc) { try { ThreadHelper.ThrowIfNotOnUIThread(); _state = new State(); _queryDoc = queryDoc; _item = queryDoc.ProjectItem; ProcessUpToStep4(queryDoc, ref _state); // Test this! If I can get source control exclusions working, team members won't get the generated file. if (!File.Exists(_state._1GeneratedClassFullFilename)) { var _ = File.Create(_state._1GeneratedClassFullFilename); _.Dispose(); } if (GetItemByFilename(queryDoc.ProjectItem, _state._1GeneratedClassFullFilename) != null) { queryDoc.ProjectItem.Collection.AddFromFile(_state._1GeneratedClassFullFilename); } // We have the config, we can instantiate our provider... if (_tiny.CanResolve <IProvider>(_state._4Config.provider)) { _provider = _tiny.Resolve <IProvider>(_state._4Config.provider); } else { _vsOutputWindow.Write(@"After resolving the config, we have no provider\n"); } if (string.IsNullOrEmpty(_state._4Config.defaultConnection)) { _vsOutputWindow.Write(@"No design time connection string. You need to create qfconfig.json beside or above your query or put --QfDefaultConnection=myConnectionString somewhere in your query file. See the Readme section at https://marketplace.visualstudio.com/items?itemName=bbsimonbb.QueryFirst "); return; // nothing to be done } if (!_tiny.CanResolve <IProvider>(_state._4Config.provider)) { _vsOutputWindow.Write(string.Format( @"No Implementation of IProvider for providerName {0}. The query {1} may not run and the wrapper has not been regenerated.\n", _state._4Config.provider, _state._1BaseName )); return; } // Scaffold inserts and updates _tiny.Resolve <_5ScaffoldUpdateOrInsert>().Go(ref _state); if (_state._3InitialQueryText != _state._5QueryAfterScaffolding) { var textDoc = ((TextDocument)queryDoc.Object()); var ep = textDoc.CreateEditPoint(); ep.ReplaceText(_state._3InitialQueryText.Length, _state._5QueryAfterScaffolding, 0); } // Execute query try { new _6FindUndeclaredParameters(_provider).Go(ref _state, out string outputMessage); // if message returned, write it to output. if (!string.IsNullOrEmpty(outputMessage)) { _vsOutputWindow.Write(outputMessage); } // if undeclared params were found, add them to the .sql if (!string.IsNullOrEmpty(_state._6NewParamDeclarations)) { ReplacePattern("-- endDesignTime", _state._6NewParamDeclarations + "-- endDesignTime"); } new _7RunQueryAndGetResultSchema(new AdoSchemaFetcher(), _provider).Go(ref _state); new _8ParseOrFindDeclaredParams(_provider).Go(ref _state); } catch (Exception ex) { StringBuilder bldr = new StringBuilder(); bldr.AppendLine("Error running query."); bldr.AppendLine(); bldr.AppendLine("/*The last attempt to run this query failed with the following error. This class is no longer synced with the query"); bldr.AppendLine("You can compile the class by deleting this error information, but it will likely generate runtime errors."); bldr.AppendLine("-----------------------------------------------------------"); bldr.AppendLine(ex.Message); bldr.AppendLine("-----------------------------------------------------------"); bldr.AppendLine(ex.StackTrace); bldr.AppendLine("*/"); File.AppendAllText(_state._1GeneratedClassFullFilename, bldr.ToString()); throw; } // dump state for reproducing issues #if DEBUG using (var ms = new MemoryStream()) { var ser = new DataContractJsonSerializer(typeof(State)); ser.WriteObject(ms, _state); byte[] json = ms.ToArray(); ms.Close(); File.WriteAllText(_state._1CurrDir + "qfDumpState.json", Encoding.UTF8.GetString(json, 0, json.Length)); } #endif var code = GenerateCode(_state); //File.WriteAllText(ctx.GeneratedClassFullFilename, Code.ToString()); var genFile = GetItemByFilename(queryDoc.ProjectItem, _state._1GeneratedClassFullFilename); WriteAndFormat(genFile, code); // what was this for ???? //var partialClassFile = GetItemByFilename(_ctx.QueryDoc.ProjectItem, _state._1CurrDir + _state._1BaseName + "Results.cs"); _vsOutputWindow.Write("QueryFirst generated wrapper class for " + _state._1BaseName + ".sql" + Environment.NewLine); } catch (Exception ex) { _vsOutputWindow.Write(ex.TellMeEverything()); } }
public override bool IsRegistered(Type type, string name) { return(container.CanResolve(type, name, ResolveOptions.FailNameNotFoundOnly)); }
public bool CanResolve <ResolveType>() where ResolveType : class { return(_container.CanResolve <ResolveType>()); }
public bool CanResolve <T> () where T : class { return(mContainer.CanResolve <T>()); }
public bool IsRegistered <T>() where T : class { return(_container.CanResolve <T>(ResolveOptions.FailUnregisteredAndNameNotFound)); }
public object GetService(Type serviceType) { return(_container.CanResolve(serviceType) ? _container.Resolve(serviceType) : null); }
public void ProcessOneQuery(string sourcePath, QfConfigModel outerConfig) { try { _state = new State(); ProcessUpToStep4(sourcePath, outerConfig, ref _state); // We have the config, we can instantiate our provider... if (_tiny.CanResolve <IProvider>(_state._3Config.Provider)) { _provider = _tiny.Resolve <IProvider>(_state._3Config.Provider); } else { QfConsole.WriteLine(@"After resolving the config, we have no provider\n"); } if (string.IsNullOrEmpty(_state._3Config.DefaultConnection)) { QfConsole.WriteLine(@"No design time connection string. You need to create qfconfig.json beside or above your query or put --QfDefaultConnection=myConnectionString somewhere in your query file. See the Readme section at https://marketplace.visualstudio.com/items?itemName=bbsimonbb.QueryFirst "); return; // nothing to be done } if (!_tiny.CanResolve <IProvider>(_state._3Config.Provider)) { QfConsole.WriteLine(string.Format( @"No Implementation of IProvider for providerName {0}. The query {1} may not run and the wrapper has not been regenerated.\n", _state._3Config.Provider, _state._1BaseName )); return; } // assign some names new _4ExtractNamesFromUserPartialClass().Go(_state); // Scaffold inserts and updates _tiny.Resolve <_5ScaffoldUpdateOrInsert>().Go(ref _state); if (_state._2InitialQueryText != _state._5QueryAfterScaffolding) { } // Execute query try { new _6FindUndeclaredParameters(_provider).Go(ref _state, out string outputMessage); // if message returned, write it to output. if (!string.IsNullOrEmpty(outputMessage)) { QfConsole.WriteLine(outputMessage); } // if undeclared params were found, modify the original .sql if (!string.IsNullOrEmpty(_state._6NewParamDeclarations)) { QfTextFileWriter.WriteFile(new QfTextFile() { Filename = _state._1SourceQueryFullPath, FileContents = _state._6QueryWithParamsAdded }); } new _7RunQueryAndGetResultSchema(new AdoSchemaFetcher(), _provider).Go(ref _state); new _8ParseOrFindDeclaredParams(_provider).Go(ref _state); } catch (Exception ex) { StringBuilder bldr = new StringBuilder(); bldr.AppendLine("Error running query."); bldr.AppendLine(); bldr.AppendLine("/*The last attempt to run this query failed with the following error. This class is no longer synced with the query"); bldr.AppendLine("You can compile the class by deleting this error information, but it will likely generate runtime errors."); bldr.AppendLine("-----------------------------------------------------------"); bldr.AppendLine(ex.Message); bldr.AppendLine("-----------------------------------------------------------"); bldr.AppendLine(ex.StackTrace); bldr.AppendLine("*/"); File.AppendAllText(_state._1GeneratedClassFullFilename, bldr.ToString()); throw; } // dump state for reproducing issues #if DEBUG using (var ms = new MemoryStream()) { var ser = new DataContractJsonSerializer(typeof(State)); ser.WriteObject(ms, _state); byte[] json = ms.ToArray(); ms.Close(); File.WriteAllText(_state._1CurrDir + "qfDumpState.json", Encoding.UTF8.GetString(json, 0, json.Length)); } #endif var code = new CSharpFrameworkGenerator().Generate(_state); //File.WriteAllText(ctx.GeneratedClassFullFilename, Code.ToString()); QfTextFileWriter.WriteFile(code); QfConsole.WriteLine("QueryFirst generated wrapper class for " + _state._1BaseName + ".sql" + Environment.NewLine); } catch (Exception ex) { QfConsole.WriteLine(ex.TellMeEverything()); } }
public override object GetService(Type serviceType) { var result = _container.CanResolve(serviceType) ? _container.Resolve(serviceType) : base.GetService(serviceType); return(result); }