Ejemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Cleans up resources (native and managed) associated with the current instance.
        /// </summary>
        /// <param name="disposing">
        /// Zero when being disposed via garbage collection; otherwise, non-zero.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (!disposed)
                {
                    if (disposing)
                    {
                        ////////////////////////////////////
                        // dispose managed resources here...
                        ////////////////////////////////////

                        if (disposeSelect && (SelectCommand != null))
                        {
                            SelectCommand.Dispose();
                            SelectCommand = null;
                        }

                        if (InsertCommand != null)
                        {
                            InsertCommand.Dispose();
                            InsertCommand = null;
                        }

                        if (UpdateCommand != null)
                        {
                            UpdateCommand.Dispose();
                            UpdateCommand = null;
                        }

                        if (DeleteCommand != null)
                        {
                            DeleteCommand.Dispose();
                            DeleteCommand = null;
                        }
                    }

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////
                }
            }
            finally
            {
                base.Dispose(disposing);

                //
                // NOTE: Everything should be fully disposed at this point.
                //
                disposed = true;
            }
        }
Ejemplo n.º 2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        protected override void Dispose(bool disposing)
        {
            try
            {
                if (!disposed)
                {
                    if (disposing)
                    {
                        ////////////////////////////////////
                        // dispose managed resources here...
                        ////////////////////////////////////

                        if (SelectCommand != null)
                        {
                            SelectCommand.Dispose();
                            SelectCommand = null;
                        }

                        if (InsertCommand != null)
                        {
                            InsertCommand.Dispose();
                            InsertCommand = null;
                        }

                        if (UpdateCommand != null)
                        {
                            UpdateCommand.Dispose();
                            UpdateCommand = null;
                        }

                        if (DeleteCommand != null)
                        {
                            DeleteCommand.Dispose();
                            DeleteCommand = null;
                        }
                    }

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////

                    disposed = true;
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Ejemplo n.º 3
0
        public LogEntryViewer(ILogEntryService logEntryService)
        {
            //build an observable filter
            var filter = this.WhenAnyValue(x => x.SearchText)
                         .Throttle(TimeSpan.FromMilliseconds(250))
                         .Select(BuildFilter);

            //filter, sort and populate reactive list.
            var loader = logEntryService.Items.Connect()
                         .Transform(le => new LogEntryProxy(le))
                         .DelayRemove(TimeSpan.FromSeconds(0.75), proxy => proxy.FlagForRemove())
                         .Filter(filter)
                         .Sort(SortExpressionComparer <LogEntryProxy> .Descending(le => le.TimeStamp).ThenByDescending(l => l.Key), SortOptions.UseBinarySearch)
                         .ObserveOn(RxApp.MainThreadScheduler)
                         .Bind(Data)
                         .DisposeMany()
                         .Subscribe();

            //aggregate total items
            var summariser = logEntryService.Items.Connect()
                             .QueryWhenChanged(items =>
            {
                var debug = items.Count(le => le.Level == LogLevel.Debug);
                var info  = items.Count(le => le.Level == LogLevel.Info);
                var warn  = items.Count(le => le.Level == LogLevel.Warning);
                var error = items.Count(le => le.Level == LogLevel.Error);
                return(new LogEntrySummary(debug, info, warn, error));
            })
                             .Subscribe(s => Summary = s);

            //manage user selection, delete items command
            var selectedItems = _selectionController.SelectedItems.Connect().Publish();

            //Build a message from selected items
            _deleteItemsText = selectedItems.QueryWhenChanged(query =>
            {
                if (query.Count == 0)
                {
                    return("Select log entries to delete");
                }
                if (query.Count == 1)
                {
                    return("Delete selected log entry?");
                }
                return($"Delete {query.Count} log entries?");
            })
                               .ToProperty(this, viewmodel => viewmodel.DeleteItemsText, "Select log entries to delete");


            //make a command out of selected items - enabling the command when there is a selection
            DeleteCommand = ReactiveCommand.Create(() =>
            {
                var toRemove = _selectionController.SelectedItems.Items.Select(proxy => proxy.Original).ToArray();
                _selectionController.Clear();
                logEntryService.Remove(toRemove);
            }, selectedItems.QueryWhenChanged(query => query.Count > 0));

            // .ToCommand();

            var connected = selectedItems.Connect();

            _cleanUp = Disposable.Create(() =>
            {
                loader.Dispose();
                connected.Dispose();
                _deleteItemsText.Dispose();
                DeleteCommand.Dispose();
                _selectionController.Dispose();
                summariser.Dispose();
            });
        }