/// <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 QFConfigModel GetConfig(string filePath, string queryText) { QFConfigModel config = new QFConfigModel(); var configFileContents = _configFileReader.GetConfigFile(filePath); if (!string.IsNullOrEmpty(configFileContents)) { config = JsonConvert.DeserializeObject <QFConfigModel>(configFileContents); 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.ProjectItems, GeneratedClassFullFilename); if (target == null) { // .net core has a little problem with nested items. target = Conductor.GetItemByFilename(queryDoc.ProjectItem.ContainingProject.ProjectItems, GeneratedClassFullFilename); } _putCodeHere = new PutCodeHere(target); string currDir = Path.GetDirectoryName(queryDoc.FullName); }
/// <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 State Go(State state) { QFConfigModel config = new QFConfigModel(); var configFileContents = _configFileReader.GetConfigFile(state._1CurrDir); if (!string.IsNullOrEmpty(configFileContents)) { using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(configFileContents))) { var ser = new DataContractJsonSerializer(typeof(QFConfigModel)); config = ser.ReadObject(ms) as QFConfigModel; ms.Close(); } if (string.IsNullOrEmpty(config.provider)) { config.provider = "System.Data.SqlClient"; } } // if the query defines a QfDefaultConnection, use it. var match = Regex.Match(state._3InitialQueryText, "^--QfDefaultConnection(=|:)(?<cstr>[^\r\n]*)", RegexOptions.Multiline); if (match.Success) { config.defaultConnection = match.Groups["cstr"].Value; var matchProviderName = Regex.Match(state._3InitialQueryText, "^--QfDefaultConnectionProviderName(=|:)(?<pn>[^\r\n]*)", RegexOptions.Multiline); if (matchProviderName.Success) { config.provider = matchProviderName.Groups["pn"].Value; } else { config.provider = "System.Data.SqlClient"; } } state._4Config = config; return(state); }