-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSettings.cs
More file actions
91 lines (80 loc) · 3.43 KB
/
Settings.cs
File metadata and controls
91 lines (80 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Xml;
using McTools.Xrm.Connection;
namespace DataImport
{
public sealed class Settings
{
private static volatile Settings instance;
private static object syncRoot = new Object();
private Settings() { }
public static Settings Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new Settings();
}
}
return instance;
}
private set
{
instance = value;
}
}
public string Entity { get; set; } // The entity that is being loaded to
public string CrmAction { get; set; } // The action being run
public string OptionSetValuesOrLabel { get; set; } // Whether option sets are values or labels
public string LookupFoundMultipleRecords { get; set; } // What to do if multiple records are found in a lookup
public string KeyFoundMultipleRecords { get; set; } // What to do if multiple records are found for the updated or deleted record
public bool CompleteRecordsPostAction { get; set; } // Allows support for completing records as part of record creation
public SerializableDataTable XMLTableMapping { get; set; } // An XML serializable version of the mapping table between the source and the destination
public void LoadSettingsFromXML(string filePath)
{
// Load settings from file
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(filePath);
Settings tempSettings = (Settings)XmlSerializerHelper.Deserialize(xmlDocument.OuterXml, typeof(Settings));
Instance.Entity = tempSettings.Entity;
Instance.CrmAction = tempSettings.CrmAction;
Instance.OptionSetValuesOrLabel = tempSettings.OptionSetValuesOrLabel;
Instance.LookupFoundMultipleRecords = tempSettings.LookupFoundMultipleRecords;
Instance.KeyFoundMultipleRecords = tempSettings.KeyFoundMultipleRecords;
Instance.CompleteRecordsPostAction = tempSettings.CompleteRecordsPostAction;
Instance.XMLTableMapping = tempSettings.XMLTableMapping;
}
catch (Exception innerException)
{
throw new Exception("Error attempting to process setting file \"" + filePath + "\"", innerException);
}
}
public void SaveSettingsToXML(string filePath)
{
try
{
// Save settings to an XML file
XmlSerializerHelper.SerializeToFile(Instance, filePath);
}
catch (Exception innerException)
{
throw new Exception("Error attempting to save file to \"" + filePath + "\"", innerException);
}
}
public void Reset()
{
Entity = null;
CrmAction = null;
OptionSetValuesOrLabel = null;
LookupFoundMultipleRecords = null;
KeyFoundMultipleRecords = null;
CompleteRecordsPostAction = false;
}
}
}