public void Execute(object parameter)
            {
                viewModel.CanExecute = false;
                var serverString = ServerPortSpecify(viewModel.Server, viewModel.IsTls);

                try
                {
                    LdapPasswordChanger.ChangePassword(viewModel.DistinguishedName, viewModel.OldPassword, viewModel.NewPassword, serverString, viewModel.IsTls);

                    viewModel.Message      = "Completed successfully.\nYour password has been changed.";
                    viewModel.MessageColor = Brushes.DodgerBlue;
                }
                catch (Exception e)
                {
                    if (e is LdapException ldapException)
                    {
                        viewModel.Message = "(" + ldapException.GetType().Name + ":" + ldapException.ErrorCode + ")\n"
                                            + ldapException.Message;
                        if (!String.IsNullOrEmpty(ldapException.ServerErrorMessage))
                        {
                            viewModel.Message += "\n" + ldapException.ServerErrorMessage;
                        }
                    }
                    else
                    {
                        viewModel.Message = "(" + e.GetType().Name + ")\n" + e.Message;
                    }
                    viewModel.MessageColor = Brushes.Red;
                    viewModel.CanExecute   = true;
                }
            }
예제 #2
0
        static void Main(string[] args)
        {
            // コマンドの .exe が置かれたフォルダーのフルパスを取得
            var fullPath = Directory.GetParent(Process.GetCurrentProcess().MainModule.FileName);

            IDictionary <string, string[]> configOptions = new Dictionary <string, string[]>();

            // 設定ファイルの読み込み
            try
            {
                configOptions = LoadConfig(fullPath + "\\" + CONFIG_FILE_NAME);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("コンフィグの書式が間違っています。");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine("--------");
                Console.Error.WriteLine(e);
                Console.Write(PRESS_ENTER_KEY_MESSAGE);
                Console.ReadLine();
                Environment.Exit(-1);
            }

            IDictionary <string, IList <string> > options = null;

            try
            {
                // パース処理。
                options = ParseArgs(args, configOptions);
            }
            catch (Exception e)
            {
                // e のメッセージにはコマンドのヘルプが格納されている。
                Console.Error.WriteLine(e.Message);
                Console.Write(PRESS_ENTER_KEY_MESSAGE);
                Console.ReadLine();
                Environment.Exit(-1);
            }

            // SSL/TLS を利用するか否か
            var isTls = false;

            if (options.ContainsKey("tls"))
            {
                if (options["tls"].Count < 1 || options["tls"][0] != "off")
                {
                    isTls = true;
                }
            }
            Console.WriteLine("tls: " + isTls + ", ");

            // サーバー ポートの明示
            options["server"][0] = ServerPortSpecify(options["server"][0], isTls);

            // オプションの表示
            foreach (KeyValuePair <string, IList <string> > option in options)
            {
                var optionName = option.Key;
                if (optionName != "tls")
                {
                    Console.Write(optionName + ": ");
                    foreach (string value in option.Value)
                    {
                        Console.Write(value + ", ");
                    }
                    Console.WriteLine();
                }
            }

            // ユーザー名の手動入力 (オプションで未指定の時)
            InputValue("dn", ref options);

            // パスワードの手動入力 (オプションで未指定の時)
            InputValue("oldpassword", ref options);

            // パスワードの手動入力 (オプションで未指定の時)
            InputValue("newpassword", ref options);

            try
            {
                // 実処理のメソッド呼び出し
                LdapPasswordChanger.ChangePassword(options["dn"][0], options["oldpassword"][0], options["newpassword"][0], options["server"][0], isTls);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.Write(PRESS_ENTER_KEY_MESSAGE);
                Console.ReadLine();
                Environment.Exit(-1);
            }

            // 実行後の待機
            Console.Write(PRESS_ENTER_KEY_MESSAGE);
            Console.ReadLine();
        }