예제 #1
0
        public List <Module> GetModules()
        {
            if (this.thisModules.Count == 0)
            {
                var list = fac.GetModules();



                Soway.Data.Graphic.Graphic <Module> moduleRelation = new Data.Graphic.Graphic <Module>();
                foreach (var item in list)
                {
                    foreach (var property in item.Depdency)
                    {
                        moduleRelation.AddEdge(item, property);
                    }
                }



                while (moduleRelation.GetTopNode() != null)
                {
                    /////// System.Diagnostics.Trace.WriteLine(moduleRelation.GetTopNode().Name);
                    thisModules.Add(moduleRelation.GetTopNode());
                    moduleRelation.Remove(moduleRelation.GetTopNode());
                }
            }
            //foreach (var i in this.thisModules)
            /////// System.Diagnostics.Trace.WriteLine(i.Name);
            return(this.thisModules);
        }
예제 #2
0
        public List <Model> GetModels(Module module)
        {
            var list = fac.GetModels(module);

            Soway.Data.Graphic.Graphic <Model> moduleRelation = new Data.Graphic.Graphic <Model>();
            foreach (var item in list)
            {
                moduleRelation.Add(item);
                if (item.BaseModel != null)
                {
                    moduleRelation.AddEdge(item.BaseModel, item);
                }
                foreach (var property in item.Properties.Where(p => p.Model != null && p.IsArray == true))
                {
                    moduleRelation.AddEdge(property.Model, item);
                }
            }

            var result = new List <Model>();


            while (moduleRelation.Nodes.Count > 0)
            {
                /////// System.Diagnostics.Trace.WriteLine("Model:" + moduleRelation.GetTopNode().Name);
                var ob = moduleRelation.GetTopNode();
                if (ob == null)
                {
                    ob = moduleRelation.Nodes[0].Data;
                }
                result.Add(ob);
                moduleRelation.Remove(ob);
            }



            return(result);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Source">模型</param>
        /// <param name="ModelSqlCon">存储模型的数据库</param>
        /// <param name="DataBaseSqlCon">要创建的数据库的</param>
        public void InstallModules(IModuleSource Source,
                                   SqlCon ModelSqlCon, SqlCon DataBaseSqlCon)
        {
            ConnectionType ConnectionType = ConnectionType.AppSys;

            if (ModelSqlCon.ToString() == DataBaseSqlCon.ToString())
            {
                ConnectionType = ConnectionType.AppSys;
            }
            else
            {
                ConnectionType = ConnectionType.Current;
            }

            //System.Diagnostics.Trace.WriteLine("MODEL:"+ModelSqlCon.ToString());
            //System.Diagnostics.Trace.WriteLine("CON:"+ModelSqlCon.ToString());
            var modelDb      = new SqlServer.dbContext(ModelSqlCon, this.ConFac);
            var DataDb       = new SqlServer.dbContext(DataBaseSqlCon, this.ConFac);
            var modelMode    = Global.ModeMode;
            var moduleMode   = Global.ModuleMode;
            var viewMode     = Global.ViewMode;
            var relationMode = Global.RelationModel;


            List <IObjectProxy>   insertItems = new List <IObjectProxy>();
            ModelSqlServerFactory sqlFac      = new ModelSqlServerFactory(Source);
            var viewFac = new Soway.Model.View.AutoViewFactory(ModelSqlCon, this.ConFac);
            Dictionary <object, System.Data.IDbCommand> commands = new Dictionary <object, System.Data.IDbCommand>();

            Dictionary <object, System.Data.IDbCommand> relationsCommands = new Dictionary <object, System.Data.IDbCommand>();
            var helper  = new ModelHelper(this.ConFac);
            var modules = Source.GetModules();

            CreateDataBase(DataBaseSqlCon);

            foreach (var module in modules.Distinct())
            {
                module.SqlCon = DataBaseSqlCon;
                IObjectProxy moduleproxy = new ObjectProxy(moduleMode, this.ConFac);
                helper.SetProxy(ref moduleproxy, module);

                if (modelDb.IsExits(moduleproxy) == true)
                {
                }
                else
                {
                    insertItems.Add(moduleproxy);
                }

                foreach (var model in Source.GetModels(module))
                {
                    IObjectProxy proxy = new ObjectProxy(modelMode, this.ConFac, LoadType.Complete);
                    helper.SetProxy(ref proxy, model);
                    if (modelDb.IsExits(proxy) == false)
                    {
                        insertItems.Add(proxy);
                    }
                    if (model.ModelType != ModelType.Enum)
                    {
                        var command = sqlFac.GerateCreateSql(model);
                        if (commands.ContainsKey(model))
                        {
                            commands[model] = command;
                        }
                        else
                        {
                            commands.Add(model, command
                                         );
                        }
                        foreach (var relation in model.Relations)
                        {
                            if (relationsCommands.ContainsKey(relation) == false)
                            {
                                relationsCommands.Add(relation, sqlFac.GetRelationSql(relation));
                            }
                        }
                        var itemView = viewFac.CreateDefaultItemView(model);
                        itemView.ConnectionType = ConnectionType;
                        IObjectProxy itemViewProxy = new ObjectProxy(viewMode, this.ConFac);
                        var          view          = viewFac.CreateDefaultListView(model);
                        IObjectProxy viewProxy     = new ObjectProxy(viewMode, this.ConFac);
                        view.ConnectionType = ConnectionType;
                        helper.SetProxy(ref itemViewProxy, itemView);
                        insertItems.Add(itemViewProxy);
                        helper.SetProxy(ref viewProxy, view);
                        insertItems.Add(viewProxy);
                    }
                }
            }



            //创建表
            foreach (var command in commands)

            {
                DataDb
                .Excute(command.Value as System.Data.SqlClient.SqlCommand);
            }

            foreach (var command in relationsCommands)

            {
                DataDb
                .Excute(command.Value as System.Data.SqlClient.SqlCommand);
            }
            //插入数据
            Soway.Data.Graphic.Graphic <IObjectProxy> proxyMaps = new Data.Graphic.Graphic <IObjectProxy>();
            foreach (var item in insertItems)
            {
                proxyMaps.Add(item);
                foreach (var ob in item.Model.Properties)
                {
                    if (item[ob] is IObjectProxy)
                    {
                        proxyMaps.AddEdge(item[ob] as IObjectProxy, item);
                    }
                }
            }

            while (proxyMaps.Nodes.Count > 0)
            {
                var ob = proxyMaps.GetTopNode();
                if (ob == null)
                {
                    ob = proxyMaps.Nodes[0].Data;
                }
                proxyMaps.Remove(ob);
                if (modelDb.IsExits(ob) == false)
                {
                    modelDb.Create(ob);
                }
                else
                {
                }
            }
        }