Example #1
0
        private string GetPerentSummrytxt(ShapeElement parentShape)
        {
            ClrClass class2 = GetClass(parentShape);

            if (class2 == null)
            {
                return("");
            }
            if (class2.Inherits == null)
            {
                return("");
            }
            if (class2.Inherits == "Object")
            {
                return("");
            }
            if (class2.Parent is ClrNamespace)
            {
                foreach (ClrType type in ((ClrNamespace)class2.Parent).ClrClasses)
                {
                    if (type.AccessibleName == class2.Inherits)
                    {
                        if (string.IsNullOrEmpty(type.DocSummary))
                        {
                            return(string.Format("¼Ì³Ð:{0}", class2.Inherits));
                        }
                        return(string.Format("¼Ì³Ð:{0}", type.DocSummary));
                    }
                }
            }
            return(string.Format("¼Ì³Ð:{0}", class2.Inherits));
        }
Example #2
0
        public static string GenerateCode(ClrClass @class, bool readOnly)
        {
            if (@class == null)
            {
                throw new ArgumentNullException("class");
            }

            var name       = @class.Name;
            var properties = @class.Properties;

            var buffer = new StringBuilder(1024);

            buffer.Append(@"public");
            buffer.Append(Space);
            buffer.Append(@"sealed");
            buffer.Append(Space);
            buffer.Append(@"class");
            buffer.Append(Space);
            buffer.Append(name);
            buffer.AppendLine();

            buffer.AppendLine(@"{");

            AppendProperties(properties, buffer, readOnly);
            AppendContructor(name, properties, buffer);

            buffer.Append(@"}");

            return(buffer.ToString());
        }
Example #3
0
        public Option <object> TryInvoke(string descriptor)
        {
            try
            {
                var opName = ifBlank(descriptor, string.Empty).LeftOf('(');
                if (isBlank(opName))
                {
                    return(none <object>(OperationNameMalformed(descriptor)));
                }

                var args = from m in descriptor.TryGetFirstIndexOf('(')
                           from n in descriptor.TryGetLastIndexOf(')')
                           select descriptor.Substring(m + 1, n - m - 1).Split(',');

                if (!args)
                {
                    return(none <object>(ArgumentsMalformed(descriptor)));
                }

                var stringArgs = args.Require();

                var candidates = (from m in ClrClass.Get(GetType()).PublicInstanceMethods
                                  where m.Name == opName
                                  select m).AsList();

                if (candidates.Count == 0)
                {
                    return(none <object>(MethodNotImplemented(opName)));
                }

                if (candidates.Count > 1)
                {
                    return(none <object>(AmbiguousMatch(opName)));
                }

                var method      = candidates[0];
                var methodParms = method.Parameters.ToList();
                var j           = Math.Min(stringArgs.Length, methodParms.Count);
                var argValues   = new object[j];
                for (int i = 0; i < j; i++)
                {
                    var param     = methodParms[i];
                    var stringArg = stringArgs[i];
                    var argValue  = ParseArgValue(param, stringArg);
                    if (!argValue)
                    {
                        return(argValue);
                    }
                    else
                    {
                        argValues[i] = argValue.Require();
                    }
                }
                return(method.Invoke(argValues));
            }
            catch (Exception e)
            {
                return(none <object>(e));
            }
        }
Example #4
0
        private static string GetAdapterWithCollection(ClrClass @class, DbTable table, DbTable[] foreignKeyTables, DbTable detailsTable)
        {
            var generator = new CodeGenerator();
            var className = AddClassDefinition(table, generator);

            generator.BeginBlock();
            var fields = AddFiledsAndContructor(generator, className, foreignKeyTables, detailsTable);

            // Add Get method
            generator.AddGetWithDetailsMethod(@class.Name, table, detailsTable);
            generator.AddEmptyLine();

            // Add IdReader method
            generator.AddIdReaderMethod();
            generator.AddEmptyLine();

            // Add Attach method
            generator.AddAttachMethod(table, detailsTable);
            generator.AddEmptyLine();

            // Add Creator
            generator.AddCreator(@class, fields, detailsTable.Columns.Length - 1);
            generator.AddEmptyLine();

            AddInsertUpdateDelete(generator, @class, table);

            generator.EndBlock();

            return(generator.GetFormattedOutput());
        }
Example #5
0
        public static string GenerateCode(ClrClass @class, DbTable table, DbSchema schema)
        {
            if (@class == null)
            {
                throw new ArgumentNullException("class");
            }
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }

            var foreignKeyTables = ForeignKeyHelper.GetForeignKeyTables(table.Columns, schema);

            if (table.IsReadOnly)
            {
                return(GetAdapterReadonOnly(@class, table, foreignKeyTables));
            }
            var collectionType = ClrTypeHelper.GetCollectionType(@class.Properties);

            if (collectionType == null)
            {
                return(GetAdapter(@class, table, foreignKeyTables));
            }
            return(GetAdapterWithCollection(@class, table, foreignKeyTables, FindCollectionTable(schema, collectionType)));
        }
Example #6
0
        public void AddDelete(ClrClass @class, DbTable table)
        {
            if (@class == null)
            {
                throw new ArgumentNullException("class");
            }
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            var varName = NameProvider.ToParameterName(@class.Name);

            _buffer.AppendLine(string.Format(@"public void Delete({0} {1})", @class.Name, varName));

            this.BeginBlock();

            _buffer.AppendLine(this.GetParameterCheck(varName));
            this.AddEmptyLine();

            _buffer.AppendLine(string.Format(@"var query = @""{0}"";", QueryCreator.GetDelete(table).Statement));
            this.AddEmptyLine();
            _buffer.AppendLine(@"var sqlParams = new []");

            this.BeginBlock();
            _buffer.AppendLine(string.Format(@"QueryHelper.Parameter(@""{0}"", {1}.{0}),", NameProvider.IdName, varName));
            this.EndBlockWith();

            this.AddEmptyLine();

            _buffer.AppendLine(@"QueryHelper.ExecuteQuery(query, sqlParams);");

            this.EndBlock();
        }
Example #7
0
        private string GetObjectUsings(ClrClass clrClass)
        {
            var buffer = new StringBuilder();

            var addSystem   = false;
            var addGenerics = false;

            foreach (var property in clrClass.Properties)
            {
                var type = property.Type;
                if (type.CheckValue)
                {
                    addSystem = true;
                }
                if (type.IsCollection)
                {
                    addGenerics = true;
                }
            }

            if (addSystem)
            {
                buffer.AppendLine(@"using System;");
            }
            if (addGenerics)
            {
                buffer.AppendLine(@"using System.Collections.Generic;");
            }

            return(buffer.ToString());
        }
Example #8
0
        private string GetSummrytxt(ShapeElement parentShape)
        {
            ClrClass class2 = GetClass(parentShape);

            if (class2 == null)
            {
                return("");
            }

            return(class2.DocSummary);
        }
Example #9
0
        public void AddInsert(ClrClass @class, DbTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            var className = table.ClassName;

            var varName = NameProvider.ToParameterName(className);

            _buffer.AppendLine(string.Format(@"public void Insert({0} {1})", className, varName));

            this.BeginBlock();

            _buffer.AppendLine(this.GetParameterCheck(varName));
            this.AddEmptyLine();

            _buffer.AppendLine(string.Format(@"var query = @""{0}"";", QueryCreator.GetInsert(table).Statement));
            this.AddEmptyLine();
            _buffer.AppendLine(@"var sqlParams = new []");

            this.BeginBlock();
            var index = 0;
            var names = QueryCreator.GetParametersWithoutPrimaryKey(table);

            foreach (var property in @class.Properties)
            {
                var type = property.Type;
                if (type.IsCollection)
                {
                    continue;
                }
                var name = property.Name;
                if (name != NameProvider.IdName)
                {
                    if (!type.IsBuiltIn)
                    {
                        name += @"." + NameProvider.IdName;
                    }
                    _buffer.AppendLine(string.Format(@"QueryHelper.Parameter(@""{0}"", {1}.{2}),", names[index++], varName, name));
                }
            }
            this.EndBlockWith();

            this.AddEmptyLine();

            _buffer.AppendLine(@"QueryHelper.ExecuteQuery(query, sqlParams);");
            _buffer.AppendLine(string.Format(@"{0}.Id = Convert.ToInt64(QueryHelper.ExecuteScalar(@""SELECT LAST_INSERT_ROWID()""));", varName));

            this.EndBlock();
        }
Example #10
0
        private static void AddInsertUpdateDelete(CodeGenerator generator, ClrClass @class, DbTable table)
        {
            // Add Insert
            generator.AddInsert(@class, table);
            generator.AddEmptyLine();

            // Add Update
            generator.AddUpdate(@class, table);
            generator.AddEmptyLine();

            // Add Delete
            generator.AddDelete(@class, table);
        }
Example #11
0
        public void AddUpdate(ClrClass @class, DbTable table)
        {
            if (@class == null)
            {
                throw new ArgumentNullException("class");
            }
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            var varName = NameProvider.ToParameterName(@class.Name);

            _buffer.AppendLine(string.Format(@"public void Update({0} {1})", @class.Name, varName));

            this.BeginBlock();

            _buffer.AppendLine(this.GetParameterCheck(varName));
            this.AddEmptyLine();

            _buffer.AppendLine(string.Format(@"var query = @""{0}"";", QueryCreator.GetUpdate(table).Statement));
            this.AddEmptyLine();
            _buffer.AppendLine(@"var sqlParams = new []");

            this.BeginBlock();
            var index      = 0;
            var parameters = QueryCreator.GetParameters(table.Columns);

            foreach (var property in @class.Properties)
            {
                var type = property.Type;
                if (type.IsCollection)
                {
                    continue;
                }

                var name = property.Name;
                if (!type.IsBuiltIn)
                {
                    name += @"." + NameProvider.IdName;
                }
                _buffer.AppendLine(string.Format(@"QueryHelper.Parameter(@""{0}"", {1}.{2}),", parameters[index++].Name, varName, name));
            }
            this.EndBlockWith();

            this.AddEmptyLine();

            _buffer.AppendLine(@"QueryHelper.ExecuteQuery(query, sqlParams);");

            this.EndBlock();
        }
Example #12
0
        EchoClient(string addr, string port)
        {
            byte[] baddr = Encoding.ASCII.GetBytes(addr),
            bport = Encoding.ASCII.GetBytes(port);
            unsafe
            {
                fixed(byte *a = baddr, p = bport)
                {
                    sbyte *sp = (sbyte *)p, sa = (sbyte *)a;

                    clr = new ClrClass(sa, sp);
                }
            }
        }
Example #13
0
        public System.Type GetType(ClrClass Class)
        {
            //Using private API, which should not be public. An ugly hack.
            AssemblyName assemblyName = Starcounter.Binding.Bindings.GetTypeDef(Class.FullName).TypeLoader.AssemblyName;

            Assembly assembly = this.GetAssembly(assemblyName.Name);

            if (assembly == null) {
                return null;
            }

            System.Type type = assembly.GetType(Class.FullName);

            return type;
        }
        /// <summary>
        /// 获取基类的泛型参数
        /// </summary>
        /// <returns></returns>
        private string GetBastGenericArgs()
        {
            if (GenericArgs == null || GenericArgs.Count <= 0)
            {
                return(null);
            }
            List <ClrClass> lstcls            = Connect.GetAllClass(DesignerInfo.SelectedDiagram);
            Dictionary <string, ClrClass> dic = new Dictionary <string, ClrClass>();
            StringBuilder sbType = new StringBuilder();

            foreach (ClrClass cls in lstcls)
            {
                sbType.Append(cls.OwnerNamespace.Name);
                if (sbType.Length > 0)
                {
                    sbType.Append(".");
                }
                sbType.Append(cls.Name);
                dic[sbType.ToString()] = cls;
                sbType.Remove(0, sbType.Length);
            }
            StringBuilder sb = new StringBuilder();

            foreach (string str in GenericArgs)
            {
                ClrClass curClass = null;

                if (dic.TryGetValue(str, out curClass))
                {
                    sb.Append("DB_" + curClass.Name);
                }
                else
                {
                    sb.Append("BQLEntityParamHandle");
                }
                sb.Append(",");
            }
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }
            return(sb.ToString());
        }
Example #15
0
        private static string GetAdapter(ClrClass @class, DbTable table, DbTable[] foreignKeyTables)
        {
            var generator = new CodeGenerator();

            var className = AddClassDefinition(table, generator);

            generator.BeginBlock();

            var fields = AddFiledsAndContructor(generator, className, foreignKeyTables);

            var addGetMethod = true;

            foreach (var property in @class.Properties)
            {
                var type = property.Type;
                if (!type.IsBuiltIn)
                {
                    if (!HasForeignKeyTableFor(foreignKeyTables, type))
                    {
                        addGetMethod = false;
                        break;
                    }
                }
            }

            if (addGetMethod)
            {
                // Add Get method
                generator.AddGetMethod(@class.Name, table);
                generator.AddEmptyLine();
            }

            // Add Creator
            generator.AddCreator(@class, fields);
            generator.AddEmptyLine();

            AddInsertUpdateDelete(generator, @class, table);

            generator.EndBlock();

            return(generator.GetFormattedOutput());
        }
Example #16
0
        /// <summary>
        /// 获取所有类
        /// </summary>
        /// <returns></returns>
        public static List <ClrClass> GetAllClass(Diagram selectedDiagram)
        {
            ShapeElementMoveableCollection nestedChildShapes = selectedDiagram.NestedChildShapes;
            List <ClrClass> lstClass = new List <ClrClass>();
            IEnumerable     shapes   = nestedChildShapes as IEnumerable;

            if (shapes == null)
            {
                return(null);
            }
            foreach (ShapeElement element in shapes)
            {
                ClrClass classType = SummaryShape.GetClass(element);
                if (classType != null)
                {
                    lstClass.Add(classType);
                }
            }
            return(lstClass);
        }
Example #17
0
        /// <summary>
        /// 填充字段和映射信息
        /// </summary>
        /// <param name="cls"></param>
        /// <param name="designerInfo"></param>
        /// <param name="dicParam"></param>
        /// <param name="dicRelation"></param>
        public static void FillBaseTypeParam(string type, ClassDesignerInfo designerInfo,
                                             Dictionary <string, EntityParamField> dicParam, Dictionary <string, EntityRelationItem> dicRelation)
        {
            if (type == typeof(EntityBase).FullName || type == typeof(ThinModelBase).FullName)
            {
                return;
            }
            ClrClass cls = Connect.FindClrClassByName(type, designerInfo.SelectedDiagram);

            if (cls == null)
            {
                return;
            }

            EntityConfig entity = new EntityConfig(cls, designerInfo);

            if (!entity.HasConfig)
            {
                return;
            }
            foreach (EntityParamField ep in entity.EParamFields)
            {
                if (!ep.IsGenerate)
                {
                    continue;
                }
                dicParam[ep.ParamName] = ep;
            }
            foreach (EntityRelationItem er in entity.ERelation)
            {
                if (!er.IsGenerate)
                {
                    continue;
                }
                string key = er.SourceProperty + "_" + er.TargetProperty;
                dicRelation[key] = er;
            }
            FillBaseTypeParam(entity.BaseTypeName, designerInfo, dicParam, dicRelation);
        }
Example #18
0
        private static string GetAdapterReadonOnly(ClrClass @class, DbTable table, DbTable[] foreignKeyTables)
        {
            var generator = new CodeGenerator();

            var className = AddClassDefinition(table, generator);

            generator.BeginBlock();
            var fields = AddFiledsAndContructor(generator, className, foreignKeyTables);

            // Add Fill method
            generator.AddFillMethod(@class.Name, table);
            generator.AddEmptyLine();

            // Add Creator
            generator.AddCreator(@class, fields);
            generator.AddEmptyLine();

            // Add Selector
            generator.AddSelector(@class.Name);

            generator.EndBlock();

            return(generator.GetFormattedOutput());
        }
Example #19
0
        /// <summary>
        /// 生成数据层
        /// </summary>
        private void GreanDataAccess()
        {
            ClassDesignerInfo cinfo    = GetDesignerInfo();
            List <ClrClass>   lstClass = Connect.GetAllClass(cinfo.SelectedDiagram);

            using (FrmProcess frmLoading = FrmProcess.ShowProcess())
            {
                frmLoading.UpdateProgress(0, 0, "正在生成类");

                for (int i = 0; i < lstClass.Count; i++)
                {
                    ClrClass      cls    = lstClass[i];
                    EntityConfig  entity = new EntityConfig(cls, cinfo);
                    Generate3Tier g3t    = new Generate3Tier(entity);
                    if (!string.IsNullOrEmpty(entity.TableName))
                    {
                        g3t.GenerateIDataAccess();
                        g3t.GenerateDataAccess();
                        g3t.GenerateBQLDataAccess();
                    }
                    frmLoading.UpdateProgress(i + 1, lstClass.Count, "正在生成");
                }
            }
        }
Example #20
0
        public void AddCreator(ClrClass @class, Field[] fields, int readerIndexOffset = 0)
        {
            var properties = @class.Properties;

            var index = 0;
            var names = new string[properties.Length];

            foreach (var property in properties)
            {
                var name = NameProvider.ToParameterName(property.Name);
                var type = property.Type;
                if (type.IsCollection)
                {
                    name = @"new " + type.Name + @"()";
                }
                names[index++] = name;
            }

            Field parameter = null;

            for (var i = 0; i < properties.Length; i++)
            {
                var property  = properties[i];
                var name      = names[i];
                var type      = property.Type;
                var readValue = type.IsBuiltIn || (Field.FindFieldByType(fields, property.Type)) != null;
                if (!readValue && !type.IsCollection)
                {
                    parameter = new Field(type.Name, name);
                }
            }

            _buffer.AppendLine(parameter == null
                                ? string.Format(@"private {0} Creator(IDataReader r)", @class.Name)
                                : string.Format(@"public {0} Creator(IDataReader r, {1} {2})", @class.Name, parameter.Type, parameter.Name));

            this.BeginBlock();

            if (parameter != null)
            {
                _buffer.AppendLine(this.GetParameterCheck(@"r"));
                _buffer.AppendLine(this.GetParameterCheck(parameter.Name));
                this.AddEmptyLine();
            }

            var readerIndex = 0;

            for (var i = 0; i < properties.Length; i++)
            {
                var property = properties[i];
                var name     = names[i];
                var type     = property.Type;

                Field field     = null;
                var   readValue = type.IsBuiltIn || (field = Field.FindFieldByType(fields, property.Type)) != null;
                if (readValue)
                {
                    var value = readerIndex + readerIndexOffset;

                    _buffer.AppendLine(string.Format(@"var {0} = {1};", name, type.DefaultValue));
                    _buffer.AppendLine(string.Format(@"if (!r.IsDBNull({0}))", value));

                    this.BeginBlock();

                    if (type.IsBuiltIn)
                    {
                        _buffer.AppendLine(string.Format(@"{0} = r.{1}({2});", name, type.ReaderMethod, value));
                    }
                    else
                    {
                        _buffer.AppendLine(string.Format(@"{0} = _{1}[r.{2}({3})];", name, field.Name, type.ReaderMethod, value));
                    }

                    this.EndBlock();
                    readerIndex++;
                }
            }

            this.AddEmptyLine();

            _buffer.AppendLine(string.Format(@"return new {0}({1});", @class.Name, string.Join(@", ", names)));

            this.EndBlock();
        }
Example #21
0
        /// <summary>实现 IDTCommandTarget 接口的 Exec 方法。此方法在调用该命令时调用。</summary>
        /// <param term='commandName'>要执行的命令的名称。</param>
        /// <param term='executeOption'>描述该命令应如何运行。</param>
        /// <param term='varIn'>从调用方传递到命令处理程序的参数。</param>
        /// <param term='varOut'>从命令处理程序传递到调用方的参数。</param>
        /// <param term='handled'>通知调用方此命令是否已被处理。</param>
        /// <seealso class='Exec' />
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                try
                {
                    if (IsCommand(commandName, "BuffaloEntityConfig"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            if (!(sp.AssociatedType is ClrClass))
                            {
                                continue;
                            }
                            using (FrmClassDesigner st = new FrmClassDesigner())
                            {
                                Diagram selDiagram = SelectedDiagram;
                                st.SelectedClass = sp;
                                st.DesignerInfo  = GetDesignerInfo();
                                st.ShowDialog();
                            }
                        }
                        handled = true;
                        return;
                    }
                    else if (IsCommand(commandName, "BuffaloDBCreater"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        List <ClrClass> lstClass = new List <ClrClass>();
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp        = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            ClrClass     classType = sp.AssociatedType as ClrClass;
                            if (classType == null)
                            {
                                continue;
                            }
                            lstClass.Add(classType);
                        }
                        using (FrmDBCreate st = new FrmDBCreate())
                        {
                            Diagram selDiagram = SelectedDiagram;
                            st.SelectedClass = lstClass;
                            //st.SelectDocView = SelectDocView;
                            //st.CurrentProject = CurrentProject;
                            //st.SelectedDiagram = selDiagram;
                            st.DesignerInfo = GetDesignerInfo();
                            st.ShowDialog();
                        }
                        handled = true;
                        return;
                    }

                    else if (IsCommand(commandName, "BuffaloDBToEntity"))
                    {
                        Diagram dia = SelectedDiagram;
                        if (!(dia is ShapeElement))
                        {
                            return;
                        }
                        using (FrmAllTables frmTables = new FrmAllTables())
                        {
                            //frmTables.SelectedDiagram = dia;
                            //frmTables.SelectDocView = SelectDocView;
                            //frmTables.CurrentProject = CurrentProject;
                            frmTables.DesignerInfo = GetDesignerInfo();
                            frmTables.ShowDialog();
                        }
                    }

                    else if (IsCommand(commandName, "BuffaloShowHideSummery"))
                    {
                        Diagram dia = this.SelectedDiagram;

                        if (dia != null)
                        {
                            VSConfigManager.InitConfig(_applicationObject.Version);
                            ShapeSummaryDisplayer.ShowOrHideSummary(dia, this);
                            this.SelectDocView.CurrentDesigner.ScrollDown();
                            this.SelectDocView.CurrentDesigner.ScrollUp();

                            handled = true;
                        }
                    }
                    else if (IsCommand(commandName, "BuffaloDBCreateAll"))
                    {
                        List <ClrClass> lstClass = GetAllClass(SelectedDiagram);
                        if (lstClass == null)
                        {
                            return;
                        }
                        using (FrmDBCreate st = new FrmDBCreate())
                        {
                            Diagram selDiagram = SelectedDiagram;
                            st.SelectedClass = lstClass;
                            //st.SelectDocView = SelectDocView;
                            //st.CurrentProject = CurrentProject;
                            //st.SelectedDiagram = selDiagram;
                            st.DesignerInfo = GetDesignerInfo();
                            st.ShowDialog();
                        }
                        handled = true;
                        return;
                    }
                    else if (IsCommand(commandName, "BuffaloDBSet"))
                    {
                        string dalNamespace = GetDesignerInfo().GetNameSpace() + ".DataAccess";
                        ShapeElementMoveableCollection nestedChildShapes = SelectedDiagram.NestedChildShapes;

                        FrmDBSetting.ShowConfig(GetDesignerInfo(), dalNamespace);
                    }
                    else if (IsCommand(commandName, "BuffaloEntityRemove"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            if (!(sp.AssociatedType is ClrClass))
                            {
                                continue;
                            }
                            EntityConfig entity = new EntityConfig(sp.AssociatedType,
                                                                   GetDesignerInfo());
                            //entity.SelectDocView = SelectDocView;
                            if (MessageBox.Show("是否要删除实体:" + entity.ClassName +
                                                " 及其相关的业务类?", "提示", MessageBoxButtons.YesNo,
                                                MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                EntityRemoveHelper.RemoveEntity(entity);
                            }
                        }
                    }

                    else if (IsCommand(commandName, "BuffaloUpdateEntityByDB"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp       = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            ClrClass     curClass = sp.AssociatedType as ClrClass;
                            if (curClass == null)
                            {
                                continue;
                            }
                            EntityConfig entity = EntityConfig.GetEntityConfigByTable(curClass,
                                                                                      GetDesignerInfo());
                            entity.GenerateCode();
                        }
                        handled = true;
                        return;
                    }
                    if (IsCommand(commandName, "BuffaloUI"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            if (!(sp.AssociatedType is ClrClass))
                            {
                                continue;
                            }
                            using (FrmUIGenerater st = new FrmUIGenerater())
                            {
                                Diagram selDiagram = SelectedDiagram;
                                st.CurEntityInfo = new EntityInfo(sp.AssociatedType, GetDesignerInfo());
                                st.BindTargetProjects(AllProjects);
                                st.ShowDialog();
                            }
                        }
                        handled = true;
                        return;
                    }
                    if (IsCommand(commandName, "commandGenDal"))
                    {
                        GreanDataAccess();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    FrmCompileResault.ShowCompileResault(null, ex.ToString(), "错误");
                }
            }
        }
Example #22
0
 /// <summary>
 /// 获取ClrClass的全名
 /// </summary>
 /// <param name="cls"></param>
 /// <returns></returns>
 public static string GetFullName(ClrClass cls)
 {
     return(cls.OwnerNamespace.Name + "." + cls.Name);
 }
Example #23
0
 /// <summary>
 /// Determines whether the class is a subclass of another
 /// </summary>
 /// <param name="candidate">The supertype to test</param>
 /// <returns></returns>
 public bool IsSublcassOf(ClrClass candidate)
 => ReflectedElement.IsSubclassOf(candidate);