Example #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);
            }
        }
Example #2
0
        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");
        }
Example #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);
        }
        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);
        }
        public void PopFromEmptyStackTest()
        {
            LimitedStack <string> stack = new LimitedStack <string>(1);

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

            exception.Should().BeOfType <InvalidOperationException>();
        }
Example #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());
        }
Example #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();
        }
Example #8
0
        /// <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));
        }
Example #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]);
        }
Example #10
0
 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);
 }
Example #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>();
        }
Example #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();
        }
        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);
        }
Example #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());
        }
Example #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);
                }
            }
Example #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]);
        }
Example #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);
        }
        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;
            }
        }
Example #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");
        }
Example #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());
        }
Example #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;
            }
        }
Example #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;
                    }
                }
            }
        }
Example #23
0
 public CommandManager(TextSource ts)
 {
     history = new LimitedStack<UndoableCommand>(maxHistoryLength);
     TextSource = ts;
 }
Example #24
0
        /// <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;
        }
 public CommandManager(TextSource ts)
 {
     _history = new LimitedStack<UndoableCommand>(_maxHistoryLength);
     TextSource = ts;
     UndoRedoStackIsEnabled = true;
 }
Example #26
0
        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);
            }
        }
 public CommandManager()
 {
     history = new LimitedStack<UndoableCommand>(maxHistoryLength);
 }
 protected void SetFileHistory(LimitedStack <UndoableCommand> history, Stack <UndoableCommand> redoStack)
 {
     // TODO: set file history in mod editor controller
 }
Example #29
0
 public CommandManager(TextSource ts)
 {
     _history               = new LimitedStack <UndoableCommand>(MaxHistoryLength);
     TextSource             = ts;
     UndoRedoStackIsEnabled = true;
 }
Example #30
0
        //--------------------------------------------------------------------------------------------------

        public UndoHandler(IUndoableTopology document)
        {
            _Document  = document;
            _UndoStack = new LimitedStack <UndoAction[]>(500);
            _RedoStack = new LimitedStack <UndoAction[]>(500);
        }
 public UndoRedoHistory(int defaultUndoCount)
 {
     undoStack = new LimitedStack <T>(defaultUndoCount);
     redoStack = new LimitedStack <T>(defaultUndoCount);
 }
Example #32
0
        /// <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);
        }
Example #33
0
 public SpellHistory(FightActor owner, IEnumerable <SpellHistoryEntry> entries)
 {
     Owner             = owner;
     InitialRound      = CurrentRound;
     m_underlyingStack = new LimitedStack <SpellHistoryEntry>(HistoryEntriesLimit, entries);
 }
Example #34
0
 public static void Reset()
 {
     Dirty     = false;
     undoStack = new LimitedStack <Track>(20);
     redoStack = new LimitedStack <Track>(20);
 }
Example #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);
 }
        /// <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);
        }
 public CourtSettingsControl()
 {
     this.InitializeComponent();
     this.backups = new LimitedStack <string>(100);
 }