Beispiel #1
0
        /// <summary>
        /// Method transfers data format from <seealso cref="DataSet"/> with <seealso cref="DataTable"/> items
        /// and <seealso cref="DataRow"/> items into the current schema of options
        /// and option values for data read from XML persistence into the in-memory model.
        /// Converts external XML format into internal format.
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="dataSet"></param>
        private void ConvertFromDataSetToModel(IEngine engine, DataSet dataSet)
        {
            AlternativeDataTypeHandler handle = new AlternativeDataTypeHandler();

            foreach (DataTable table in dataSet.Tables)
            {
                string optionName;

                // Locate options group for this table
                IOptionGroup optionsGroup = FindOptionsGroup(engine, table.TableName, out optionName);

                // Found a table that refers to a list of values stored in an optiongroup/option
                if (string.IsNullOrEmpty(optionName) == false)
                {
                    // Empty list is allowed but requires no processing
                    // -> remove defaults if actual data is available
                    if (table.Rows.Count > 0)
                    {
                        optionsGroup.List_Clear(optionName);

                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            // assumption: Address first column in each row since list
                            // table contains only 1 data column
                            optionsGroup.SetValue(optionName, table.Rows[i].ItemArray[0]);
                        }
                    }
                }
                else
                {
                    // This code requires at least a header row and 1 data row in order to work!
                    if (table.Rows.Count >= 2)
                    {
                        for (int i = 0; i < table.Columns.Count; i++)
                        {
                            IOptionsSchema schema = null;

                            schema = optionsGroup.GetOptionDefinition(table.Columns[i].ColumnName);

                            var handler = handle.FindHandler(schema.TypeOfValue);

                            if (handler != null)
                            {
                                object s = handler.ConvertBack(table.Rows[1].ItemArray[i] as string);

                                optionsGroup.SetValue(table.Columns[i].ColumnName, s);
                            }
                            else
                            {
                                optionsGroup.SetValue(table.Columns[i].ColumnName, table.Rows[1].ItemArray[i]);
                            }
                        }
                    }
                }
            }

            dataSet = null;
        }
        /// <summary>
        /// Save changed settings back to model for further
        /// application and persistence in file system.
        /// </summary>
        /// <param name="settingData"></param>
        private void SaveOptionsToModel(IOptionGroup optionsOptionGroup)
        {
            var loginData = MSTranslateGetData();

            optionsOptionGroup.SetValue("MSTranslate.TranslationServiceUri", loginData.TranslationServiceUri);
            optionsOptionGroup.SetValue("MSTranslate.TranslationServiceUser", loginData.TranslationServiceUser);
            optionsOptionGroup.SetValue("MSTranslate.TranslationServicePassword", loginData.TranslationServicePassword);

            optionsOptionGroup.SetValue("ReloadOpenFilesFromLastSession", ReloadFilesOnAppStart);
            optionsOptionGroup.SetValue("LanguageSelected", LanguageSelected.BCP47);

            optionsOptionGroup.SetValue("DefaultSourceLanguage", DefaultSourceLanguageSelected.Bcp47_LangCode);
            optionsOptionGroup.SetValue("DefaultTargetLanguage", DefaultTargetLanguageSelected.Bcp47_LangCode);

            optionsOptionGroup.SetValue("DefaultIconSize", (int)IconSize);

            optionsOptionGroup.SetValue("ColorGridOption", (bool)ColorGridOption);
            optionsOptionGroup.SetValue("AlternatingGridColor", AlternatingColor);
        }
        /// <summary>
        /// Save changed settings back to model for further
        /// application and persistence in file system.
        /// </summary>
        /// <param name="settingData"></param>
        public void SaveOptionsToModel(IOptionGroup optGroup)
        {
            optGroup.SetValue("ReloadOpenFilesFromLastSession", ReloadFilesOnAppStart);

            if (LanguageSelected != null)
            {
                optGroup.SetValue("LanguageSelected", LanguageSelected.BCP47);
            }

            var opt = optGroup.GetOptionDefinition("BookmarkedFolders");

            optGroup.List_Clear("BookmarkedFolders");

            if (Bookmarks.Count > 0)
            {
                var schema = optGroup.GetOptionDefinition("BookmarkedFolders");

                foreach (var item in Bookmarks)
                {
                    schema.List_AddValue(item, item);
                }
            }
        }