public void DescribeCandidateProcesses(IList<IProcessInfo> candidates, ConsoleLog console)
        {
            var byArchitecture = candidates.ToLookup(c => c.Architecture);
            var self = ProcessArchitecture.FromCurrentProcess();

            if(self is ProcessArchitecture.x86)
            {
                if(!x86Thunk.Bootstrap.WasUsed)
                {
                    // Native x86. Write out everything.
                    WriteProcessList(candidates, console);
                }
                else
                {
                    // Write out only matching processes.
                    WriteProcessList(byArchitecture[self].ToList(), console);
                }
            }
            else
            {
                WriteProcessList(byArchitecture[self].ToList(), console);
                if(byArchitecture[new ProcessArchitecture.x86()].Any())
                {
                    // Go to 32-bit and render the rest of the process information.
                    Bootstrap.RecurseInto32BitProcess();
                }
            }
        }
		public IEnumerable<IssueMatch> Match (IList<ActionSummary> summaries, IList<CodeAction> realActions)
		{
			var summaryLookup = summaries.ToLookup (summary => summary.Region);
			foreach (var action in realActions) {
				if (summaryLookup.Contains (action.DocumentRegion)) {
					yield return new IssueMatch {
						Action = action,
						Summary = summaryLookup[action.DocumentRegion].First ()
					};
				}
			}
		}
Example #3
0
        public void GuardarRedes(IList<Resultado> lista, string archivo, IList<FichaIndicadores> fichas)
        {
            var map = fichas.ToDictionary(x => x.Nombre);
            var grupos = lista.ToLookup(x => x.Tipo_item);

            using (var pck = new ExcelPackage(new FileInfo(archivo))) {
                try {
                    foreach (var grupo in grupos) {
                        if (!map.ContainsKey(grupo.Key))
                            continue;
                        Ficha = map[grupo.Key];
                        CrearHoja(grupo.ToList(), Ficha.Nombre, pck);
                    }
                    pck.Save();
                } catch (Exception ex) {
                    AppNotifier.Print("Error " + ex.Message, ex);
                }
            }
        }
        public IList<Result> Judge(IList<IPlayer> playerList)
        {
            if (playerList == null) {
                throw new ArgumentNullException("player is missing");
            }

            if (playerList.Count < 1) {
                throw new ArgumentException("MajorityDecision need one person or more.");
            }

            var handLookup = playerList.ToLookup(player => player.ChoosedHand);
            if (handLookup.Count == 1) {
                return playerList.Map(player => new Result(player, ResultType.Draw));
            }
            var maxCount = handLookup.Max(hand => handLookup[hand.Key].Count());
            if (handLookup.Count(group => group.Count() == maxCount) > 1) {
                return playerList.Map(player => new Result(player, ResultType.Draw));
            }
            var winHand = handLookup.First(group => group.Count() == maxCount).Key;
            return playerList.Map(player => new Result(player, player.ChoosedHand.Equals(winHand) ? ResultType.Win : ResultType.Lose));
        }
Example #5
0
        /// <summary>
        ///     create a hashtable of start->list of tuples that start there
        ///     put all tuples in a queue of tupleSets
        ///     set the longestTupleSet to the first tuple
        ///     while the queue is not empty
        ///     take tupleSet from the queue
        ///     if any tuples start where the tupleSet ends
        ///     foreach tuple that starts where the tupleSet ends
        ///     enqueue new tupleSet of tupleSet + tuple
        ///     continue
        /// 
        ///     if tupleSet is longer than longestTupleSet
        ///     replace longestTupleSet with tupleSet
        /// 
        ///     return longestTupleSet
        /// </summary>
        /// <param name = "input"></param>
        /// <returns></returns>
        public static IList<Pair<int, int>> FindLongestNonOverlappingRangeSet(IList<Pair<int, int>> input)
        {
            var rangeStarts = input.ToLookup(x => x.First, x => x);
            var adjacentTuples = new Queue<List<Pair<int, int>>>(
                input.Select(x => new List<Pair<int, int>>
                    {
                        x
                    }));

            var longest = new List<Pair<int, int>>
                {
                    input[0]
                };
            int longestLength = input[0].Second - input[0].First;

            while (adjacentTuples.Count > 0)
            {
                var tupleSet = adjacentTuples.Dequeue();
                var last = tupleSet.Last();
                int end = last.First + last.Second;
                var sameStart = rangeStarts[end];
                if (sameStart.Any())
                {
                    foreach (var nextTuple in sameStart)
                    {
                        adjacentTuples.Enqueue(tupleSet.Concat(new[] { nextTuple }).ToList());
                    }
                    continue;
                }
                int length = end - tupleSet.First().First;
                if (length > longestLength)
                {
                    longestLength = length;
                    longest = tupleSet;
                }
            }

            return longest;
        }
Example #6
0
        public void ReplaceIndexersCalls(MethodDefinition method, IList<SliceParameters> slices)
        {
            var processor = method.Body.GetILProcessor();
            var instructions = processor.Body.Instructions;

            var slicesLookup = slices.ToLookup(x => x.Definition);

            for (int offset = 0; offset < instructions.Count; offset++)
            {
                var instruction = instructions[offset];
                if (!instruction.OpCode.IsCall())
                    continue;

                var methodReference = instruction.Operand as MethodReference;
                if (methodReference == null)
                    continue;

                if (methodReference.Name != "get_Item" && methodReference.Name != "set_Item")
                    continue;

                var objectToCall = instruction.TraceBack(methodReference, 0);
                var parameter = instruction.TraceBack(methodReference, -1);

                var slice = slicesLookup[objectToCall.Operand].FirstOrDefault();
                if (slice == null)
                    continue;

                var arraySliceType = ModuleDefinition.Import(typeof(ArraySlice<>)).MakeGenericInstanceType(slice.GenericArgument);

                var methodDefinition = methodReference.Resolve();

                // FIXME: We know we cannot process if anything happens between the push of the array slice and the final operation.
                if (methodDefinition.IsGetter)
                {
                    // Original GET:
                    // 1    ldarg.s segment              $ Push the object to call
                    // =    ldloc.1                      $ Push the parameter
                    // 2    callvirt instance !0 class ArraySegment.ArraySlice`1<float32>::get_Item(int32)
                    // =    stloc.s t                    $ Do whatever with the result of the GET call

                    // Target GET:
                    // 1    ldloc.s data                 $ Push the object to call
                    // =    ldloc.1                      $ Push the parameter
                    // 2    ldloc.s offset
                    // 2    add                          $ Add the parameter (i) and the offset.
                    // 2    ldelem.r4                    $ Use standard ldelem with type to get the value from the array.
                    // =    stloc.s t                    $ Do whatever with the result of the GET call

                    //HACK: We rewrite it to avoid killing the loop.
                    objectToCall.OpCode = OpCodes.Ldloc;
                    objectToCall.Operand = slice.ArrayVariable;

                    processor.Replace(instruction, Instruction.Create(OpCodes.Ldelem_Any, slice.GenericArgument));

                    processor.InsertAfter(parameter, new[] {
                                Instruction.Create( OpCodes.Ldloc, slice.OffsetVariable ),
                                Instruction.Create( OpCodes.Add )
                        });
                }
                else if (methodDefinition.IsSetter)
                {
                    // Original SET:
                    // 1		ldarg segment	    $ Push the object to call
                    // =		ldloc.0		        $ Push the parameter
                    // =		ldc.r4 2		    $ Push the value to set
                    // 2		callvirt instance void class ArraySegment.ArraySlice`1<float32>::set_Item(int32, !0)
                    // -        nop			        $ Check if it even exists after SimplifyMacros in the collection.

                    // Target SET
                    // 1		ldloc data		    $ Push the array
                    // =		ldloc.0		        $ Push the parameter
                    // 2		ldloc offset
                    // 2		add      		    $ Add the parameter (i) and the offset.
                    // =		ldc.r4 2		    $ Push the value to set. Use standard ldc with type and check if it  is optimized afterwards.
                    // 2		stelem   		    $ Use standard stelem with type and check if it is optimized afterwards.

                    //HACK: We rewrite it to avoid killing the loop.
                    objectToCall.OpCode = OpCodes.Ldloc;
                    objectToCall.Operand = slice.ArrayVariable;

                    processor.Replace(instruction, Instruction.Create(OpCodes.Stelem_Any, slice.GenericArgument));

                    processor.InsertAfter(parameter, new[] {
                                Instruction.Create( OpCodes.Ldloc, slice.OffsetVariable ),
                                Instruction.Create( OpCodes.Add )
                        });

                }
                else continue;
            }
        }
        public void ApplyPendingDownloadIncrements(IList<LucenePackage> increments, ISession<LucenePackage> session)
        {
            if (increments.Count == 0) return;

            var byId = increments.ToLookup(p => p.Id);

            foreach (var grouping in byId)
            {
                var packageId = grouping.Key;
                var packages = from p in session.Query() where p.Id == packageId select p;
                var byVersion = grouping.ToLookup(p => p.Version);

                foreach (var lucenePackage in packages)
                {
                    lucenePackage.DownloadCount += grouping.Count();
                    lucenePackage.VersionDownloadCount += byVersion[lucenePackage.Version].Count();
                }
            }
        }
 public static IList<AlbumTarget> FromListAndTargets(IList<Track> iTracks, IList<Artist> Artists, string AlbumName, string itGenre = null, int? tYear = null)
 {
     var res = iTracks.ToLookup(t => t.RawAlbum).ToLookup(a => new AlbumTarget(Artists ?? a.Key.RawArtists, AlbumName ?? a.Key.Name, itGenre, tYear));
     return res.Apply(g => g.Key.OrderedTrack = g.Select((gg) => new OriginedGroupedTrack(gg.Key, gg.ToList(), g.Key)).ToList()).Select(g => g.Key).ToList();
 }