Browse Source

Импорт

master
commit
861aa7ed1f
  1. 63
      .gitattributes
  2. 231
      .gitignore
  3. 22
      LdapImport.sln
  4. 6
      LdapImport/App.config
  5. 75
      LdapImport/Connection.cs
  6. 322
      LdapImport/Form1.Designer.cs
  7. 73
      LdapImport/Form1.cs
  8. 132
      LdapImport/Form1.resx
  9. 95
      LdapImport/LdapImport.csproj
  10. 22
      LdapImport/Program.cs
  11. 36
      LdapImport/Properties/AssemblyInfo.cs
  12. 10
      LdapImport/Properties/DataSources/User.datasource
  13. 71
      LdapImport/Properties/Resources.Designer.cs
  14. 117
      LdapImport/Properties/Resources.resx
  15. 30
      LdapImport/Properties/Settings.Designer.cs
  16. 7
      LdapImport/Properties/Settings.settings
  17. 16
      LdapImport/User.cs
  18. 0
      README.md

63
.gitattributes vendored

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

231
.gitignore vendored

@ -0,0 +1,231 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Azure Emulator
ecf/
rcf/
# Windows Store app package directory
AppPackages/
BundleArtifacts/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
#*.mdf
#*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
# FAKE - F# Make
.fake/

22
LdapImport.sln

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LdapImport", "LdapImport\LdapImport.csproj", "{3D341CFC-6B19-4980-B936-9CC7C48708D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3D341CFC-6B19-4980-B936-9CC7C48708D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D341CFC-6B19-4980-B936-9CC7C48708D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D341CFC-6B19-4980-B936-9CC7C48708D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D341CFC-6B19-4980-B936-9CC7C48708D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

6
LdapImport/App.config

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

75
LdapImport/Connection.cs

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LdapImport
{
internal class Connection
{
private string domain;
private string user;
private string password;
internal Connection(string domain, string user, string password)
{
this.domain = domain;
this.user = user;
this.password = password;
}
internal bool Test()
{
string userPrincipalName = $"{user}@{domain}";
try
{
using (var context = new PrincipalContext(ContextType.Domain, domain))
{
return context.ValidateCredentials(userPrincipalName, password);
}
}
catch
{
return false;
}
}
internal List<User> SearchUsers(string groupName, bool searchLocked)
{
var list = new List<User>();
using (var context = new PrincipalContext(ContextType.Domain, domain, user, password))
{
var group = GroupPrincipal.FindByIdentity(context, groupName);
if (group != null)
{
foreach (Principal p in group.GetMembers())
{
var theUser = p as UserPrincipal;
if (theUser != null)
{
if (theUser.Enabled.Value || (!theUser.Enabled.Value && searchLocked))
{
var u = new User();
u.SamAccountName = theUser.SamAccountName;
u.FirstName = theUser.GivenName;
u.LastName = theUser.Surname;
list.Add(u);
}
}
}
}
}
return list;
}
}
}

322
LdapImport/Form1.Designer.cs generated

@ -0,0 +1,322 @@
namespace LdapImport
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox_connection = new System.Windows.Forms.GroupBox();
this.textBox_domain = new System.Windows.Forms.TextBox();
this.label_domain = new System.Windows.Forms.Label();
this.label_user = new System.Windows.Forms.Label();
this.label_password = new System.Windows.Forms.Label();
this.textBox_user = new System.Windows.Forms.TextBox();
this.textBox_password = new System.Windows.Forms.TextBox();
this.button_test = new System.Windows.Forms.Button();
this.groupBox_searchSettings = new System.Windows.Forms.GroupBox();
this.label_group = new System.Windows.Forms.Label();
this.textBox_group = new System.Windows.Forms.TextBox();
this.groupBox_results = new System.Windows.Forms.GroupBox();
this.button_search = new System.Windows.Forms.Button();
this.button_import = new System.Windows.Forms.Button();
this.dataGridView_results = new System.Windows.Forms.DataGridView();
this.checkBox_locked = new System.Windows.Forms.CheckBox();
this.userBindingSource2 = new System.Windows.Forms.BindingSource();
this.userBindingSource = new System.Windows.Forms.BindingSource();
this.userBindingSource1 = new System.Windows.Forms.BindingSource();
this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.samAccountNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.firstNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.lastNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupBox_connection.SuspendLayout();
this.groupBox_searchSettings.SuspendLayout();
this.groupBox_results.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView_results)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.userBindingSource2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.userBindingSource)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.userBindingSource1)).BeginInit();
this.SuspendLayout();
//
// groupBox_connection
//
this.groupBox_connection.Controls.Add(this.button_test);
this.groupBox_connection.Controls.Add(this.textBox_password);
this.groupBox_connection.Controls.Add(this.textBox_user);
this.groupBox_connection.Controls.Add(this.label_password);
this.groupBox_connection.Controls.Add(this.label_user);
this.groupBox_connection.Controls.Add(this.label_domain);
this.groupBox_connection.Controls.Add(this.textBox_domain);
this.groupBox_connection.Location = new System.Drawing.Point(12, 12);
this.groupBox_connection.Name = "groupBox_connection";
this.groupBox_connection.Size = new System.Drawing.Size(283, 146);
this.groupBox_connection.TabIndex = 0;
this.groupBox_connection.TabStop = false;
this.groupBox_connection.Text = "Соединение";
//
// textBox_domain
//
this.textBox_domain.Location = new System.Drawing.Point(101, 23);
this.textBox_domain.Name = "textBox_domain";
this.textBox_domain.Size = new System.Drawing.Size(163, 20);
this.textBox_domain.TabIndex = 0;
//
// label_domain
//
this.label_domain.AutoSize = true;
this.label_domain.Location = new System.Drawing.Point(15, 26);
this.label_domain.Name = "label_domain";
this.label_domain.Size = new System.Drawing.Size(42, 13);
this.label_domain.TabIndex = 1;
this.label_domain.Text = "Домен";
//
// label_user
//
this.label_user.AutoSize = true;
this.label_user.Location = new System.Drawing.Point(15, 52);
this.label_user.Name = "label_user";
this.label_user.Size = new System.Drawing.Size(80, 13);
this.label_user.TabIndex = 2;
this.label_user.Text = "Пользователь";
//
// label_password
//
this.label_password.AutoSize = true;
this.label_password.Location = new System.Drawing.Point(15, 78);
this.label_password.Name = "label_password";
this.label_password.Size = new System.Drawing.Size(45, 13);
this.label_password.TabIndex = 3;
this.label_password.Text = "Пароль";
//
// textBox_user
//
this.textBox_user.Location = new System.Drawing.Point(101, 49);
this.textBox_user.Name = "textBox_user";
this.textBox_user.Size = new System.Drawing.Size(163, 20);
this.textBox_user.TabIndex = 1;
//
// textBox_password
//
this.textBox_password.Location = new System.Drawing.Point(101, 75);
this.textBox_password.Name = "textBox_password";
this.textBox_password.PasswordChar = '*';
this.textBox_password.Size = new System.Drawing.Size(163, 20);
this.textBox_password.TabIndex = 2;
//
// button_test
//
this.button_test.Location = new System.Drawing.Point(101, 101);
this.button_test.Name = "button_test";
this.button_test.Size = new System.Drawing.Size(100, 23);
this.button_test.TabIndex = 3;
this.button_test.Text = "Тест";
this.button_test.UseVisualStyleBackColor = true;
this.button_test.Click += new System.EventHandler(this.button_test_Click);
//
// groupBox_searchSettings
//
this.groupBox_searchSettings.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox_searchSettings.Controls.Add(this.checkBox_locked);
this.groupBox_searchSettings.Controls.Add(this.label_group);
this.groupBox_searchSettings.Controls.Add(this.textBox_group);
this.groupBox_searchSettings.Location = new System.Drawing.Point(301, 12);
this.groupBox_searchSettings.Name = "groupBox_searchSettings";
this.groupBox_searchSettings.Size = new System.Drawing.Size(280, 146);
this.groupBox_searchSettings.TabIndex = 7;
this.groupBox_searchSettings.TabStop = false;
this.groupBox_searchSettings.Text = "Настройки поиска";
//
// label_group
//
this.label_group.AutoSize = true;
this.label_group.Location = new System.Drawing.Point(18, 26);
this.label_group.Name = "label_group";
this.label_group.Size = new System.Drawing.Size(42, 13);
this.label_group.TabIndex = 1;
this.label_group.Text = "Группа";
//
// textBox_group
//
this.textBox_group.Location = new System.Drawing.Point(104, 23);
this.textBox_group.Name = "textBox_group";
this.textBox_group.Size = new System.Drawing.Size(163, 20);
this.textBox_group.TabIndex = 4;
//
// groupBox_results
//
this.groupBox_results.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox_results.Controls.Add(this.dataGridView_results);
this.groupBox_results.Location = new System.Drawing.Point(12, 164);
this.groupBox_results.Name = "groupBox_results";
this.groupBox_results.Size = new System.Drawing.Size(569, 312);
this.groupBox_results.TabIndex = 7;
this.groupBox_results.TabStop = false;
this.groupBox_results.Text = "Найдено";
//
// button_search
//
this.button_search.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button_search.Location = new System.Drawing.Point(12, 482);
this.button_search.Name = "button_search";
this.button_search.Size = new System.Drawing.Size(100, 23);
this.button_search.TabIndex = 6;
this.button_search.Text = "Найти";
this.button_search.UseVisualStyleBackColor = true;
this.button_search.Click += new System.EventHandler(this.button_search_Click);
//
// button_import
//
this.button_import.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button_import.Location = new System.Drawing.Point(118, 482);
this.button_import.Name = "button_import";
this.button_import.Size = new System.Drawing.Size(100, 23);
this.button_import.TabIndex = 7;
this.button_import.Text = "Импортировать";
this.button_import.UseVisualStyleBackColor = true;
this.button_import.Click += new System.EventHandler(this.button_import_Click);
//
// dataGridView_results
//
this.dataGridView_results.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView_results.AutoGenerateColumns = false;
this.dataGridView_results.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView_results.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.samAccountNameDataGridViewTextBoxColumn,
this.firstNameDataGridViewTextBoxColumn,
this.lastNameDataGridViewTextBoxColumn});
this.dataGridView_results.DataSource = this.userBindingSource2;
this.dataGridView_results.Location = new System.Drawing.Point(18, 29);
this.dataGridView_results.Name = "dataGridView_results";
this.dataGridView_results.Size = new System.Drawing.Size(538, 268);
this.dataGridView_results.TabIndex = 8;
//
// checkBox_locked
//
this.checkBox_locked.AutoSize = true;
this.checkBox_locked.Location = new System.Drawing.Point(104, 52);
this.checkBox_locked.Name = "checkBox_locked";
this.checkBox_locked.Size = new System.Drawing.Size(119, 17);
this.checkBox_locked.TabIndex = 5;
this.checkBox_locked.Text = "Заблокированные";
this.checkBox_locked.UseVisualStyleBackColor = true;
//
// userBindingSource2
//
this.userBindingSource2.DataSource = typeof(LdapImport.User);
//
// userBindingSource
//
this.userBindingSource.DataSource = typeof(LdapImport.User);
//
// userBindingSource1
//
this.userBindingSource1.DataSource = typeof(LdapImport.User);
//
// Column1
//
this.Column1.DataPropertyName = "Import";
this.Column1.HeaderText = "Импортировать";
this.Column1.Name = "Column1";
//
// samAccountNameDataGridViewTextBoxColumn
//
this.samAccountNameDataGridViewTextBoxColumn.DataPropertyName = "SamAccountName";
this.samAccountNameDataGridViewTextBoxColumn.HeaderText = "SamAccountName";
this.samAccountNameDataGridViewTextBoxColumn.Name = "samAccountNameDataGridViewTextBoxColumn";
this.samAccountNameDataGridViewTextBoxColumn.ReadOnly = true;
//
// firstNameDataGridViewTextBoxColumn
//
this.firstNameDataGridViewTextBoxColumn.DataPropertyName = "FirstName";
this.firstNameDataGridViewTextBoxColumn.HeaderText = "Имя";
this.firstNameDataGridViewTextBoxColumn.Name = "firstNameDataGridViewTextBoxColumn";
this.firstNameDataGridViewTextBoxColumn.ReadOnly = true;
//
// lastNameDataGridViewTextBoxColumn
//
this.lastNameDataGridViewTextBoxColumn.DataPropertyName = "LastName";
this.lastNameDataGridViewTextBoxColumn.HeaderText = "Фамилия";
this.lastNameDataGridViewTextBoxColumn.Name = "lastNameDataGridViewTextBoxColumn";
this.lastNameDataGridViewTextBoxColumn.ReadOnly = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(593, 543);
this.Controls.Add(this.button_import);
this.Controls.Add(this.button_search);
this.Controls.Add(this.groupBox_results);
this.Controls.Add(this.groupBox_searchSettings);
this.Controls.Add(this.groupBox_connection);
this.Name = "Form1";
this.Text = "Импорт из LDAP";
this.groupBox_connection.ResumeLayout(false);
this.groupBox_connection.PerformLayout();
this.groupBox_searchSettings.ResumeLayout(false);
this.groupBox_searchSettings.PerformLayout();
this.groupBox_results.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView_results)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.userBindingSource2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.userBindingSource)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.userBindingSource1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox_connection;
private System.Windows.Forms.Button button_test;
private System.Windows.Forms.TextBox textBox_password;
private System.Windows.Forms.TextBox textBox_user;
private System.Windows.Forms.Label label_password;
private System.Windows.Forms.Label label_user;
private System.Windows.Forms.Label label_domain;
private System.Windows.Forms.TextBox textBox_domain;
private System.Windows.Forms.GroupBox groupBox_searchSettings;
private System.Windows.Forms.Label label_group;
private System.Windows.Forms.TextBox textBox_group;
private System.Windows.Forms.GroupBox groupBox_results;
private System.Windows.Forms.DataGridView dataGridView_results;
private System.Windows.Forms.Button button_search;
private System.Windows.Forms.Button button_import;
private System.Windows.Forms.BindingSource userBindingSource;
private System.Windows.Forms.BindingSource userBindingSource1;
private System.Windows.Forms.BindingSource userBindingSource2;
private System.Windows.Forms.CheckBox checkBox_locked;
private System.Windows.Forms.DataGridViewCheckBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn samAccountNameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn firstNameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn lastNameDataGridViewTextBoxColumn;
}
}

73
LdapImport/Form1.cs

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LdapImport
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox_user.Text = Environment.UserName;
textBox_domain.Text = Environment.UserDomainName;
}
private void button_test_Click(object sender, EventArgs e)
{
var conn = new Connection(textBox_domain.Text, textBox_user.Text, textBox_password.Text);
if (conn.Test())
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Error");
}
}
private void button_search_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(textBox_group.Text))
{
var conn = new Connection(textBox_domain.Text, textBox_user.Text, textBox_password.Text);
if (conn.Test())
{
var search = conn.SearchUsers(textBox_group.Text, checkBox_locked.Checked);
dataGridView_results.DataSource = search;
groupBox_results.Text = $"Найдено ({search.Count})";
}
else
{
MessageBox.Show("Error");
}
}
else
{
MessageBox.Show("Введите группу");
}
}
private void button_import_Click(object sender, EventArgs e)
{
var ds = dataGridView_results.DataSource as List<User>;
if (ds != null)
{
// ds.ForEach( import... );
}
else
{
MessageBox.Show("Нечего импортировать");
}
}
}
}

132
LdapImport/Form1.resx

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="userBindingSource2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>330, 17</value>
</metadata>
<metadata name="userBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="userBindingSource1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>170, 17</value>
</metadata>
</root>

95
LdapImport/LdapImport.csproj

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3D341CFC-6B19-4980-B936-9CC7C48708D3}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LdapImport</RootNamespace>
<AssemblyName>LdapImport</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Connection.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="User.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\DataSources\User.datasource" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

22
LdapImport/Program.cs

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LdapImport
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

36
LdapImport/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LdapImport")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LdapImport")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3d341cfc-6b19-4980-b936-9cc7c48708d3")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

10
LdapImport/Properties/DataSources/User.datasource

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="User" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>LdapImport.User, LdapImport, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>

71
LdapImport/Properties/Resources.Designer.cs generated

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace LdapImport.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LdapImport.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

117
LdapImport/Properties/Resources.resx

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

30
LdapImport/Properties/Settings.Designer.cs generated

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace LdapImport.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

7
LdapImport/Properties/Settings.settings

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

16
LdapImport/User.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LdapImport
{
public class User
{
public bool Import { get; set; } = true;
public string SamAccountName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
Loading…
Cancel
Save