示例#1
0
        public void Save(string productName)
        {
            this.Info.Name               = productName;
            this.Info.Modify             = DateTime.Now;
            FilePath                     = Path + productName + "\\";
            AppConfig.CurrentProductName = productName;
            foreach (var item in this.GetType().GetProperties())
            {
                if (typeof(ProductBase).IsAssignableFrom(item.PropertyType))
                {
                    ProductBase       pro       = item.GetValue(this) as ProductBase;
                    AppLevelAttribute attribute = item.GetCustomAttribute <AppLevelAttribute>();
                    if (attribute != null)
                    {
                        string filename = AppDomain.CurrentDomain.BaseDirectory + "Config\\" + item.Name + ".config";
                        pro.Save(filename + item.Name);
                    }
                    else
                    {
                        pro.Save(FilePath + item.Name);
                    }
                }
            }

            if (SaveEvent != null)
            {
                SaveEvent(this, EventArgs.Empty);
            }

            AppConfig.Save(Inst.Path + "app.config");
        }
示例#2
0
        public void Load(string productName)
        {
            FilePath = Path + productName + "\\";
            foreach (var item in this.GetType().GetProperties())
            {
                if (typeof(ProductBase).IsAssignableFrom(item.PropertyType))
                {
                    ProductBase pro = item.GetValue(this) as ProductBase;
                    if (pro == null)
                    {
                        object[] customAttributes = item.GetCustomAttributes(typeof(DefaultValueAttribute), false);
                        if (customAttributes.Length > 0)
                        {
                            DefaultValueAttribute attribute = (DefaultValueAttribute)customAttributes[0];
                            item.SetValue(this, attribute.Value);
                        }
                        else
                        {
                            object obj = item.PropertyType.Assembly.CreateInstance(item.PropertyType.FullName);
                            item.SetValue(this, obj);
                        }
                        pro = item.GetValue(this) as ProductBase;
                    }

                    AppLevelAttribute attribute2 = item.GetCustomAttribute <AppLevelAttribute>();
                    if (attribute2 != null && item.PropertyType != typeof(ProductInfo))
                    {
                        string filename = AppDomain.CurrentDomain.BaseDirectory + "Config\\" + item.Name + ".config";
                        pro.Load(filename + item.Name);
                    }
                }
            }

            foreach (var item in this.GetType().GetProperties())
            {
                if (typeof(ProductBase).IsAssignableFrom(item.PropertyType))
                {
                    ProductBase pro = item.GetValue(this) as ProductBase;

                    AppLevelAttribute attribute2 = item.GetCustomAttribute <AppLevelAttribute>();
                    if (attribute2 == null)
                    {
                        pro.Load(FilePath + item.Name);
                    }
                }
            }

            this.Info.Name = productName;
            AppConfig.CurrentProductName = productName;
            AppConfig.Save(Inst.Path + "app.config");

            if (LoadEvent != null)
            {
                LoadEvent(this, EventArgs.Empty);
            }
        }
示例#3
0
        public void Save(string productName)
        {
            this.Info.Name   = productName;
            this.Info.Modify = DateTime.Now;
            string filePath = Path + productName + "\\";

            foreach (var item in this.GetType().GetProperties())
            {
                if (typeof(ProductBase).IsAssignableFrom(item.PropertyType))
                {
                    ProductBase pro = item.GetValue(this) as ProductBase;
                    pro.Save(filePath + item.Name);
                }
            }

            AppConfig.CurrentProductName = productName;
            AppConfig.Save(Inst.Path + "app.config");

            if (SaveEvent != null)
            {
                SaveEvent(this, EventArgs.Empty);
            }
        }