Exemplo n.º 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>
        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);
                }
            }
        }
        /// <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 schema = optionsOptionGroup.GetOptionDefinition("BookmarkedFolders");

            schema.List_Clear();

            if (Bookmarks.Count > 0)
            {
                foreach (var item in Bookmarks)
                {
                    schema.List_AddValue(item, item);
                }
            }
        }
        /// <summary>
        /// Reset the view model to those options that are going to be presented for editing.
        /// </summary>
        /// <param name="settingData"></param>
        internal static void LoadOptionsFromModel(IOptionGroup optGroup, IList collection)
        {
            var opt = optGroup.GetOptionDefinition("BookmarkedFolders");

            foreach (var item in opt.List_GetListOfKeyValues())
            {
                string sValue = item.Value as string;

                if (sValue != null)
                {
                    collection.Add(sValue);
                }
            }
        }
        internal static bool SaveBookmarksToModel(IEnumerable <IFSItemViewModel> collection,
                                                  IOptionGroup optionsOptionGroup)
        {
            var schema = optionsOptionGroup.GetOptionDefinition("BookmarkedFolders");

            bool listsAreEqual = true;
            int  iCount        = 0;

            foreach (var item in collection)
            {
                object val;
                if (schema.List_TryGetValue(item.FullPath, out val) == false)
                {
                    listsAreEqual = false;
                    break;
                }

                iCount++;
            }

            if (listsAreEqual == true)
            {
                if (iCount == collection.Count())
                {
                    return(false);
                }
            }

            // Clear list and copy all values since they differ
            schema.List_Clear();
            foreach (var item in collection)
            {
                schema.List_AddValue(item.FullPath, item.FullPath);
            }

            optionsOptionGroup.SetUndirty(true);

            return(true);
        }