Example #1
0
        private async void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                string computername    = NativeMethods.GetHostName().ToLower();
                string computerfqdn    = NativeMethods.GetFQDN().ToLower();
                string windowsusername = NativeMethods.GetProcessUserName(System.Diagnostics.Process.GetCurrentProcess().Id).ToLower();

                var servers = await global.webSocketClient.Query <RDService.unattendedserver>("openrpa", "{'_type':'unattendedserver', 'computername':'" + computername + "', 'computerfqdn':'" + computerfqdn + "'}");

                server = servers.FirstOrDefault();
                if (server == null)
                {
                    Log.Error("Server not found in OpenFlow, does current user have access to object " + computername + "?");
                }

                var clients = await global.webSocketClient.Query <RDService.unattendedclient>("openrpa", "{'_type':'unattendedclient', 'computername':'" + computername + "', 'computerfqdn':'" + computerfqdn + "', 'windowsusername':'******'}");

                AddcurrentuserButton.Content = "Add current user";
                if (clients.Length == 1)
                {
                    client = clients.First();
                    AddcurrentuserButton.Content = "Update current user";
                    chkautosignout.IsChecked     = client.autosignout;
                    lblWindowsLogin.Text         = client.windowslogin;
                }
                txtreloadinterval.Text            = RDService.PluginConfig.reloadinterval.ToString();
                chkUseFreeRDP.IsChecked           = RDService.PluginConfig.usefreerdp;
                AddcurrentuserButton.IsEnabled    = false;
                RemovecurrentuserButton.IsEnabled = false;
                ReauthenticateButton.IsEnabled    = false;
                StartServiceButton.IsEnabled      = false;
                StopServiceButton.IsEnabled       = false;
                InstallServiceButton.IsEnabled    = true;
                UninstallServiceButton.IsEnabled  = false;
                if (client != null)
                {
                    lblExecutable.Text = client.openrpapath;
                }
                if (Plugin.manager.IsServiceInstalled)
                {
                    AddcurrentuserButton.IsEnabled    = true;
                    RemovecurrentuserButton.IsEnabled = (client != null);
                    ReauthenticateButton.IsEnabled    = true;
                    StartServiceButton.IsEnabled      = (Plugin.manager.Status != System.ServiceProcess.ServiceControllerStatus.Running);
                    StopServiceButton.IsEnabled       = (Plugin.manager.Status == System.ServiceProcess.ServiceControllerStatus.Running);

                    InstallServiceButton.IsEnabled   = false;
                    UninstallServiceButton.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                Log.Information("UserControl_Loaded: " + ex.Message);
            }
        }
        private async void AddcurrentuserButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                DisableButtons();
                string computername    = NativeMethods.GetHostName().ToLower();
                string computerfqdn    = NativeMethods.GetFQDN().ToLower();
                string windowsusername = NativeMethods.GetProcessUserName(System.Diagnostics.Process.GetCurrentProcess().Id).ToLower();
                var    asm             = System.Reflection.Assembly.GetEntryAssembly();
                var    path            = asm.CodeBase.Replace("file:///", "");
                if (client == null)
                {
                    client = new RDService.unattendedclient()
                    {
                        computername = computername, computerfqdn = computerfqdn, windowsusername = windowsusername, name = computername + " " + windowsusername, openrpapath = path
                    };
                    client.windowslogin = lblWindowsLogin.Text;
                    client._acl         = server._acl;
                    client = await global.webSocketClient.InsertOne("openrpa", 1, false, client);
                }
                lblExecutable.Text = client.openrpapath;
                if (!string.IsNullOrEmpty(windowspassword.Password))
                {
                    client.windowspassword = windowspassword.Password;
                }
                client.computername    = computername;
                client.computerfqdn    = computerfqdn;
                client.windowsusername = windowsusername;
                client.name            = computername + " " + windowsusername;
                client.openrpapath     = path;
                client.windowslogin    = lblWindowsLogin.Text;
                client = await global.webSocketClient.UpdateOne("openrpa", 1, false, client);

                windowspassword.Clear();
                plugin.ReloadConfig();
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                MessageBox.Show("AddcurrentuserButtonClick: " + ex.Message);
            }
            finally
            {
                UserControl_Loaded(null, null);
            }
        }
        private async void RemovecurrentuserClick(object sender, RoutedEventArgs e)
        {
            if (client == null)
            {
                return;
            }
            try
            {
                DisableButtons();
                await global.webSocketClient.DeleteOne("openrpa", client._id);

                client = null;
                plugin.ReloadConfig();
            }
            catch (Exception ex)
            {
                MessageBox.Show("AddcurrentuserButtonClick: " + ex.Message);
            }
            finally
            {
                UserControl_Loaded(null, null);
            }
        }