Beispiel #1
0
        protected void InsertPreConditionEdges(BlockWithLabels <Label> previousBlock, BlockWithLabels <Label> newBlock)
        {
            var methodCallBlock = newBlock as MethodCallBlock <Label>;

            if (methodCallBlock == null || CurrentSubroutine.IsContract || CurrentSubroutine.IsOldValue)
            {
                return;
            }

            if (CurrentSubroutine.IsMethod)
            {
                var      methodInfo = CurrentSubroutine as IMethodInfo;
                Property property;
                if (methodInfo != null && MetaDataProvider.IsConstructor(methodInfo.Method) &&
                    MetaDataProvider.IsPropertySetter(methodCallBlock.CalledMethod, out property) &&
                    MetaDataProvider.IsAutoPropertyMember(methodCallBlock.CalledMethod))
                {
                    return;
                }
            }

            EdgeTag    callTag  = methodCallBlock.IsNewObj ? EdgeTag.BeforeNewObj : EdgeTag.BeforeCall;
            Subroutine requires = this.SubroutineFacade.GetRequires(methodCallBlock.CalledMethod);

            CurrentSubroutine.AddEdgeSubroutine(previousBlock, newBlock, requires, callTag);
        }
Beispiel #2
0
        protected void InsertPostConditionEdges(BlockWithLabels <Label> previousBlock, BlockWithLabels <Label> newBlock)
        {
            var methodCallBlock = previousBlock as MethodCallBlock <Label>;

            if (methodCallBlock == null)
            {
                return;
            }

            if (CurrentSubroutine.IsMethod)
            {
                var      methodInfo = CurrentSubroutine as IMethodInfo;
                Property property;
                if (methodInfo != null && MetaDataProvider.IsConstructor(methodInfo.Method) &&
                    MetaDataProvider.IsPropertyGetter(methodCallBlock.CalledMethod, out property) &&
                    MetaDataProvider.IsAutoPropertyMember(methodCallBlock.CalledMethod))
                {
                    return;
                }
            }

            EdgeTag    callTag = methodCallBlock.IsNewObj ? EdgeTag.AfterNewObj : EdgeTag.AfterCall;
            Subroutine ensures = this.SubroutineFacade.GetEnsures(methodCallBlock.CalledMethod);

            CurrentSubroutine.AddEdgeSubroutine(previousBlock, newBlock, ensures, callTag);
        }
Beispiel #3
0
        private IImmutableSet <Subroutine> GetInheritedRequires(Method method)
        {
            IImmutableSet <Subroutine> result = ImmutableSet <Subroutine> .Empty();

            if (MetaDataProvider.IsVirtual(method) && ContractProvider.CanInheritContracts(method))
            {
                Method rootMethod;
                if (MetaDataProvider.TryGetRootMethod(method, out rootMethod))
                {
                    Subroutine sub = Get(MetaDataProvider.Unspecialized(method));
                    if (sub != null)
                    {
                        result = result.Add(sub);
                    }
                }
                foreach (Method implMethod in MetaDataProvider.ImplementedMethods(method))
                {
                    Subroutine sub = Get(MetaDataProvider.Unspecialized(implMethod));
                    if (sub != null)
                    {
                        result = result.Add(sub);
                    }
                }
            }

            return(result);
        }
Beispiel #4
0
                public override TDomain Assert(APC pc, EdgeTag tag, TVar condition, TDomain data)
                {
                    var boxed = ToBoxedExpression(pc, condition);

                    bool result;

                    if (boxed.IsTrivialCondition(out result))
                    {
                        return(result ? data : data.Bottom);
                    }

                    data = data.AssumeTrue(boxed);

                    var type =
                        ContextProvider.ValueContext.GetType(
                            ContextProvider.MethodContext.CFG.Post(pc), condition);

                    if (type.IsNormal() &&
                        MetaDataProvider.Equal(type.Value, MetaDataProvider.System_Boolean))
                    {
                        var guard =
                            BoxedExpression.Binary(BinaryOperator.Ceq, boxed,
                                                   BoxedExpression.Const(1,
                                                                         MetaDataProvider.
                                                                         System_Int32));

                        data = data.AssumeTrue(guard);
                    }

                    return(data);
                }
        public void MetaDataProvider_resolves_valid_meta_data()
        {
            SetupDependencies();

            var myTestEntity = new MyTestEntity();
            var expectedDate = new DateTime(2017, 01, 01, 12, 30, 00);

            _metaDataProvider = new MetaDataProvider(_clockProviderMock.Object);
            _clockProviderMock.Setup(clockProvider => clockProvider.DateTime).Returns(expectedDate);

            _metaDataProvider.ResolveMetaData(myTestEntity, true);

            Assert.AreEqual(expectedDate, myTestEntity.Created);
            Assert.AreEqual(expectedDate, myTestEntity.Modified);
            Assert.AreEqual(true, myTestEntity.IsActive);

            var expectedNewDate = new DateTime(2017, 01, 01, 13, 30, 00);

            _clockProviderMock.Setup(clockProvider => clockProvider.DateTime).Returns(expectedNewDate);

            myTestEntity.IsActive = false;

            _metaDataProvider.ResolveMetaData(myTestEntity, false);

            Assert.AreEqual(expectedDate, myTestEntity.Created);
            Assert.AreEqual(expectedNewDate, myTestEntity.Modified);
            Assert.AreEqual(false, myTestEntity.IsActive);
        }
Beispiel #6
0
        public StackInfo LoadArg(APC pc, Parameter argument, bool isOld, Dummy dest, StackInfo data)
        {
            if (!MetaDataProvider.IsStatic(MetaDataProvider.DeclaringMethod(argument)) && MetaDataProvider.ParameterIndex(argument) == 0)
            {
                return(data.PushThis());
            }

            return(data.Push());
        }
        public void Verify_that_serializestream_null_parameters_throws_exception()
        {
            var metadataprovider = new MetaDataProvider();

            var cdp4JsonSerializer = new Cdp4JsonSerializer();

            cdp4JsonSerializer.Initialize(metadataprovider, new Version(1, 0, 0));

            Assert.Throws <ArgumentNullException>(() => cdp4JsonSerializer.SerializeToStream(null, null));
        }
Beispiel #8
0
        ICommunicator CreateCommunicator(int connectTimeout = 50000, int socketTimeout = 50000)
        {
            IConnection      connection       = CreateConnection(connectTimeout, socketTimeout);
            IAuthenticator   authenticator    = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
            MetaDataProvider metaDataProvider = new MetaDataProvider("OnlinePayments");
            var uriBuilder = new UriBuilder("http", "localhost");

            uriBuilder.Port = Port;
            return(Factory.CreateCommunicator(uriBuilder.Uri, connection, authenticator, metaDataProvider));
        }
        /// <summary>
        /// Builds the basket.
        /// </summary>
        /// <param name="connector">The connector.</param>
        /// <param name="order">The order.</param>
        /// <returns>
        /// A string containing the contents of the order
        /// </returns>
        private static string BuildBasket(CrmConnector connector, OrderProvider orderProvider, SalesOrder order)
        {
            StringBuilder basket = new StringBuilder();

            // A basket item comprises of Product Name, Quantity, Unit Cost, Tax, Cost inc. Tax, and Total Cost (Cost*Quantity).  These are all seperated with colons (i.e. %3A).
            string basketItem = String.Empty;
            string seperator  = "%3A";

            // Get a list of the names for the level Option Set.
            MetaDataProvider         metaDataProvider     = new MetaDataProvider(connector);
            OptionMetadataCollection levelOptionSetLabels = metaDataProvider.RetrieveOptionSetMetaDataCollection(SalesOrderDetail.EntityLogicalName, "lss_level");

            int basketCount = 0;
            List <SalesOrderDetail> productExtras;
            List <SalesOrderDetail> orderDetails = orderProvider.GetOrderDetail(order.Id, ProductType.Course);

            foreach (SalesOrderDetail detail in orderDetails)
            {
                string basketItemName = GetBasketNameOfProduct(detail, levelOptionSetLabels);

                // Add name of basket item with a hard-coded Quantity of 1
                basketItem = seperator + basketItemName + seperator + "1" + seperator;

                // For each product check if it has any related products
                productExtras = orderProvider.GetProductExtras(detail.Id);
                decimal extraUnitCost = 0;
                decimal extraTax      = 0;
                decimal extraTotal    = 0;
                foreach (SalesOrderDetail extra in productExtras)
                {
                    extraUnitCost += extra.BaseAmount == null ? 0 : extra.BaseAmount.Value;
                    extraTax      += extra.Tax == null ? 0 : extra.Tax.Value;
                    extraTotal    += extra.ExtendedAmount == null ? 0 : extra.ExtendedAmount.Value;
                }

                // Add unit cost
                basketItem += (detail.BaseAmount.Value + extraUnitCost).ToString("#.##") + seperator;

                // Add Tax
                basketItem += detail.Tax == null ? "0" : (detail.Tax.Value + extraTax).ToString("#.##") + seperator;

                // Add Cost inc. Tax
                basketItem += (detail.ExtendedAmount.Value + extraTotal).ToString("#.##") + seperator;

                // Add Total Cost
                basketItem += (detail.ExtendedAmount.Value + extraTotal).ToString("#.##");

                basket.Append(basketItem);
                basketCount++;
            }

            basket.Insert(0, "&Basket=" + basketCount.ToString());

            return(basket.ToString());
        }
Beispiel #10
0
        private int OldStartDepth(Subroutine subroutine)
        {
            Method method = ((IMethodInfo)subroutine).Method;
            int    count  = MetaDataProvider.Parameters(method).Count;

            if (!MetaDataProvider.IsConstructor(method) && !MetaDataProvider.IsStatic(method))
            {
                ++count;
            }
            return(count);
        }
        public bool TrySizeOf(TExpr expr, out int size)
        {
            TypeNode type;

            if (VisitorForSizeOf <TVar, TExpr> .IsSizeOf(expr, out type, this))
            {
                size = MetaDataProvider.TypeSize(type);
                return(size != -1);
            }

            return(false.Without(out size));
        }
Beispiel #12
0
        IClient CreateClient()
        {
            IConnection      connection       = new DefaultConnection(TimeSpan.FromMilliseconds(500000000), 500);
            IAuthenticator   authenticator    = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
            MetaDataProvider metaDataProvider = new MetaDataProvider("OnlinePayments");
            var uriBuilder = new UriBuilder("http", "localhost")
            {
                Port = Port
            };
            ICommunicator communicator = Factory.CreateCommunicator(uriBuilder.Uri, connection, authenticator, metaDataProvider);

            return(Factory.CreateClient(communicator));
        }
        private IEnumerable CreateDataSource()
        {
            SearchInfo info = this.Info;
            if (null != info)
            {
                SqlQuery query = CreateISearchEntitySelectQuery(info.EntityType);
                query.Combine(this.UserControlBuilder1.GenerateWhereQuery());

                IEntityMetaDataProvider provider = new MetaDataProvider(info.EntityType);
                return base.Factory.Query(info.EntityType, provider, query);
            }

            return null;
        }
Beispiel #14
0
        Client CreateClient()
        {
            IConnection      connection       = new DefaultConnection(TimeSpan.FromMilliseconds(500000000), 500);
            IAuthenticator   authenticator    = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
            MetaDataProvider metaDataProvider = new MetaDataProvider("Ingenico");
            var uriBuilder = new UriBuilder("http", "localhost");

            uriBuilder.Port = Port;
            Session      session      = new Session(uriBuilder.Uri, connection, authenticator, metaDataProvider);
            Communicator communicator = Factory.CreateCommunicator(session);
            Client       client       = Factory.CreateClient(communicator);

            return(client);
        }
Beispiel #15
0
        public void Setup()
        {
            var metamodel = new MetaDataProvider();

            this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0));

            this.aliasJson = "[{ \"classKind\" : \"Alias\"," +
                             "  \"content\" : \"some conent\"," +
                             "  \"iid\" : \"d46aa66e-96c2-461e-91f3-1dfc4ce744b1\"," +
                             "  \"isSynonym\" : true," +
                             "  \"languageCode\" : \"en\"," +
                             "  \"modifiedOn\":\"2015-04-17T07:48:14.56Z\"," +
                             "  \"revisionNumber\" : 1" +
                             "}]";
        }
        public ActionResult SiteObjectEdit(string typeName, object id)
        {
            var entityType = typeof(SpecialistDataContext).Assembly.GetTypes()
                             .Where(t => t.FullName == typeName).First();
            var type       = LinqToSqlUtils.GetTableName(entityType);
            var siteObject = SiteObjectService
                             .GetBy(type, LinqToSqlUtils.CorrectPKType(id, entityType));

            if (siteObject == null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(View(ViewNames.EditRelationList, new EditVM(siteObject,
                                                               MetaDataProvider.Get(typeof(SiteObject)))));
        }
Beispiel #17
0
        public void AddColumns <T>(AjaxGridVM model,
                                   params Expression <Func <T, object> >[] selectors)
        {
            var metaData = MetaDataProvider.Get(typeof(T)).GetProperties();
            var columns  = new Dictionary <string, AjaxGridVM.Column>();

            foreach (var selector in selectors)
            {
                var info = ExpressionUtils.GetPropertyInfo(selector);
                var meta = metaData.First(x => x.Info == info);
                columns.Add(meta.DisplayName(), new AjaxGridVM.Column(info.Name));
            }
            model.ColumnTitles.AddRange(columns.Select(x => x.Key));
            model.Columns.AddRange(columns.Select(x => x.Value));
        }
        public void MetaDataProvider_throws()
        {
            SetupDependencies();

            var myTestEntity = new MyTestEntity();

            _metaDataProvider = new MetaDataProvider(_clockProviderMock.Object);

            Assert.Throws <ArgumentNullException>(() => { _metaDataProvider.ResolveMetaData(default(MyTestEntity), false); });
            Assert.Throws <ArgumentNullException>(() => { _metaDataProvider.ResolveMetaData(myTestEntity, false); });

            _clockProviderMock.Setup(clockProvider => clockProvider.DateTime).Returns(new DateTime(2017, 01, 01, 12, 30, 0));

            Assert.Throws <InvalidOperationException>(() => { _metaDataProvider.ResolveMetaData(myTestEntity, false); });
        }
Beispiel #19
0
        protected override List <object> GetValuesForRow(Product item)
        {
            var values      = base.GetValuesForRow(item);
            var vendors     = SiteObjectService.GetSingleRelation <Vendor>(item);
            var entityLinks = new ListVM.EntityLinkList();

            var metaData = MetaDataProvider.Get(typeof(Vendor));

            foreach (var vendor in vendors)
            {
                entityLinks.Add(new ListVM.EntityLink(vendor, metaData, Url));
            }
            values.Add(entityLinks);
            return(values);
        }
        Client CreateClient(int connectTimeout = 50000, int socketTimeout = 50000)
        {
            // Connect timeout not implemented
            IConnection      connection       = new DefaultConnection(TimeSpan.FromMilliseconds(socketTimeout), 2);
            IAuthenticator   authenticator    = new DefaultAuthenticator(AuthorizationType.V1HMAC, "apiKey", "secret");
            MetaDataProvider metaDataProvider = new MetaDataProvider("Ingenico");
            var uriBuilder = new UriBuilder("http", "localhost");

            uriBuilder.Port = 5357;
            Session      session      = new Session(uriBuilder.Uri, connection, authenticator, metaDataProvider);
            Communicator communicator = Factory.CreateCommunicator(session);
            Client       client       = Factory.CreateClient(communicator);

            return(client);
        }
Beispiel #21
0
        public void SetUp()
        {
            this.uri = new Uri("http://www.rheagroup.com");

            var response = File.ReadAllText(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData/SiteDiretoryExtentDeep.json"));

            var metaDataProvider = new MetaDataProvider();
            var version          = new Version(1, 0, 0);

            var jsonSerializer = new CDP4JsonSerializer.Cdp4JsonSerializer(metaDataProvider, version);

            using (var stream = GenerateStreamFromString(response))
            {
                this.dtos = jsonSerializer.Deserialize(stream);
            }
        }
Beispiel #22
0
        private IImmutableSet <Subroutine> GetInheritedEnsures(Method method)
        {
            IImmutableSet <Subroutine> result = ImmutableSet <Subroutine> .Empty();

            if (MetaDataProvider.IsVirtual(method) && ContractProvider.CanInheritContracts(method))
            {
                foreach (Method implementedMethod in MetaDataProvider.OverridenAndImplementedMethods(method))
                {
                    Subroutine subroutine = Get(MetaDataProvider.Unspecialized(implementedMethod));
                    if (subroutine != null)
                    {
                        result = result.Add(subroutine);
                    }
                }
            }
            return(result);
        }
Beispiel #23
0
        public StackInfo Calli <TypeList, ArgList> (APC pc, TypeNode returnType, TypeList argTypes, bool instance, Dummy dest, Dummy functionPointer, ArgList args, StackInfo data)
            where TypeList : IIndexable <TypeNode>
            where ArgList : IIndexable <Dummy>
        {
            int count = 1;

            if (instance)
            {
                ++count;
            }
            int slots = count + (argTypes == null ? 0 : argTypes.Count);

            data.Pop(slots);
            if (MetaDataProvider.IsVoid(returnType))
            {
                return(data);
            }
            return(data.Push());
        }
        public void Setup()
        {
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            var uri = new Uri("http://www.rheagroup.com");

            this.session           = new Mock <ISession>();
            this.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            this.serviceLocator = new Mock <IServiceLocator>();
            var metadataProvider = new MetaDataProvider();

            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IMetaDataProvider>()).Returns(metadataProvider);
            this.siteDir = new SiteDirectory(Guid.NewGuid(), this.cache, uri);
            var person = new Person(Guid.NewGuid(), this.cache, uri)
            {
                Container = this.siteDir
            };

            this.session.Setup(x => x.ActivePerson).Returns(person);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.IsVersionSupported(It.IsAny <Version>())).Returns(true);
            this.personRole = new PersonRole {
                Name = "Person role", ShortName = "personRole", IDalUri = uri
            };
            this.siteDir.PersonRole.Add(this.personRole);
            this.cache.TryAdd(new CacheKey(this.siteDir.Iid, null), new Lazy <Thing>(() => this.siteDir));
            this.clone = this.siteDir.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, this.clone);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());

            this.viewmodel = new PersonRoleDialogViewModel(this.personRole, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, this.clone);
        }
Beispiel #25
0
        public void Verify_that_ParameterValueSet_is_serialized_and_deserialized()
        {
            var values = new List <string>();

            values.Add("this is a\nnewline");
            values.Add("this is another\nnewline");

            var engineeringModel = new EngineeringModel {
                Iid = Guid.Parse("5643764e-f880-44bf-90ae-361f6661ceae")
            };
            var iteration = new Iteration {
                Iid = Guid.Parse("f744ae63-cf36-4cc4-8d76-e83edd44f6d2")
            };
            var elementDefinition = new ElementDefinition {
                Iid = Guid.Parse("f7f173ea-a742-42a5-81f1-59da2f470f16")
            };
            var parameter = new Parameter {
                Iid = Guid.Parse("607764de-7598-4be2-9a95-34669de273e3")
            };
            var parameterValueSet = new ParameterValueSet
            {
                Iid    = Guid.Parse("2366c662-b857-4313-85ea-51f9bf4588b1"),
                Manual = new ValueArray <string>(values)
            };

            engineeringModel.Iteration.Add(iteration);
            iteration.Element.Add(elementDefinition);
            elementDefinition.Parameter.Add(parameter);
            parameter.ValueSet.Add(parameterValueSet);

            var metadataprovider = new MetaDataProvider();
            var serializer       = new Cdp4JsonSerializer(metadataprovider, new Version(1, 1, 0));

            var result = serializer.SerializeToString(parameterValueSet, false);

            var stream = StreamHelper.GenerateStreamFromString(result);
            var dtos   = serializer.Deserialize(stream);
            var dto    = dtos.Single() as CDP4Common.DTO.ParameterValueSet;

            Assert.That(dto.Manual, Is.EquivalentTo(values));
        }
Beispiel #26
0
        public StackInfo Call <TypeList, ArgList> (APC pc, Method method, bool virt, TypeList extraVarargs, Dummy dest, ArgList args, StackInfo data)
            where TypeList : IIndexable <TypeNode>
            where ArgList : IIndexable <Dummy>
        {
            int count = MetaDataProvider.Parameters(method).Count + (extraVarargs == null ? 0 : extraVarargs.Count);

            if (!MetaDataProvider.IsStatic(method))
            {
                if (data.IsThis(count))
                {
                    this.stack_depth_mirror_for_end_old.AddCallOnThis(pc);
                }
                ++count;
            }
            data = data.Pop(count);
            if (MetaDataProvider.IsVoidMethod(method))
            {
                return(data);
            }
            return(data.Push());
        }
Beispiel #27
0
                public override INumericalEnvironmentDomain <BoxedVariable <TVar>, BoxedExpression> Entry
                    (APC pc, Method method,
                    INumericalEnvironmentDomain <BoxedVariable <TVar>, BoxedExpression> data)
                {
                    foreach (var param in MetaDataProvider.Parameters(method).AsEnumerable())
                    {
                        TVar variable;
                        var  readAt = ContextProvider.MethodContext.CFG.Post(pc);
                        if (!ContextProvider.ValueContext.TryParameterValue(readAt, param, out variable))
                        {
                            continue;
                        }

                        var abstractType = ContextProvider.ValueContext.GetType(readAt,
                                                                                variable);
                        if (abstractType.IsNormal() && MetaDataProvider.IsPrimitive(abstractType.Value))
                        {
                            data = SetInitialRange(variable, abstractType.Value, data);
                        }
                    }

                    return(data);
                }
        public ExpressionType TypeOf(TExpr expr)
        {
            if (IsConstant(expr))
            {
                return(ExpressionContext.Decode <Dummy, ExpressionType, VisitorForTypeOf> (expr, type_of, Dummy.Value));
            }

            var abstractType = ExpressionContext.GetType(expr);

            if (abstractType.IsNormal())
            {
                var type = abstractType.Value;

                if (MetaDataProvider.IsPrimitive(type))
                {
                    if (MetaDataProvider.Equal(type, MetaDataProvider.System_Int32))
                    {
                        return(ExpressionType.Int32);
                    }
                    if (MetaDataProvider.Equal(type, MetaDataProvider.System_Single))
                    {
                        return(ExpressionType.Float32);
                    }
                    if (MetaDataProvider.Equal(type, MetaDataProvider.System_Double))
                    {
                        return(ExpressionType.Float64);
                    }
                    if (MetaDataProvider.Equal(type, MetaDataProvider.System_Boolean))
                    {
                        return(ExpressionType.Bool);
                    }
                }
            }

            return(ExpressionType.Unknown);
        }
        [HttpPost]//Örneğin İki Tarih Arası İStenirse bunu bir attribute ile meta dataya göm ve sayı tarih vb tüm alanlar için Kullan.
        public virtual MvcResult<object> Search(SearchRequest request, int? take, int? page, SearchSortRequest[] sort)//Button Edit Search. Ek paramatreler kendo dan.
        {
            return this.ResultList(() =>
            {
                Datas<object> ret = new Datas<object>();

                Type entityType;
                CacheMetaDataConfig.MetaData.TryGetType(request.TypeFullName, out entityType);
                if (null == entityType)
                    throw  new CacheMetaDataNotFoundException(request.TypeFullName);

                object entity = JsonConvert.DeserializeObject(request.EntityJson, entityType);
                IEntityMetaData metaData = new MetaDataProvider(entityType).CreateEntityMetaData();

                ISqlQueryBuilder builder = entity as ISqlQueryBuilder; ;

                if (null == builder)
                {
                    builder = new SqlQueryBuilderSelect(metaData);
                }

                FilterCriteriaList criteriaList = new FilterCriteriaList(this.Prefix);
                HashSet<string> betweenColumns = new HashSet<string>();
                IEnumerable<BetweenAttribute> bas = entityType.GetCustomAttributes<BetweenAttribute>();
                if (!bas.IsEmptyList())
                {
                    foreach (BetweenAttribute ba in bas)
                    {
                        betweenColumns.Add(ba.FirstProperty);
                        betweenColumns.Add(ba.SecondProperty);

                        betweenColumns.Add(ba.ColumnName); //?

                    object firstVal = entityType.GetProperty(ba.FirstProperty).GetValue(entity);
                        if (!firstVal.IsNull())
                        {
                            object secVal = entityType.GetProperty(ba.SecondProperty).GetValue(entity);
                            if (secVal.IsNull())
                                secVal = firstVal;

                            FilterCriteria criteria = new FilterCriteria(ba.ColumnName, ConditionOperator.Between,  this.Prefix, firstVal, secVal);
                            criteriaList.Add(criteria);
                        }
                    }
                }


                SqlQuery query = builder.ToQuery().ToInnerQuery();
                foreach (PropertyMetaData pmd in metaData.Properties)
                {
                    if (betweenColumns.Contains(pmd.Schema.ColumnName)) continue;

                    PropertyInfo pi = pmd.Property;

                    object entityValue = pi.GetValue(entity);
                    if (null != entityValue && entityValue.ToString().Length != 0)
                    {
                        object defaultValue = MvcExtensions.GetSearchDefaultValue(pi.PropertyType);
                        if (!Object.Equals(defaultValue, entityValue))//Kullanıcı Değer Girdi İse.
                        {
                            FilterCriteria criteria = null;
                            Type propertyType = pi.PropertyType;
                            if (propertyType == CachedTypes.String)
                            {
                                criteria = new FilterCriteria(pi.Name, ConditionOperator.Contains, this.Prefix, entityValue);
                            }
                            else
                            {
                                criteria = new FilterCriteria(pi.Name, ConditionOperator.Equals, this.Prefix, entityValue);
                            }

                            criteriaList.Add(criteria);
                        }
                    }
                }

                if (!request.CustomFilters.IsEmptyList())
                {
                    foreach(CustomFilter filter in request.CustomFilters)
                    {
                        FilterCriteria criteria = filter.ToCriteria(this.Prefix);
                        if (null != criteria)
                        {
                            criteriaList.Add(filter.ToCriteria(this.Prefix));
                        }
                    }
                }

                if (criteriaList.Count != 0)
                {
                    query.Combine(criteriaList.ToQuery("T."));
                }

                SqlQuery nonPagingQuery = query;
                bool pagingEnabled = take.HasValue && page.HasValue;
                if (pagingEnabled)//Yani Sayfalama var ise ???....
                {
                    if (sort.IsEmptyList())
                    {
                        PropertyMetaData pm = metaData.Properties.FirstOrDefault((p) => p.Schema.IsKey);
                        if (null == pm)//Hiç pk yok ise.
                        {
                            pm = metaData.Properties.First();
                        }

                        sort = new [] { new SearchSortRequest() { Field = pm.Schema.ColumnName, Dir = "asc"} };
                    }

                    var fp = this.CreateFluentPaging();

                    fp.Select("*")
                        .From("(" + query + ") TP")
                        .OrderBy(sort.First().Field + " "  + sort.First().Dir)
                        .Page(page.Value)
                        .Take(take.Value);

                    SqlQuery temp = fp.ToQuery();
                    query.Parameters.ForEach((p) =>
                    {
                        temp.Parameters.Add(p);
                    });

                    query = temp;
                }

                ret.EntityList =  (IEnumerable<object>)base.Cmd.Query(entityType, query);

                if (pagingEnabled)
                {
                    SqlQuery countQuery = "SELECT COUNT(*) FROM ( ".ToQuery();
                    countQuery.Combine(nonPagingQuery);
                    countQuery.Sql(" ) T");

                    ret.Total = base.Cmd.Factory.DataAccess.ExecuteScalarSafely<int>(countQuery);
                }

                return ret;
            });
        }
Beispiel #30
0
        public StackInfo NewObj <ArgList> (APC pc, Method ctor, Dummy dest, ArgList args, StackInfo data) where ArgList : IIndexable <Dummy>
        {
            int paramsCount = MetaDataProvider.Parameters(ctor).Count;

            return(data.Pop(paramsCount).Push());
        }
Beispiel #31
0
        public void Setup()
        {
            var metamodel = new MetaDataProvider();

            this.serializer = new Cdp4JsonSerializer(metamodel, new Version(1, 1, 0));
        }
Beispiel #32
0
                public override TDomain Assume(APC pc, EdgeTag tag, TVar condition, TDomain data)
                {
                    var boxed = ToBoxedExpression(pc, condition);

                    if (tag != EdgeTag.False)
                    {
                        bool value;
                        if (boxed.IsTrivialCondition(out value))
                        {
                            return(!value ? data.Bottom : data);
                        }
                    }

                    List <int> thresholds;

                    if (ThresholdDB.TryGetAThreshold(boxed, expression_decoder, out thresholds))
                    {
                        ThresholdDB.Add(thresholds);
                    }

                    TDomain result;

                    switch (tag)
                    {
                    case EdgeTag.True:
                    case EdgeTag.Requires:
                    case EdgeTag.Assume:
                    case EdgeTag.Invariant:
                        result = data.AssumeTrue(boxed);
                        break;

                    case EdgeTag.False:
                        result = data.AssumeFalse(boxed);
                        break;

                    default:
                        result = data;
                        break;
                    }

                    if (tag != EdgeTag.False)
                    {
                        var abstractType =
                            ContextProvider.ValueContext.GetType(
                                ContextProvider.MethodContext.CFG.Post(pc), condition);
                        if (abstractType.IsNormal() &&
                            MetaDataProvider.Equal(abstractType.Value,
                                                   MetaDataProvider.System_Boolean))
                        {
                            var guard =
                                BoxedExpression.Binary(BinaryOperator.Ceq, boxed,
                                                       BoxedExpression.Const(1,
                                                                             MetaDataProvider
                                                                             .
                                                                             System_Int32));

                            result = result.AssumeTrue(guard);
                        }
                    }

                    return(result);
                }