Exemple #1
0
        private void buttonOpenDictionary_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "CSPro Dictionary (*.dcf)|*.dcf";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    dictionary = DataDictionaryReader.Load(ofd.FileName);

                    if (dictionary.Levels.Count != 1)
                    {
                        throw new Exception(Messages.Dictionary_TwoLevelError);
                    }

                    else if (dictionary.RecTypeLength == 0)
                    {
                        throw new Exception(Messages.Dictionary_NoRecordType);
                    }

                    labelDictionary.Text = dictionary.Label;

                    SetupInitialRecordTypes();
                    casesRead      = 0;
                    recordsRead    = 0;
                    recordsWritten = 0;

                    UpdateStats(false);
                }

                catch (Exception exception)
                {
                    dictionary           = null;
                    labelDictionary.Text = "";
                    MessageBox.Show(String.Format(Messages.Dictionary_LoadError, exception.Message));
                }
            }

            EnableCleanButton();
        }
Exemple #2
0
        // OPEN -- dictionary-filename
        private void ProcessOpen(string[] commands)
        {
            string filename = new FileInfo(commands[1]).FullName;

            if (!File.Exists(filename))
            {
                throw new Exception(String.Format(Messages.FileNotExist, filename));
            }

            DataDictionary dictionary = DataDictionaryReader.Load(filename); // Load can throw an exception

            if (dictionary.Levels.Count != 1)
            {
                throw new Exception(Messages.DictionaryNotOneLevel);
            }

            if (dictionary.Relations.Count > 0)
            {
                throw new Exception(Messages.DictionaryHasRelations);
            }

            if (_dictionaries.ContainsKey(dictionary.Name))
            {
                throw new Exception(String.Format(Messages.DictionaryAlreadyLoaded, dictionary.Name));
            }

            // make sure that the dictionary name doesn't already exist as a name of an already loaded object
            if (_symbolParents.ContainsKey(dictionary.Name))
            {
                throw new Exception(String.Format(Messages.DictionaryNameInUse, dictionary.Name, _symbolParents[dictionary.Name][0].Name));
            }

            LoadDictionarySymbols(dictionary);

            _dictionaries.Add(dictionary.Name, dictionary);

            RefreshSymbolParents();

            SetOutputSuccess(String.Format(Messages.DictionaryLoaded, dictionary.Name));
        }