Пример #1
0
        public virtual DBForeignKey Generate()
        {
            if (ReferenceType == null ||
                Table == null || Table.Schema == null ||
                Column == null || Column.Column == null)
            {
                throw new Exception($"{nameof(ReferenceAttribute)} is not initialized!");
            }
            if (ForeignKey == null)
            {
                var referenceTable = CheckReference();

                ForeignKey = new DBForeignKey()
                {
                    Table     = Table.Table,
                    Column    = Column.Column,
                    Reference = referenceTable.PrimaryKey,
                    Name      = Attribute.Name,
                };
                Table.Table.Foreigns.Add(ForeignKey);
            }
            Column.Column.IsReference = true;
            ForeignKey.Property       = PropertyInfo.Name;
            ForeignKey.PropertyInfo   = PropertyInfo;
            if (ForeignKey.PropertyInvoker == null)
            {
                ForeignKey.PropertyInvoker = EmitInvoker.Initialize(PropertyInfo, true);
            }
            return(ForeignKey);
        }
Пример #2
0
        public ReferencingGenerator(TableGenerator table, PropertyInfo property, ReferencingAttribute referencingAttribuite)
        {
            if (!property.PropertyType.IsGenericType)
            {
                throw new InvalidOperationException($"{nameof(ReferencingAttribute)} Property type expect generic enumerable!");
            }

            var referenceTable = DBTable.GetTableAttributeInherit(property.PropertyType.GetGenericArguments()[0]);

            if (referenceTable == null)
            {
                throw new InvalidOperationException($"{nameof(ReferencingAttribute)} Property type expect {nameof(TableAttribute)}!");
            }

            var referenceColumn = referenceTable.GetColumnByProperty(referencingAttribuite.ReferenceProperty);

            if (referenceColumn == null)
            {
                throw new InvalidOperationException($"{nameof(ReferencingAttribute.ReferenceProperty)} expect {nameof(ColumnAttribute)}!");
            }
            Attribute       = referencingAttribuite;
            Table           = table;
            PropertyInfo    = property;
            ReferenceTable  = referenceTable;
            ReferenceColumn = referenceColumn;
            PropertyInvoker = EmitInvoker.Initialize(property, true);
        }
Пример #3
0
        protected virtual IEnumerable ListFind(string filter)
        {
            if (listSource is ISelectable selectable)
            {
                return(selectable.Select(ListProperty, CompareType.Like, filter));
            }

            return(ListHelper.Search(listSource, EmitInvoker.Initialize(listSource[0].GetType(), ListProperty), filter, CompareType.Like, null));
        }
Пример #4
0
        public void TestQuery()
        {
            var query = new Query <TestClass>(new[] {
                new QueryParameter <TestClass>()
                {
                    Invoker  = EmitInvoker.Initialize <TestClass>(nameof(TestClass.Name)),
                    Comparer = CompareType.Like,
                    Value    = "Threading"
                },
                new QueryParameter <TestClass>()
                {
                    Invoker  = EmitInvoker.Initialize <TestClass>(nameof(TestClass.Field)),
                    Comparer = CompareType.NotEqual,
                    Value    = 6
                }
            });
            var result = list.Select(query);

            Assert.AreEqual(1, result.Count(), "Select by Query Name and Field Fail");

            query = new Query <TestClass>(new[] {
                new QueryParameter <TestClass>()
                {
                    Invoker  = EmitInvoker.Initialize <TestClass>(nameof(TestClass.Name)),
                    Comparer = CompareType.Like,
                    Value    = "Threading"
                },
                new QueryParameter <TestClass>()
                {
                    Logic    = LogicType.AndNot,
                    Invoker  = EmitInvoker.Initialize <TestClass>(nameof(TestClass.Field)),
                    Comparer = CompareType.Equal,
                    Value    = 6
                }
            });
            result = list.Select(query);
            Assert.AreEqual(1, result.Count(), "Select by Query Name and not Field Fail");

            query = new Query <TestClass>(new[] {
                new QueryParameter <TestClass>()
                {
                    Invoker  = EmitInvoker.Initialize <TestClass>(nameof(TestClass.Name)),
                    Comparer = CompareType.Like,
                    Value    = "Threading"
                },
                new QueryParameter <TestClass>()
                {
                    Logic    = LogicType.Or,
                    Invoker  = EmitInvoker.Initialize <TestClass>(nameof(TestClass.Field)),
                    Comparer = CompareType.Less,
                    Value    = 3
                }
            });
            result = list.Select(query);
            Assert.AreEqual(4, result.Count(), "Select by Query Name or Field Fail");
        }
Пример #5
0
        private void ToolLoadFileClick(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog()
            {
                Multiselect = true
            };

            if (dialog.Run(ParentWindow))
            {
                foreach (string fileName in dialog.FileNames)
                {
                    string name  = Path.GetFileName(fileName);
                    var    query = new Query <DBProcedure>(new[]
                    {
                        new QueryParameter <DBProcedure>()
                        {
                            Invoker = EmitInvoker.Initialize <DBProcedure>(nameof(DBProcedure.DataName)),
                            Value   = name
                        },
                        new QueryParameter <DBProcedure>()
                        {
                            Invoker = EmitInvoker.Initialize <DBProcedure>(nameof(DBProcedure.ProcedureType)),
                            Value   = ProcedureTypes.File
                        },
                    });
                    if (!(CurrentSchema.Procedures.Find(query) is DBProcedure procedire))
                    {
                        procedire = new DBProcedure
                        {
                            ProcedureType = ProcedureTypes.File,
                            DataName      = name,
                            Name          = Path.GetFileNameWithoutExtension(name)
                        };
                    }
                    procedire.Data  = File.ReadAllBytes(fileName);
                    procedire.Stamp = File.GetLastWriteTime(fileName);
                    procedire.Save();
                }
                MessageDialog.ShowMessage(ParentWindow, Locale.Get("FlowExplorer", "Files load complete!"), "File Loader!");
            }
        }
Пример #6
0
        public static SelectableList <TestResult> Test(int c = 100000)
        {
            var list = new SelectableList <TestResult>();

            var test     = new TestClass();
            var aTest    = test as TestAbstract;
            var iTest    = test as IOrder;
            var pOrder   = test.GetType().GetProperty("Order");
            var pItem    = test.GetType().GetProperty("Item", new Type[] { typeof(string) });
            var cDefault = typeof(TestClass).GetConstructor(Type.EmptyTypes);
            var cParam   = typeof(TestClass).GetConstructor(new Type[] { typeof(int), typeof(string) });

            var aOrder   = EmitInvoker.Initialize(pOrder);
            var aItem    = EmitInvoker.Initialize(pItem, "fdsfds");
            var aDefault = EmitInvoker.Initialize(cDefault);
            var aParam   = EmitInvoker.Initialize(cParam);

            var param        = new object[] { "cfsdf" };
            var paramDefault = new object[] { };
            var paramParam   = new object[] { 12, "1dasdas" };

            var actionBinder = new ActionInvoker <TestClass, int>(
                nameof(TestClass.Order),
                (item) => item.Order,
                (item, value) => item.Order = value);


            int       val;
            string    sval;
            object    oval;
            Stopwatch watch = new Stopwatch();

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                val = actionBinder.GetValue(test);
                //tc.Order = val;
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Action", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                val = test.Order;
                //tc.Order = val;
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Direct", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                val = aTest.Order;
                //tc.Order = val;
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Abstract", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                val = iTest.Order;
                //tc.Order = val;
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Interface", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                oval = pOrder.GetValue(test, null);
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Reflection", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                val = (int)pOrder.GetValue(test, null);
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Reflection UNBOX", watch.Elapsed));


            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                oval = aOrder.GetValue(test);
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Emit Invoke", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                val = (int)aOrder.GetValue(test);
            }
            watch.Stop();
            list.Add(new TestResult("Property Get", "Emit Invoke UNBOX", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                sval = test["fsdfdsf"];
            }
            watch.Stop();
            list.Add(new TestResult("Property Index", "Direct", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                oval = pItem.GetValue(test, param);
            }
            watch.Stop();
            list.Add(new TestResult("Property Index", "Reflection", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                sval = (string)pItem.GetValue(test, param);
            }
            watch.Stop();
            list.Add(new TestResult("Property Index", "Reflection UNBOX", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                oval = aItem.GetValue(test);
            }
            watch.Stop();
            list.Add(new TestResult("Property Index", "Emit Invoke", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                sval = (string)aItem.GetValue(test);
            }
            watch.Stop();
            list.Add(new TestResult("Property Index", "Emit Invoke UNBOX", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                test = new TestClass();
            }
            watch.Stop();
            list.Add(new TestResult("Constructor", "Direct", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                test = (TestClass)cDefault.Invoke(paramDefault);
            }
            watch.Stop();
            list.Add(new TestResult("Constructor", "Reflection UNBOX", watch.Elapsed));

            watch.Reset();
            watch.Start();
            //object[] obj = new object[] { };
            for (int i = 0; i <= c; i++)
            {
                test = (TestClass)aDefault.Create(paramDefault);
            }
            watch.Stop();
            list.Add(new TestResult("Constructor", "Emit Invoke UNBOX", watch.Elapsed));


            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                test = new TestClass(12, "dsadas");
            }
            watch.Stop();
            list.Add(new TestResult("Constructor Params", "Direct", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                oval = cParam.Invoke(paramParam);
            }
            watch.Stop();
            list.Add(new TestResult("Constructor Params", "Reflection", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                test = (TestClass)cParam.Invoke(paramParam);
            }
            watch.Stop();
            list.Add(new TestResult("Constructor Params", "Reflection UNBOX", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                oval = aParam.Create(paramParam);
            }
            watch.Stop();
            list.Add(new TestResult("Constructor Params", "Emit Invoke", watch.Elapsed));

            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                test = (TestClass)aParam.Create(paramParam);
            }
            watch.Stop();
            list.Add(new TestResult("Constructor Params", "Emit Invoke UNBOX", watch.Elapsed));

            TestClass p1 = new TestClass(123112365, "test string compa3rision");
            TestClass p2 = new TestClass(124312312, "test string comp4arision");

            //Compare string
            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                p1.Comment.CompareTo(p2.Comment);
            }
            watch.Stop();
            list.Add(new TestResult("Compare String", "Direct", watch.Elapsed));

            //Compare string Invariant
            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                CultureInfo.InvariantCulture.CompareInfo.Compare(p1.Comment, p2.Comment, CompareOptions.Ordinal);
            }
            watch.Stop();
            list.Add(new TestResult("Compare String", "Direct Invariant", watch.Elapsed));

            //Compare Accessor string
            watch.Reset();
            watch.Start();
            var ce = new InvokerComparer(EmitInvoker.Initialize(typeof(TestClass).GetProperty("Comment")), ListSortDirection.Ascending);

            for (int i = 0; i <= c; i++)
            {
                ce.Compare(p1, p2);
            }
            watch.Stop();
            list.Add(new TestResult("Compare String", "Emit Invoke Property", watch.Elapsed));

            //Compare integer
            watch.Reset();
            watch.Start();
            for (int i = 0; i <= c; i++)
            {
                p1.Order.CompareTo(p2.Order);
            }
            watch.Stop();
            list.Add(new TestResult("Compare Int", "Direct", watch.Elapsed));

            //Compare Accessor Int
            watch.Reset();
            watch.Start();
            ce = new InvokerComparer(EmitInvoker.Initialize(typeof(TestClass).GetProperty("Order")), ListSortDirection.Ascending);
            for (int i = 0; i <= c; i++)
            {
                ce.Compare(p1, p2);
            }
            watch.Stop();
            list.Add(new TestResult("Compare Int", "Emit Invoke Property", watch.Elapsed));


            return(list);
        }
Пример #7
0
 public void Bind(object bindSource, string bindProperty)
 {
     Bind(bindSource, bindSource == null ? null : EmitInvoker.Initialize(bindSource.GetType(), bindProperty));
 }
Пример #8
0
 public CodeAttributeCache(CodeAttribute attribute, MemberInfo member)
 {
     Attribute     = attribute;
     Member        = member;
     MemberInvoker = EmitInvoker.Initialize(member, true);
 }
Пример #9
0
 protected virtual IInvoker GetFileNameInvoker(object dataSource)
 {
     return(EmitInvoker.Initialize(dataSource.GetType(), propertyFileName));
 }
Пример #10
0
 public void BindData(DBItem dataSource, DBColumn column, DBTable refer = null)
 {
     if (Column != column && dataSource?.GetType() != DataSource.GetType())
     {
         Binding?.Dispose();
         if (column != null)
         {
             CellEditor = TableLayoutList.InitCellEditor(column);
             if (CellEditor is CellEditorTable && refer != null)
             {
                 ((CellEditorTable)CellEditor).Table = refer;
             }
             Binding = new InvokeBinder <DBItem, FieldEditor>(dataSource, column, this, EmitInvoker.Initialize <FieldEditor>(nameof(Value)));
         }
     }
     DataSource = dataSource;
 }
Пример #11
0
 public ParameterInvoker(ParameterAttribute parameter, MemberInfo member)
 {
     Parameter     = parameter;
     Member        = member;
     MemberInvoker = EmitInvoker.Initialize(member, true);
 }