Пример #1
0
        private void ConfigureAgatha()
        {
            var agathaContainer = new Container(Container);

            IoC.Container = agathaContainer;
            Container.RegisterInstance <IContainer> (agathaContainer);
            var clientConfiguration = new ClientConfiguration(agathaContainer)
            {
                AsyncRequestDispatcherImplementation = typeof(AsyncRequestDispatcher)
            };

            KnownTypeProvider.Register(typeof(LookupValueDto));

            KnownTypeHelper.RegisterNonGenericRequestsAndResponses(typeof(InfrastructureModule).Assembly);

            clientConfiguration.AddRequestAndResponseAssembly(typeof(GetLookupValuesRequest).Assembly);

            var genericsToApply = KnownTypeHelper.GetGenerics(typeof(Const).Assembly);

            KnownTypeHelper.RegisterGenerics(genericsToApply, typeof(InfrastructureModule).Assembly);

            KnownTypeHelper.RegisterKnownTypesFromIKnownTypeProviders(typeof(IMetadataItemDto).Assembly);      // metadata

            clientConfiguration.RequestProcessorImplementation = typeof(CustomAsyncRequestProcessorProxy);

            clientConfiguration.Initialize();
        }
Пример #2
0
        protected T[] GetRequests <T>(NameValueCollection collection)
        {
            ValidateCollection(collection);

            var requests = new List <T>();

            if (IsSingleRequestCollection(collection))
            {
                var type = KnownTypeProvider.GetKnownTypes(null).Where(x => x.Name == collection.Get("request")).FirstOrDefault();

                if (type == null)
                {
                    throw new InvalidOperationException("Cannot resolve the name of the Request Type");
                }

                requests.Add((T)RecurseType(collection, type, null));
            }
            else
            {
                var collections = SplitTypeCollections(collection);
                foreach (var splitCollection in collections)
                {
                    var type = KnownTypeProvider.GetKnownTypes(null).Where(x => x.Name == splitCollection.Get("request")).FirstOrDefault();
                    if (type == null)
                    {
                        throw new InvalidOperationException("Cannot resolve the name of the Request Type");
                    }
                    var request = (T)RecurseType(splitCollection, type, null);
                    requests.Add(request);
                }
            }

            return(requests.ToArray());
        }
Пример #3
0
 private void RegisterRequestAndResponseTypes()
 {
     foreach (var assembly in requestsAndResponseAssemblies)
     {
         KnownTypeProvider.RegisterDerivedTypesOf <Request>(assembly);
         KnownTypeProvider.RegisterDerivedTypesOf <Response>(assembly);
     }
 }
Пример #4
0
        protected ClientComponentResolving()
        {
            IoC.Container = null;
            KnownTypeProvider.ClearAllKnownTypes();
            var configuration = new ClientConfiguration(Assembly.GetExecutingAssembly(), Activator.CreateInstance <TContainer>());

            configuration.AddRequestAndResponseAssembly(typeof(RequestB).Assembly);
            configuration.Initialize();
        }
Пример #5
0
 public void RegisterRequestAndResponseTypes(params Assembly[] assemblies)
 {
     foreach (var assembly in assemblies)
     {
         KnownTypeProvider.AddKnownTypes(_requestResponseSerice.GetAsyncRequestTypes(assembly));
         KnownTypeProvider.AddKnownTypes(_requestResponseSerice.GetAsyncResponseTypes(assembly));
         KnownTypeProvider.AddKnownTypes(_requestResponseSerice.GetSyncRequestTypes(assembly));
         KnownTypeProvider.AddKnownTypes(_requestResponseSerice.GetSyncResponseTypes(assembly));
     }
 }
Пример #6
0
        /// <summary>
        /// Configures the agatha.
        /// </summary>
        /// <param name="appContainer">The app container.</param>
        protected virtual void ConfigureAgatha(IContainer appContainer)
        {
            var structureMapContainer = new Agatha.StructureMap.Container(appContainer);

            IoC.Container = structureMapContainer;

            var assemblyLocator          = appContainer.GetInstance <IAssemblyLocator> ();
            var infrastructureAssemblies = assemblyLocator.LocateInfrastructureAssemblies();

            var genericsToApply = new Dictionary <Type, Type> ();

            foreach (var infrastructureAssembly in infrastructureAssemblies)
            {
                var genericsToApplyInAssebmly = KnownTypeHelper.GetGenerics(infrastructureAssembly);

                foreach (KeyValuePair <Type, Type> keyValuePair in genericsToApplyInAssebmly)
                {
                    genericsToApply.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }

            var serviceLayerConfiguration = new ServiceLayerConfiguration(structureMapContainer);

            var serviceAssemblies = assemblyLocator.LocateWebServiceAssemblies();

            foreach (var assembly in serviceAssemblies)
            {
                var assemblyRef = assembly;
                Logger.Debug("Registering Requests, Responses, Handlers, and Dtos for Assembly: {0}", assemblyRef);

                KnownTypeHelper.RegisterNonGenericRequestsAndResponses(assembly);
                serviceLayerConfiguration.AddRequestHandlerAssembly(assembly);

                KnownTypeProvider.RegisterDerivedTypesOf <AbstractDataTransferObject> (assembly.GetTypes().Where(t => !t.IsGenericType));

                KnownTypeHelper.RegisterGenerics(genericsToApply, assembly);
            }

            KnownTypeProvider.Register <TerminologyConcept> ();
            KnownTypeProvider.Register <TerminologyProperty> ();
            KnownTypeProvider.Register <TerminologyPropertyType> ();
            KnownTypeProvider.Register <TerminologyVocabulary> ();

            // register the agatha interceptors
            serviceLayerConfiguration.RegisterRequestHandlerInterceptor <SecurityInterceptor>();
            serviceLayerConfiguration.RegisterRequestHandlerInterceptor <RuleViolationEventInterceptor> ();

            serviceLayerConfiguration.RequestProcessorImplementation = typeof(Service.PerformanceLoggingRequestProcessor);
            serviceLayerConfiguration.Initialize();

            RegisterIRequestHandlerOfGetRequestDtoByKey(appContainer);
            CallKnownTypeProviders(appContainer);
        }
Пример #7
0
            /// <summary>
            /// Registers the requests and responses.
            /// </summary>
            /// <param name="assembly">The assembly.</param>
            public static void RegisterRequestsAndResponses(Assembly assembly)
            {
                var list = new List <Type> ();

                list.AddRange(GetNonGenericRequestsAndResponses(assembly));
                list.AddRange(GetGenericRequestsAndResponses(assembly));

                foreach (var type in list)
                {
                    KnownTypeProvider.Register(type);
                }
            }
Пример #8
0
        /// <summary>
        /// Registers the non generic requests and responses for an assembly.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        public static void RegisterNonGenericRequestsAndResponses(Assembly assembly)
        {
            var nonGenericTypes = (from t in assembly.GetTypes()
                                   where
                                   t.IsAbstract == false && t.IsGenericTypeDefinition == false &&
                                   (t.IsSubclassOf(typeof(Request)) || t.IsSubclassOf(typeof(Response)))
                                   select t).ToArray();

            foreach (var nonGenericType in nonGenericTypes)
            {
                KnownTypeProvider.Register(nonGenericType);
            }
        }
Пример #9
0
        public void RegisterTypes_InSpecificAssembly_Succeed()
        {
            var assembly = typeof(IMetadataItemDto).Assembly;
            var metadataKnowTypeProvider = new MetadataKnownTypeProvider(assembly);

            metadataKnowTypeProvider.RegisterTypes();

            var knownTypes         = KnownTypeProvider.GetKnownTypes(null).ToList();
            var expectedKnownTypes = assembly.GetExportedTypes()
                                     .Where(x => typeof(IMetadataItemDto).IsAssignableFrom(x))
                                     .ToList();

            CollectionAssert.AreEqual(expectedKnownTypes, knownTypes);
        }
Пример #10
0
        public static void RegisterWCFAgathaTypes(Assembly assembly)
        {
            // Taken from - http://www.xavierdecoster.com/post/2010/05/07/Automate-WCF-KnownTypes-in-a-3-Tier-Silverlight-application.aspx

            // get all public types
            var publicTypes = assembly.GetExportedTypes();

            // get all data contracts
            var dataContracts = publicTypes.Where(type => type.GetCustomAttributes(typeof(DataContractAttribute), true).Length > 0);

            // register all data contracts to WCF (using Agatha)
            // notice that we have to provide a base type to Agatha's KnownTypeProvider (it does not support interfaces...), so what the heck, let's use object :-)
            KnownTypeProvider.RegisterDerivedTypesOf <object>(dataContracts);
        }
Пример #11
0
 /// <summary>
 /// Registers the generics.
 /// </summary>
 /// <param name="generics">The generics.</param>
 /// <param name="assembly">The assembly.</param>
 public static void RegisterGenerics(Dictionary <Type, Type> generics, Assembly assembly)
 {
     foreach (var genericType in generics.Keys)
     {
         var typesToApply = from t in assembly.GetTypes()
                            where !t.IsGenericType && t.IsSubclassOf(generics[genericType])
                            select t;
         foreach (var type in typesToApply)
         {
             Type genericType1 = genericType;
             KnownTypeProvider.Register(genericType1.MakeGenericType(type));
         }
     }
 }
Пример #12
0
 static ServiceLayerComponentResolving()
 {
     IoC.Container = null;
     KnownTypeProvider.ClearAllKnownTypes();
     requestHandlerAssemblies = new List <Assembly> {
         Assembly.GetExecutingAssembly(), typeof(RequestHandlerB).Assembly
     };
     requestResponseAssemblies = new List <Assembly> {
         Assembly.GetExecutingAssembly(), typeof(RequestB).Assembly
     };
     configuration = new ServiceLayerConfiguration(requestHandlerAssemblies[0], requestResponseAssemblies[0],
                                                   Activator.CreateInstance <TContainer>());
     configuration.AddRequestHandlerAssembly(requestHandlerAssemblies[1]);
     configuration.AddRequestAndResponseAssembly(requestResponseAssemblies[1]);
     configuration.Use <RequestHandlerBasedConventions>();
     configuration.Initialize();
 }
Пример #13
0
        private void RegisterServices()
        {
            var genericsToApply = KnownTypeHelper.GetGenerics(typeof(Const).Assembly);

            KnownTypeHelper.RegisterNonGenericRequestsAndResponses(typeof(PatientModule).Assembly);
            KnownTypeHelper.RegisterGenerics(genericsToApply, typeof(PatientModule).Assembly);
            KnownTypeHelper.RegisterKnownTypesFromIKnownTypeProviders(typeof(PatientModule).Assembly);

            KnownTypeProvider.RegisterDerivedTypesOf <AbstractDataTransferObject>(typeof(PatientModule).Assembly.GetTypes().Where(t => !t.IsGenericType));

            _container.RegisterType <ITerminologyProxy, TerminologyProxy> ();
            _container.RegisterType <ICdsAlertService, CdsAlertService> ();
            _container.RegisterType <IPatientAccessService, PatientAccessService> ();
            _accessControlManager.RegisterPermissionDescriptor(
                new ClientPermissionDescriptor());
            _metadataService.LoadMetadataForModule(this);
        }
Пример #14
0
        /// <summary>
        /// Configures agatha.
        /// </summary>
        /// <param name="appContainer">The app container.</param>
        protected virtual void ConfigureAgatha(IContainer appContainer)
        {
            var structureMapContainer = new Agatha.StructureMap.Container(appContainer);

            Agatha.Common.InversionOfControl.IoC.Container = structureMapContainer;

            var assemblyLocator          = appContainer.GetInstance <IAssemblyLocator> ();
            var infrastructureAssemblies = assemblyLocator.LocateInfrastructureAssemblies();

            var genericsToApply = new Dictionary <Type, Type> ();

            foreach (var infrastructureAssembly in infrastructureAssemblies)
            {
                var genericsToApplyInAssebmly = KnownTypeHelper.GetGenerics(infrastructureAssembly);

                foreach (var keyValuePair in genericsToApplyInAssebmly)
                {
                    genericsToApply.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }

            var serviceAssemblies = assemblyLocator.LocateWebServiceAssemblies();

            foreach (var assembly in serviceAssemblies)
            {
                KnownTypeHelper.RegisterNonGenericRequestsAndResponses(assembly);

                KnownTypeProvider.RegisterDerivedTypesOf <AbstractDataTransferObject> (assembly.GetTypes().Where(t => !t.IsGenericType));

                KnownTypeHelper.RegisterGenerics(genericsToApply, assembly);
            }

            var clientConfiguration = new ClientConfiguration(structureMapContainer)
            {
                AsyncRequestDispatcherImplementation = typeof(AsyncRequestDispatcher)
            };

            clientConfiguration.AddRequestAndResponseAssembly(typeof(GetLookupValuesRequest).Assembly);

            clientConfiguration.RequestProcessorImplementation = typeof(CustomSyncRequestProcessorProxy);

            clientConfiguration.Initialize();
        }
Пример #15
0
        // TODO - Would be "more than nice" to have a test harness on this class
        public static ResultBase DeserialiseResultBase(string json)
        {
            var regexId = new Regex("__type\\\":\\\"(?<one>[^:]*):#(?<two>[^\\\"]*)\"");
            var matchId = regexId.Match(json);

            if (!matchId.Success)
            {
                throw new FormatException("Failed to decoded result - missing __type field");
            }

            var className    = matchId.Groups[1].Value;
            var assemblyName = matchId.Groups[2].Value;

            var type = Type.GetType(assemblyName + "." + className);
            var dcs  = new DataContractJsonSerializer(type, KnownTypeProvider.GetKnownTypesFor(typeof(ResultBase)));

            var textStream = new MemoryStream(UTF8Encoding.Default.GetBytes(json));

            return((ResultBase)dcs.ReadObject(textStream));
        }
Пример #16
0
 public IEnumerable <Type> GetRegisteredRequestTypes()
 {
     return(KnownTypeProvider.GetKnownTypes(null));
 }
 static PhoneAutomationService()
 {
     KnownTypeProvider.RegisterDerivedTypesOf <CommandBase>(typeof(CommandBase).Assembly);
     KnownTypeProvider.RegisterDerivedTypesOf <ResultBase>(typeof(ResultBase).Assembly);
 }
 public void ResponseTypeIsRegistered()
 {
     Assert.Contains(typeof(ResponseA), KnownTypeProvider.GetKnownTypes(null));
 }
 public void ResponseTypeFromExtraAssemblyIsRegistered()
 {
     Assert.Contains(typeof(ResponseB), KnownTypeProvider.GetKnownTypes(null));
 }
Пример #20
0
 public RestRequestBuilderTests()
 {
     KnownTypeProvider.Register(typeof(TRequestType1));
     KnownTypeProvider.Register(typeof(TRequestType2));
 }