示例#1
0
    public void RemoveCharacterFromBoard(Character character)
    {
        // Debug.Log("Remove Character Called " + character.name);
        if (!boardPositions.Any())
        {
            return;
        }

        int amountColumns = boardPositions.Keys.Max() + 1;

        for (int columnNumber = 0; columnNumber < amountColumns; columnNumber++)
        {
            // Debug.Log("columnNumber "+columnNumber);
            if (boardPositions.Keys.Contains(columnNumber))
            {
                if (boardPositions[columnNumber].Contains(character))
                {
                    boardPositions[columnNumber].Remove(character);
                }
            }
            else
            {
                // Debug.Log("added column "+columnNumber);
                List <Character> newColumnList = new List <Character>();
                boardPositions.Add(columnNumber, newColumnList);
            }
        }
    }
示例#2
0
        // Actual worker for GetPreferredInstance()
        internal KSP _GetPreferredInstance()
        {
            // First check if we're part of a portable install
            // Note that this *does not* register in the registry.
            string path = KSP.PortableDir();

            if (path != null)
            {
                KSP portableInst = new KSP(path, "portable", User);
                if (portableInst.Valid)
                {
                    return portableInst;
                }
            }

            // If we only know of a single instance, return that.
            if (instances.Count == 1 && instances.First().Value.Valid)
            {
                return instances.First().Value;
            }

            // Return the autostart, if we can find it.
            // We check both null and "" as we can't write NULL to the registry, so we write an empty string instead
            // This is necessary so we can indicate that the user wants to reset the current AutoStartInstance without clearing the windows registry keys!
            if (!string.IsNullOrEmpty(AutoStartInstance)
                    && instances[AutoStartInstance].Valid)
            {
                return instances[AutoStartInstance];
            }

            // If we know of no instances, try to find one.
            // Otherwise, we know of too many instances!
            // We don't know which one to pick, so we return null.
            return !instances.Any() ? FindAndRegisterDefaultInstance() : null;
        }
示例#3
0
        private TempFileInfo DequeueInternal()
        {
            if (!queuedTempFiles.Any())
            {
                return(null);
            }

            var firstKey = queuedTempFiles.Keys.First();

            queuedTempFiles.Remove(firstKey, out var value);
            return(value);
        }
示例#4
0
 private bool TryGetLastScheduledTime(out DateTimeOffset when)
 {
     lock (pending)
     {
         when = default;
         if (!pending.Any())
         {
             return(false);
         }
         when = pending.Keys.Last();
         return(true);
     }
 }
示例#5
0
 public void ReceiverIsLive(int receiverNumber)
 {
     lock (this)
     {
         var node = _receivers[receiverNumber];
         node.IsLive            = true;
         _requiredPastReceiver -= 1;
         if (_buffer.Any())
         {
             var receiverToWakeup = _buffer.Values[0];
             _receivers[receiverToWakeup].ResetEvent.Set();
         }
     }
 }
    private void HandoutDevices()
    {
        if (!inputRequests.Any())
        {
            return;
        }
        IEnumerable <InputDevice> unusedDevices =
            from pair in devices
            where pair.Key != null && !pair.Value
            select pair.Key;
        List <InputDevice> sortedDevices = unusedDevices.OrderBy(d => d.SortOrder).ToList();

        if (sortedDevices.Any())
        {
            // This int is outside the loop because it must be used to remove
            // all fulfilled requests (if there are more requests than devices,
            // i will go up to the index of the first request left unfulfilled)
            int i = 0;
            for (; i < sortedDevices.Count && i < inputRequests.Count; i++)
            {
                InputDevice         device          = sortedDevices[i];
                InputDeviceCallback createdCallback = inputRequests.Values[i].Item1;
                Action action = inputRequests.Values[i].Item2;
                devices[device] = true;
                actions[device] = action;
                createdCallback(device);
            }
            Dictionary <int, Tuple <InputDeviceCallback, Action> > unfufilledRequestsDictionary = inputRequests.Skip(i).ToDictionary(
                pair => pair.Key, pair => pair.Value);
            inputRequests = new SortedList <int, Tuple <InputDeviceCallback, Action> >(unfufilledRequestsDictionary);
        }
    }
示例#7
0
        public static List <SportEventListModel> GetSportEventsFiltered(SortedList <string, string> paramDictionary)
        {
            List <SportEventListModel> resultList = new List <SportEventListModel>();

            ErrorList = new List <string>();
            string sqlSelectSportEventsFiltered = "SELECT * FROM [FitbourhoodDB].[dbo].[SportEvents]";

            if (paramDictionary.Any(x => x.Value != null))
            {
                sqlSelectSportEventsFiltered += " WHERE ";
                foreach (var param in paramDictionary)
                {
                    if (!string.IsNullOrWhiteSpace(param.Value))
                    {
                        sqlSelectSportEventsFiltered += string.Format("[{0}] {1}", param.Key, param.Value);
                        var nextParam = paramDictionary.ElementAtOrDefault(paramDictionary.IndexOfKey(param.Key) + 1);
                        if (nextParam.Key != null && !string.IsNullOrWhiteSpace(nextParam.Value))
                        {
                            sqlSelectSportEventsFiltered += " AND ";
                        }
                    }
                }
            }

            using (var connection = new SqlConnection(ConnectionString))
            {
                resultList = connection.Query <SportEventListModel>(sqlSelectSportEventsFiltered).ToList();
            }

            return(resultList);
        }
示例#8
0
        protected void LateUpdate()
        {
            if (!referencesHolder || referencesHolder.childCount == 0)
            {
                return;
            }

            // First we categorize the childs
            // (This is not necesary if the childs wont change)
            var staticChilds = new List <ScenePositioner>();

            heights.Clear();
            finalOrder.Clear();

            for (int i = 0; i < referencesHolder.childCount; i++)
            {
                var representable = referencesHolder.GetChild(i).GetComponent <ScenePositioner>();
                // Not layered element
                if (representable.Context.getLayer() < 0)
                {
                    heights[representable]    = representable.Context.getY();
                    finalOrder[representable] = representable.Context.getY();
                }
                else
                {
                    staticChilds.Add(representable);
                }
            }

            // Then we sort the static childs by layer
            staticChilds.Sort((r1, r2) => r1.Context.getLayer() - r2.Context.getLayer());

            // Then we stabilish a layer Y:
            //  Higher layers should appear on top of lower layers.
            //  Lower Y elements should also appear on top of higher Y elements.
            //  Since the first rule is more important, to fix this, we simulate the Y coordinate for elements
            //  that have higher Y coordinate, but lower layer. The Y used is the minimum Y for the lower layer elements.
            var maxY = staticChilds.Any() ? staticChilds.First().Position.y : 0;

            foreach (var child in staticChilds)
            {
                // Since we're iterating backwards we carry the minimum to the higher layers
                maxY = Mathf.Max(maxY, child.Position.y);
                // Finally we insert the elements: The layered elements use the simulated Y, whereas the dynamic ones use their real Y.
                heights[child]    = maxY;
                finalOrder[child] = maxY;
            }

            // And then we apply the Z coordinate
            if (finalOrder.Any())
            {
                var zStep = (maxZ - minZ) / finalOrder.Count;
                var count = 0;
                foreach (var kv in finalOrder)
                {
                    kv.Key.Z = minZ + zStep * count;
                    count++;
                }
            }
        }
示例#9
0
文件: Asks.cs 项目: Fehrox/Tachyon
        public byte[] PackAsk <T>(byte[] data, Action <T> reply)
        {
            var methodHash = BitConverter.ToInt16(data, 0);

            methodHash = AskHasher.SetAskBit(methodHash, true);
            var methodHashBytes = BitConverter.GetBytes(methodHash);

            _pendingRequests.Add(methodHash);

            var callbackId = _pendingResponses.Any() ?
                             (_pendingResponses.Last().Key + 1) % short.MaxValue : 0;
            var callbackIdBytes = BitConverter.GetBytes(callbackId);
            var callback        = new Stub.RemoteMethod(reply.Method, reply.Target);

            _pendingResponses.Add((short)callbackId, callback);

            var dataBody = data.Skip(methodHashBytes.Length).ToArray();

            var dataLen    = methodHashBytes.Length + callbackIdBytes.Length + dataBody.Length;
            var packedData = new byte[dataLen];

            methodHashBytes.CopyTo(packedData, 0);
            callbackIdBytes.CopyTo(packedData, methodHashBytes.Length);
            dataBody.CopyTo(packedData, methodHashBytes.Length + callbackIdBytes.Length);

            return(packedData);
        }
示例#10
0
        protected override async Task <string> ExecuteImpl()
        {
            var arr = new[] { 1, 2, 3, 6, 7, 7 };
            var sl  = new SortedList <int, int>(new DecendingDuplicateComparer <int>());

            foreach (var i in arr)
            {
                sl.Add(i, i);
            }
            while (sl.Count() > 1)
            {
                Print(sl);

                var f = sl.First().Value; sl.RemoveAt(0);
                var s = sl.First().Value; sl.RemoveAt(0);

                if (f == s)
                {
                    continue;
                }
                var remains = Math.Max(f, s) - Math.Min(f, s);
                sl.Add(remains, remains);
            }


            var result = sl.Any() ? sl.First().Key : 0;

            return(await Task.FromResult($"{result}"));
        }
示例#11
0
        public void ClearStateHistory()
        {
            if (States.Any())
            {
                KeyValuePair <int, byte[]> power = States.FirstOrDefault(s => s.Key == 0);
                if (power.Value == null)
                {
                    StateAccessed(power.Key);
                    power = States.FirstOrDefault(s => s.Key == 0);
                }
                States.Clear();
                accessed.Clear();

                if (power.Value.Length > 0)
                {
                    SetState(0, power.Value);
                    Used = (ulong)power.Value.Length;
                }
                else
                {
                    Used     = 0;
                    DiskUsed = 0;
                }
            }
        }
示例#12
0
 public void ValidateTeam(long teamId)
 {
     if (!TableTeams.Any(x => x.Key.Equals(teamId)))
     {
         throw new TeamNotFoundException();
     }
 }
示例#13
0
 public void ValidatePlayer(long playerId)
 {
     if (!TablePlayers.Any(x => x.Key.Equals(playerId)))
     {
         throw new PlayerNotFoundException();
     }
 }
        /// <summary>
        /// Associate the parameters of the selected family to the current family
        /// </summary>
        public void Wire()
        {
            if (!doc.IsFamilyDocument || !famParam.Any())
            {
                return;                                                         //Only work in Family Document that has parameters to associate with
            }
            var wireFamily = Utils.PickObject(uidoc, "Pick a Nested Family.");  //Get the family to associate to

            if (wireFamily == null)
            {
                return;
            }
            var fam = doc.GetElement(wireFamily) as FamilyInstance;

            if (fam == null)
            {
                return;                                   //We could get a random selection, we haven't implemented a Filter (which we could TO DO)
            }
            AssociateParameters(fam, ParamType.Instance); //Associate all possible Instance parameters
            AssociateParameters(fam, ParamType.Type);     //Associate all possible Type

            if (!String.IsNullOrEmpty(AlertMessage))
            {
                DialogUtils.Alert("Warning", AlertMessage);                                                     //Finally, alert the user if we had any issues
            }
            if (!String.IsNullOrEmpty(SuccessMessage))
            {
                DialogUtils.OK("Wire successful", SuccessMessage);                                                     //And, issue an OK message the user for all the successfully processed parameters
            }
        }
示例#15
0
 public void RemoteCameraAdded(RemoteCameraModel cameraModel)
 {
     //lock (_LayoutLock)
     System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
     {
         _ParticipantCameraMapping.Add(cameraModel.Participant.GetId(), cameraModel.Camera);
         if (_sortedHandles.Any())
         {
             var currentTuple = Tuple.Create(_sortedHandles.First().Key, _sortedHandles.First().Value);
             _sortedHandles.Remove(currentTuple.Item1);
             _connector.AssignViewToRemoteCamera(currentTuple.Item2, cameraModel.Camera, false, false);
             var theHandle = _wfHostSizes.First(wf => wf.Value.Item3 == currentTuple.Item2).Value;
             _connector.ShowViewAtPoints(currentTuple.Item2, 0, 0, theHandle.Item1, theHandle.Item2);
             _participantHandleMapping.Add(cameraModel.Participant.GetId(), currentTuple);
         }
     }));
 }
        private bool NeedsGap(int frame)
        {
            // When starting to fill gaps we won't actually know the true frequency, so fall back to current
            // Current may very well not be the same as gap, but it's a reasonable behavior to have a current sized gap before seeing filler sized gaps
            var frequency = _gapFiller.Count == 0 ? _current.RewindFrequency : _gapFiller.RewindFrequency;

            return(!StateCache.Any(sc => sc < frame && sc > frame - frequency));
        }
示例#17
0
 public void ClearStateHistory()
 {
     if (_states.Any())
     {
         StateManagerState power = _states.Values.First(s => s.Frame == 0);
         _states.Clear();
         SetState(0, power.State);
         Used = (ulong)power.State.Length;
         NdbDatabase?.Clear();
     }
 }
示例#18
0
 // Update is called once per frame
 void Update()
 {
     if (isRuning)
     {
         if (!isPaused)
         {
             if (!sortedList.Any())
             {
                 Exit();
                 return;
             }
             CurrentTime += Time.deltaTime / Speed;
             while (sortedList.Any() && sortedList.First().Key <= CurrentTime)
             {
                 sortedList.First().Value?.Action();
                 sortedList.RemoveAt(0);
             }
         }
     }
 }
示例#19
0
 public void SignalUnlock()
 {
     // l'elemento in cima e' lo piu' anziano
     lock (_listona.SyncRoot)
     {
         if (listona.Any())
         {
             listona.First().Value.Set();
         }
     }
 }
            public bool Any()
            {
                bool _Any;

                Monitor.Enter(this);

                if (isLocked)
                {
                    Monitor.Wait(this);
                }
                isLocked = true;

                _Any = PriorityQueue_multithreads.Any();

                isLocked = false;
                Monitor.Pulse(this);
                Monitor.Exit(this);

                return(_Any);
            }
示例#21
0
        public Candle GetLast()
        {
            if (!_candles.Any())
            {
                return(null);
            }

            var key = _candles.Keys.Last();

            return(_candles[key]);
        }
 public string Build()
 {
     if (queries.Any())
     {
         return("?" + string.Join("&", queries.Select(q => $"{q.Key}={Uri.EscapeDataString(q.Value)}")));
     }
     else
     {
         return(string.Empty);
     }
 }
示例#23
0
        public List <Node> SolveWithAStar(int stepCost)
        {
            Dictionary <Node, int> openHash  = new Dictionary <Node, int>();
            HashSet <Node>         closeHash = new HashSet <Node>();
            SortedList <int, Node> open      = new SortedList <int, Node>(new DuplicateKeyComparer <int>());
            Node best;

            //0. start the timer
            calcStopwatch.Reset();
            calcStopwatch.Start();

            //1. put IS on open
            open.Add(initialState.HVal, initialState);
            openHash.Add(initialState, initialState.HVal);

            while (true)
            {
                //2. if open is empty, fail
                if (!open.Any())
                {
                    openCount  = open.Count();
                    closeCount = closeHash.Count();
                    calcStopwatch.Stop();
                    return(null);
                }

                //pick out best from open and put on close
                best = open.First().Value;
                openHash.Remove(best);
                open.RemoveAt(0);
                closeHash.Add(best);

                //3. expand n
                foreach (Operator op in GetValidOperators(best))
                {
                    Node successor = ApplyOperator(op, best, stepCost);
                    if (successor.Equals(goalState))
                    {
                        //4. if successor is goal, output solution
                        openCount  = open.Count();
                        closeCount = closeHash.Count();
                        solution   = GenerateSolutionPath(closeHash.ToList(), successor);
                        calcStopwatch.Stop();
                        return(solution);
                    }

                    if (!closeHash.Contains(successor) && !openHash.ContainsKey(successor))
                    {
                        open.Add(successor.HVal, successor);
                        openHash.Add(successor, successor.HVal);
                    }
                }
            }
        }
示例#24
0
        public void TestRemoveAt()
        {
            var list = new SortedList <int>(Comparer <int> .Create((a, b) => a - b));

            list.Add(10);
            list.Add(8);
            list.Add(13);
            list.Add(-10);
            list.RemoveAt(0);
            Assert.IsFalse(list.Any(i => i == -10));
            Assert.AreEqual(3, list.Count);
        }
示例#25
0
        public void TestClear()
        {
            var list = new SortedList <int>(Comparer <int> .Create((a, b) => a - b));

            list.Add(10);
            list.Add(8);
            list.Add(13);
            list.Add(-10);
            list.Clear();
            Assert.IsFalse(list.Any());
            Assert.AreEqual(0, list.Count);
        }
示例#26
0
        // Actual worker for GetPreferredInstance()
        internal GameInstance _GetPreferredInstance()
        {
            foreach (IGame game in knownGames)
            {
                // TODO: Check which ones match, prompt user if >1

                // First check if we're part of a portable install
                // Note that this *does not* register in the config.
                string path = GameInstance.PortableDir(game);

                if (path != null)
                {
                    GameInstance portableInst = new GameInstance(game, path, "portable", User);
                    if (portableInst.Valid)
                    {
                        return(portableInst);
                    }
                }
            }

            // If we only know of a single instance, return that.
            if (instances.Count == 1 && instances.First().Value.Valid)
            {
                return(instances.First().Value);
            }

            // Return the autostart, if we can find it.
            // We check both null and "" as we can't write NULL to the config, so we write an empty string instead
            // This is necessary so we can indicate that the user wants to reset the current AutoStartInstance without clearing the config!
            if (!string.IsNullOrEmpty(AutoStartInstance) &&
                instances[AutoStartInstance].Valid)
            {
                return(instances[AutoStartInstance]);
            }

            // If we know of no instances, try to find one.
            // Otherwise, we know of too many instances!
            // We don't know which one to pick, so we return null.
            return(!instances.Any() ? FindAndRegisterDefaultInstance() : null);
        }
 public void Add(int b, int e)
 {
     if (ranges.Any())
     {
         if (ranges.ContainsKey(b))
         {
             if (e > ranges[b])
             {
                 ranges[b] = e;
             }
         }
         else
         {
             ranges.Add(b, e);
         }
         FixUp();
     }
     else
     {
         ranges.Add(b, e);             // new ranges list
     }
 }
示例#28
0
        public void TestRemove()
        {
            var list = new SortedList <int>(Comparer <int> .Create((a, b) => a - b))
            {
                10,
                8,
                13,
                -10
            };

            list.Remove(8);
            Assert.IsFalse(list.Any(i => i == 8));
            Assert.AreEqual(3, list.Count);
        }
示例#29
0
        public static List <Span> GetHighlightedSpans(string displayText, string typed)
        {
            string typedLower = typed.ToLowerInvariant();
            var    matches    = new SortedList <int, Span>();
            string match      = string.Empty;
            int    startIndex = 0;

            for (int i = 0; i < typedLower.Length; i++)
            {
                char c = typedLower[i];

                if (!displayText.Contains(match + c))
                {
                    if (!matches.Any())
                    {
                        return(_defaultEmptyList);
                    }

                    match      = string.Empty;
                    startIndex = matches.Last().Value.End;
                }

                string current = match + c;
                int    index   = displayText.IndexOf(current, startIndex);
                int    offset  = 0;

                if (index == -1)
                {
                    return(_defaultEmptyList);
                }

                if (index > 0)
                {
                    index  = displayText.IndexOf("_" + current, startIndex);
                    offset = 1;
                }

                if (index > -1)
                {
                    matches[index] = new Span(index + offset, current.Length);
                    match         += c;
                }
                else
                {
                    return(_defaultEmptyList);
                }
            }

            return(matches.Values.ToList());
        }
示例#30
0
        /// <summary>
        /// Get last commit in a particular PR
        /// </summary>
        /// <param name="supportedRepo"></param>
        /// <param name="prNumber"></param>
        /// <returns></returns>
        public string GetLastCommitForPr(SupportedGitHubRepos supportedRepo, long prNumber)
        {
            string     repoName = supportedRepo.GetRepoName();
            Repository r        = GetRepository(repoName);
            SortedList <DateTime, string> sortedCommitHistory = GetPrWithCommitList(r.Id, prNumber);
            string lastcommit = string.Empty;

            if (sortedCommitHistory.Any <KeyValuePair <DateTime, string> >())
            {
                lastcommit = sortedCommitHistory.Values[sortedCommitHistory.Count - 1];
            }

            return(lastcommit);
        }
        private static IEnumerable<SortedList<DateTime, IList<PackageIdentity>>> SegmentPackageDeletes(SortedList<DateTime, IList<PackageIdentity>> packageDeletes)
        {
            var packageIdentityTracker = new HashSet<string>();
            var currentSegment = new SortedList<DateTime, IList<PackageIdentity>>();
            foreach (var entry in packageDeletes)
            {
                if (!currentSegment.ContainsKey(entry.Key))
                {
                    currentSegment.Add(entry.Key, new List<PackageIdentity>());
                }

                var curentSegmentPackages = currentSegment[entry.Key];
                foreach (var packageIdentity in entry.Value)
                {
                    var key = packageIdentity.Id + "|" + packageIdentity.Version;
                    if (packageIdentityTracker.Contains(key))
                    {
                        // Duplicate, return segment
                        yield return currentSegment;

                        // Clear current segment
                        currentSegment.Clear();
                        currentSegment.Add(entry.Key, new List<PackageIdentity>());
                        curentSegmentPackages = currentSegment[entry.Key];
                        packageIdentityTracker.Clear();
                    }

                    // Add to segment
                    curentSegmentPackages.Add(packageIdentity);
                    packageIdentityTracker.Add(key);
                }
            }

            if (currentSegment.Any())
            {
                yield return currentSegment;
            }
        }