コード例 #1
0
        private void UpdateConfiguration()
        {
            string exePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), APP_CONFIGFILE);
            Configuration conf = ConfigurationManager.OpenExeConfiguration(exePath);

            LiveUpgradeConfigurationSection newCS = new LiveUpgradeConfigurationSection();
            LiveUpgradeConfigurationSection cs = conf.GetSection(UPGRADE_SECTION) as LiveUpgradeConfigurationSection;

            if (cs != null)
            {
                foreach (UpgradeElement element in cs.UpgradeProducts)
                {
                    if (element.Product != project.Product)
                    {
                        newCS.UpgradeProducts.AddElement(element);
                    }
                }
            }

            UpgradeElement ele = new UpgradeElement();
            ele.Product = project.Product;
            ele.UpgradeDate = DateTime.Now.ToLocalTime();
            ele.LocalVersion = project.Version;
            newCS.UpgradeProducts.AddElement(ele);

            conf.Sections.Remove(UPGRADE_SECTION);
            conf.Sections.Add(UPGRADE_SECTION, newCS);
            conf.Save();
        }
コード例 #2
0
        /// <summary>
        /// Gets the element key for a specified configuration element when overridden in a derived class.
        /// </summary>
        /// <param name="element">The <see cref="T:System.Configuration.ConfigurationElement"/> to return the key for.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            UpgradeElement ue = element as UpgradeElement;

            return(ue.Product);
        }