private void Window_Loaded(object sender, RoutedEventArgs e) { bIsConnectedComplete = false; mgr = new CrmConnectionManager(); mgr.ParentControl = CrmLoginCtrl; mgr.UseUserLocalDirectoryForConfigStore = true; mgr.ClientId = "51f81489-12ee-4a9e-aaae-a2591f45987d"; mgr.RedirectUri = new Uri("app://58145B91-0C36-4500-8554-080854F2AC97"); CrmLoginCtrl.SetGlobalStoreAccess(mgr); CrmLoginCtrl.SetControlMode(ServerLoginConfigCtrlMode.FullLoginPanel); CrmLoginCtrl.ConnectionCheckBegining += new EventHandler(CrmLoginCtrl_ConnectionCheckBegining); CrmLoginCtrl.ConnectErrorEvent += new EventHandler <ConnectErrorEventArgs>(CrmLoginCtrl_ConnectErrorEvent); CrmLoginCtrl.ConnectionStatusEvent += new EventHandler <ConnectStatusEventArgs>(CrmLoginCtrl_ConnectionStatusEvent); CrmLoginCtrl.UserCancelClicked += new EventHandler(CrmLoginCtrl_UserCancelClicked); if (!mgr.RequireUserLogin()) { if (MessageBox.Show("Credentials already saved in configuration\nChoose Yes to Auto Login or No to Reset Credentials", "DynamicsCrm.DevKit - Auto Login", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { CrmLoginCtrl.IsEnabled = false; mgr.ServerConnectionStatusUpdate += new EventHandler <ServerConnectStatusEventArgs>(mgr_ServerConnectionStatusUpdate); mgr.ConnectionCheckComplete += new EventHandler <ServerConnectStatusEventArgs>(mgr_ConnectionCheckComplete); mgr.ConnectToServerCheck(); CrmLoginCtrl.ShowMessageGrid(); } } }
private void mgr_ConnectionCheckComplete(object sender, ServerConnectStatusEventArgs e) { ((CrmConnectionManager)sender).ConnectionCheckComplete -= mgr_ConnectionCheckComplete; ((CrmConnectionManager)sender).ServerConnectionStatusUpdate -= mgr_ServerConnectionStatusUpdate; if (!e.Connected) { if (e.MultiOrgsFound) { MessageBox.Show("Unable to Login to CRM using cached credentials. Org Not found", "Login Failure"); } else { MessageBox.Show("Unable to Login to CRM using cached credentials", "Login Failure"); } resetUiFlag = true; CrmLoginCtrl.GoBackToLogin(); Dispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() => { this.Title = "Failed to Login with cached credentials."; MessageBox.Show(this.Title, "Notification from ConnectionManager", MessageBoxButton.OK, MessageBoxImage.Error); CrmLoginCtrl.IsEnabled = true; } )); resetUiFlag = false; } else { if (e.Connected && !bIsConnectedComplete) { ProcessSuccess(); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { /* * This is the setup process for the login control, * The login control uses a class called CrmConnectionManager to manage the interaction with CRM, this class and also be queried as later points for information about the current connection. * In this case, the login control is referred to as CrmLoginCtrl */ // Set off flag. _bIsConnectedComplete = false; // Init the CRM Connection manager.. _mgr = new CrmConnectionManager(); // Pass a reference to the current UI or container control, this is used to synchronize UI threads In the login control _mgr.ParentControl = CrmLoginCtrl; // if you are using an unmanaged client, excel for example, and need to store the config in the users local directory // set this option to true. _mgr.UseUserLocalDirectoryForConfigStore = true; if (_profileName != null) { _mgr.ProfileName = _profileName; } _mgr.ClientId = "2ad88395-b77d-4561-9441-d0e40824f9bc"; _mgr.RedirectUri = new Uri("app://5d3e90d6-aa8e-48a8-8f2c-58b45cc67315"); // if you are using an unmanaged client, you need to provide the name of an exe to use to create app config key's for. //mgr.HostApplicatioNameOveride = "MyExecName.exe"; // CrmLoginCtrl is the Login control, this sets the CrmConnection Manager into it. CrmLoginCtrl.SetGlobalStoreAccess(_mgr); // There are several modes to the login control UI CrmLoginCtrl.SetControlMode(ServerLoginConfigCtrlMode.FullLoginPanel); // this wires an event that is raised when the login button is pressed. CrmLoginCtrl.ConnectionCheckBegining += CrmLoginCtrl_ConnectionCheckBegining; // this wires an event that is raised when an error in the connect process occurs. CrmLoginCtrl.ConnectErrorEvent += CrmLoginCtrl_ConnectErrorEvent; // this wires an event that is raised when a status event is returned. CrmLoginCtrl.ConnectionStatusEvent += CrmLoginCtrl_ConnectionStatusEvent; // this wires an event that is raised when the user clicks the cancel button. CrmLoginCtrl.UserCancelClicked += CrmLoginCtrl_UserCancelClicked; // Check to see if its possible to do an Auto Login if (_mgr.RequireUserLogin()) { return; } MessageBoxResult result = MessageBoxResult.No; if (!_autoLogin) { result = MessageBox.Show( "Credentials already saved in configuration\nChoose Yes to Auto Login or No to Reset Credentials", "Auto Login", MessageBoxButton.YesNo, MessageBoxImage.Question); } if (_autoLogin || result == MessageBoxResult.Yes) { DoLogin(); } }
private void Mgr_ConnectionCheckComplete(object sender, ServerConnectStatusEventArgs e) { ((CrmConnectionManager)sender).ConnectionCheckComplete -= Mgr_ConnectionCheckComplete; ((CrmConnectionManager)sender).ServerConnectionStatusUpdate -= Mgr_ServerConnectionStatusUpdate; if (!e.Connected) { if (e.MultiOrgsFound) { MessageBox.Show("Unable to Login to CRM using cached credentials. Org Not found", "Login Failure"); } else { MessageBox.Show("Unable to Login to CRM using cached credentials", "Login Failure"); } resetUiFlag = true; CrmLoginCtrl.GoBackToLogin(); ThreadHelper.JoinableTaskFactory.Run(async delegate { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); this.Title = "Failed to Login with cached credentials."; MessageBox.Show(this.Title, "Notification from ConnectionManager", MessageBoxButton.OK, MessageBoxImage.Error); CrmLoginCtrl.IsEnabled = true; }); resetUiFlag = false; } else { if (e.Connected && !bIsConnectedComplete) { ProcessSuccess(); } } }
/// <summary> /// Raised when the window loads for the first time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { /* * This is the setup process for the login control, * The login control uses a class called CrmConnectionManager to manage the interaction with CRM, this class and also be queried as later points for information about the current connection. * In this case, the login control is referred to as CrmLoginCtrl */ // Set off flag. bIsConnectedComplete = false; // Init the CRM Connection manager.. mgr = new CrmConnectionManager(); // Pass a reference to the current UI or container control, this is used to synchronize UI threads In the login control mgr.ParentControl = CrmLoginCtrl; // if you are using an unmanaged client, excel for example, and need to store the config in the users local directory // set this option to true. mgr.UseUserLocalDirectoryForConfigStore = true; // if you are using an unmanaged client, you need to provide the name of an exe to use to create app config key's for. //mgr.HostApplicatioNameOveride = "MyExecName.exe"; // CrmLoginCtrl is the Login control, this sets the CrmConnection Manager into it. CrmLoginCtrl.SetGlobalStoreAccess(mgr); // There are several modes to the login control UI CrmLoginCtrl.SetControlMode(ServerLoginConfigCtrlMode.FullLoginPanel); // this wires an event that is raised when the login button is pressed. CrmLoginCtrl.ConnectionCheckBegining += new EventHandler(CrmLoginCtrl_ConnectionCheckBegining); // this wires an event that is raised when an error in the connect process occurs. CrmLoginCtrl.ConnectErrorEvent += new EventHandler <ConnectErrorEventArgs>(CrmLoginCtrl_ConnectErrorEvent); // this wires an event that is raised when a status event is returned. CrmLoginCtrl.ConnectionStatusEvent += new EventHandler <ConnectStatusEventArgs>(CrmLoginCtrl_ConnectionStatusEvent); // this wires an event that is raised when the user clicks the cancel button. CrmLoginCtrl.UserCancelClicked += new EventHandler(CrmLoginCtrl_UserCancelClicked); // Check to see if its possible to do an Auto Login }
/// <summary> /// This raises and processes Success /// </summary> private void ProcessSuccess() { resetUiFlag = true; bIsConnectedComplete = true; CrmSvc = mgr.CrmSvc; CrmLoginCtrl.GoBackToLogin(); Dispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() => { this.Title = "Notification from Parent"; CrmLoginCtrl.IsEnabled = true; } )); //here we should be connected to crm and we need connection info to generate model if requested! if (CrmConnectionMgr != null && CrmConnectionMgr.CrmSvc != null && CrmConnectionMgr.CrmSvc.IsReady) { connectionStringService.ApplyDBInfoInfoFromClientService(CrmConnectionMgr.CrmSvc, cxInfo.DatabaseInfo); } this.DialogResult = true; // Notify Caller that we are done with success. ContextClassSelectionCompleted?.Invoke(this, null); resetUiFlag = false; }
/// <summary> /// Raised when the window loads for the first time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { Headingtext.Text = "Connecting to " + ConnectionLabel; /* * This is the setup process for the login control, * The login control uses a class called CrmConnectionManager to manage the interaction with CRM, this class and also be queried as later points for information about the current connection. * In this case, the login control is referred to as CrmLoginCtrl */ // Set off flag. bIsConnectedComplete = false; // Init the CRM Connection manager.. mgr = new CrmConnectionManager(); // Pass a reference to the current UI or container control, this is used to synchronize UI threads In the login control mgr.ParentControl = CrmLoginCtrl; // if you are using an unmanaged client, excel for example, and need to store the config in the users local directory // set this option to true. mgr.UseUserLocalDirectoryForConfigStore = true; // Client ID to use for oAuth. ID: 51f81489-12ee-4a9e-aaae-a2591f45987d is a sample ID that should be replaced by a ID created for your use. mgr.ClientId = "51f81489-12ee-4a9e-aaae-a2591f45987d"; // Redirect URI required for oAuth. mgr.RedirectUri = new Uri("app://58145B91-0C36-4500-8554-080854F2AC97"); mgr.ProfileName = ConnectionId; // if you are using an unmanaged client, you need to provide the name of an exe to use to create app config key's for. //mgr.HostApplicatioNameOveride = "MyExecName.exe"; // CrmLoginCtrl is the Login control, this sets the CrmConnection Manager into it. CrmLoginCtrl.SetGlobalStoreAccess(mgr); // There are several modes to the login control UI CrmLoginCtrl.SetControlMode(ServerLoginConfigCtrlMode.FullLoginPanel); // this wires an event that is raised when the login button is pressed. CrmLoginCtrl.ConnectionCheckBegining += new EventHandler(CrmLoginCtrl_ConnectionCheckBegining); // this wires an event that is raised when an error in the connect process occurs. CrmLoginCtrl.ConnectErrorEvent += new EventHandler <ConnectErrorEventArgs>(CrmLoginCtrl_ConnectErrorEvent); // this wires an event that is raised when a status event is returned. CrmLoginCtrl.ConnectionStatusEvent += new EventHandler <ConnectStatusEventArgs>(CrmLoginCtrl_ConnectionStatusEvent); // this wires an event that is raised when the user clicks the cancel button. CrmLoginCtrl.UserCancelClicked += new EventHandler(CrmLoginCtrl_UserCancelClicked); // Check to see if its possible to do an Auto Login if (!mgr.RequireUserLogin()) { // If RequireUserLogin is false, it means that there has been a successful login here before and the credentials are cached. CrmLoginCtrl.IsEnabled = false; // When running an auto login, you need to wire and listen to the events from the connection manager. // Run Auto User Login process, Wire events. mgr.ServerConnectionStatusUpdate += new EventHandler <ServerConnectStatusEventArgs>(mgr_ServerConnectionStatusUpdate); mgr.ConnectionCheckComplete += new EventHandler <ServerConnectStatusEventArgs>(mgr_ConnectionCheckComplete); // Start the connection process. mgr.ConnectToServerCheck(); // Show the message grid. CrmLoginCtrl.ShowMessageGrid(); } }
/// <summary> /// Raised when the window loads for the first time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { /* * This is the setup process for the login control, * The login control uses a class called CrmConnectionManager to manage the interaction with CRM, this class and also be queried as later points for information about the current connection. * In this case, the login control is referred to as CrmLoginCtrl */ // Set off flag. bIsConnectedComplete = false; // Init the CRM Connection manager.. mgr = new CrmConnectionManager(); mgr.UseUserLocalDirectoryForConfigStore = true; mgr.ProfileName = connectionDetailId.ToString("B"); mgr.ClientId = AppId; mgr.RedirectUri = RedirectUri; // Pass a reference to the current UI or container control, this is used to synchronize UI threads In the login control mgr.ParentControl = CrmLoginCtrl; // if you are using an unmanaged client, excel for example, and need to store the config in the users local directory // set this option to true. mgr.UseUserLocalDirectoryForConfigStore = true; // if you are using an unmanaged client, you need to provide the name of an exe to use to create app config key's for. //mgr.HostApplicatioNameOveride = "MyExecName.exe"; // CrmLoginCtrl is the Login control, this sets the CrmConnection Manager into it. CrmLoginCtrl.SetGlobalStoreAccess(mgr); // There are several modes to the login control UI CrmLoginCtrl.SetControlMode(ServerLoginConfigCtrlMode.FullLoginPanel); // this wires an event that is raised when the login button is pressed. CrmLoginCtrl.ConnectionCheckBegining += new EventHandler(CrmLoginCtrl_ConnectionCheckBegining); // this wires an event that is raised when an error in the connect process occurs. CrmLoginCtrl.ConnectErrorEvent += new EventHandler <ConnectErrorEventArgs>(CrmLoginCtrl_ConnectErrorEvent); // this wires an event that is raised when a status event is returned. CrmLoginCtrl.ConnectionStatusEvent += new EventHandler <ConnectStatusEventArgs>(CrmLoginCtrl_ConnectionStatusEvent); // this wires an event that is raised when the user clicks the cancel button. CrmLoginCtrl.UserCancelClicked += new EventHandler(CrmLoginCtrl_UserCancelClicked); // Check to see if its possible to do an Auto Login if (!mgr.RequireUserLogin() && !isUpdate) { //if (MessageBox.Show("Credentials already saved in configuration\nChoose Yes to Auto Login or No to Reset Credentials", "Auto Login", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) //{ // If RequireUserLogin is false, it means that there has been a successful login here before and the credentials are cached. CrmLoginCtrl.IsEnabled = false; // When running an auto login, you need to wire and listen to the events from the connection manager. // Run Auto User Login process, Wire events. mgr.ServerConnectionStatusUpdate += new EventHandler <ServerConnectStatusEventArgs>(mgr_ServerConnectionStatusUpdate); mgr.ConnectionCheckComplete += new EventHandler <ServerConnectStatusEventArgs>(mgr_ConnectionCheckComplete); // Start the connection process. mgr.ConnectToServerCheck(); // Show the message grid. CrmLoginCtrl.ShowMessageGrid(); //} } }
private void DoLogin() { // If RequireUserLogin is false, it means that there has been a successful login here before and the credentials are cached. CrmLoginCtrl.IsEnabled = false; // When running an auto login, you need to wire and listen to the events from the connection manager. // Run Auto User Login process, Wire events. _mgr.ServerConnectionStatusUpdate += mgr_ServerConnectionStatusUpdate; _mgr.ConnectionCheckComplete += mgr_ConnectionCheckComplete; // Start the connection process. _mgr.ConnectToServerCheck(); // Show the message grid. CrmLoginCtrl.ShowMessageGrid(); }
private void ProcessSuccess() { resetUiFlag = true; bIsConnectedComplete = true; CrmLoginCtrl.GoBackToLogin(); ThreadHelper.JoinableTaskFactory.Run(async delegate { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); this.Title = "Notification from Parent"; CrmLoginCtrl.IsEnabled = true; }); ConnectionToCrmCompleted?.Invoke(this, null); resetUiFlag = false; }
private void ProcessSuccess() { resetUiFlag = true; bIsConnectedComplete = true; CrmLoginCtrl.GoBackToLogin(); Dispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() => { this.Title = "Notification from Parent"; CrmLoginCtrl.IsEnabled = true; } )); ConnectionToCrmCompleted?.Invoke(this, null); resetUiFlag = false; }
private void mgr_ConnectionCheckComplete(object sender, ServerConnectStatusEventArgs e) { // The Status event will contain information about the current login process, if Connected is false, then there is not yet a connection. // Unwire events that we are not using anymore, this prevents issues if the user uses the control after a failed login. ((CrmConnectionManager)sender).ConnectionCheckComplete -= mgr_ConnectionCheckComplete; ((CrmConnectionManager)sender).ServerConnectionStatusUpdate -= mgr_ServerConnectionStatusUpdate; if (!e.Connected) { // if its not connected pop the login screen here. if (e.MultiOrgsFound) { MessageBox.Show("Unable to Login to CRM using cached credentials. Org Not found", "Login Failure"); } else { MessageBox.Show("Unable to Login to CRM using cached credentials", "Login Failure"); } _resetUiFlag = true; CrmLoginCtrl.GoBackToLogin(); // Bad Login Get back on the UI. Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { Title = "Failed to Login with cached credentials."; MessageBox.Show(Title, "Notification from ConnectionManager", MessageBoxButton.OK, MessageBoxImage.Error); CrmLoginCtrl.IsEnabled = true; })); _resetUiFlag = false; } else { // Good Login Get back on the UI if (e.Connected && !_bIsConnectedComplete) { ProcessSuccess(); } OutputLogger.WriteToOutputWindow(HostWindow.GetCaption(string.Empty, _mgr.CrmSvc).Substring(3), MessageType.Info); } }
private void ProcessSuccess() { _resetUiFlag = true; _bIsConnectedComplete = true; _crmSvc = _mgr.CrmSvc; CrmLoginCtrl.GoBackToLogin(); Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { Title = "Notification from Parent"; CrmLoginCtrl.IsEnabled = true; } )); // Notify Caller that we are done with success. ConnectionToCrmCompleted?.Invoke(this, null); _resetUiFlag = false; }
/// <summary> /// Complete Event from the Auto Login process /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mgr_ConnectionCheckComplete(object sender, ServerConnectStatusEventArgs e) { // The Status event will contain information about the current login process, if Connected is false, then there is not yet a connection. // Unwire events that we are not using anymore, this prevents issues if the user uses the control after a failed login. ((CrmConnectionManager)sender).ConnectionCheckComplete -= mgr_ConnectionCheckComplete; ((CrmConnectionManager)sender).ServerConnectionStatusUpdate -= mgr_ServerConnectionStatusUpdate; if (!e.Connected) { // if its not connected pop the login screen here. if (e.MultiOrgsFound) { MessageBox.Show("Unable to sign in to CRM using cached credentials. Org Not found", "Sign In failed"); } else { MessageBox.Show("Unable to sign in to CRM using cached credentials", "Sign In failed"); } resetUiFlag = true; CrmLoginCtrl.GoBackToLogin(); // Bad Login Get back on the UI. Dispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() => { this.Title = "Failed to sign in with cached credentials."; MessageBox.Show(this.Title, "Notification from ConnectionManager", MessageBoxButton.OK, MessageBoxImage.Error); CrmLoginCtrl.IsEnabled = true; } )); resetUiFlag = false; } else { // On successful sign in, return to the UI if (e.Connected && !bIsConnectedComplete) { ProcessSuccess(); } } }
/// <summary> /// This raises and processes Success /// </summary> private void ProcessSuccess() { resetUiFlag = true; bIsConnectedComplete = true; CrmSvc = mgr.CrmSvc; CrmLoginCtrl.GoBackToLogin(); Dispatcher.Invoke(DispatcherPriority.Normal, new System.Action(() => { this.Title = "Notification from Parent"; CrmLoginCtrl.IsEnabled = true; } )); // Notify Caller that we are done with success. //if (ConnectionToCrmCompleted != null) ConnectionToCrmCompleted(this, null); //Michael: just cancel in case of success: this.Close(); resetUiFlag = false; }
/// <summary> /// Raised when the window loads for the first time. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { // This is the setup process for the login control. // The login control uses a class called CrmConnectionManager to manage // the interaction with CRM. This class can also be queried at later points // for information about the current connection. // In this case, the login control is referred to as CrmLoginCtrl. // Set off flag. bIsConnectedComplete = false; // Initialize the CRM Connection manager. mgr = new CrmConnectionManager(); // Pass a reference to the current UI or container control. This is used to // synchronize UI threads In the login control. mgr.ParentControl = CrmLoginCtrl; // If you are using an unmanaged client, say Microsoft Excel, and need to // store the config in the users local directory, you must set this option to true. mgr.UseUserLocalDirectoryForConfigStore = true; // If you are using an unmanaged client, you need to provide the name of // an executable (.exe) to use to create app config key. //mgr.HostApplicatioNameOveride = "MyExecName.exe"; // This sets the CRM Connection manager for CrmLoginCtrl. CrmLoginCtrl.SetGlobalStoreAccess(mgr); // There are several modes to the login control UI. CrmLoginCtrl.SetControlMode(ServerLoginConfigCtrlMode.FullLoginPanel); // This wires an event that is raised when the login button is pressed. CrmLoginCtrl.ConnectionCheckBegining += new EventHandler(CrmLoginCtrl_ConnectionCheckBegining); // This wires an event that is raised when an error in the connect process occurs. CrmLoginCtrl.ConnectErrorEvent += new EventHandler <ConnectErrorEventArgs>(CrmLoginCtrl_ConnectErrorEvent); // This wires an event that is raised when a status event is returned. CrmLoginCtrl.ConnectionStatusEvent += new EventHandler <ConnectStatusEventArgs>(CrmLoginCtrl_ConnectionStatusEvent); // This wires an event that is raised when the user clicks the cancel button. CrmLoginCtrl.UserCancelClicked += new EventHandler(CrmLoginCtrl_UserCancelClicked); // This prompts the user to automatically sign in using the cached credentials // when signing for the second time or later. if (!mgr.RequireUserLogin()) { if (MessageBox.Show("Credentials already saved in configuration.\nClick Yes to sign in using saved credentials.\nClick No to reset credentials to sign in.", "Auto Sign-In", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { // If RequireUserLogin is false, it means that there has been a successful login here before and the credentials are cached. CrmLoginCtrl.IsEnabled = false; // When running an auto login, you need to wire and listen to the events from the connection manager. // Run Auto User Login process, Wire events. mgr.ServerConnectionStatusUpdate += new EventHandler <ServerConnectStatusEventArgs>(mgr_ServerConnectionStatusUpdate); mgr.ConnectionCheckComplete += new EventHandler <ServerConnectStatusEventArgs>(mgr_ConnectionCheckComplete); // Start the connection process. mgr.ConnectToServerCheck(); // Show the message grid. CrmLoginCtrl.ShowMessageGrid(); } } }