/// <summary> /// Returns the QueryFirst config for a given query file. Values specified directly in /// the query file will trump values specified in the qfconfig.json file. /// We look for a qfconfig.json file beside the query file. If none found, we look in the parent directory, /// and so on up to the root directory. /// /// If the query specifies a QfDefaultConnection but no QfDefaultConnectionProviderName, "System.Data.SqlClient" /// will be assumed. /// </summary> /// <param name="filePath"></param> /// <param name="queryText"></param> /// <returns></returns> public IQFConfigModel GetConfig(string filePath, string queryText) { IQFConfigModel config = TinyIoCContainer.Current.Resolve <IQFConfigModel>(); var configFileContents = _configFileReader.GetConfigFile(filePath); if (!string.IsNullOrEmpty(configFileContents)) { config = (IQFConfigModel)JsonConvert.DeserializeObject(configFileContents, config.GetType()); if (string.IsNullOrEmpty(config.Provider)) { config.Provider = "System.Data.SqlClient"; } } // if the query defines a QfDefaultConnection, use it. var match = Regex.Match(queryText, "^--QfDefaultConnection(=|:)(?<cstr>[^\r\n]*)", RegexOptions.Multiline); if (match.Success) { config.DefaultConnection = match.Groups["cstr"].Value; var matchProviderName = Regex.Match(queryText, "^--QfDefaultConnectionProviderName(=|:)(?<pn>[^\r\n]*)", RegexOptions.Multiline); if (matchProviderName.Success) { config.Provider = matchProviderName.Groups["pn"].Value; } else { config.Provider = "System.Data.SqlClient"; } } return(config); }
public void InitForQuery(Document queryDoc) { tiny = TinyIoCContainer.Current; queryHasRun = false; this.queryDoc = queryDoc; dte = queryDoc.DTE; query = new Query(this); _config = _configResolver.GetConfig(queryDoc.FullName, query.Text); if (string.IsNullOrEmpty(Config.DefaultConnection)) { return; // absence will be picked up in conductor. Not fabulous. } provider = tiny.Resolve <IProvider>(Config.Provider); // resolving the target project item for code generation. We know the file name, we loop through child items of the query til we find it. var target = Conductor.GetItemByFilename(queryDoc.ProjectItem, GeneratedClassFullFilename); _putCodeHere = new PutCodeHere(target); string currDir = Path.GetDirectoryName(queryDoc.FullName); }