Ejemplo n.º 1
0
            void StartLoadMenu(RowData rowData)
            {
                if (menus[0].IsUsable &&
                    loadingRowData != rowData &&
                    (menus[rowData.MenuLevel + 1] == null ||
                     menus[rowData.MenuLevel + 1].Tag as RowData != rowData))
                {
                    loadingRowData = rowData;
                    LoadStarted();
                    BackgroundWorker workerSubMenu = workersSubMenu.
                                                     Where(w => !w.IsBusy).FirstOrDefault();
                    if (workerSubMenu == null)
                    {
                        workerSubMenu = new BackgroundWorker
                        {
                            WorkerSupportsCancellation = true,
                        };
                        workerSubMenu.DoWork             += LoadMenu;
                        workerSubMenu.RunWorkerCompleted += LoadSubMenuCompleted;
                        workersSubMenu.Add(workerSubMenu);
                    }

                    workerSubMenu.RunWorkerAsync(rowData);
                }

                void LoadSubMenuCompleted(object senderCompleted, RunWorkerCompletedEventArgs e)
                {
                    LoadStopped();
                    MenuData menuData = (MenuData)e.Result;

                    if (menus[0].IsUsable &&
                        menuData.Validity != MenuDataValidity.AbortedOrUnknown)
                    {
                        Menu menu = Create(menuData);
                        switch (menuData.Validity)
                        {
                        case MenuDataValidity.Valid:
                            menu.SetTypeSub();
                            break;

                        case MenuDataValidity.Empty:
                            menu.SetTypeEmpty();
                            break;

                        case MenuDataValidity.NoAccess:
                            menu.SetTypeNoAccess();
                            break;
                        }

                        menu.Tag = menuData.RowDataParent;
                        menuData.RowDataParent.SubMenu = menu;
                        if (menus[0].IsUsable)
                        {
                            ShowSubMenu(menu);
                        }
                    }

                    loadingRowData = null;
                }
            }
Ejemplo n.º 2
0
        private void CreateMenuRow(RowData rowData, Menu menu, DataTable dataTable)
        {
            rowData.SetData(rowData, dataTable);
            rowData.OpenMenu += OpenSubMenu;
            rowData.Reading.WorkerSupportsCancellation = true;
            rowData.Reading.DoWork += ReadMenu_DoWork;
            void ReadMenu_DoWork(object senderDoWork,
                                 DoWorkEventArgs eDoWork)
            {
                int level = (int)eDoWork.Argument;
                BackgroundWorker worker = (BackgroundWorker)senderDoWork;

                eDoWork.Result = Business.Menus.GetData(worker, rowData.TargetFilePath, level);
            }

            rowData.Reading.RunWorkerCompleted += ReadMenu_RunWorkerCompleted;
            void ReadMenu_RunWorkerCompleted(object senderCompleted,
                                             RunWorkerCompletedEventArgs e)
            {
                MenuData menuData = (MenuData)e.Result;

                if (rowData.RestartLoading)
                {
                    rowData.RestartLoading = false;
                    rowData.Reading.RunWorkerAsync(menuData.Level);
                }
                else
                {
                    LoadStopped();
                    if (menuData.Validity != MenuDataValidity.Invalid)
                    {
                        menu = Create(menuData);
                        if (menuData.RowDatas.Count > 0)
                        {
                            menu.SetTypeSub();
                        }
                        else if (menuData.Validity == MenuDataValidity.NoAccess)
                        {
                            menu.SetTypeNoAccess();
                        }
                        else
                        {
                            menu.SetTypeEmpty();
                        }
                        menu.Tag        = rowData;
                        rowData.SubMenu = menu;
                        rowData.MenuLoaded();
                    }
                }
            }
        }