Skip to content

Commit

Permalink
Complexdemo set up (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksulikow authored Apr 9, 2019
1 parent 34f197e commit 37cba7b
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
<applicationSettings>
<Capgemini.Xrm.Datamigration.Examples.Properties.Settings>
<setting name="CrmExportConnectionString" serializeAs="String">
<value>Url = https://sourcerepo.dynamics.com; Username=xxxx; Password=xxxx; AuthType=Office365; RequireNewInstance=True;</value>
<value>Url = CRMUrl; Username=user; Password=password; AuthType=Office365; RequireNewInstance=True;</value>
</setting>
<setting name="CrmImportConnectionString" serializeAs="String">
<value>Url = https://targetrepo.crm4.dynamics.com; Username=xxx; Password=xxxx; AuthType=Office365; RequireNewInstance=True;</value>
<value>Url = CRMUrl; Username=user; Password=password; AuthType=Office365; RequireNewInstance=True;</value>
</setting>
<setting name="DemoScenarioName" serializeAs="String">
<value>Contacts</value>
</setting>
</Capgemini.Xrm.Datamigration.Examples.Properties.Settings>
</applicationSettings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<Content Include="ConfigExamples\Contacts\ContactsSchema.xml">
<None Include="DemoScenarios\Contacts\Schema.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</None>
<None Include="DemoScenarios\Contacts\ExportConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DemoScenarios\Contacts\ImportConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"CrmMigrationToolSchemaPaths": [
"C:\\GitRepos\\Capgemini\\xrm-datamigration\\Capgemini.Xrm.Datamigration\\Capgemini.Xrm.Datamigration.Examples\\bin\\Debug\\DemoScenarios\\Contacts\\Schema.xml"
],
"PageSize": 500,
"BatchSize": 1000,
"TopCount": 10000,
"OnlyActiveRecords": false,
"JsonFolderPath": "C:\\GitRepos\\Capgemini\\xrm-datamigration\\Capgemini.Xrm.Datamigration\\Capgemini.Xrm.Datamigration.Examples\\bin\\Debug\\DemoScenarios\\Contacts\\ExportedData",
"OneEntityPerBatch": true,
"FilePrefix": "DemoContacts",
"SeperateFilesPerEntity": true,
"LookupMapping": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"IgnoreStatuses": false,
"IgnoreSystemFields": false,
"SaveBatchSize": 50,
"JsonFolderPath": "C:\\GitRepos\\Capgemini\\xrm-datamigration\\Capgemini.Xrm.Datamigration\\Capgemini.Xrm.Datamigration.Examples\\bin\\Debug\\DemoScenarios\\Contacts\\ExportedData",
"DeactivateAllProcesses": false,
"FilePrefix": "DemoContacts",
"PassOneReferences": [
"businessunit",
"uom",
"uomschedule",
"queue"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,86 +20,137 @@ class Program
static void Main(string[] args)
{
ConsoleLogger.LogLevel = 5;

Console.WriteLine($"Using demo scenario {Settings.Default.DemoScenarioName}");
Console.WriteLine("Exporting data - press enter to export");
Console.ReadLine();
ExportData(Settings.Default.CrmExportConnectionString, GetConfigSchemaPath(), GetExportPath());

if (Directory.Exists(GetExportPath()))
{
Console.WriteLine($"Folder Exists {GetExportPath()} - press enter to delete and continue");
Console.ReadLine();
Directory.Delete(GetExportPath(), true);
}

Directory.CreateDirectory(GetExportPath());

ExportData(Settings.Default.CrmExportConnectionString, GetSchemaPath(), GetExportPath());

Console.WriteLine("Importing data - press enter to import");
Console.ReadLine();
ImportData(Settings.Default.CrmImportConnectionString, GetConfigSchemaPath(), GetExportPath());
ImportData(Settings.Default.CrmImportConnectionString, GetSchemaPath(), GetExportPath());

Console.WriteLine("Operations completed - press enter to exit");
Console.ReadLine();
}

static void ExportData(string connectionString, string schemaPath, string exportFolderPath)
{
if (!Directory.Exists(exportFolderPath))
Directory.CreateDirectory(exportFolderPath);

Console.WriteLine("Export Started");

var tokenSource = new CancellationTokenSource();
var serviceClient = new CrmServiceClient(connectionString);
var entityRepo = new EntityRepository(serviceClient, new ServiceRetryExecutor());
var logger = new ConsoleLogger();
var exportConfig = new CrmExporterConfig()
{
BatchSize = 1000,
PageSize = 500,
FilePrefix = "EX0.1",
JsonFolderPath = exportFolderPath,
OneEntityPerBatch = true,
SeperateFilesPerEntity = true,
TopCount = 10000,
CrmMigrationToolSchemaPaths = new List<string>() {schemaPath}
};

// Json Export
var fileExporterJson = new CrmFileDataExporter(logger, entityRepo, exportConfig, tokenSource.Token);
var fileExporterJson = new CrmFileDataExporter(logger, entityRepo, GetExportConfig(), tokenSource.Token);
fileExporterJson.MigrateData();

// Csv Export
var schema = CrmSchemaConfiguration.ReadFromFile(schemaPath);
var fileExporterCsv = new CrmFileDataExporterCsv(logger, entityRepo, exportConfig, tokenSource.Token, schema);
var fileExporterCsv = new CrmFileDataExporterCsv(logger, entityRepo, GetExportConfig(), tokenSource.Token, schema);
fileExporterCsv.MigrateData();

Console.WriteLine("Export Finished");
}

public static void ImportData(string connectionString, string schemaPath, string exportFolderPath)
{
Console.WriteLine("Import Started");

var tokenSource = new CancellationTokenSource();
var serviceClient = new CrmServiceClient(connectionString);
var entityRepo = new EntityRepository(serviceClient, new ServiceRetryExecutor());
var logger = new ConsoleLogger();

var importConfig = new CrmImportConfig()
{
FilePrefix = "EX0.1",
JsonFolderPath = exportFolderPath,
SaveBatchSize = 20
};

// Json Import
var fileImporterJson = new CrmFileDataImporter(logger, entityRepo, importConfig, tokenSource.Token);
var fileImporterJson = new CrmFileDataImporter(logger, entityRepo, GetImportConfig(), tokenSource.Token);
fileImporterJson.MigrateData();

//Csv Import
var schema = CrmSchemaConfiguration.ReadFromFile(schemaPath);
var fileImporterCsv = new CrmFileDataImporterCsv(logger, entityRepo, importConfig, schema, tokenSource.Token);
var fileImporterCsv = new CrmFileDataImporterCsv(logger, entityRepo, GetImportConfig(), schema, tokenSource.Token);
fileImporterCsv.MigrateData();

Console.WriteLine("Import Finished");
}

static string GetConfigSchemaPath()
#region Helpers

static CrmImportConfig GetImportConfig()
{
string folderPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
var schemaPath = Path.Combine(folderPath, "ConfigExamples", "Contacts", "ContactsSchema.xml");
var importConfig = new CrmImportConfig()
{
FilePrefix = $"Demo{Settings.Default.DemoScenarioName}",
SaveBatchSize = 50
};

var filePath = $"{GetScenarioPath()}\\ImportConfig.json";

if (!File.Exists(filePath))
importConfig.SaveConfiguration(filePath);
else
importConfig = CrmImportConfig.GetConfiguration(filePath);

importConfig.JsonFolderPath = GetExportPath();

return importConfig;
}

static CrmExporterConfig GetExportConfig()
{
var exportConfig = new CrmExporterConfig()
{
BatchSize = 1000,
PageSize = 500,
FilePrefix = $"Demo{Settings.Default.DemoScenarioName}",
OneEntityPerBatch = true,
SeperateFilesPerEntity = true,
TopCount = 10000
};

var filePath = $"{GetScenarioPath()}\\ExportConfig.json";

if (!File.Exists(filePath))
exportConfig.SaveConfiguration(filePath);
else
exportConfig = CrmExporterConfig.GetConfiguration(filePath);

exportConfig.JsonFolderPath = GetExportPath();
exportConfig.CrmMigrationToolSchemaPaths = new List<string>() { GetSchemaPath() };

return exportConfig;
}

static string GetSchemaPath()
{
var schemaPath = Path.Combine(GetScenarioPath(), "Schema.xml");
return schemaPath;
}

static string GetExportPath()
{
string folderPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
var exportFolderPath = Path.Combine(folderPath, "ConfigExamples", "Contacts", "ExportedData");
var exportFolderPath = Path.Combine(GetScenarioPath(), "ExportedData");
return exportFolderPath;
}

static string GetScenarioPath()
{
string folderPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
var scenarioPath = Path.Combine(folderPath, "DemoScenarios", Settings.Default.DemoScenarioName);
return scenarioPath;
}

#endregion
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
<Setting Name="CrmImportConnectionString" Type="System.String" Scope="Application">
<Value Profile="(Default)">Url = https://targetrepo.crm4.dynamics.com; Username=xxx; Password=xxxx; AuthType=Office365; RequireNewInstance=True;</Value>
</Setting>
<Setting Name="DemoScenarioName" Type="System.String" Scope="Application">
<Value Profile="(Default)">Contacts</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit 37cba7b

Please sign in to comment.