Exemplo n.º 1
0
        void IStrategyCodeInjector.OnMetaModelUpdate(CodeInjectionContext context)
        {
            // Reference pour le ServiceLocator
            if (context.CurrentElement is Layer)
            {
                Layer layer = context.CurrentElement as Layer;
                foreach (ClassImplementation clazz in layer.Classes)
                {
                    foreach (ClassUsesOperations service in ClassUsesOperations.GetLinksToServicesUsed(clazz))
                    {
                        if (!context.GenerationContext.Mode.CheckConfigurationMode(service.ConfigurationMode) || service.TargetService is ExternalServiceContract)
                        {
                            continue;
                        }

                        foreach (Implementation impl in Implementation.GetLinksToImplementations((ServiceContract)service.TargetService))
                        {
                            if (context.GenerationContext.Mode.CheckConfigurationMode(impl.ConfigurationMode))
                            {
                                if (CheckAllHandler(impl.ClassImplementation, impl.ClassImplementation.Layer))
                                {
                                    layer.AddReferenceToService(entLibId, "EnterpriseLibrary", new VersionInfo(3, 1, 0, 0), "Microsoft.Practices.EnterpriseLibrary.PolicyInjection");
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            if (context.CurrentElement is ClassImplementation)
            {
                ClassImplementation clazz = context.CurrentElement as ClassImplementation;
                if (clazz.Contract == null)
                {
                    return;
                }

                bool flag = false;
                foreach (Operation op in clazz.Contract.Operations)
                {
                    IPIABHandler handler = CheckHandler <LogCallHandler>(LogCallHandlerProperty, op, clazz);
                    if (handler != null && handler.Enabled)
                    {
                        ((ClassImplementation)context.CurrentElement).Layer.AddReferenceToService(entLibId, "EnterpriseLibrary", new VersionInfo(3, 1, 0, 0), "Microsoft.Practices.EnterpriseLibrary.Logging", ReferenceScope.Runtime, "*");
                        flag = true;
                    }

                    handler = CheckHandler <CacheCallHandler>(CacheCallHandlerProperty, op, clazz);
                    if (handler != null && handler.Enabled)
                    {
                        ((ClassImplementation)context.CurrentElement).Layer.AddReferenceToService(entLibId, "EnterpriseLibrary", new VersionInfo(3, 1, 0, 0), "Microsoft.Practices.EnterpriseLibrary.Caching", ReferenceScope.Runtime, "*");
                        flag = true;
                    }

                    // PerformanceCounterCallHandler
                    handler = CheckHandler <PerformanceCounterCallHandler>(PerformanceCounterCallHandlerProperty, op, clazz);
                    if (handler != null && handler.Enabled)
                    {
                        ((ClassImplementation)context.CurrentElement).Layer.AddReferenceToService(entLibId, "EnterpriseLibrary", new VersionInfo(3, 1, 0, 0), "Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation", ReferenceScope.Runtime, "*");
                        flag = true;
                    }
                }

                if (flag)
                {
                    ((ClassImplementation)context.CurrentElement).Layer.AddReferenceToService(entLibId, "EnterpriseLibrary", new VersionInfo(3, 1, 0, 0), "Microsoft.Practices.EnterpriseLibrary.PolicyInjection");
                    ((ClassImplementation)context.CurrentElement).Layer.AddReferenceToService(entLibId, "EnterpriseLibrary", new VersionInfo(3, 1, 0, 0), "Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers", ReferenceScope.Runtime | ReferenceScope.Compilation, "*");
                }
            }
        }