Ejemplo n.º 1
0
 /// <summary>
 /// 找到单播地址对应的客户端,由于当客户端刚刚掉线时,session有可能来不及释放,这时候客户端再次登录,就有可能产生多个满足条件的客户端
 /// </summary>
 /// <param name="unicastAddress"></param>
 /// <returns></returns>
 public IServerSession[] GetSessions(string unicastAddress)
 {
     IServerSession[] sessions = null;
     lock (_sessions)
     {
         var temp = _sessions.GetValues(unicastAddress);
         sessions = temp != null?temp.ToArray() : Array.Empty <IServerSession>();
     }
     return(sessions);
 }
Ejemplo n.º 2
0
        public async Task <MutationResult> ExecuteMutation(Mutant mutant, CciModuleSource moduleSource)
        {
            var type   = new TypeIdentifier((INamedTypeDefinition)mutant.MutationTarget.ProcessingContext.Type.Object);
            var method = new MethodIdentifier((IMethodDefinition)mutant.MutationTarget.ProcessingContext.Method.Object);
            var filter = new MutationFilter(type.InList(), method.InList());

            _log.Debug("ExecuteMutation of: " + type + " - " + method);
            IMutationOperator mutationOperator = mutant.MutationTarget.OperatorId == null ? new IdentityOperator() :
                                                 _mutOperators.Single(m => mutant.MutationTarget.OperatorId == m.Info.Id);
            var cci = moduleSource;

            try
            {
                _log.Info("Execute mutation of " + mutant.MutationTarget + " contained in " + mutant.MutationTarget.MethodRaw + " modules. ");
                var mutatedModules = new List <IModuleInfo>();
                var module         = moduleSource.Modules.Single();

                var visitorBack = new VisualCodeVisitorBack(mutant.MutationTarget.InList(),
                                                            _sharedTargets.GetValues(mutationOperator, returnEmptySet: true),
                                                            module.Module, mutationOperator.Info.Id);
                var traverser2 = new VisualCodeTraverser(_filter, visitorBack, moduleSource);
                traverser2.Traverse(module.Module);
                visitorBack.PostProcess();
                var operatorCodeRewriter = mutationOperator.CreateRewriter();

                var rewriter = new VisualCodeRewriter(cci.Host, visitorBack.TargetAstObjects,
                                                      visitorBack.SharedAstObjects, _filter, operatorCodeRewriter, traverser2);

                operatorCodeRewriter.MutationTarget =
                    new UserMutationTarget(mutant.MutationTarget.Variant.Signature, mutant.MutationTarget.Variant.AstObjects);


                operatorCodeRewriter.NameTable     = cci.Host.NameTable;
                operatorCodeRewriter.Host          = cci.Host;
                operatorCodeRewriter.Module        = module.Module;
                operatorCodeRewriter.OperatorUtils = _operatorUtils;
                operatorCodeRewriter.Initialize();

                var rewrittenModule = rewriter.Rewrite(module.Module);

                rewriter.CheckForUnfoundObjects();

                mutant.MutationTarget.Variant.AstObjects = null; //TODO: avoiding leaking memory. refactor
                mutatedModules.Add(new ModuleInfo(rewrittenModule, ""));

                var result = new MutationResult(mutant, cci, null,
                                                mutant.MutationTarget.MethodMutated);
                mutant.MutationTarget.MethodMutated = null; //TODO: avoiding leaking memory. refactor
                return(result);
            }
            catch (Exception e)
            {
                throw new MutationException("CreateMutants failed on operator: {0}.".Formatted(mutationOperator.Info.Name), e);
            }
        }
 public void RemoveNode(T n)
 {
     nodes.Remove(n);
     foreach (T n2 in edges.GetValues(n).ToList())
     {
         RemoveEdge(n, n2);
     }
     foreach (T n2 in nodes)
     {
         RemoveEdge(n2, n);
     }
 }
Ejemplo n.º 4
0
 public DirectTable()
 {
     _getAddresses = LazyIndexer.Init <string, string[]>((fullName) =>
     {
         return(_data.GetValues(fullName).ToArray());
     });
 }
Ejemplo n.º 5
0
 public void RemoveNode(T n)
 {
     // TODO: This algorithm is very inefficient if the graph is
     // TODO: large; can you think of ways to improve it?
     // Remove the incoming edges
     foreach (T n1 in nodes)
     {
         RemoveEdge(n1, n);
     }
     // Remove the outgoing edges
     foreach (T n2 in edges.GetValues(n).ToList())
     {
         RemoveEdge(n, n2);
     }
     // The node is now isolated; remove it.
     nodes.Remove(n);
 }
Ejemplo n.º 6
0
 public string[] GetMulticastAddresses(IServerSession session)
 {
     string[] multicastAddresses = null;
     lock (_reverseMulticastSessions)
     {
         var temp = _reverseMulticastSessions.GetValues(session);
         multicastAddresses = temp != null?temp.ToArray() : Array.Empty <string>();
     }
     return(multicastAddresses);
 }
    public static List <string> GetContext(EventType typeContext)
    {
        if (context == null)
        {
            context = new MultiDictionary <EventType, string>();
        }

        //TESTING PURPOSES
        //context.Remove(typeContext);

        List <string> temp;

        if (context.HasKey(typeContext))
        {
            temp = new List <string>(context.GetValues(typeContext));
        }
        else
        {
            ReadContextFromFile(typeContext);
            temp = new List <string>(context.GetValues(typeContext));
        }

        return(temp);
    }
Ejemplo n.º 8
0
    private GameObject FindUnused(string enemyName)
    {
        GameObject[] instances = activeInstances.GetValues(enemyName);

        if (instances != null)
        {
            for (int i = 0; i < instances.Length; i++)
            {
                if (instances[i] != null)
                {
                    if (!instances[i].activeSelf)
                    {
                        return(instances[i]);
                    }
                }
            }
        }

        return(null);
    }
Ejemplo n.º 9
0
        /// <summary>
        /// 根据服务请求获取契约
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public MockContract Find(ServiceRequest request)
        {
            var contracts = _contracts.GetValues(request.Name);

            if (contracts == null)
            {
                throw new ServiceException("没有找到服务" + request.Name + "的mock契约");
            }
            MockContract target = BestMatch(contracts, request);

            if (target != null)
            {
                return(target);
            }

            target = ArgumentMatch(contracts, request);
            if (target != null)
            {
                return(target);
            }

            target = GetDefaultContract(contracts);
            if (target != null)
            {
                return(target);
            }

            if (target == null)
            {
                throw new ServiceException("没有找到服务"
                                           + request.Name + "下调用约定为"
                                           + request.Argument.GetCode() + "、身份信息为"
                                           + request.Identity.GetCode() + "的mock数据");
            }
            return(target);
        }
Ejemplo n.º 10
0
 public void AddObject(string Category, DynamicObject Object)
 {
     Debug.Log("Added " + Object.Name + " to Category " + Category);
     ManagedObjects.Add(Category, Object);
     Debug.Log(ManagedObjects.GetValues(Category).Length);
 }