public HearingDetailsResponse Build()
        {
            var cases = new List <CaseResponse>
            {
                new CaseResponse
                {
                    IsLeadCase = _request.Cases.First().IsLeadCase,
                    Name       = _request.Cases.First().Name,
                    Number     = _request.Cases.First().Number
                }
            };

            var participants = (from participant in _request.Participants
                                let userType = GetUserType.FromUserLastName(participant.LastName)
                                               let userRoleName = UserTypeName.FromUserType(userType)
                                                                  select new ParticipantResponse
            {
                CaseRoleName = participant.CaseRoleName,
                ContactEmail = participant.ContactEmail,
                DisplayName = participant.DisplayName,
                FirstName = participant.FirstName,
                HearingRoleName = participant.HearingRoleName,
                Id = Guid.NewGuid(),
                LastName = participant.LastName,
                MiddleNames = participant.MiddleNames,
                Organisation = participant.OrganisationName,
                Representee = participant.Representee,
                TelephoneNumber = participant.TelephoneNumber,
                Title = participant.Title,
                UserRoleName = userRoleName,
                Username = participant.Username
            }).ToList();

            return(new HearingDetailsResponse
            {
                AudioRecordingRequired = _request.AudioRecordingRequired,
                CancelReason = null,
                CaseTypeName = _request.CaseTypeName,
                Cases = cases,
                ConfirmedBy = null,
                ConfirmedDate = null,
                CreatedBy = _request.CreatedBy,
                CreatedDate = DateTime.UtcNow,
                HearingRoomName = _request.HearingRoomName,
                HearingTypeName = _request.HearingTypeName,
                HearingVenueName = _request.HearingVenueName,
                Id = Guid.NewGuid(),
                OtherInformation = _request.OtherInformation,
                Participants = participants,
                QuestionnaireNotRequired = _request.QuestionnaireNotRequired,
                ScheduledDateTime = _request.ScheduledDateTime,
                ScheduledDuration = _request.ScheduledDuration,
                Status = BookingStatus.Booked,
                UpdatedBy = _request.CreatedBy,
                UpdatedDate = DateTime.UtcNow
            });
        }
Beispiel #2
0
            /// <summary>
            /// Helper function that returns the type of an object based on namespace and name
            /// </summary>
            /// <param name="Namespace"></param>
            /// <param name="TestName"></param>
            /// <returns></returns>
            private static Type GetTypeForTest(string TestName, IEnumerable <string> Namespaces)
            {
                var SearchAssemblies = AppDomain.CurrentDomain.GetAssemblies();

                // turn foo into [n1.foo, n2.foo, foo]
                IEnumerable <string> FullNames;

                if (Namespaces != null)
                {
                    FullNames = Namespaces.Select(N => N + "." + TestName);
                }
                else
                {
                    FullNames = new[] { TestName };
                }

                Log.VeryVerbose("Will search {0} for test {1}", string.Join(" ", FullNames), TestName);

                // find all types from loaded assemblies that implement testnode
                List <Type> CandidateTypes = new List <Type>();

                foreach (var Assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    foreach (var Type in Assembly.GetTypes())
                    {
                        if (typeof(ITestNode).IsAssignableFrom(Type))
                        {
                            CandidateTypes.Add(Type);
                        }
                    }
                }

                Log.VeryVerbose("Possible candidates for {0}: {1}", TestName, string.Join(" ", CandidateTypes));

                // check our expanded names.. need to search in namespace order
                foreach (string UserTypeName in FullNames)
                {
                    // Even tho the user might have specified N1.Foo it still might be Other.N1.Foo so only
                    // compare based on the number of namespaces that were specified.
                    foreach (var Type in CandidateTypes)
                    {
                        string[] UserNameComponents = UserTypeName.Split('.');
                        string[] TypeNameComponents = Type.FullName.Split('.');

                        int MissingUserComponents = TypeNameComponents.Length - UserNameComponents.Length;

                        if (MissingUserComponents > 0)
                        {
                            //
                            TypeNameComponents = TypeNameComponents.Skip(MissingUserComponents).ToArray();
                        }

                        var Difference = TypeNameComponents.Except(UserNameComponents, StringComparer.OrdinalIgnoreCase);

                        if (Difference.Count() == 0)
                        {
                            Log.VeryVerbose("Considering {0} as best match for {1}", Type, TestName);
                            return(Type);
                        }
                    }
                }


                throw new AutomationException("Unable to find type {0} in assemblies. Namespaces= {1}.", TestName, Namespaces);
            }