/// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing"><c>true</c> if managed resources should be disposed; otherwise, <c>false</c>.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }

                if (LoadedTables != null)
                {
                    LoadedTables.ForEach(dbo => dbo.Dispose());
                    LoadedTables.Clear();
                }

                if (LoadedViews != null)
                {
                    LoadedViews.ForEach(dbo => dbo.Dispose());
                    LoadedViews.Clear();
                }

                if (LoadedProcedures != null)
                {
                    LoadedProcedures.ForEach(dbo => dbo.Dispose());
                    LoadedProcedures.Clear();
                }

                _wbConnection = null;
            }

            base.Dispose(disposing);
        }
        internal void NavigateToView(ILogicWithViewModel <IViewModel> logic, StateManager stateManager, bool isModal = false)
        {
            IViewModel view = logic.ViewModel;

            view.Visible = true;
            if (!LoadedViews.Any(x => x.UniqueID == view.UniqueID))
            {
                _viewsDelta.AddNewView(view, isModal);

                if (isModal)
                {
                    ModalViews.Add(view.UniqueID);
                }

                LoadedViews.Add(new ViewInfo {
                    UniqueID = view.UniqueID, Visible = view.Visible, ZOrder = 0
                });
                // Added to support promises in the first request(SKS Demo Splash)
                // The view is created but is not sent to the client because it is not loaded by the first request
                // Therefore the navigateToView requires to send the view's viewmodel completely.
                stateManager.Tracker.DetachModel(view);
                stateManager.Tracker.MarkAllAsModified(view);
                stateManager.AddInCache(view.UniqueID, view, true);
                // Lets fire the load event
                //Load can have no parameters or some parameters
                InvokeLifeCycleStartup(logic);
            }
            else
            {
                var currentView = LoadedViews.FirstOrDefault(v => v.UniqueID == view.UniqueID);
                currentView.Visible = view.Visible;
                currentView.ZOrder  = 0;
            }
            stateManager.Tracker.MarkAsModified(this, "LoadedViews");
        }
        /// <summary>
        /// It is used to sync the ViewsState from the client.
        /// When a form is removed on the client side, it will make sure to remove that view from the loaded views
        /// It does not remove it from the state.
        /// </summary>
        /// <param name="viewId"></param>
        internal void DisposeViewInternal(string viewId)
        {
            LoadedViews.RemoveAll(x => x.UniqueID == viewId);
            var stateManager = StateManager.Current;

            stateManager.RemoveObject(viewId, true);
            stateManager.Tracker.MarkAsModified(this, "LoadedViews");
        }
        /// <summary>
        /// Disposes the view bound to the given <c>ILogicView</c> object.
        /// </summary>
        /// <param name="logic">The <c>ILogicView</c> object bound to the view to dispose.</param>
        internal void DisposeView(ILogicWithViewModel <IViewModel> logic)
        {
            IViewModel view  = logic.ViewModel;
            int        count = LoadedViews.RemoveAll(x => x.UniqueID == view.UniqueID);

            _viewsDelta.RemoveView(view);
            var stateManager = StateManager.Current;

            stateManager.RemoveObject(view.UniqueID, true, isDispose: true, formBaseVM: view as UpgradeHelpers.Helpers.FormBaseViewModel);
            stateManager.Tracker.MarkAsModified(this, "LoadedViews");
            ModalViews.Remove(view.UniqueID);
            Debug.Assert(count <= 1, "Exactly one view must be removed");
        }
 public override void Load()
 {
     LoadedViews.TryAddView(webView);
 }