/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Show the dialog to allow the user to specify a FieldWorks database as a data source.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void HandleAddFw7DataSourceClick(object sender, EventArgs e)
        {
            string name;
            string server;

            if (!FwDBUtils.GetFw7Project(this, out name, out server))
            {
                return;
            }

            Utils.WaitCursors(true);
            var info = new FwDataSourceInfo(name, server, DataSourceType.FW7);

            if (ProjectContainsFwDataSource(info) &&
                Utils.MsgBox(string.Format(DupDataSourceMsg, info.ProjectName),
                             MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            _dataSources.Add(new PaDataSource(Project.Fields, info));
            LoadGrid(m_grid.Rows.Count);
            m_dirty = true;
            Utils.WaitCursors(false);
        }
예제 #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Creates a FieldWorks data source.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public PaDataSource(IEnumerable <PaField> projectFields, FwDataSourceInfo fwDbItem) : this()
 {
     FwDataSourceInfo = fwDbItem;
     Type             = fwDbItem.DataSourceType;
     FieldMappings    = (Type == DataSourceType.FW7 ?
                         CreateDefaultFw7Mappings(projectFields) : CreateDefaultFw6Mappings(projectFields)).ToList();
 }
예제 #3
0
        /// ------------------------------------------------------------------------------------
        private IEnumerable <FieldMapping> CreateDefaultFw7Mappings(IEnumerable <PaField> projectFields)
        {
            var prjFields         = projectFields.ToArray();
            var writingSystems    = FwDataSourceInfo.GetWritingSystems().ToArray();
            var defaultFieldNames = Properties.Settings.Default.DefaultMappedFw7Fields.Cast <string>()
                                    .Where(n => n != PaField.kAudioFileFieldName).ToList();

            // Add a mapping for the phonetic field.
            //yield return new FieldMapping(prjFields.First(f => f.Type == FieldType.Phonetic), true)
            //	{ FwWsId = FwDBUtils.GetDefaultPhoneticWritingSystem(writingSystems).Id };

            // Add a mapping for the audio file field.
            var    audioWs   = FwDBUtils.GetDefaultAudioWritingSystem(writingSystems);
            string audioWsId = audioWs != null ? audioWs.Id : null;

            yield return(new FieldMapping(prjFields.Single(f => f.Type == FieldType.AudioFilePath), false)
            {
                FwWsId = audioWsId
            });

            // Add mappings for all the other fields.
            foreach (var mapping in prjFields.Where(f => defaultFieldNames.Contains(f.Name))
                     .Select(field => new FieldMapping(field, Properties.Settings.Default.ParsedFw7Fields.Cast <string>())))
            {
                FieldMapping.CheckMappingsFw7WritingSystem(mapping, writingSystems);
                yield return(mapping);
            }
        }
예제 #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get's the data source's file name or database name when the data source is
        /// FieldWorks data direct from a FW database.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public string ToString(bool showServerForFwDataSource)
        {
            if (Type == DataSourceType.FW || Type == DataSourceType.FW7)
            {
                return(FwDataSourceInfo.ToString(showServerForFwDataSource));
            }

            return(SourceFile);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Returns true if the project contains a FW data source with the specified project
        /// and machine name.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private bool ProjectContainsFwDataSource(FwDataSourceInfo fwDataSourceInfo)
        {
            var name   = fwDataSourceInfo.Name.ToLower();
            var server = (fwDataSourceInfo.Server == null ? null : fwDataSourceInfo.Server.ToLower());

            return(_dataSources.Any(ds =>
                                    ds.FwDataSourceInfo != null &&
                                    ds.FwDataSourceInfo.Server != null &&
                                    ds.FwDataSourceInfo.Server.ToLower() == server &&
                                    ds.FwDataSourceInfo.Name != null &&
                                    ds.FwDataSourceInfo.Name.ToLower() == name));
        }
예제 #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public QueryResultOutputDlg(FwDataSourceInfo dataSourceInfo) : this()
        {
            Text = string.Format("Database: {0} on {1}",
                                 dataSourceInfo.DBName, dataSourceInfo.MachineName);

            tpgData.Text = string.Format(tpgData.Text, dataSourceInfo.DBName);

            FwDataReader reader = new FwDataReader(dataSourceInfo);

            reader.GetData(HandleReadingFwData);

            GetSQL(dataSourceInfo);
        }
예제 #7
0
        /// ------------------------------------------------------------------------------------
        private IEnumerable <FieldMapping> CreateDefaultFw6Mappings(IEnumerable <PaField> projectFields)
        {
            var writingSystems    = FwDataSourceInfo.GetWritingSystems();
            var defaultFieldNames = Properties.Settings.Default.DefaultMappedFw6Fields.Cast <string>();

            // Add mappings for all the other fields.
            return(from field in projectFields.Where(f => defaultFieldNames.Contains(f.Name))
                   let wsId = (field.Type == FieldType.Phonetic ?
                               FwDBUtils.GetDefaultPhoneticWritingSystem(writingSystems).Hvo.ToString() :
                               FieldMapping.GetDefaultFw6WsIdForField(field, writingSystems))
                              select new FieldMapping(field, field.Type == FieldType.Phonetic)
            {
                FwWsId = wsId
            });
        }
예제 #8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Makes a deep copy of the data source.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public PaDataSource Copy()
 {
     return(new PaDataSource
     {
         SourceFile = SourceFile,
         Type = Type,
         ParseType = ParseType,
         FirstInterlinearField = FirstInterlinearField,
         Editor = Editor,
         LastModification = LastModification,
         SfmRecordMarker = SfmRecordMarker,
         SkipLoadingBecauseOfProblem = SkipLoadingBecauseOfProblem,
         SkipLoading = SkipLoading,
         ToolboxSortField = ToolboxSortField,
         TotalLinesInFile = TotalLinesInFile,
         XSLTFile = XSLTFile,
         FwDataSourceInfo = (FwDataSourceInfo == null ? null : FwDataSourceInfo.Copy()),
         FieldMappings = (FieldMappings == null ? null : FieldMappings.Select(m => m.Copy()).ToList()),
     });
 }
예제 #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void GetSQL(FwDataSourceInfo dataSourceInfo)
        {
            if (dataSourceInfo.WritingSystemInfo == null || dataSourceInfo.WritingSystemInfo.Count == 0)
            {
                return;
            }

            string sql =
                (dataSourceInfo.PhoneticStorageMethod == FwDBUtils.PhoneticStorageMethod.LexemeForm ?
                 dataSourceInfo.Queries.LexemeFormSQL : dataSourceInfo.Queries.PronunciationFieldSQL);

            foreach (FwDataSourceWsInfo dswsi in dataSourceInfo.WritingSystemInfo)
            {
                string replace = string.Format("${0}Ws$", dswsi.FieldName);
                sql = sql.Replace(replace, dswsi.Ws.ToString());
            }

            sql         = sql.Replace("    ", "   ");
            sql         = sql.Replace("   ", Environment.NewLine + "  ");
            txtSQL.Text = sql;
        }