コード例 #1
0
        /// <summary>
        /// Closes this layer.
        /// </summary>
        public override void Close()
        {
            base.Close();

            try
            {
                if (_timer != null)
                {
                    _timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                    _timer.Dispose();
                    _timer = null;
                }

                lock (_cache)
                {
                    _cache.OnRemove = null;
                    _cache.Clear();
                }
                _cache = null;

                lock (_stack)
                { // make sure the tile range is not in use.
                    _stack.Clear();
                }
                _stack = null;

                // flushes all images from the cache.
                _nativeImageCache.Flush();
            }
            catch (Exception ex)
            { // don't worry about exceptions here.
                OsmSharp.Logging.Log.TraceEvent("LayerTile", Logging.TraceEventType.Error, ex.Message);
            }
        }
コード例 #2
0
ファイル: PerformanceService.cs プロジェクト: Spanfile/DocBot
        public PerformanceService(DiscordSocketClient discord, LoggingService logger, IConfigurationRoot config)
        {
            this.discord = discord;
            this.logger  = logger;
            this.config  = config;

            currentProcess = Process.GetCurrentProcess();

            sampleLimit        = int.Parse(this.config["perf:samples"]);
            collectionInterval = int.Parse(this.config["perf:collectionInterval"]);

            latencies       = new LimitedStack <int>(sampleLimit);
            heapMemories    = new LimitedStack <long>(sampleLimit);
            processMemories = new LimitedStack <long>(sampleLimit);

            signal = new AsyncAutoResetEvent();

            updateTimer = new System.Timers.Timer(collectionInterval)
            {
                AutoReset = true
            };
            updateTimer.Elapsed += UpdateTimerOnElapsedAsync;
            updateTimer.Start();

            discord.LatencyUpdated += DiscordOnLatencyUpdatedAsync;

            logger.LogDebug($"Collection interval: {collectionInterval} ms. Samples to collect: {sampleLimit}", "PerformanceService");
        }
コード例 #3
0
        public void LimitedStack_AddingValuesAfterPopping_WithOverflow_StillGivesCorrectOrder()
        {
            var stack = new LimitedStack <int>(4);

            stack.Add(1);
            stack.Add(2);
            stack.Pop();

            stack.Add(3);
            stack.Add(4);
            stack.Pop();

            stack.Add(5);
            stack.Add(6);
            stack.Pop();

            stack.Add(7);
            stack.Add(8);
            stack.Pop();
            stack.Add(9);

            var arr = stack.ToArray();

            Assert.AreEqual(9, arr[0]);
            Assert.AreEqual(7, arr[1]);
            Assert.AreEqual(5, arr[2]);
            Assert.AreEqual(3, arr[3]);
            Assert.AreEqual(4, arr.Length);
        }
コード例 #4
0
        public void PushAndPeekTest()
        {
            var newIntStack = new LimitedStack <int>(4);

            Assert.AreEqual(newIntStack.Count, 0);

            for (int i = 1; i <= 4; i++)
            {
                newIntStack.Push(i);
                Assert.AreEqual(newIntStack.Count, i);
                var top = newIntStack.Peek();
                Assert.AreEqual(top, i);
            }

            newIntStack.Push(5);
            var afterOverflowTop = newIntStack.Peek();

            Assert.AreEqual(afterOverflowTop, 5);
            Assert.AreEqual(newIntStack.Count, 4);

            for (int i = 5; i >= 2; i--)
            {
                Assert.AreEqual(newIntStack.Pop(), i);
            }

            Assert.AreEqual(newIntStack.Peek(), 0);
            Assert.AreEqual(newIntStack.Count, 0);
        }
コード例 #5
0
        public void PopFromEmptyStackTest()
        {
            LimitedStack <string> stack = new LimitedStack <string>(1);

            Exception exception = Record.Exception(() => stack.Pop());

            exception.Should().BeOfType <InvalidOperationException>();
        }
コード例 #6
0
        public void LimitedStack_HasCorrectCount_InNonOverflowScenario()
        {
            var stack = new LimitedStack <int>(5);

            stack.Add(1);
            stack.Add(2);
            stack.Add(3);

            Assert.AreEqual(3, stack.Count());
        }
コード例 #7
0
        /*  public IPCamStreamRepeater()
         * {
         *
         * }*/

        public StreamRepeater(StreamTask iPCamStreamTask, string hostname)
        {
            this.iPCamStreamTask = iPCamStreamTask;
            this.hostname        = hostname;
            readThread           = new System.Threading.Thread(Thread)
            {
                Name = "Read Thread for" + hostname
            };
            ReadData = new LimitedStack <byte[]>(20);
            readThread.Start();
        }
コード例 #8
0
ファイル: MapGrid.cs プロジェクト: Octavic/SpaceDefence
        /// <summary>
        /// Called when the state of the grid changes
        /// </summary>
        public void OnStateChange(List <ResourceCost> costDiff = null)
        {
            var newState = this.SaveState();

            if (this._redoStack.Count > 0)
            {
                this._redoStack = new LimitedStack <MapGridUndoItem>(GeneralSettings.GridUndoSteps);
            }

            this._undoStack.Push(new MapGridUndoItem(newState, costDiff));
        }
コード例 #9
0
        public void LimitedStack_HasCorrectValues_InOrder_NoOverflow()
        {
            var stack = new LimitedStack <int>(3);

            stack.Add(1);
            stack.Add(2);

            var arr = stack.ToArray();

            Assert.AreEqual(2, arr[0]);
            Assert.AreEqual(1, arr[1]);
        }
コード例 #10
0
ファイル: DocumentBuffer.cs プロジェクト: vorov2/slot
 public DocumentBuffer(Document doc, FileInfo file, Encoding encoding, Guid id)
 {
     Id         = id;
     Document   = doc;
     Selections = new SelectionList();
     UndoStack  = new LimitedStack <CommandInfo>();
     RedoStack  = new LimitedStack <CommandInfo>();
     Tips       = new List <CallTip>();
     Encoding   = encoding;
     File       = file;
     editorLock = new EditorLock(this);
 }
コード例 #11
0
        public MultiLineScanner(
            IScannerConfig config,
            IScanPreprocessor preprocessor,
            IHashProvider <string> hashProvider)
        {
            _config            = config;
            _preprocessor      = preprocessor;
            _hashProvider      = hashProvider;
            _singleLineScanner = new SingleLineScanner(config, preprocessor, hashProvider);

            _lines   = new LimitedStack <Line>(BufferSize);
            _results = new HashSet <ScanResult>();
        }
コード例 #12
0
        /// <summary>
        /// Creates a new tiles layer.
        /// </summary>
        /// <param name="tilesURL">The tiles URL.</param>
        /// <param name="tileCacheSize">The tile cache size.</param>
        public LayerTile(string tilesURL, int tileCacheSize)
        {
            _nativeImageCache = NativeImageCacheFactory.Create();
            _tilesURL         = tilesURL;
            _cache            = new LRUCache <Tile, Image2D>(tileCacheSize);
            _cache.OnRemove  += OnRemove;
            _stack            = new LimitedStack <Tile>(tileCacheSize, tileCacheSize);
            _timer            = new Timer(this.LoadQueuedTiles, null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
            _attempts         = new Dictionary <Tile, int>();
            _suspended        = false;

            _projection = new WebMercator();
        }
コード例 #13
0
        public void PushTest(
            int size,
            string[] values,
            string[] expectedResult)
        {
            LimitedStack <String> stack = new LimitedStack <string>(size);

            foreach (string value in values)
            {
                stack.Push(value);
            }

            stack.Count.Should().Be(expectedResult.Length);
            stack.ShouldAllBeEquivalentTo(expectedResult);
        }
コード例 #14
0
        public void LimitedStack_PopGivesBackCorrectValues_NoOverflow()
        {
            var stack = new LimitedStack <int>(4);

            stack.Add(1);
            stack.Add(2);
            stack.Add(3);

            Assert.AreEqual(3, stack.Pop());
            Assert.AreEqual(2, stack.Pop());
            Assert.AreEqual(1, stack.Count());

            Assert.AreEqual(1, stack.Pop());
            Assert.AreEqual(0, stack.Count());
        }
コード例 #15
0
            public void Push(T value)
            {
                var last = GetLastStack();

                try
                {
                    last.Push(value);
                }
                catch (Exception)
                {
                    var stack = new LimitedStack <T>(Capacity);
                    stack.Push(value);
                    this.stacks.Add(stack);
                }
            }
コード例 #16
0
        public void LimitedStack_HasCorrectValues_InOrder_AfterOverflow()
        {
            var stack = new LimitedStack <int>(3);

            stack.Add(1);
            stack.Add(2);
            stack.Add(3);
            stack.Add(4);
            stack.Add(5);

            var arr = stack.ToArray();

            Assert.AreEqual(5, arr[0]);
            Assert.AreEqual(4, arr[1]);
            Assert.AreEqual(3, arr[2]);
        }
コード例 #17
0
        public void LimitedStackConstructorTest()
        {
            var newIntStack = new LimitedStack <int>(4);

            Assert.AreNotEqual(newIntStack, null);
            Assert.AreEqual(newIntStack.Size, 4);

            var newBoolStack = new LimitedStack <bool>(10);

            Assert.AreNotEqual(newBoolStack, null);
            Assert.AreEqual(newBoolStack.Size, 10);

            var newDataStack = new LimitedStack <MyData>(100);

            Assert.AreNotEqual(newDataStack, null);
            Assert.AreEqual(newDataStack.Size, 100);
        }
コード例 #18
0
        public static ObservableCollection <T> ToOveObservableCollection <T>(this LimitedStack <T> input) where T : class
        {
            try
            {
                var observableCollection = new ObservableCollection <T>();

                while (input.Count > 0)
                {
                    observableCollection.Add(input.Pop());
                }

                return(observableCollection);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #19
0
        public void LimitedStack_PopingEmptyStack_Throws()
        {
            var stack = new LimitedStack <int>(4);

            stack.Add(1);
            stack.Pop();

            bool gotException = false;

            try
            {
                stack.Pop();
            }
            catch (Exception)
            {
                gotException = true;
            }

            Assert.IsTrue(gotException, "No exception if poping empty stack");
        }
コード例 #20
0
        public void LimitedStack_PopGivesBackCorrectValues_AfterOverflow()
        {
            var stack = new LimitedStack <int>(4);

            stack.Add(1);
            stack.Add(2);
            stack.Add(3);
            stack.Add(4);
            stack.Add(5);
            stack.Add(6);
            stack.Add(7);

            Assert.AreEqual(7, stack.Pop());
            Assert.AreEqual(6, stack.Pop());
            Assert.AreEqual(2, stack.Count());

            Assert.AreEqual(5, stack.Pop());
            Assert.AreEqual(4, stack.Pop());
            Assert.AreEqual(0, stack.Count());
        }
コード例 #21
0
        public static LimitedStack <T> ToLimitedStack <T>(this ObservableCollection <T> input, int limit) where T : class
        {
            try
            {
                var limitedStack = new LimitedStack <T>(limit);

                if (input.Count > 0)
                {
                    for (var i = input.Count - 1; i >= 0; i--)
                    {
                        limitedStack.Push(input[i]);
                    }
                }

                return(limitedStack);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
コード例 #22
0
        public void InvalidConstructorSizeTest()
        {
            var invalidSizes = new List <int>()
            {
                -1, -2, 0
            };

            foreach (var invalidSize in invalidSizes)
            {
                try
                {
                    var newIntStack = new LimitedStack <int>(invalidSize);
                    throw new Exception("Should not pass with size of " + invalidSize);
                }
                catch (Exception e)
                {
                    var expectedError = e as ArgumentOutOfRangeException;
                    if (expectedError == null)
                    {
                        throw e;
                    }
                }
            }
        }
コード例 #23
0
ファイル: CommandManager.cs プロジェクト: Rex-Hays/GNIDA2
 public CommandManager(TextSource ts)
 {
     history = new LimitedStack<UndoableCommand>(maxHistoryLength);
     TextSource = ts;
 }
コード例 #24
0
ファイル: TilesLayer.cs プロジェクト: jorik041/osmsharp
        /// <summary>
        /// Creates a new tiles layer.
        /// </summary>
        /// <param name="is_lazy"></param>
        public TilesLayer(bool is_lazy, float zoom_offset,TimeSpan? max_tile_age)
        {
            this.Visible = true;
            this.Name = "Tiles Layer";

            _tiles_url = ConfigurationManager.AppSettings["OsmTilesUrl"];

            _valid = false;
            _is_lazy = is_lazy;
            _zoom_offset = zoom_offset;

            // holds all tiles already loaded.
            _tiles_cache = new Dictionary<int, IDictionary<int, IDictionary<int, IElement>>>();

            // initialize the stack to hold unloaded tile requests.
            _tiles_to_load_stack = new LimitedStack<ThreadParameterObject>();
            _tiles_to_load_stack.Limit = 20;

            // initialize the async tile loading.
            this.InitializeTileLoading(5);

            // set the min zoom.
            _min_zoom = 1;
            // set the max zoom.
            _max_zoom = 18;

            this.MinZoom = _min_zoom;
            this.MaxZoom = _max_zoom;
        }
コード例 #25
0
 public CommandManager(TextSource ts)
 {
     _history = new LimitedStack<UndoableCommand>(_maxHistoryLength);
     TextSource = ts;
     UndoRedoStackIsEnabled = true;
 }
コード例 #26
0
ファイル: History.cs プロジェクト: huizh/xenadmin
        private static void PopulateMenuWith(ToolStripSplitButton button, LimitedStack<HistoryItem> history, 
            HistoryNavigationDelegate historyNaviagtionDelegate)
        {
            button.DropDownItems.Clear();

            int i = 0;
            foreach (HistoryItem item in history)
            {
                int j = ++i;
                ToolStripMenuItem menuItem = new ToolStripMenuItem();
                menuItem.Text = item.Name.EscapeAmpersands();
                menuItem.Image = item.Image;
                menuItem.ImageScaling = ToolStripItemImageScaling.None;
                menuItem.Click += delegate(Object sender, EventArgs e)
                {
                    historyNaviagtionDelegate(j);
                };

                button.DropDownItems.Add(menuItem);
            }
        }
コード例 #27
0
 public CommandManager()
 {
     history = new LimitedStack<UndoableCommand>(maxHistoryLength);
 }
コード例 #28
0
 protected void SetFileHistory(LimitedStack <UndoableCommand> history, Stack <UndoableCommand> redoStack)
 {
     // TODO: set file history in mod editor controller
 }
コード例 #29
0
ファイル: CommandManager.cs プロジェクト: TheAstro30/CodePad
 public CommandManager(TextSource ts)
 {
     _history               = new LimitedStack <UndoableCommand>(MaxHistoryLength);
     TextSource             = ts;
     UndoRedoStackIsEnabled = true;
 }
コード例 #30
0
        //--------------------------------------------------------------------------------------------------

        public UndoHandler(IUndoableTopology document)
        {
            _Document  = document;
            _UndoStack = new LimitedStack <UndoAction[]>(500);
            _RedoStack = new LimitedStack <UndoAction[]>(500);
        }
コード例 #31
0
 public UndoRedoHistory(int defaultUndoCount)
 {
     undoStack = new LimitedStack <T>(defaultUndoCount);
     redoStack = new LimitedStack <T>(defaultUndoCount);
 }
コード例 #32
0
ファイル: MapFrame.cs プロジェクト: ExRam/DotSpatial-PCL
        /// <summary>
        /// Fires the ExtentsChanged event
        /// </summary>
        /// <param name="ext"></param>
        protected override void OnExtentsChanged(Extent ext)
        {
            if (ext.X == -180 && ext.Y == 90) { return; }
            if (_isZoomingNextOrPrevious)
            {
                // reset the flag for the next extents change
                _isZoomingNextOrPrevious = false;
            }
            else
            {
                // Add the last extent to the stack
                // We shouldn't really need to peek and compare, but found that the method
                // Might be called too freqently in some case.
                if (ViewExtents != _previousExtents.Peek())
                {
                    if (_lastExtent != null)
                        _previousExtents.Push(_lastExtent);

                    _lastExtent = ext;

                    // clear the forward history.
                    _nextExtents = new LimitedStack<Extent>();
                }
            }
            base.OnExtentsChanged(ext);
        }
コード例 #33
0
 public SpellHistory(FightActor owner, IEnumerable <SpellHistoryEntry> entries)
 {
     Owner             = owner;
     InitialRound      = CurrentRound;
     m_underlyingStack = new LimitedStack <SpellHistoryEntry>(HistoryEntriesLimit, entries);
 }
コード例 #34
0
 public static void Reset()
 {
     Dirty     = false;
     undoStack = new LimitedStack <Track>(20);
     redoStack = new LimitedStack <Track>(20);
 }
コード例 #35
0
 /// <summary>
 /// Créer un nouveau manager d'historique de modifications
 /// </summary>
 public UndoRedoManager()
 {
     this.undoStack = new LimitedStack <T>(MAX_LENGHT);
     this.redoStack = new LimitedStack <T>(MAX_LENGHT);
 }
コード例 #36
0
        /// <summary>
        /// Initialize the tile loading functionality.
        /// </summary>
        private void InitializeTileLoading(int max_threads)
        {
            _max_loading_thread_count = max_threads;

            _tiles_to_load_stack = new LimitedStack<ThreadParameterObject>();

            _current_loading_objects = new List<ThreadParameterObject>();
            _loaded_tiles = new Dictionary<int, Dictionary<int, bool>>();

            _tmr = new Timer(new TimerCallback(Timer_Callback));
            _tmr.Change(10, 500);
        }
コード例 #37
0
 public CourtSettingsControl()
 {
     this.InitializeComponent();
     this.backups = new LimitedStack <string>(100);
 }