示例#1
0
        /// <summary>
        /// 设置内容模型字典
        /// </summary>
        /// <param name="assistat"></param>
        public static void SetModelDataDic(ObjectAssistant assistat)
        {
            if (assistat == null)
            {
                return;
            }
            ContentModelCollection cmc = ModelHelper.GetAllContentModel();

            foreach (ContentModel item in cmc)
            {
                ModelInfo info = ModelHelper.GetModelInfo(item.Name);
                foreach (var table in info.DataSet.Tables)
                {
                    ObjectManager om = new ObjectManager();
                    EntityObject  eo = new EntityObject();
                    eo.TypeForDT      = typeof(TableInfo);
                    eo.IdentityName   = "ID";
                    eo.IsDataTable    = true;
                    eo.PrimaryKeyName = "ID";
                    eo.TableName      = table.Name;
                    //亲,此处取的是内容模型的描述,不是写错了
                    eo.Description = item.Description;
                    Dictionary <string, Property> diccolumn = new Dictionary <string, Property>(StringComparer.OrdinalIgnoreCase);
                    foreach (var column in table.Columns)
                    {
                        Property pt = new Property();
                        pt.Description = column.Label;
                        pt.Field       = column.Name;
                        pt.Nullable    = column.Nullable;
                        pt.Size        = column.MaxLength;
                        pt.Name        = column.Name;
                        //pt.Type = column.DataType;
                        diccolumn.Add(column.Name, pt);
                    }

                    eo.PropertyDict = diccolumn;
                    om.CurObject    = eo;
                    DataBase db = new DataBase();
                    db.DbDriver         = assistat.GetDatabases()["We7.CMS.Common"].DbDriver;
                    db.Name             = assistat.GetDatabases()["We7.CMS.Common"].Name;
                    db.ConnectionString = assistat.GetDatabases()["We7.CMS.Common"].ConnectionString;
                    om.CurDatabase      = db;
                    om.ObjType          = eo.TypeForDT;
                    if (assistat.DicForTable().ContainsKey(table.Name)) //如果存在此KEY
                    {
                        assistat.DicForTable().Remove(table.Name);      //移除此项
                    }
                    if (!assistat.DicForTable().ContainsKey(table.Name))
                    {
                        assistat.DicForTable().Add(table.Name, om);                          //添加
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// 执行数据迁移
        /// </summary>
        /// <param name="xmlPath">数据结构映射XML文件存放路径(需要确保两个库的结构相同)</param>
        /// <param name="oldConfig">源数据库</param>
        /// <param name="newConfig">目标数据库</param>
        public static void DoMigrate(string xmlPath, BaseConfigInfo oldConfig, BaseConfigInfo newConfig, List <string> tables)
        {
            //导入数据
            string    newConnString = newConfig.DBConnectionString.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory);
            IDbDriver driver        = Installer.CreateDbDriver(newConfig.DBType);

            using (IConnection newConn = driver.CreateConnection(newConnString))
            {
                if (Directory.Exists(xmlPath))
                {
                    DirectoryInfo dir   = new DirectoryInfo(xmlPath);
                    FileInfo[]    files = dir.GetFiles("*.xml");
                    foreach (FileInfo file in files)
                    {
                        string          xmlFile = file.FullName;
                        ObjectAssistant oa      = new ObjectAssistant();

                        if (oldConfig.DBConnectionString != "")
                        {
                            oldConfig.DBConnectionString = oldConfig.DBConnectionString.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory);
                            oa.LoadDBConnectionString(oldConfig.DBConnectionString, oldConfig.DBDriver);
                        }
                        oa.LoadFromFile(xmlFile);

                        //过滤:找出两个数据库都有的表对象
                        IDbDriver     oldDriver = Installer.CreateDbDriver(oldConfig.DBType);
                        IConnection   oldConn   = oldDriver.CreateConnection(oldConfig.DBConnectionString.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory));
                        List <string> objects   = GetUpdateObjects(xmlFile, newConn, oldConn, tables);
                        if (objects.Count > 0)
                        {
                            //进行数据转换
                            foreach (string tpName in objects)
                            {
                                if (tpName == "")
                                {
                                    continue;
                                }
                                Type           tp = Type.GetType(tpName);
                                Type           mt = typeof(MigrateObject <>);
                                Type           gt = mt.MakeGenericType(new Type[] { tp });
                                IMigrateObject mo = Activator.CreateInstance(gt) as IMigrateObject;
                                mo.Connection = newConn;
                                mo.Assistant  = oa;
                                mo.Update();
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public static void ResetApplication()
        {
            lock (lockHelper)
            {
                HttpContext context = HttpContext.Current;
                context.Application.Clear();
                if (context.Session != null)
                {
                    context.Session.Clear();
                }

                BaseConfigs.ResetConfig();
                SiteConfigs.ResetConfig();
                GeneralConfigs.ResetConfig();
                context.Application["We7.Application.OnlinePeople.Key"] = 0;
                if (BaseConfigs.ConfigFileExist())
                {
                    BaseConfigInfo  baseconfig = BaseConfigs.GetBaseConfig();
                    string          root       = context.Server.MapPath("~/");
                    string          dataPath   = context.Server.MapPath("~/App_Data/XML");
                    ObjectAssistant assistant  = new ObjectAssistant();
                    try
                    {
                        if (baseconfig != null && baseconfig.DBConnectionString != "")
                        {
                            baseconfig.DBConnectionString = baseconfig.DBConnectionString.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory).Replace("\\\\", "\\");
                            assistant.LoadDBConnectionString(baseconfig.DBConnectionString, baseconfig.DBDriver);
                        }
                        assistant.LoadDataSource(dataPath);
                    }
                    catch (DataException ex)
                    {
                        Debug.WriteLine(ex.ToString());
                        string s = string.Format("注意检查:/app_data/xml目录下的配置文件:\r\n错误代码:{0}\r\n错误消息:{1}",
                                                 ex.Errorcode, ex.Message);
                        LogHelper.WriteLog(typeof(ApplicationHelper), s);
                        throw ex;
                    }

                    HelperFactory factory = new HelperFactory();
                    factory.Assistant = assistant;
                    factory.Root      = root;
                    factory.Initialize();
                    context.Application["We7.HelperFactory"] = factory;
                }
            }
        }
示例#4
0
        BaseConfigInfo LoadOldXMLConfig()
        {
            string          dbPath = Server.MapPath("~/app_data/db/");
            ObjectAssistant oa     = new ObjectAssistant();

            if (File.Exists(Path.Combine(dbPath, "cd.xml")))
            {
                oa.LoadOldDBConfig(Path.Combine(dbPath, "cd.xml"));
                Dictionary <string, IDatabase> databases = oa.GetDatabases();
                BaseConfigInfo bci = new BaseConfigInfo();
                bci.DBConnectionString = databases["We7.CMS.Common"].ConnectionString;
                bci.DBConnectionString = bci.DBConnectionString.ToLower().Replace(AppDomain.CurrentDomain.BaseDirectory.ToLower(), "{$App}\\");
                bci.DBDriver           = databases["We7.CMS.Common"].DbDriver.ToString();
                bci.DBType             = Installer.GetDBTypeFromDriver(databases["We7.CMS.Common"].DbDriver.ToString());
                return(bci);
            }
            return(null);
        }
示例#5
0
        /// <summary>
        /// 重启应用程序
        /// </summary>
        public static void LoadHelperFactory()
        {
            lock (lockHelper2)
            {
                //如果数据库配置文件存在,加载配置
                if (BaseConfigs.ConfigFileExist())
                {
                    BaseConfigInfo baseconfig = BaseConfigs.GetBaseConfig();

                    //加载数据库映射表
                    string          root     = AppDomain.CurrentDomain.BaseDirectory;
                    string          dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/XML");
                    ObjectAssistant assistat = new ObjectAssistant();
                    try
                    {
                        if (baseconfig != null && baseconfig.DBConnectionString != "")
                        {
                            baseconfig.DBConnectionString = baseconfig.DBConnectionString.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory);
                            assistat.LoadDBConnectionString(baseconfig.DBConnectionString, baseconfig.DBDriver);
                        }
                        assistat.LoadDataSource(dataPath);
                    }
                    catch (Thinkment.Data.DataException ex)
                    {
                        Debug.WriteLine(ex.ToString());
                        string source = "CD.Utils_CDHelper_ResetApplication";
                        EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error);
                        throw ex;
                    }

                    HelperFactory hf = new HelperFactory();

                    hf.Assistant = assistat;
                    hf.Root      = root;
                    hf.Initialize();
                    AppCtx.Cache.AddObject(HelperFactory.CacheKey, hf);
                }
            }
        }
示例#6
0
        /// <summary>
        /// 重启网站
        /// </summary>
        public static void ResetApplication()
        {
            lock (lockHelper)
            {
                HttpContext context = HttpContext.Current;
                context.Application.Clear();

                if (context.Session != null)
                {
                    context.Session.Clear();
                }

                BaseConfigs.ResetConfig();
                SiteConfigs.ResetConfig();
                GeneralConfigs.ResetConfig();
                PluginManager.LoadPlugins();
                context.Application["We7.Application.OnlinePeople.Key"] = 0;

                //如果数据库配置文件存在,加载配置
                if (BaseConfigs.ConfigFileExist())
                {
                    BaseConfigInfo baseconfig = BaseConfigs.GetBaseConfig();

                    //加载数据库映射表
                    string          root     = context.Server.MapPath("~/");
                    string          dataPath = context.Server.MapPath("~/App_Data/XML");
                    ObjectAssistant assistat = new ObjectAssistant();
                    try
                    {
                        if (baseconfig != null && baseconfig.DBConnectionString != "")
                        {
                            baseconfig.DBConnectionString = baseconfig.DBConnectionString.
                                                            Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory).Replace("\\\\", "\\");
                            assistat.LoadDBConnectionString(baseconfig.DBConnectionString, baseconfig.DBDriver);
                        }
                        assistat.LoadDataSource(dataPath);
                    }
                    catch (Thinkment.Data.DataException ex)
                    {
                        Debug.WriteLine(ex.ToString());
                        string source = "CD.Utils_CDHelper_ResetApplication";
                        EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error);

                        string msg = string.Format("注意检查:/app_data/xml里的配置文件:\r\n错误代码:{0}\r\n错误消息:{1}"
                                                   , ex.ErrorCode, ex.Message);
                        We7.Framework.LogHelper.WriteLog(typeof(ApplicationHelper), msg);
                        throw ex;
                    }

                    HelperFactory hf = new HelperFactory();

                    /*
                     * 添加内容模型表结构(系统内置字段已在LoadDataSource里添加)
                     * author:丁乐
                     */
                    ModelHelper.ReCreateModelIndex();
                    MoudelMonitoring.SetModelDataDic(assistat);

                    hf.Assistant = assistat;
                    hf.Root      = root;
                    hf.Initialize();
                    context.Application.Add("We7.HelperFactory", hf);
                    AppCtx.Cache.AddObject(HelperFactory.CacheKey, hf);

                    MoudelMonitoring ml = new MoudelMonitoring();  //监控内容模型
                }
            }
        }