public BypassResult GetResult(string department)
 {
     try
     {
         var result = Execute(department);
         return(result);
     }
     catch (Exception ex)
     {
         BypassResult result = new BypassResult();
         result.Exception  = ex;
         result.Successful = false;
         return(result);
     }
 }
        private BypassResult Execute(string department)
        {
            bool ShouldContuinue(BypassSheet _sheet, int[] _path, BypassResult _result)
            {
                if (_sheet.LastDepartment.Equals(Configuration.EndDepartment))
                {
                    return(false);
                }

                if (IsLoop(_path))
                {
                    _result.IsLoop = true;
                    _result.BypassSheetSnapshots = _result.BypassSheetSnapshots.Distinct().ToList();
                    return(false);
                }
                return(true);
            }

            Dictionary <string, int> departmetsNumericId = new Dictionary <string, int>();

            string[] dep = Configuration.Departments.Select(x => x.Id).ToArray();

            for (int i = 0; i < dep.Length; i++)
            {
                departmetsNumericId.Add(dep[i], i);
            }

            List <int> path = new List <int>();

            BypassSheet  sheet  = new BypassSheet(Configuration.StartDepartment, Configuration);
            BypassResult result = new BypassResult();

            do
            {
                sheet.CurrentDepartment.ExecuteRule(sheet);
                if (sheet.LastDepartment.Id.Equals(department))
                {
                    result.AddSnapshot(sheet.MakeSnaphot());
                }
                path.Add(departmetsNumericId[sheet.LastDepartment.Id]);
            }while (ShouldContuinue(sheet, path.ToArray(), result));

            result.Successful = true;
            return(result);
        }