예제 #1
0
 public static ScoreDetail GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return(context.t_score_detail.Find(id));
     }
 }
예제 #2
0
 public static TEntity FindEntity <TEntity>(Expression <Func <TEntity, bool> > predicate) where TEntity : class, new()
 {
     using (DistributionContext dbcontext = new DistributionContext())
     {
         return(dbcontext.Set <TEntity>().FirstOrDefault(predicate));
     }
 }
예제 #3
0
 public static Product GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return(context.t_product.Find(id));
     }
 }
예제 #4
0
        public void WhenInstancesRemoved_ShouldOnlyDistributeAcrossRemainingInstances()
        {
            var strategy = new SingleInstanceRoundRobinDistributionStrategy("endpointA", DistributionStrategyScope.Send);

            var instances = new[]
            {
                "1",
                "2",
                "3"
            };

            var distributionContext = new DistributionContext(instances, null, null, null, null, null);
            var result = new List <string>
            {
                strategy.SelectDestination(distributionContext),
                strategy.SelectDestination(distributionContext)
            };

            instances           = instances.Take(2).ToArray(); // remove last instance.
            distributionContext = new DistributionContext(instances, null, null, null, null, null);
            result.Add(strategy.SelectDestination(distributionContext));

            Assert.That(result.Count, Is.EqualTo(3));
            Assert.That(result, Has.Exactly(2).EqualTo(instances[0]));
            Assert.That(result, Has.Exactly(1).EqualTo(instances[1]));
        }
예제 #5
0
 public static Order GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return(context.t_order.Find(id));
     }
 }
        /// <summary>
        /// 统计人数
        /// </summary>
        /// <param name="agentId"></param>
        /// <param name="secondCount">二代人数</param>
        /// <param name="otherCount">二代外人数</param>
        /// <param name="expCount">体验店数</param>
        /// <returns></returns>
        public static int GetFirstCount(string agentId, out int secondCount, out int otherCount, out int expCount)
        {
            using (DistributionContext context = new DistributionContext())
            {
                expCount   = 0;
                otherCount = 0;
                var list      = context.t_agent_relation.ToList();
                var firstList = list.Where(t => t.c_parent_id == agentId && t.ChildrenAgent != null &&
                                           t.ChildrenAgent.c_state > 0
                                           ).ToList();
                expCount += list.Where(t => t.c_parent_id == agentId && t.ChildrenAgent != null && t.ChildrenAgent.c_agnet_type == (int)AgentType.Exp).Count();
                var pIds       = firstList.Select(t => t.c_child_id).ToList();
                var secondList = list.Where(t => pIds.Contains(t.c_parent_id) && t.ChildrenAgent != null &&
                                            t.ChildrenAgent.c_state > 0).ToList();
                expCount   += list.Where(t => pIds.Contains(t.c_parent_id) && t.ChildrenAgent != null && t.ChildrenAgent.c_agnet_type == (int)AgentType.Exp).Count();
                secondCount = secondList.Where(t => t.ChildrenAgent.c_agnet_type != (int)AgentType.Exp).Count();//二代数量
                while (secondList.Count() > 0)
                {
                    var otherParentIds = secondList.Select(t => t.c_child_id).ToList();
                    secondList = list.Where(t => otherParentIds.Contains(t.c_parent_id) && t.ChildrenAgent != null &&
                                            t.ChildrenAgent.c_state > 0).ToList();
                    otherCount += secondList.Where(t => t.ChildrenAgent.c_agnet_type != (int)AgentType.Exp).Count();
                }

                return(firstList.Where(t => t.ChildrenAgent.c_agnet_type != (int)AgentType.Exp).Count());
            }
        }
예제 #7
0
        public void WhenNewInstancesAdded_ShouldIncludeAllInstancesInDistribution()
        {
            var strategy = new SingleInstanceRoundRobinDistributionStrategy("endpointA", DistributionStrategyScope.Send);

            var instances = new[]
            {
                "1",
                "2",
            };

            var distributionContext = new DistributionContext(instances, null, null, null, null, null);
            var result = new List <string>
            {
                strategy.SelectDestination(distributionContext),
                strategy.SelectDestination(distributionContext)
            };

            instances           = instances.Concat(new[] { "3" }).ToArray(); // add new instance
            distributionContext = new DistributionContext(instances, null, null, null, null, null);
            result.Add(strategy.SelectDestination(distributionContext));

            Assert.That(result.Count, Is.EqualTo(3));
            Assert.That(result, Has.Exactly(1).EqualTo(instances[0]));
            Assert.That(result, Has.Exactly(1).EqualTo(instances[1]));
            Assert.That(result, Has.Exactly(1).EqualTo(instances[2]));
        }
예제 #8
0
 public static ScoreCash GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return context.t_score_cash.Find(id);
     }
 }
 public static AgentRelation GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return(context.t_agent_relation.Find(id));
     }
 }
예제 #10
0
 public static PublicNotice GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return(context.t_public_notice.Find(id));
     }
 }
예제 #11
0
 public static ExpApply GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return(context.t_exp_apply.Find(id));
     }
 }
예제 #12
0
        HashSet <string> SelectDestinationsForEachEndpoint(IEnumerable <UnicastRouteGroup> routeGroups, IOutgoingPublishContext context)
        {
            //Make sure we are sending only one to each transport destination. Might happen when there are multiple routing information sources.
            var addresses = new HashSet <string>();

            foreach (var group in routeGroups)
            {
                if (group.EndpointName == null) //Routing targets that do not specify endpoint name
                {
                    //Send a message to each target as we have no idea which endpoint they represent
                    foreach (var subscriber in group.Routes)
                    {
                        foreach (var address in ResolveRoute(subscriber))
                        {
                            addresses.Add(address);
                        }
                    }
                }
                else
                {
                    var candidates          = group.Routes.SelectMany(ResolveRoute).ToArray();
                    var distributionContext = new DistributionContext(candidates, context.Message, context.MessageId, context.Headers, _resolveTransportAddress, context.Extensions);
                    var selected            = _distributionPolicy.GetDistributionStrategy(group.EndpointName, DistributionStrategyScope.Publish).SelectDestination(distributionContext);
                    addresses.Add(selected);
                }
            }

            return(addresses);
        }
예제 #13
0
 public static CommConfig GetEnityById(string id)
 {
     using (DistributionContext context = new DistributionContext())
     {
         return(context.t_common_config.Find(id));
     }
 }
예제 #14
0
        /// <summary>
        /// 代理等级提升判断并执行
        /// </summary>
        /// <param name="RecomAgent">需要判断升级的代理商</param>
        /// <returns></returns>
        public static bool  IsLevelUpWithCondition(Agent RecomAgent)
        {
            bool result = false;

            using (DistributionContext context = new DistributionContext())
            {
                context.SaveChanges();
                if (RecomAgent.c_agnet_type == (int)AgentType.Exp)
                {
                    return(result);
                }
                int currentLevel = (int)RecomAgent.c_levle;                                                        //当前等级
                int maxLevel     = (int)context.t_level_config.Where(t => t.c_is_delete == 0).Max(t => t.c_level); //当前系统的最高级别
                if (currentLevel == maxLevel)
                {
                    return(result);
                }

                var list = context.t_level_config.Where(f => f.c_is_delete == 0 && f.c_level == (currentLevel + 1));
                if (list.Count() > 0)
                {
                    //升级所需条件配置
                    LevelConfig config      = list.First();
                    var         list_direct = context.t_agent_relation.Where(f => f.c_parent_id == RecomAgent.c_id && f.ChildrenAgent.c_agnet_type != (int)AgentType.Exp);//直推人数
                    if (list_direct.Count() < config.c_need_nums)
                    {
                        result = false;
                    }
                    else
                    {
                        //达到相应等级的人数
                        int levelCount = list_direct.Where(f => f.ChildrenAgent.c_levle >= config.c_need_level && f.ChildrenAgent.c_agnet_type != (int)AgentType.Exp).Count();
                        if (config.c_need_level == null)
                        {
                            RecomAgent.c_levle = currentLevel + 1;
                            AgentLogic.UpdateEntity(RecomAgent);
                            result = true;
                        }
                        else if (levelCount >= config.c_level_num)
                        {
                            RecomAgent.c_levle = currentLevel + 1;
                            AgentLogic.UpdateEntity(RecomAgent);
                            result = true;
                        }
                    }
                }
                var plist = context.t_agent_relation.Where(f => f.c_child_id == RecomAgent.c_id).ToList();
                if (plist.Count() > 0)
                {
                    Agent pAg = plist.FirstOrDefault().ParentAgent;
                    IsLevelUpWithCondition(pAg);
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
예제 #15
0
 public static void DeleteEntity(int ProductId)
 {
     using (DistributionContext context = new DistributionContext())
     {
         PublicNotice DelProduct = context.t_public_notice.Find(ProductId);
         context.t_public_notice.Remove(DelProduct);
         context.SaveChanges();
     }
 }
예제 #16
0
 public static void UpdateEntity(PublicNotice UpdateProduct)
 {
     using (DistributionContext context = new DistributionContext())
     {
         PublicNotice ag = context.t_public_notice.Find(UpdateProduct.F_Id);
         CommLogic.DeepClone <PublicNotice>(ag, UpdateProduct);
         context.SaveChanges();
     }
 }
예제 #17
0
 public static void InsertNewEntiy(PublicNotice NewProduct)
 {
     using (DistributionContext context = new DistributionContext())
     {
         NewProduct.F_Id = Guid.NewGuid().ToString();
         context.t_public_notice.Add(NewProduct);
         context.SaveChanges();
     }
 }
예제 #18
0
 public static void DeleteEntity(string OrderId)
 {
     using (DistributionContext context = new DistributionContext())
     {
         Order DelOrder = context.t_order.Find(OrderId);
         context.t_order.Remove(DelOrder);
         context.SaveChanges();
     }
 }
예제 #19
0
 public static void UpdateEntity(CommConfig UpdateCommConfig)
 {
     using (DistributionContext context = new DistributionContext())
     {
         CommConfig ag = context.t_common_config.Find(UpdateCommConfig.c_id);
         CommLogic.DeepClone <CommConfig>(ag, UpdateCommConfig);
         context.SaveChanges();
     }
 }
예제 #20
0
 public static void DeleteEntity(string AgentRelationId)
 {
     using (DistributionContext context = new DistributionContext())
     {
         AgentRelation DelAgentRelation = context.t_agent_relation.Find(AgentRelationId);
         context.t_agent_relation.Remove(DelAgentRelation);
         context.SaveChanges();
     }
 }
예제 #21
0
 public static void DeleteEntity(string ExpApplyId)
 {
     using (DistributionContext context = new DistributionContext())
     {
         ExpApply DelExpApply = context.t_exp_apply.Find(ExpApplyId);
         context.t_exp_apply.Remove(DelExpApply);
         context.SaveChanges();
     }
 }
예제 #22
0
 public static void UpdateEntity(ExpApply UpdateExpApply)
 {
     using (DistributionContext context = new DistributionContext())
     {
         ExpApply ag = context.t_exp_apply.Find(UpdateExpApply.F_Id);
         CommLogic.DeepClone <ExpApply>(ag, UpdateExpApply);
         context.SaveChanges();
     }
 }
예제 #23
0
 public static void DeleteEntity(string CommConfigId)
 {
     using (DistributionContext context = new DistributionContext())
     {
         CommConfig DelCommConfig = context.t_common_config.Find(CommConfigId);
         context.t_common_config.Remove(DelCommConfig);
         context.SaveChanges();
     }
 }
예제 #24
0
 public static void InsertNewEntiy(AgentRelation NewAgentRelation)
 {
     using (DistributionContext context = new DistributionContext())
     {
         NewAgentRelation.c_id = Guid.NewGuid().ToString();
         context.t_agent_relation.Add(NewAgentRelation);
         context.SaveChanges();
     }
 }
예제 #25
0
 public static void UpdateEntity(AgentRelation UpdateAgentRelation)
 {
     using (DistributionContext context = new DistributionContext())
     {
         AgentRelation ag = context.t_agent_relation.Find(UpdateAgentRelation.c_id);
         CommLogic.DeepClone <AgentRelation>(ag, UpdateAgentRelation);
         context.SaveChanges();
     }
 }
예제 #26
0
 public static void InsertNewEntiy(CommConfig NewCommConfig)
 {
     using (DistributionContext context = new DistributionContext())
     {
         NewCommConfig.c_id = Guid.NewGuid().ToString();
         context.t_common_config.Add(NewCommConfig);
         context.SaveChanges();
     }
 }
예제 #27
0
    public string SelectDestination(string endpoint, string[] addresses, MessageContext context)
    {
        // NOTE: We don't deserialize the message so we can't create a logical message
        var distributionContext = new DistributionContext(addresses, NoMessage, context.MessageId, context.Headers, transportAddressTranslation, context.Extensions);
        var strategy            = distributionPolicy.GetDistributionStrategy(endpoint, DistributionStrategyScope.Publish);
        var destination         = strategy.SelectDestination(distributionContext);

        return(destination);
    }
예제 #28
0
    public string SelectTopicExchangeAddress(string messageId, Dictionary <string, string> headers, ContextBag context)
    {
        var addresses = GetAllTopicExchangeAddresses().ToArray();
        // NOTE: We don't deserialize the message so we can't create a logical message
        var distributionContext = new DistributionContext(addresses, NoMessage, messageId, headers, transportAddressTranslation, context);
        var strategy            = distributionPolicy.GetDistributionStrategy(topicExchangeName, DistributionStrategyScope.Send);

        return(strategy.SelectDestination(distributionContext));
    }
예제 #29
0
 public static void UpdateEntity(Order UpdateOrder)
 {
     using (DistributionContext context = new DistributionContext())
     {
         Order ag = context.t_order.Find(UpdateOrder.F_Id);
         CommLogic.DeepClone <Order>(ag, UpdateOrder);
         context.SaveChanges();
     }
 }
예제 #30
0
 public static void DeleteEntity(int ProductId)
 {
     using (DistributionContext context = new DistributionContext())
     {
         LevelConfig DelProduct = context.t_level_config.Find(ProductId);
         context.t_level_config.Remove(DelProduct);
         context.SaveChanges();
     }
 }