public void Configure(string jsonConfiguration)
        {
            JObject           jConfiguration = JObject.Parse(jsonConfiguration);
            JArray            jDepartments   = (JArray)jConfiguration["departments"];
            List <Department> departments    = new List <Department>();

            foreach (JObject jDep in jDepartments)
            {
                Department dep;
                JObject    jRule = (JObject)jDep["rule"];
                if (jRule.Count == 1)
                {
                    JObject jEvent = (JObject)jRule["event"];
                    dep = new Department(
                        (string)jDep["id"],
                        JsonConvert.DeserializeObject <RuleEvent>(jEvent.ToString())
                        );
                }
                else if (jRule.Count == 3)
                {
                    string  jconditionalStamp = (string)jRule["conditionalStamp"];
                    JObject jEvent1           = (JObject)jRule["event1"];
                    JObject jEvent2           = (JObject)jRule["event2"];
                    dep = new Department(
                        (string)jDep["id"],
                        jconditionalStamp,
                        JsonConvert.DeserializeObject <RuleEvent>(jEvent1.ToString()),
                        JsonConvert.DeserializeObject <RuleEvent>(jEvent2.ToString()));
                }
                else
                {
                    throw new InvalidOperationException();
                }
                departments.Add(dep);
            }

            string startDeparment = (string)jConfiguration["startDepartment"] ?? throw new ArgumentNullException();
            string endDepartment  = (string)jConfiguration["endDepartment"] ?? throw new ArgumentNullException();

            if (!departments.Any(dep => dep.Id.Equals(startDeparment)))
            {
                throw new ArgumentException($"There is no department with this ID: {startDeparment}");
            }
            if (!departments.Any(dep => dep.Id.Equals(endDepartment)))
            {
                throw new ArgumentException($"There is no department with this ID: {endDepartment}");
            }

            Configuration = new OrganizationConfiguration(startDeparment, endDepartment, departments);
        }
 public void Configure(OrganizationConfiguration configuration)
 {
     this.Configuration = configuration;
 }
 public Organization(OrganizationConfiguration configuration)
 {
     Configure(configuration);
 }
Exemple #4
0
 public BypassSheet(Department currentDepartment, OrganizationConfiguration configuration)
 {
     CurrentDepartment = currentDepartment;
     Configuration     = configuration;
 }