Example #1
0
        private void QueryWuAuServiceStatus(object obj)
        {
            char[] separator = new char[1] {
                ';'
            };
            ASyncClientParameters parameters = (ASyncClientParameters)obj;

            try
            {
                int      index    = parameters.RowIndex;
                string   login    = parameters.Login;
                string   password = parameters.Password;
                object[] args     = new object[3];

                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Properties.Settings.Default.Language);
                ADComputer computer = (ADComputer)dtGrdVResult.Rows[index].Cells["ComputerName"].Value;
                args[0] = resMan.GetString("FailedToConnect");
                args[1] = index;
                args[2] = "ServiceStatus";

                if (!_closing && !_aborting && !chkBxDontPing.Checked && !computer.Ping((int)nupPingTimeout.Value))
                {
                    args[0] = resMan.GetString("Unreachable");
                }
                else
                {
                    if (!_closing && !_aborting)
                    {
                        lock (_QueryWuAuSrvStatusLocker)
                        {
                            string result = string.Empty;
                            try
                            {
                                if (!_closing && !_aborting && !_wrongCrendentialsWatcher.IsAbortRequested)
                                {
                                    result = computer.QueryWuAuSrvStatus(login, password);
                                    if (result.IndexOf(';') != -1)
                                    {
                                        string[] tab = result.Split(separator);
                                        if (tab != null && tab.Length == 2)
                                        {
                                            result = resMan.GetString(tab[0]) + " " + tab[1];
                                        }
                                    }
                                    args[0] = result;
                                }
                                else
                                {
                                    args[0] = resMan.GetString("Aborted");
                                }
                            }
                            catch (UnauthorizedAccessException)
                            {
                                _wrongCrendentialsWatcher.IsWrongCredentials = true;

                                if (!_wrongCrendentialsWatcher.ContinueWithFailedCredentials)
                                {
                                    if (MessageBox.Show(resMan.GetString("CredentialFailed"), resMan.GetString("FailedToConnect"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                                    {
                                        Logger.Write("interrupt on failed credentials.");
                                        _wrongCrendentialsWatcher.IsAbortRequested = true;
                                        args[0] = resMan.GetString("Aborted");
                                    }
                                    else
                                    {
                                        Logger.Write("Continue with bad credentials.");
                                        _wrongCrendentialsWatcher.ContinueWithFailedCredentials = true;
                                        args[0] = resMan.GetString("FailedToConnect");
                                    }
                                }
                                else
                                {
                                    args[0] = resMan.GetString("FailedToConnect");
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.Write(ex.Message);
                                args[0] = resMan.GetString("FailedToSendCommand");
                            }
                        }
                    }
                    else
                    {
                        args[0] = resMan.GetString("Aborted");
                    }
                }
                UpdateRow(args);
            }
            catch (Exception) { }
            finally { parameters.CountEvent.Signal(); }
        }