示例#1
0
        //=============================
        //  Internal
        //=============================
        private void RemoveDuplicates <T>(ref List <T> items) where T : StateBase
        {
            string typeName = typeof(T).ToString();

            foreach (T targetA in items.Copy())
            {
                foreach (T targetB in items.Copy())
                {
                    if (targetA == targetB)
                    {
                        continue;
                    }
                    bool duplicateGUID   = !targetA.id.IsEmpty() && targetA.id == targetB.id;
                    bool duplicateName   = !targetA.name.IsEmpty() && targetA.name == targetB.name;
                    bool duplicateSource = targetA.name == "@Active" || targetB.name == "@Active";
                    if (duplicateGUID && (duplicateSource || duplicateName))
                    {
                        var removeTarget = duplicateSource && targetA.name == "@Active" ? targetB : targetA;
                        if (items.Contains(removeTarget))
                        {
                            items.Remove(removeTarget);
                            Log.Warning("[StateTable] Removing duplicate " + typeName + " -- " + removeTarget.name, this.gameObject);
                        }
                    }
                }
            }
        }
        public List <SoundFile> CreateRandomList(List <SoundFile> source, int outputSize)
        {
            var output = new List <SoundFile>();

            var sourceCopy = source.Copy();

            for (int i = 0; i < outputSize; i++)
            {
                int min = 0;
                int max = sourceCopy.Count;

                int choicePosition = _random.Next(min, max);
                var choice         = sourceCopy[choicePosition];
                output.Add(choice);

                sourceCopy.RemoveAt(choicePosition);

                //If desired output is greater than source then reuse source
                if (sourceCopy.Count == 0)
                {
                    sourceCopy = source.Copy();
                }
            }

            return(output);
        }
示例#3
0
    private IEnumerator HandleVision()
    {
        while (true)
        {
            hitTargets = vision.QueryVision().ToList();

            GameObject target = FindClosest(transform.position);

            if (prevHitTargets.Count == 0 && hitTargets.Count > 0)
            {
                EventManager.Instance.TriggerEvent(new Events.Senses.SpottingChanged(this, target));
            }
            else if (prevHitTargets.Count > 0 && hitTargets.Count == 0)
            {
                EventManager.Instance.TriggerEvent(new Events.Senses.SpottingChanged(this, target));
            }
            else if (prevHitTargets.Count > 0 && hitTargets.Count > 0 && !prevTarget.Equals(target))
            {
                EventManager.Instance.TriggerEvent(new Events.Senses.SpottingChanged(this, target));
            }

            prevHitTargets = hitTargets.Copy();

            prevTarget = target;

            yield return(null);
        }
    }
        public ActionResult FilterScreeningRecords(List <FilterData> filters)
        {
            List <ScreenResponseEntity> lstScreenData = JsonConvert.DeserializeObject <List <ScreenResponseEntity> >(SessionHelper.ScreenResultData);
            List <ScreenResponseEntity> result        = lstScreenData.Copy();

            try
            {
                foreach (var item in filters)
                {
                    var valLst = item.FilterValue.Split(',').ToList();
                    if (item.Operator == "equalto")
                    {
                        if (item.FieldName == "Category")
                        {
                            result = result.Where(x => valLst.Contains(x.Category)).ToList();
                        }
                        else if (item.FieldName == "AlertType")
                        {
                            if (valLst.Count < 5)
                            {
                                result = result.Where(x => valLst.Contains(x.LastScreenedAlertType)).ToList();
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //Empty catch block to stop from breaking
            }
            return(PartialView("ListScreeningResult", result));
        }
示例#5
0
 public List <ToDoItem> GetAll()
 {
     lock (_sync)
     {
         return(_list.Copy());
     }
 }
示例#6
0
        public static List <string> Sorted(this List <string> list)
        {
            var copy = list.Copy();

            copy.Sort(string.CompareOrdinal);
            return(copy);
        }
示例#7
0
        public static List <T> Sorted <T>(this List <T> list) where T : IComparable <T>
        {
            var copy = list.Copy();

            copy.Sort();
            return(copy);
        }
示例#8
0
        public static bool SaveFileDialog(List <IRecorderItem> items)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "ESR files (*.ESR)|*.ESR|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(false);
            }

            //Get the path of specified file
            string filePath = saveFileDialog.FileName;

            ESRFile file = new ESRFile();

            file.FileName       = filePath;
            file.FileBody.Items = items.Copy <List <IRecorderItem> >();

            using (new WaitCursor())
            {
                if (!file.SaveFile())
                {
                    System.Windows.MessageBox.Show("File Save Error!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
            }
            return(true);
        }
示例#9
0
        public IEnumerable <Sound> Dequeue()
        {
            var queue = _queued.Copy();

            _queued.Clear();
            return(queue);
        }
示例#10
0
文件: ProofState.cs 项目: ggrov/dafny
        public void SetBackTrackCount(List <int> cnt)
        {
            var cur = GetBackTrackCount();

            //restore from the root
            cur.Reverse();
            List <int> tmp = cnt.Copy();

            tmp.Reverse();

            for (int j = 0; j < cur.Count; j++)
            {
                int count;
                count  = j >= tmp.Count ? cur[j] : tmp[j];
                cur[j] = count;
            }

            cur.Reverse();

            var frame = _scope.Peek();

            frame.FrameCtrl.Backtrack = cur[0];
            cur.RemoveAt(0);

            while (frame.Parent != null)
            {
                frame = frame.Parent;
                frame.FrameCtrl.Backtrack = cur[0];
                cur.RemoveAt(0);
            }
        }
        private static TACBaseBlocks AllOptimization(List <TACInstruction> Instructions)
        {
            if (TACOptimizersAllBlock.Count == 0)
            {
                var r = new TACBaseBlocks(Instructions);
                r.GenBaseBlocks();
                return(r);
            }
            List <TACInstruction> previos;

            previos = Instructions;
            int AllOptimizationCount = 0;

            do
            {
                TACOptimizersAllBlock[AllOptimizationCount].Instructions = previos.Copy();
                TACOptimizersAllBlock[AllOptimizationCount].Run();
                if (previos.SequenceEqual(TACOptimizersAllBlock[AllOptimizationCount].Instructions))
                {
                    AllOptimizationCount++;
                }
                else
                {
                    previos = TACOptimizersAllBlock[AllOptimizationCount].Instructions;
                    AllOptimizationCount    = 0;
                    GlobalOptimizationCount = 0;
                }
            } while (AllOptimizationCount < TACOptimizersAllBlock.Count);
            ++GlobalOptimizationCount;
            var res = new TACBaseBlocks(previos);

            res.GenBaseBlocks();
            return(res);
        }
        public static List <List <int> > CopyReverse(this List <List <int> > L, bool doReverse)
        {
            List <List <int> > res;

            if (doReverse)
            {
                int i, j, m, n = L.Count, t;
                res = new List <List <int> >();
                for (i = 0; i < n; i++)
                {
                    m = L[i].Count;
                    t = m - 1;
                    if (m > 0)
                    {
                        res.Add(new List <int>());
                    }
                    for (j = 0; j < m; j++)
                    {
                        res[i].Add(L[i][t - j]);
                    }
                }
            }
            else
            {
                res = L.Copy();
            }
            return(res);
        }
示例#13
0
        private void AppendImpl(IList <T> list, Int32 offset, Int32 count)
        {
            var copied = Math.Min(count, ChunkSize - this.chunkPosition);

            List.Copy(list, offset, this.currentChunk, this.chunkPosition, copied);
            this.chunkPosition += copied;
            if (this.chunkPosition == ChunkSize)
            {
                var remainingCount = count - copied;
                // We've filled the chunk
                if (remainingCount > ChunkSize)
                {
                    // rather than breaking the remaining items into chunks, make a single extra large chunk
                    var bigChunk = new T[remainingCount];
                    List.Copy(list, offset + copied, bigChunk, 0, remainingCount);
                    this.chunks.AddLast(bigChunk);
                    this.chunks.AddLast(this.currentChunk = new T[ChunkSize]);
                    this.chunkPosition = 0;
                }
                else
                {
                    // Make a new standard chunk and copy what's left
                    this.chunks.AddLast(this.currentChunk = new T[ChunkSize]);
                    List.Copy(list, offset + copied, this.currentChunk, 0, remainingCount);
                    this.chunkPosition = remainingCount;
                }
            }

            this.Length += count;
        }
        public static List <int> ConcatWith(this List <int> L1, ref List <int> L2)
        {
            List <int> res = L1.Copy();

            res.AddRange(L2.Copy());
            return(res);
        }
示例#15
0
 public void UnbindAll()
 {
     foreach (var endpoint in EndPoints.Copy())
     {
         Unbind(endpoint);
     }
 }
示例#16
0
        private void RepairUnmatched <T>(ref List <T> items) where T : StateBase
        {
            string typeName = typeof(T).ToString();

            foreach (T item in items.Copy())
            {
                if (this.controller.IsEnabled() && item.name == "@External")
                {
                    continue;
                }
                StateBehaviour match = this.scripts.Find(x => x.id == item.id);
                if (match == null)
                {
                    match = this.scripts.Find(x => x.alias == item.name);
                    if (match != null)
                    {
                        item.id     = match.id;
                        item.target = match;
                    }
                    else
                    {
                        items.Remove(item);
                    }
                    if (StateTable.debug)
                    {
                        string itemInfo = typeName + " -- " + item.name + " [" + item.id + "]";
                        string action   = match == null ? "Removing" : "Repairing";
                        Log.Show("[StateTable] " + action + " old " + itemInfo, this.gameObject);
                    }
                }
            }
        }
示例#17
0
 private void btnRebind_Click(object sender, EventArgs e)
 {
     if (MsgBox.YesNo("确认还原为初始数据?", false))
     {
         _comparaResult = _backupResult.Copy <List <ComparaResult> >();
         Bind();
     }
 }
示例#18
0
        public void Copy_WorksAsExpected_OnLists()
        {
            var a = new List <int> {
                1, 2, 3, 4, 5
            };

            TestHelper.AssertSequence(a.Skip(1).Take(3), a.Copy(1, a.Count - 2));
        }
示例#19
0
        public void Should_Throw_SerializationException_Try_Serialize_Non_Serializeble_IEnumerable_Class()
        {
            IEnumerable <object> value = new List <object> {
                new { Anything = "anything" }
            };

            Assert.Throws <SerializationException>(() => value.Copy());
        }
示例#20
0
        public void CopyTest()
        {
            var list = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };
            var newList = list.Copy();

            Assert.True(newList.Count == list.Count);
        }
示例#21
0
        private async void BackgroundSync()
        {
            queuedAPIEvents = new BlockingCollection <InaraAPIEvent>();
            using (syncCancellationTS = new CancellationTokenSource())
            {
                try
                {
                    // Pause a short time to allow any initial events to build in the queue before our first sync
                    await Task.Delay(startupDelayMilliSeconds, syncCancellationTS.Token).ConfigureAwait(false);

                    await Task.Run(async() =>
                    {
                        // The `GetConsumingEnumerable` method blocks the thread while the underlying collection is empty
                        // If we haven't extracted events to send to Inara, this will wait / pause background sync until `queuedAPIEvents` is no longer empty.
                        List <InaraAPIEvent> holdingQueue = new List <InaraAPIEvent>();
                        try
                        {
                            foreach (var pendingEvent in queuedAPIEvents.GetConsumingEnumerable(syncCancellationTS.Token))
                            {
                                holdingQueue.Add(pendingEvent);

                                if (queuedAPIEvents.Count == 0)
                                {
                                    // Once we hit zero queued events, wait a couple more seconds for any concurrent events to register
                                    await Task.Delay(2000, syncCancellationTS.Token).ConfigureAwait(false);
                                    if (queuedAPIEvents.Count > 0)
                                    {
                                        continue;
                                    }
                                    // No additional events registered, send any events we have in our holding queue
                                    if (holdingQueue.Count > 0)
                                    {
                                        var sendingQueue = holdingQueue.Copy();
                                        holdingQueue     = new List <InaraAPIEvent>();
                                        await Task.Run(() => SendAPIEvents(sendingQueue), syncCancellationTS.Token).ConfigureAwait(false);
                                        await Task.Delay(!tooManyRequests ? syncIntervalMilliSeconds : delayedSyncIntervalMilliSeconds, syncCancellationTS.Token).ConfigureAwait(false);
                                    }
                                }
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            // Operation was cancelled. Return any events we've extracted back to the primary queue.
                            foreach (var pendingEvent in holdingQueue)
                            {
                                queuedAPIEvents.Add(pendingEvent);
                            }
                        }
                    }).ConfigureAwait(false);
                }
                catch (TaskCanceledException)
                {
                    // Task cancelled. Nothing to do here.
                }
            }
            tooManyRequests = false;
        }
示例#22
0
 /// <summary>
 /// Gives a copy of needs
 /// </summary>
 internal List <Storage> GetBuildNeeds()
 //internal StorageSet GetBuildNeeds()
 {
     return(buildingNeeds.Copy());//.Copy();
     //TODO!has connection in pop.invest!!
     ////if (whoCanProduce(Product.Gold) == this)
     ////        result.Set(new Storage(Product.Wood, 40f));
     //return result;
 }
示例#23
0
        public ResultForm(List <ComparaResult> compara)
        {
            InitializeComponent();

            _comparaResult = compara;
            _backupResult  = _comparaResult.Copy <List <ComparaResult> >();

            InitForm();
            InitData();
        }
示例#24
0
        public void ListCloneTest()
        {
            var original = new List <string> {
                "gotta", "go", "learn", "Redux"
            };
            var cloned = original.Copy();

            Assert.AreEqual(original, cloned);
            Assert.AreNotSame(original, cloned);
        }
示例#25
0
        public void ObjExt_Copy()
        {
            var persons  = new List <Person>().FromJsonPath(@"PersonRepo\GetPersons\01.json\persons");
            var persons2 = persons.Copy();

            var json1 = JToken.FromObject(persons).ToString();
            var json2 = JToken.FromObject(persons2).ToString();

            Assert.True(persons.GetHashCode() != persons2.GetHashCode());
            Assert.Equal(json1, json2);
        }
示例#26
0
        public void ObjExt_IsEqualWithFilter()
        {
            var persons  = new List <Person>().FromJsonPath(@"PersonRepo\GetPersons\01.json\persons");
            var persons2 = persons.Copy();

            persons2[0].FirstName = "XXX";
            persons2[1].FirstName = "XXX";

            Assert.False(persons.IsEqual(persons2));
            Assert.True(persons.IsEqual(persons2, new string[] { "FirstName" }));
        }
示例#27
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        public Events Copy()
        {
            Events copy = new Events();

            copy.EventType = this.EventType;
            foreach (Functions functions in this.Functions)
            {
                copy.Functions.Add(functions.Copy());
            }

            return(copy);
        }
示例#28
0
        public void TestCopy()
        {
            using (var list = new List <OpaqueInt> ()) {
                list.Append(null);
                Assume.That(list.Length, Is.EqualTo(1));
                var newList = list.Copy();
                Assert.That(list.Length, Is.EqualTo(1));
                Assert.That(newList.Length, Is.EqualTo(1));
            }

            Utility.AssertNoGLibLog();
        }
示例#29
0
        public void Test_ListCopy( )
        {
            var list1 = new List <int>
            {
                1,
                2
            };
            List <int> list2 = list1.Copy( );

            list2.Should().BeEquivalentTo(list1);            // data has been copied
            list2.As <object>().Should().NotBeSameAs(list1); // but its not the same list
        }
示例#30
0
        public void ObjExt_IsSame()
        {
            var persons  = new List <Person>().FromJsonPath(@"PersonRepo\GetPersons\01.json\persons");
            var persons2 = persons.Copy();
            var persons3 = persons;

            Assert.NotEqual(persons, persons2);
            Assert.False(persons.IsSame(persons2));

            Assert.Equal(persons, persons3);
            Assert.True(persons.IsSame(persons3));
        }
示例#31
0
        public ImageEffectsForm(Image img, List<ImageEffect> effects = null)
        {
            InitializeComponent();
            DefaultImage = img;
            eiImageEffects.ObjectType = typeof(List<ImageEffect>);
            AddAllEffectsToContextMenu();

            if (effects != null)
            {
                AddEffects(effects.Copy());
            }

            UpdatePreview();
        }
示例#32
0
        public ImageEffectsForm(Image img, List<ImageEffect> effects = null)
        {
            InitializeComponent();
            Icon = ShareXResources.Icon;
            DefaultImage = img;
            AddAllEffectsToTreeView();

            if (effects != null)
            {
                AddEffects(effects.Copy());
            }

            UpdatePreview();
        }
        public ImageEffectsForm(Image img, List<ImageEffect> effects = null)
        {
            InitializeComponent();
            DefaultImage = img;
            AddAllEffectsToTreeView();

            if (effects != null)
            {
                AddEffects(effects.Copy());
            }

            UpdatePreview();

            #if DEBUG
            btnRefresh.Visible = true;
            btnTest.Visible = true;
            #endif
        }