Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static SkippedDataSourceList Load(PaProject project)
        {
            if (project != null)
            {
                SkippedDataSourceList sdsl = new SkippedDataSourceList();
                foreach (PaDataSource ds in project.DataSources)
                {
                    sdsl[ds.ToString(true)] = false;
                }

                string filename = project.ProjectPathFilePrefix + kDataSourceInfoFilePrefix;

                if (File.Exists(filename))
                {
                    InternalSkipList skipList = STUtils.DeserializeData(filename,
                                                                        typeof(InternalSkipList)) as InternalSkipList;

                    if (skipList != null)
                    {
                        foreach (string dsName in skipList)
                        {
                            if (sdsl.ContainsKey(dsName))
                            {
                                sdsl[dsName] = true;
                            }
                        }
                    }
                }

                return(sdsl);
            }

            return(new SkippedDataSourceList());
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Rectangle rc = ClientRectangle;

            if (m_insertMode || Capture)
            {
                PaintingHelper.DrawHotBackground(e.Graphics, rc, PaintState.Hot);
                if (m_labels.Count > 0 && m_insertMode)
                {
                    DrawInsertionMarker(e.Graphics);
                }
            }
            else
            {
                m_insertPoint = new Point(0, rc.Bottom - 3);

                if (m_labels.Count > 0)
                {
                    e.Graphics.FillRectangle(SystemBrushes.Control, rc);
                }
                else
                {
                    // At this point, we know the panel is empty and the mouse isn't over it.
                    // Therefore, fill in the background so the user can see there is something
                    // here. Otherwise the panel would be invisible.
                    Color clr1 = SystemColors.ControlDark;
                    Color clr2 = ColorHelper.CalculateColor(Color.White, clr1, 30);
                    using (LinearGradientBrush br = new LinearGradientBrush(rc, Color.White, clr2, 60))
                        e.Graphics.FillRectangle(br, rc);

                    // Draw a border around the label.
                    ControlPaint.DrawBorder(e.Graphics, rc, SystemColors.ButtonShadow,
                                            ButtonBorderStyle.Solid);
                }
            }

            // Put the word "Empty" (or localized equivalent) in the panel when
            // it doesn't yet contain a search pattern.
            if (m_labels.Count == 0)
            {
                using (Font fnt = new Font(FontHelper.UIFont.Name, 8, GraphicsUnit.Point))
                    using (StringFormat sf = STUtils.GetStringFormat(true))
                    {
                        e.Graphics.DrawString(Properties.Resources.kstidEmptySearchPatternText, fnt,
                                              SystemBrushes.ControlText, rc, sf);
                    }

                if (!m_insertMode && m_tooltip.GetToolTip(this) != m_emptyPatternTooltip)
                {
                    m_tooltip.SetToolTip(this, m_emptyPatternTooltip);
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Determines whether or not the PaAddOnMediator.dll assembly exists in the add-on
        /// folder. Returns true if it does. This add-on depends on the existence of that
        /// assembly.
        /// </summary>
        /// <param name="assembly">This add-on's assembly object.</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private bool VerifyAddOnMediatorExists(Assembly assembly)
        {
            string assemblyPath = Path.GetDirectoryName(assembly.Location);

            if (!File.Exists(Path.Combine(assemblyPath, "PaAddOnMediator.dll")))
            {
                string msg = Properties.Resources.kstidAddOnMediatorMissingMsg;
                msg = string.Format(msg, Path.GetFileName(assembly.Location), assemblyPath);
                STUtils.STMsgBox(msg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            return(true);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected bool OnBeforeXYChartFilled(object args)
        {
            try
            {
                STUtils.SetWindowRedraw(m_xyGrid, false, false);
                OnResetAutoFilledChart(null);
                bool dirtyState = m_xyGrid.IsDirty;

                for (int i = 1; i < m_xyGrid.ColumnCount; i++)
                {
                    string environment = m_xyGrid[i, 0].Value as string;
                    if (environment != null)
                    {
                        if (environment.Contains(kAutoFillConMarker))
                        {
                            FillCVInEnvironment(IPACharacterType.Consonant, environment, i);
                        }
                        else if (environment.Contains(kAutoFillVowMarker))
                        {
                            FillCVInEnvironment(IPACharacterType.Vowel, environment, i);
                        }
                    }
                }

                for (int i = 1; i < m_xyGrid.RowCount; i++)
                {
                    string srchItem = m_xyGrid[0, i].Value as string;
                    if (srchItem != null)
                    {
                        if (srchItem.Contains(kAutoFillConMarker))
                        {
                            FillCVInSearchItem(IPACharacterType.Consonant, srchItem, i);
                        }
                        else if (srchItem.Contains(kAutoFillVowMarker))
                        {
                            FillCVInSearchItem(IPACharacterType.Vowel, srchItem, i);
                        }
                    }
                }

                m_xyGrid.IsDirty = dirtyState;
            }
            catch { }

            STUtils.SetWindowRedraw(m_xyGrid, true, true);
            return(false);
        }
Пример #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void Save(PaProject project)
        {
            if (project != null)
            {
                InternalSkipList skipList = new InternalSkipList();
                foreach (KeyValuePair <string, bool> kvp in this)
                {
                    if (kvp.Value)
                    {
                        skipList.Add(kvp.Key);
                    }
                }

                string filename = project.ProjectPathFilePrefix + kDataSourceInfoFilePrefix;
                STUtils.SerializeData(filename, skipList);
            }
        }
Пример #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Read the data sources from the restored project file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void GetDataSourcePathsFromPap()
        {
            string    dummy = string.Empty;
            PaProject prj   = PaProject.LoadProjectFileOnly(m_papPath, true, ref dummy);

            if (prj == null || prj.DataSources == null || prj.DataSources.Count == 0)
            {
                MessageBox.Show(this, Properties.Resources.kstidPrjIsEmptyMsg,
                                Application.ProductName, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            m_progressDlg.prgressBar.Value   = 0;
            m_progressDlg.prgressBar.Maximum = prj.DataSources.Count;

            foreach (PaDataSource dataSource in prj.DataSources)
            {
                m_progressDlg.prgressBar.Value++;

                // Skip FieldWorks data source since we don't backup those.
                if (dataSource.DataSourceType != DataSourceType.FW)
                {
                    int i = ProcessDataSourceFromPap(dataSource);
                    dataSource.DataSourceFile = (i < 0 ? "X" : i.ToString());
                }
            }

            // This should never happen, but just in case, remove all data
            // sources whose file couldn't be found for some reason.
            for (int i = prj.DataSources.Count - 1; i >= 0; i--)
            {
                if (prj.DataSources[i].DataSourceFile == "X")
                {
                    prj.DataSources.RemoveAt(i);
                }
            }

            m_progressDlg.prgressBar.Value = m_progressDlg.prgressBar.Maximum;
            m_prjName = prj.ProjectName;
            STUtils.SerializeData(m_papPath, prj);
            prj.Dispose();
        }
Пример #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Goes through the data sources in the project just restored and changes the data
        /// source file paths to the path where the data sources were restored.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void ModifyDataSourcePathsInRestoredProject()
        {
            m_papPath = Path.Combine(txtPrjLocation.Text, Path.GetFileName(m_papPath));
            PaProject prj = STUtils.DeserializeData(m_papPath, typeof(PaProject)) as PaProject;

            if (prj == null)
            {
                return;
            }

            foreach (PaDataSource dataSource in prj.DataSources)
            {
                int i;
                if (int.TryParse(dataSource.DataSourceFile, out i))
                {
                    string path = grid[1, i].Value as string;
                    string file = grid[0, i].Value as string;
                    dataSource.DataSourceFile = Path.Combine(path, file);
                }
            }

            STUtils.SerializeData(m_papPath, prj);
            prj.Dispose();
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public int Compare(WordListCacheEntry x, WordListCacheEntry y)
        {
            if (x == null && y == null)
            {
                return(0);
            }

            bool ascending = (m_sortInfoList.Count > 0 ? m_sortInfoList[0].ascending : true);

            if (x == null)
            {
                return(ascending ? -1 : 1);
            }

            if (y == null)
            {
                return(ascending ? 1 : -1);
            }

            // First compare CIE group Id's before anything else.
            if (x.CIEGroupId >= 0 && y.CIEGroupId >= 0 && x.CIEGroupId != y.CIEGroupId)
            {
                return(x.CIEGroupId - y.CIEGroupId);
            }

            // Continue with the next iteration if the fieldValues are EQUAL
            for (int i = 0; i < m_sortInfoList.Count; i++)
            {
                ascending = m_sortInfoList[i].ascending;
                int compareResult;

                // Use a special comparison for phonetic fields.
                if (m_sortInfoList[i].FieldInfo.IsPhonetic)
                {
                    compareResult = m_baseCasheSortComparer.ComparePhonetic(x, y);
                    if (compareResult == 0)
                    {
                        continue;
                    }

                    return(ascending ? compareResult : -compareResult);
                }

                string fieldName   = m_sortInfoList[i].FieldInfo.FieldName;
                string fieldValue1 = x[fieldName];
                string fieldValue2 = y[fieldName];

                if (m_sortInfoList[i].FieldInfo.IsReference)
                {
                    if (x.WordCacheEntry.RecordEntry.DataSource.DataSourceType == DataSourceType.SA)
                    {
                        fieldValue1 = x.WordCacheEntry.GetField(fieldName, false);
                    }

                    if (y.WordCacheEntry.RecordEntry.DataSource.DataSourceType == DataSourceType.SA)
                    {
                        fieldValue2 = y.WordCacheEntry.GetField(fieldName, false);
                    }

                    // Try to compare references as numeric values before
                    // assuming they're string values.
                    float val1, val2;
                    if (STUtils.TryFloatParse(fieldValue1, out val1) &&
                        STUtils.TryFloatParse(fieldValue2, out val2) && val1 != val2)
                    {
                        compareResult = (val1 > val2 ? 1 : -1);
                        return(ascending ? compareResult : -compareResult);
                    }
                }

                if (fieldValue1 == fieldValue2)
                {
                    // Use a special comparison for references.
                    if (m_sortInfoList[i].FieldInfo.IsReference)
                    {
                        compareResult = m_baseCasheSortComparer.CompareReferences(x, y);
                        if (compareResult == 0)
                        {
                            continue;
                        }

                        return(ascending ? compareResult : -compareResult);
                    }

                    // If we're sorting by the entry's audio file and the audio file for each
                    // entry is the same, then compare the order in which the words occur within
                    // the sound file transcription.
                    if (m_sortInfoList[i].FieldInfo.IsAudioFile &&
                        x.WordCacheEntry.WordIndex != y.WordCacheEntry.WordIndex)
                    {
                        compareResult = x.WordCacheEntry.WordIndex - y.WordCacheEntry.WordIndex;
                        return(ascending ? compareResult : -compareResult);
                    }

                    // Fields are equal, so continue onto the next comparison column
                    continue;
                }

                // Check for date or numeric fields and compare appropriately.
                if (m_sortInfoList[i].FieldInfo.IsDate)
                {
                    compareResult = m_baseCasheSortComparer.CompareDates(fieldValue1, fieldValue2);
                }
                else if (m_sortInfoList[i].FieldInfo.IsNumeric)
                {
                    compareResult = m_baseCasheSortComparer.CompareNumerics(fieldValue1, fieldValue2);
                }
                else
                {
                    compareResult = m_baseCasheSortComparer.CompareStrings(fieldValue1, fieldValue2);
                }

                if (compareResult == 0)
                {
                    continue;
                }

                // Return a negative value for descending order
                return(ascending ? compareResult : -compareResult);
            }

            return(0);            // They are equal
        }
Пример #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void btnBkup_Click(object sender, EventArgs e)
        {
            // I'm not sure what I was doing with all these changes. This version of the click
            // event is very different from version 1.0.0 of the release version of this DLL.
            // Apparently, I started working on some changes and stopped before they were
            // finished, and upon returning to the code, I don't recall what I was doing. I
            // will have to get into the code later to see if I can figure it all out.

            m_progressDlg                    = new BRProgressDlg();
            m_progressDlg.lblMsg.Text        = string.Empty;
            m_progressDlg.prgressBar.Maximum = m_prjFiles.Count + m_dsFiles.Count;
            m_progressDlg.CenterInParent(this);
            m_progressDlg.Show();
            Hide();
            Application.DoEvents();
            //RestoreProjectFiles();
            //RestoreDataSources();
            //m_progressDlg.prgressBar.Value = m_progressDlg.prgressBar.Maximum;
            //ModifyDataSourcePathsInRestoredProject();
            m_progressDlg.Hide();
            //LoadRestoredProject();


            if (!chkIncludeDataSources.Checked)
            {
                m_dsFiles.Clear();
            }

            m_dsFiles.Add(STUtils.GetLocalPath(DataUtils.IPACharCache.CacheFileName, true));

            string normalizationExceptionFile = ReflectionHelper.GetField(
                typeof(FFNormalizer), "kstidNormalizationExceptionsFile") as string;

            if (!string.IsNullOrEmpty(normalizationExceptionFile))
            {
                m_dsFiles.Add(Path.Combine(Application.StartupPath, normalizationExceptionFile));
            }

            lblInfo.Visible = false;
            chkIncludeDataSources.Visible = false;
            btnBkup.Visible   = false;
            btnCancel.Enabled = false;

            lblProgress.Text    = string.Empty;
            lblProgress.Visible = true;
            //prgBar.Maximum = m_prjFiles.Count + m_dsFiles.Count;
            //prgBar.Visible = true;

            ZipFile zip = ZipFile.Create(m_backupFile);

            BackupFileList(zip, m_prjFiles);
            BackupFileList(zip, m_dsFiles);
            prgBar.Value = m_prjFiles.Count + m_dsFiles.Count;
            Application.DoEvents();
            zip.Close();

            btnCancel.Enabled = true;
            btnCancel.Text    = Properties.Resources.kstidCloseButtonText;
            //prgBar.Visible = false;
            //lblProgress.Visible = false;
            //lblInfo.Text = Properties.Resources.kstidBackupCompleteMsg;
            //lblInfo.Visible = true;
        }