/// ------------------------------------------------------------------------------------ public void Read(RecordCache recCache) { var allLexEntries = FwDBUtils.GetLexEntriesFromFw7Project(m_fwDsInfo).ToArray(); if (allLexEntries == null) { return; } m_worker.ReportProgress(allLexEntries.Length, m_dataSource.DisplayTextWhenReading); var customnames = m_customfield.FieldNames(); foreach (var lxEntry in allLexEntries) { m_worker.ReportProgress(0); var entry = ReadSingleLexEntry(lxEntry); if (entry != null) { var customvalues = m_customfield.CustomValues.FindAll(m => m.Guid == lxEntry.Guid.ToString()); SetCustomFieldsforEntry(customnames, customvalues, entry); if (m_dataSource.FwDataSourceInfo != null && m_dataSource.FwDataSourceInfo.PhoneticSourceField != null) { var vernacularMapping = new PaField(m_dataSource.FwDataSourceInfo.PhoneticSourceField); entry.SetValue(PaField.kPhoneticSourceFieldName.ToString(CultureInfo.InvariantCulture), m_fwDsInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.PronunciationField && m_fwDsInfo.PhoneticStorageMethod != FwDBUtils.PhoneticStorageMethod.AllPronunciationFields ? vernacularMapping.Name : m_fwDsInfo.PhoneticStorageMethod.ToString()); } recCache.Add(entry); } } m_dataSource.UpdateLastModifiedTime(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the data from the SQL database. Returns false if reading failed. /// </summary> /// ------------------------------------------------------------------------------------ public bool GetData() { if (m_fwDsInfo.Queries == null || m_fwDsInfo.Queries.Error) { return(false); } string sql = (m_fwDsInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.LexemeForm ? m_fwDsInfo.Queries.LexemeFormSQL : m_fwDsInfo.Queries.PronunciationFieldSQL); if (m_dataSource.FieldMappings == null || m_dataSource.FieldMappings.Count == 0) { ErrorReport.NotifyUserOfProblem(LocalizationManager.GetString( "Miscellaneous.Messages.DataSourceReading.MissingFieldWorks6WritingSystemsMsg", "There are no writing systems for the '{0}' project. Therefore, no data " + "from it can be displayed. To fix this problem, modify the FieldWorks data " + "source properties for this project by selecting 'Project Settings' from " + "the File menu. Then select the project in the data sources list and click " + "the 'Properties' button."), m_fwDsInfo.ProjectName); return(true); } foreach (var fname in Properties.Settings.Default.AllPossibleFw6Fields.Cast <string>()) { var mapping = m_dataSource.FieldMappings.SingleOrDefault(m => m.Field.Name == fname); var replace = string.Format("${0}Ws$", fname); sql = sql.Replace(replace, (mapping != null && mapping.FwWsId != null ? mapping.FwWsId : "0")); } try { using (var connection = FwDBUtils.FwConnection(m_fwDsInfo.Name, m_fwDsInfo.Server)) { var command = new SqlCommand(sql, connection); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { HandleReadingFwData(reader); } reader.Close(); } connection.Close(); } } catch (Exception e) { ErrorReport.NotifyUserOfProblem(e, LocalizationManager.GetString( "Miscellaneous.Messages.DataSourceReading.ErrorRetrievingFieldWorks6DataMsg", "There was an error retrieving the data from the {0} database. It's " + "possible the file '{1}' is either missing or corrupt. Reading this " + "data will be skipped."), m_fwDsInfo.Name, Path.GetFileName(m_fwDsInfo.Queries.QueryFile)); return(false); } return(true); }
/// ------------------------------------------------------------------------------------ internal static FwQueries GetQueriesForDB(string dbName, string machineName) { string longNameCheckSQL = FwDBAccessInfo.LongNameCheckSQL; if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(longNameCheckSQL)) { return(null); } FwQueries fwqueries = null; using (SqlConnection connection = FwDBUtils.FwConnection(dbName, machineName)) { if (connection != null) { try { SqlCommand command = new SqlCommand(longNameCheckSQL, connection); using (SqlDataReader reader = command.ExecuteReader()) { reader.Close(); if (s_fwLongNameQueries == null) { s_fwLongNameQueries = Load("FwSQLQueries.xml"); } fwqueries = s_fwLongNameQueries; } } catch { if (s_fwShortNameQueries == null) { s_fwShortNameQueries = CheckForShortNameFile(dbName, machineName, "FwSQLQueriesShortNames.xml") ? Load("FwSQLQueriesShortNames.xml") : new FwQueries(true); } fwqueries = s_fwShortNameQueries; } connection.Close(); } } return(fwqueries); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the writing systems returned by the SQL statement found in the specified file. /// </summary> /// ------------------------------------------------------------------------------------ private static Dictionary <int, string> GetWritingSystemsUsingQuery(string sql, FwDataSourceInfo fwDsInfo, string errMsg) { var wsCollection = new Dictionary <int, string>(); try { using (var connection = FwDBUtils.FwConnection(fwDsInfo.Name, fwDsInfo.Server)) { if (connection != null && !string.IsNullOrEmpty(sql)) { var command = new SqlCommand(sql, connection); using (var reader = command.ExecuteReader()) { while (reader.Read()) { wsCollection[(int)reader["Obj"]] = reader["Txt"] as string; } reader.Close(); } connection.Close(); } } // There should be at least one writing system defined. if (wsCollection.Count == 0) { ErrorReport.NotifyUserOfProblem(errMsg, fwDsInfo.Name, Path.GetFileName(fwDsInfo.Queries.QueryFile)); } } catch (Exception e) { ErrorReport.NotifyUserOfProblem(e, errMsg, fwDsInfo.Name, Path.GetFileName(fwDsInfo.Queries.QueryFile)); } return(wsCollection); }
/// ------------------------------------------------------------------------------------ public IEnumerable<FwWritingSysInfo> GetWritingSystems() { return m_writingSystems ?? (m_writingSystems = (DataSourceType == DataSourceType.FW ? Fw6WritingSystemReader.GetWritingSystems(this) : FwDBUtils.GetWritingSystemsForFw7Project(Name, Server)).ToList()); }