private void radio_Checked(object sender, RoutedEventArgs e)
        {
            if (_openingDialog)
            {
                return;
            }

            // Check which radio button was pressed
            bool?state = (sender as RadioButton).Name == "radioAllow" ?
                         (bool?)true :
                         (sender as RadioButton).Name == "radioDeny" ?
                         (bool?)false :
                         (bool?)null;


            // Retrieve the data of the permission being set
            ListBoxItem lbItem          = VisualTree.GetParent <ListBoxItem>(sender as RadioButton);
            ApiMenuItem x               = (ApiMenuItem)lbItem.Content;
            string      permissionValue = x.Path;

            if (permissionValue == null)
            {
                return;
            }

            // Retrieve relevant parameters
            object[]          parameters = PermissionTarget_dialog.Content as object[];
            Oltp.UserRow      user       = parameters[0] as Oltp.UserRow;
            Oltp.UserGroupRow group      = parameters[0] as Oltp.UserGroupRow;
            Oltp.AccountPermissionDataTable permissionsTable = parameters[1] as Oltp.AccountPermissionDataTable;

            // Get the row with the last value for this permissions
            Oltp.AccountPermissionRow perm = permissionsTable.FindByAccountIDTargetIDTargetIsGroupPermissionType(
                Window.CurrentAccount.ID,
                user == null ? group.ID : user.ID,
                user == null,
                permissionValue);

            if (state == null && perm != null)
            {
                // Moving to unset, so if a permission exists, delete it
                perm.Delete();
            }
            else if (state != null)
            {
                if (perm == null)
                {
                    // Create a new permission target if none exists
                    perm                = permissionsTable.NewAccountPermissionRow();
                    perm.AccountID      = Window.CurrentAccount.ID;
                    perm.TargetID       = user != null ? user.ID : group.ID;
                    perm.TargetIsGroup  = user == null;
                    perm.PermissionType = permissionValue;
                    perm.Value          = true;
                    permissionsTable.Rows.Add(perm);
                }
                else if (perm.RowState == DataRowState.Deleted)
                {
                    // If the target was deleted, restore it
                    perm.RejectChanges();
                }

                // Apply the correct value
                if (state == true)
                {
                    perm.Value = true;
                }
                else
                {
                    perm.Value = false;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Version v = ApplicationDeployment.IsNetworkDeployed ?
                        ApplicationDeployment.CurrentDeployment.CurrentVersion :
                        Assembly.GetExecutingAssembly().GetName().Version;

            //Version v = Assembly.GetExecutingAssembly().GetName().Version;
            _version.Content = "Version " + v.ToString();

            // Settings we should get from the deployment URL
            int    accountID;
            string menuItemPath;
            string sessionID;

                        #if DEBUG
            accountID    = 1240244;
            sessionID    = "4F873C89AEE75E485893C7AE16E09020";
            menuItemPath = "management/trackers";
                        #endif

            // Normal producion
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                if (ApplicationDeployment.CurrentDeployment.ActivationUri.Query == null)
                {
                    HidePageContents("This page must be accessed via the Edge.BI interface.");
                    return;
                }

                NameValueCollection urlParams =
                    HttpUtility.ParseQueryString(ApplicationDeployment.CurrentDeployment.ActivationUri.Query);

                // Invalid account
                string accountIDParam = urlParams["account"];
                if (accountIDParam == null || !Int32.TryParse(accountIDParam, out accountID))
                {
                    HidePageContents("Invalid account specified. Please select another account.");
                    return;
                }

                // Log in from session param
                sessionID = urlParams["session"];
                if (String.IsNullOrEmpty(sessionID))
                {
                    HidePageContents("Invalid session specified. Try logging out and logging back in.");
                    return;
                }

                menuItemPath = urlParams["path"];
                if (String.IsNullOrEmpty(menuItemPath))
                {
                    HidePageContents("Invalid menu path specified. Please select an item from the menu.");
                    return;
                }
            }
            else
            {
                                #if !DEBUG
                {
                    HidePageContents("This page must be accessed via the Edge.BI interface.");
                    return;
                }
                                #endif
            }

            ApiMenuItem menuItem = null;

            // Get user settings
            AsyncOperation(delegate()
            {
                OltpProxy.SessionStart(sessionID);
                using (OltpProxy proxy = new OltpProxy())
                {
                    _accountsTable   = proxy.Service.Account_Get();
                    _userPermissions = proxy.Service.User_GetAllPermissions();
                    menuItem         = proxy.Service.ApiMenuItem_GetByPath(menuItemPath);
                }
            },
                           delegate(Exception ex)
            {
                HidePageContents(null, ex);
                return(false);
            },
                           delegate()
            {
                CurrentUser  = OltpProxy.CurrentUser;
                DataRow[] rs = _accountsTable.Select("ID = " + accountID.ToString());
                if (rs.Length < 1)
                {
                    HidePageContents("Specified account was not found. Please select another account.");
                    return;
                }

                _currentAccount = (Oltp.AccountRow)rs[0];
                LoadPage(menuItem);
            });
        }
        /// <summary>
        /// Open the dialog
        /// </summary>
        private void PermissionTarget_dialog_Open(object sender, RoutedEventArgs e)
        {
            // Set dataItem as current item
            ListViewItem currentItem = _listTable.GetParentListViewItem(e.OriginalSource as FrameworkElement);

            Oltp.UserRow      user  = currentItem.Content as Oltp.UserRow;
            Oltp.UserGroupRow group = currentItem.Content as Oltp.UserGroupRow;

            // Retrieve applied permissions from the server
            Oltp.AccountPermissionDataTable permissionsTable = null;
            Window.AsyncOperation(delegate()
            {
                using (OltpProxy proxy = new OltpProxy())
                {
                    permissionsTable = proxy.Service.AccountPermission_Get(Window.CurrentAccount.ID,
                                                                           user == null ? group.ID : user.ID,
                                                                           user == null
                                                                           );
                }
            },
                                  delegate(Exception ex)
            {
                MainWindow.MessageBoxError("Failed to open permissions.", ex);
                return(false);
            },
                                  delegate()
            {
                _openingDialog = true;

                // Apply retrieved permissions to the GUI radio buttons
                ListBox permissionsList = VisualTree.GetChild <ListBox>(PermissionTarget_dialog);
                for (int i = 0; i < permissionsList.Items.Count; i++)
                {
                    ApiMenuItem x          = (ApiMenuItem)permissionsList.Items[i];
                    string permissionValue = x.Path;
                    if (permissionValue == null)
                    {
                        continue;
                    }

                    Oltp.AccountPermissionRow perm = permissionsTable.FindByAccountIDTargetIDTargetIsGroupPermissionType(
                        Window.CurrentAccount.ID,
                        user == null ? group.ID : user.ID,
                        user == null,
                        permissionValue);

                    ListBoxItem lbItem = (ListBoxItem)permissionsList.ItemContainerGenerator.ContainerFromIndex(i);

                    if (perm == null)
                    {
                        VisualTree.GetChild <RadioButton>(lbItem, "radioNotSet").IsChecked = true;
                    }
                    else if (perm.Value)
                    {
                        VisualTree.GetChild <RadioButton>(lbItem, "radioAllow").IsChecked = true;
                    }
                    else
                    {
                        VisualTree.GetChild <RadioButton>(lbItem, "radioDeny").IsChecked = true;
                    }
                }

                currentItem.IsSelected = true;

                // Show the dialog
                PermissionTarget_dialog.Title = String.Format("Editing permissions for {0}", user == null ? group.Name : user.Name);
                PermissionTarget_dialog.BeginEdit(new object[] { user == null ? group as DataRow : user as DataRow, permissionsTable });

                _openingDialog = false;
            });
        }
Exemplo n.º 4
0
        ///
        /// </summary>
        private void LoadPage(ApiMenuItem menuItem)
        {
            if (CurrentPage != null)
            {
                bool unloadCurrent = CurrentPage.Unload();

                // Cancel
                if (!unloadCurrent)
                {
                    return;
                }
            }

            // Kill all async wait handles
            foreach (System.Threading.AutoResetEvent handle in _asyncHandles.Values)
            {
                handle.Set();
            }
            _asyncHandles.Clear();

            DataRow[] permissions = _userPermissions.Select(String.Format("PermissionType = '{0}' and (AccountID = -1 or AccountID = {1})", menuItem.Path, CurrentAccount.ID));
            if (permissions.Length < 1)
            {
                HidePageContents("You don't have permission to view this page for the current account.");
                return;
            }

            string className;

            if (!menuItem.Metadata.TryGetValue("WpfClass", out className))
            {
                HidePageContents("This menu item cannot be loaded in WPF.");
                return;
            }

            // Try to get the class
            Type newPageType = Type.GetType(className, false);

            if (newPageType == null)
            {
                try { newPageType = Type.GetType(className, true); }
                catch (Exception ex)
                {
                    HidePageContents("Could not load the requested page.", ex);
                    return;
                }
            }

            // Try loading the class
            try
            {
                CurrentPage = (PageBase)Activator.CreateInstance(newPageType);
            }
            catch (Exception ex)
            {
                CurrentPage = null;
                HidePageContents("Failed to load page.", ex);
            }

            CurrentPage.PageData       = menuItem;
            _currentPageViewer.Content = CurrentPage;

            if (newPageType.GetCustomAttributes(typeof(AccountDependentPageAttribute), false).Length > 0)
            {
                if (CurrentAccount != null)
                {
                    // Tell the page to load the account
                    CurrentPage.OnAccountChanged();
                }
                else
                {
                    // Tell the page to hide the account
                    HidePageContents("You do not have permission to view this page for the selected account.");
                }
            }

            // Force garbage collection
            this.FloatingDialogContainer.Children.Clear();
            GC.Collect();
        }