コード例 #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
コード例 #2
0
        public void Dispose()
        {
            if (_disposing)
            {
                throw new ObjectDisposedException(nameof(ADCachedPrincipal));
            }

            _disposing = true;
            Principal.Dispose();
        }
コード例 #3
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            //Create a shortcut to the appropriate Windows domain
            PrincipalContext domainContext = new PrincipalContext(ContextType.Domain,
                                                                  addomain);

            //Create a "user object" in the context
            UserPrincipal user = new UserPrincipal(domainContext);

            //Specify the search parameters
            bool fHasSpace = adtext.Contains(" ");

            if (fHasSpace)
            {
                string[] ssize = adtext.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                string   first = ssize[0];
                string   last  = ssize[1];
                user.GivenName = first;
                user.Surname   = last;
            }
            else
            {
                user.SamAccountName = adtext;
            }

            //Create the searcher
            //pass (our) user object
            PrincipalSearcher pS = new PrincipalSearcher();

            pS.QueryFilter = user;

            //Perform the search
            PrincipalSearchResult <Principal> results = pS.FindAll();

            //If necessary, request more details


            //Output first result of the test
            try
            {
                Principal      pc = results.ToList()[0];
                DirectoryEntry de = (DirectoryEntry)pc.GetUnderlyingObject();
                //Gets SamAcctName
                string sam = pc.SamAccountName.ToString();
                //Finds account using sam
                UserPrincipal usr = UserPrincipal.FindByIdentity(domainContext, sam);
                //Test to see if account is locked, if it is unlocks account
                string password = this.textBoxPass.Text;

                if (usr.IsAccountLockedOut())
                {
                    usr.UnlockAccount();
                    usr.SetPassword(password);
                    pc.Dispose();
                    //ResetPass.ActiveForm.Close();
                    long     filetime = TheAdminToolBox.ConvertADSLargeIntegerToInt64(de.Properties["pwdLastSet"].Value);
                    DateTime pwdSet   = DateTime.FromFileTime(filetime);
                    System.Windows.Forms.MessageBox.Show("Account is now unlocked" + "\r\nPassword has been changed.", "Password set", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    usr.SetPassword(password);
                    de.CommitChanges();
                    long     filetime = TheAdminToolBox.ConvertADSLargeIntegerToInt64(de.Properties["pwdLastSet"].Value);
                    DateTime pwdSet   = DateTime.FromFileTime(filetime);
                    System.Windows.Forms.MessageBox.Show("Password has been changed.", "Password set", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    de.Close();
                    pc.Dispose();
                    this.Close();
                }

                pS.Dispose();
            }
            catch (SystemException err)
            {
                System.Windows.Forms.MessageBox.Show(err.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                                     MessageBoxDefaultButton.Button1,
                                                     MessageBoxOptions.DefaultDesktopOnly);
                this.Close();
            }
        }
コード例 #4
0
        static void Main()
        {
            bool TestPass = false;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                //test conexion
                System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
                con.ConnectionString = ConfiguracionDataAccess.GetInstance().CadenaConexion;
                con.Open();
                con.Close();
                TestPass = true;
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Error de Conexion, proporciona este error a soporte tecnico: \n\n" + ex.Message, "Mensaje del Sistem");
            }
            if (TestPass)
            {
                try
                {
                    CargadorArchivos cargador = new CargadorArchivos();
                    // Creamos el subproceso
                    Thread hiloAuxiliar = new Thread(new ThreadStart(cargador.cargar));
                    // Ejecutamos el subproceso
                    hiloAuxiliar.Start();
                    // Esperamos a que se carguen los archivos mientras ejecuta el splash
                    while (!hiloAuxiliar.IsAlive)
                    {
                        ;
                    }
                    PantallaDeCarga formCarga = new PantallaDeCarga(2, hiloAuxiliar);
                    // -------  Cargamos y mostramos el formulario Splash durante 2 minimo  -----
                    // Mostramos el formulario de forma modal.
                    formCarga.ShowDialog();
                    formCarga.Dispose();

                    LogicControlSistema enlaceControlSistema = new LogicControlSistema();
                    do
                    {
                        FormInicioSesion form = new FormInicioSesion();
                        form.ShowDialog();
                        form.Dispose();
                        if (enlaceControlSistema.EsLoggeado())
                        {
                            Principal formPrincipal = new Principal();
                            Application.Run(formPrincipal);
                            if (!formPrincipal.Visible)
                            {
                                formPrincipal.Dispose();
                            }
                            enlaceControlSistema.CerrarSesion();
                        }
                        else
                        {
                            isRunning = false;
                        }
                    } while (isRunning);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    isRunning = false;
                }
            }

            //Application.Run(new Test());
        }