예제 #1
0
        /// <summary>
        /// 通过 key 查找 BlockConfig。
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public BlockConfig GetBlockConfig(BlockConfigKey key)
        {
            if (key.Type == BlockConfigType.Config || XmlConfigFileSystem.IsCustomizing)
            {
                var path = key.GetFilePath();

                if (File.Exists(path))
                {
                    var xDoc = XDocument.Load(path);

                    var blockCfg = new BlockConfig
                    {
                        Key = key,
                        Xml = xDoc.Root
                    };

                    return blockCfg;
                }
            }

            return null;
        }
예제 #2
0
        /// <summary>
        /// 通过 key 查找 BlockConfig。
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public BlockConfig GetBlockConfig(BlockConfigKey key)
        {
            if (key.Type == BlockConfigType.Config || XmlConfigFileSystem.IsCustomizing)
            {
                var path = key.GetFilePath();

                if (File.Exists(path))
                {
                    var xDoc = XDocument.Load(path);

                    var blockCfg = new BlockConfig
                    {
                        Key = key,
                        Xml = xDoc.Root
                    };

                    return(blockCfg);
                }
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// 把某个 BlockConfig 保存为 XML 文件。
        /// </summary>
        /// <param name="blockCfg"></param>
        public void Save(BlockConfig blockCfg)
        {
            var path = blockCfg.Key.GetFilePath();

            if (blockCfg.IsChanged())
            {
                var doc = new XDocument(blockCfg.Xml);

                var dir = Path.GetDirectoryName(path);
                if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); }

                doc.Save(path);
            }
            else
            {
                //UI配置没有变化时,Xml 文件应该删除。
                if (File.Exists(path)) { File.Delete(path); }
            }
        }
예제 #4
0
 private void SerializeProperties(ConfigInputOutput io, BlockConfig blockConfig)
 {
     if (io.InputView is WebEntityViewMeta)
     {
         blockConfig.PageSize = (this.PageSize != io.InputView.AsWebView().PageSize) ? (int?)this.PageSize : null;
     }
     var hasGroup = !string.IsNullOrEmpty(this.GroupBy);
     if (io.InputView.GroupBy == null)
     {
         blockConfig.GroupBy = hasGroup ? this.GroupBy : null;
     }
     else
     {
         if (hasGroup)
         {
             blockConfig.GroupBy = io.InputView.GroupBy.Name != this.GroupBy ? this.GroupBy : null;
         }
         else
         {
             blockConfig.GroupBy = BlockConfig.NullString;
         }
     }
 }
예제 #5
0
        private void SerializeEntityProperties(ConfigInputOutput io, BlockConfig blockConfig)
        {
            var properties = blockConfig.EntityProperties;
            foreach (var propertyChanged in this.ViewConfigurationPropertyList)
            {
                //查找或添加一个新的属性配置项。
                bool exsits = true;
                var propertyCfg = properties.FirstOrDefault(p => p.Name == propertyChanged.Name);
                if (propertyCfg == null)
                {
                    propertyCfg = new BlockPropertyConfig() { Name = propertyChanged.Name };
                    exsits = false;
                }

                //重算所有属性值。
                var propertyVM = io.InputView.Property(propertyChanged.Name);
                var siw = (ShowInWhere)propertyChanged.ShowInWhere;
                propertyCfg.ShowInWhere = siw != propertyVM.ShowInWhere ? (ShowInWhere?)siw : null;
                propertyCfg.OrderNo = propertyChanged.OrderNo != propertyVM.OrderNo ? (double?)propertyChanged.OrderNo : null;
                propertyCfg.Label = propertyChanged.Label != propertyVM.Label ? propertyChanged.Label : null;

                //如果配置项有用,则加入到列表中,否则应该从列表中移除。
                if (propertyCfg.IsChanged())
                {
                    if (!exsits)
                    {
                        properties.Add(propertyCfg);
                    }
                }
                else
                {
                    if (exsits)
                    {
                        properties.Remove(propertyCfg);
                    }
                }
            }
        }
예제 #6
0
        private void SerializeCommands(ConfigInputOutput io, BlockConfig blockConfig)
        {
            bool isWeb = RafyEnvironment.Location.IsWebUI;

            foreach (var cmdChanged in this.ViewConfigurationCommandList)
            {
                //查找或添加一个新的属性配置项。
                bool exsits = true;
                var cmdCfg = blockConfig.Commands.FirstOrDefault(p => p.Name == cmdChanged.Name);
                if (cmdCfg == null)
                {
                    cmdCfg = new BlockCommandConfig() { Name = cmdChanged.Name };
                    exsits = false;
                }

                //重算所有属性值。
                if (isWeb)
                {
                    var cmdVM = io.InputView.AsWebView().Commands.Find(cmdChanged.Name);
                    cmdCfg.Label = cmdChanged.Label != cmdVM.Label ? cmdChanged.Label : null;
                    cmdCfg.IsVisible = cmdChanged.IsVisible != cmdVM.IsVisible ? (bool?)cmdChanged.IsVisible : null;
                }
                else
                {
                    var cmdVM = io.InputView.AsWPFView().Commands.Find(cmdChanged.Name);
                    cmdCfg.Label = cmdChanged.Label != cmdVM.Label ? cmdChanged.Label : null;
                    cmdCfg.IsVisible = cmdChanged.IsVisible != cmdVM.IsVisible ? (bool?)cmdChanged.IsVisible : null;
                }

                //如果配置项有用,则加入到列表中,否则应该从列表中移除。
                if (cmdCfg.IsChanged())
                {
                    if (!exsits)
                    {
                        blockConfig.Commands.Add(cmdCfg);
                    }
                }
                else
                {
                    if (exsits)
                    {
                        blockConfig.Commands.Remove(cmdCfg);
                    }
                }
            }
        }
예제 #7
0
        internal void SaveToXml()
        {
            var io = GetInputOutput(this.Id);
            if (io.InputView == null) return;

            //先从 xml 文件中读取当前的配置。
            var blockConfig = UIModel.XmlConfigMgr.GetBlockConfig(io.OutputBlockConfigKey);
            if (blockConfig == null)
            {
                blockConfig = new BlockConfig
                {
                    Key = io.OutputBlockConfigKey
                };
            }

            //把所有所有变更的差异都存储到 blockConfig 中。
            this.SerializeProperties(io, blockConfig);
            this.SerializeEntityProperties(io, blockConfig);
            this.SerializeCommands(io, blockConfig);

            UIModel.XmlConfigMgr.Save(blockConfig);
        }