/// <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(); // Log in from cookie int? userID = GetUserIDFromCookie(); bool logout = userID == null; if (userID != null) { try { OltpProxy.SessionStart(userID.Value); } catch { logout = true; } } if (logout) { LogoutUser(); } else { LoginUser(); } }
public void LoginUser() { CurrentUser = OltpProxy.CurrentUser; // Try to get the user's client list AsyncOperation(delegate() { using (OltpProxy proxy = new OltpProxy()) { _accountsTable = proxy.Service.Account_Get(); _userPermissions = proxy.Service.User_GetAllPermissions(); } }, delegate(Exception ex) { PageBase.MessageBoxError("Failed to load user settings.", ex); return(false); }, delegate() { // Hide all menu items/sections that have NO PERMISSIONS at all (account = null) _mainMenu.Visibility = Visibility.Visible; _mainMenu.UpdateLayout(); _mainMenu.ApplyPermissions(null); _header.Visibility = Visibility.Visible; _currentPageViewer.Content = CurrentPage = null; _pageTitle.Content = ""; _accountsSelector.ItemsSource = _accountsTable; string selectedAccountCookie = String.Format("{0}.SelectedAccount", OltpProxy.CurrentUser.ID); string selectedAccount = App.Cookies[selectedAccountCookie]; if (selectedAccount != null) { DataRow[] rs = _accountsTable.Select("ID = " + selectedAccount); if (rs.Length > 0) { _accountsSelector.SelectedIndex = _accountsTable.Rows.IndexOf(rs[0]); } } }); }
public void LogoutUser() { if (CurrentPage != null && !CurrentPage.TryToCloseDialogs()) { return; } OltpProxy.SessionEnd(); App.Cookies.ClearCookie(Const.Cookies.Login); _mainMenu.Visibility = Visibility.Hidden; _mainMenu.CollapseAll(); _accountsSelector.ItemsSource = null; _accountsSelector.SelectedItem = null; _header.Visibility = Visibility.Hidden; CurrentPage = new Pages.GeneralLogin(); _currentPageViewer.Content = CurrentPage; _pageTitle.Content = "Login"; }
/// <summary> /// /// </summary> /// <param name="async">When true, runs the specified server method in a seperate thread.</param> /// <param name="postApplying"> /// If specified, this function is called after applying is complete. It is the /// function's responsibility to call FloatingDialog.EndApplyChanges() in order to complete the apply cycle. /// </param> protected static void Dialog_ApplyingChanges <TableType, RowType>(TableType sourceTable, FloatingDialog dialog, MethodInfo saveMethod, CancelRoutedEventArgs e, object[] additionalArgs, bool async, Action postApplying) where TableType : DataTable, new() where RowType : DataRow { RowType editVersion = dialog.Content as RowType; DataTable changes = editVersion.Table.GetChanges(); // No changes were made, skip the apply (but don't cancel) if (changes == null) { e.Skip = true; if (postApplying != null) { postApplying(); } else { dialog.EndApplyChanges(e); } return; } // Remember data state DataRowState state = changes.Rows[0].RowState; // Will store updated data TableType savedVersion = null; object[] actualArgs = additionalArgs != null? new object[additionalArgs.Length + 1] : new object[1]; actualArgs[0] = Oltp.Prepare <TableType>(changes); if (additionalArgs != null) { additionalArgs.CopyTo(actualArgs, 1); } // Save the changes to the DB Delegate[] delegates = new Delegate[] { (Action) delegate() { using (OltpProxy proxy = new OltpProxy()) { savedVersion = (TableType)saveMethod.Invoke(proxy.Service, actualArgs); } }, (Func <Exception, bool>) delegate(Exception ex) { // Failed, so cancel and display a message MessageBoxError("Error while updating.", ex); e.Cancel = true; return(false); }, (Action) delegate() { // Special case when adding a new row if (state == DataRowState.Added) { // Import the saved row sourceTable.ImportRow(savedVersion.Rows[0]); // Even though nothing needs to be updated, mark it as added so AppliedChanges handled treats it properly RowType newRow = sourceTable.Rows[sourceTable.Rows.Count - 1] as RowType; newRow.SetAdded(); // Set as new target content dialog.TargetContent = newRow; dialog.Content = Dialog_MakeEditVersion <TableType, RowType>(sourceTable, newRow); } // Activate the post applying action if (postApplying != null) { postApplying(); } else { dialog.EndApplyChanges(e); } } }; if (async) { App.CurrentPage.Window.AsyncOperation(delegates[0] as Action, delegates[1] as Func <Exception, bool>, delegates[2] as Action); } else { bool exception = false; try { (delegates[0] as Action).Invoke(); } catch (Exception ex) { (delegates[1] as Func <Exception, bool>).Invoke(ex); exception = true; } if (!exception) { (delegates[2] as Action).Invoke(); } if (postApplying != null) { postApplying(); } else { dialog.EndApplyChanges(e); } } }
/// <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> /// /// </summary> /// <param name="async">When true, runs the specified server method in a seperate thread.</param> /// <param name="postApplying"> /// If specified, this function is called after applying is complete. It is the /// function's responsibility to call FloatingDialog.EndApplyChanges() in order to complete the apply cycle. /// </param> protected static void Dialog_ApplyingChanges <TableT, RowT> ( TableT sourceTable, FloatingDialog dialog, MethodInfo saveMethod, CancelRoutedEventArgs e, object[] additionalArgs, bool async, Action postApplying ) where TableT : DataTable, new() where RowT : DataRow { RowT controlRow = dialog.Content as RowT; DataTable changes = controlRow.Table.GetChanges(); // No changes were made, skip the apply (but don't cancel) if (changes == null) { e.Skip = true; if (postApplying != null) { postApplying(); } else { dialog.EndApplyChanges(e); } return; } if (dialog.IsBatch) { // Copy all target rows and apply the changed values to them TableT clonedTargetTable = new TableT(); foreach (RowT row in (IEnumerable)dialog.TargetContent) { clonedTargetTable.ImportRow(row); } clonedTargetTable.AcceptChanges(); dialog.ApplyBindingsToItems(clonedTargetTable.Rows); // Get these changes changes = clonedTargetTable.GetChanges(); } // No changes were made, skip the apply (but don't cancel) if (changes == null) { e.Skip = true; if (postApplying != null) { postApplying(); } else { dialog.EndApplyChanges(e); } return; } // Remember data state DataRowState state = controlRow.RowState; // Will store updated data TableT savedVersion = null; // Create a typed version of the changes object[] actualArgs = additionalArgs != null? new object[additionalArgs.Length + 1] : new object[1]; actualArgs[0] = Oltp.Prepare <TableT>(changes); if (additionalArgs != null) { additionalArgs.CopyTo(actualArgs, 1); } // Save the changes to the DB Delegate[] delegates = new Delegate[] { (Action) delegate() { using (OltpProxy proxy = new OltpProxy()) { savedVersion = (TableT)saveMethod.Invoke(proxy.Service, actualArgs); } }, (Func <Exception, bool>) delegate(Exception ex) { // Failed, so cancel and display a message MainWindow.MessageBoxError("Error while updating.\n\nChanges may have been saved, if re-saving doesn't work please refresh the page.", ex); e.Cancel = true; return(false); }, (Action) delegate() { // Special case when adding a new row if (!dialog.IsBatch && state == DataRowState.Added) { // Import the saved row sourceTable.ImportRow(savedVersion.Rows[0]); // Even though nothing needs to be updated, mark it as added so AppliedChanges handled treats it properly RowT newRow = sourceTable.Rows[sourceTable.Rows.Count - 1] as RowT; newRow.SetAdded(); // Set as new target content dialog.TargetContent = newRow; dialog.Content = Dialog_MakeEditVersion <TableT, RowT>(newRow); } // Activate the post applying action if (postApplying != null) { postApplying(); } else { dialog.EndApplyChanges(e); } } }; if (async) { App.CurrentPage.Window.AsyncOperation( delegates[0] as Action, // out-of-ui action delegates[1] as Func <Exception, bool>, // exception handler delegates[2] as Action // in-ui action ); } else { bool exception = false; try { // out-of-ui action, done in ui because async is not required (delegates[0] as Action).Invoke(); } catch (Exception ex) { // exception handler (delegates[1] as Func <Exception, bool>).Invoke(ex); exception = true; } // in-ui action if (!exception) { (delegates[2] as Action).Invoke(); } if (postApplying != null) { postApplying(); } else { dialog.EndApplyChanges(e); } } }