コード例 #1
0
ファイル: Step1.cs プロジェクト: dmn58/ADImport
        /// <summary>
        /// Check if current step is valid.
        /// </summary>
        public override Task <bool> IsValid()
        {
            bool validationResult = radNewImportProfile.Checked;

            string permissionsCheckResult = ADProvider.CheckPermissions();

            if (!string.IsNullOrEmpty(permissionsCheckResult))
            {
                SetError(permissionsCheckResult);
                validationResult = false;
            }
            else
            {
                if (radExistingImportProfile.Checked)
                {
                    if (!string.IsNullOrEmpty(txtImportProfile.Text))
                    {
                        // Verify that file exists
                        if (!File.Exists(txtImportProfile.Text))
                        {
                            SetError("Error_FileNotFound");
                            validationResult = false;
                        }
                        else
                        {
                            validationResult = true;
                        }
                    }
                    else
                    {
                        SetError("Error_SelectPath");
                        validationResult = false;
                    }
                    // Setup import profile
                    if (validationResult)
                    {
                        string validationError = ImportProfile.InitializeImportProfile(txtImportProfile.Text);
                        if (!String.IsNullOrEmpty(validationError))
                        {
                            SetError(ResHelper.GetString("Error_ProfileIsNotValid") + Environment.NewLine + validationError);
                            validationResult = false;
                        }
                        else
                        {
                            lblMessage.Visible = false;
                        }
                    }
                }
                else
                {
                    lblMessage.Visible = false;
                }
            }

            return(Task.FromResult(validationResult));
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            string profileName = string.Empty;

            // Create new instance of AD provider
            ImportProfile.OnDirectoryControllerChanged += () => PrincipalProvider.ClearContext();

            // If there are some arguments specified
            if (args.Length != 0)
            {
                // Try to attach console
                if (!AttachConsole(-1))
                {
                    // Create new console
                    AllocConsole();
                }

                // For each argument
                for (int i = 0; i < args.Length; i++)
                {
                    string arg = args[i];

                    // If argument specifies profile
                    if ((arg == "/profile") || (arg == "-profile"))
                    {
                        // Get profile name
                        if ((i + 1) < args.Length)
                        {
                            if (profileName == string.Empty)
                            {
                                profileName = args[i + 1].Trim();
                            }
                        }
                    }
                    if ((arg == "/h") || (arg == "-h") || (arg == "--help") || (arg == "-?") || (arg == "/?"))
                    {
                        // Write help
                        Console.Write(ResHelper.GetString("Console_Help").Replace("\\n", "\n").Replace("\\r", "\r"));
                        return;
                    }
                }

                // If there was profile specified
                if (profileName != string.Empty)
                {
                    // If there is no such file
                    if (!File.Exists(profileName))
                    {
                        Console.WriteLine(ResHelper.GetString("Error_ProfileDoesNotExist", profileName));
                    }
                    else
                    {
                        // Try to get file info
                        FileInfo fi = FileInfo.New(profileName);

                        Console.WriteLine(ResHelper.GetString("Console_SelectedImportProfile", fi.FullName));

                        // Initialize import profile
                        string validationError = ImportProfile.InitializeImportProfile(profileName);
                        if (!String.IsNullOrEmpty(validationError))
                        {
                            Console.WriteLine(ResHelper.GetString("Error_ProfileIsNotValid"));
                            Console.WriteLine(validationError);
                        }
                        else
                        {
                            // Application is in console mode
                            ImportProfile.UsesConsole = true;

                            // Check permissions
                            string permissionsCheckResult = PrincipalProvider.CheckPermissions();
                            if (!string.IsNullOrEmpty(permissionsCheckResult))
                            {
                                Console.WriteLine(permissionsCheckResult);
                            }
                            else
                            {
                                // Initialize principal provider
                                bool providerInitialized = ValidatePrincipalProvider(PrincipalProvider);
                                bool databaseValid       = ValidateDatabase();

                                if (providerInitialized && databaseValid)
                                {
                                    // Initialize CMS connection
                                    CMSImport.ConfigureApplicationSettings();

                                    // Perform CMS import
                                    CMSImport.Import(PrincipalProvider, MessageLog);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Write message
                    Console.WriteLine(ResHelper.GetString("Console_SpecifyProfile"));
                }
            }
            // Launch windows form application
            else
            {
                // Preinitialize CMS context
                CMSApplication.PreInit();

                // Initialize application
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ADWizard(PrincipalProvider));
            }
        }