예제 #1
0
        public IEnumerable <RegistrationInfo> Analyze(IPsiSourceFile sourceFile)
        {
            ICSharpFile cSharpFile;

#if SDK70
            cSharpFile = sourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance) as ICSharpFile;
#else
            cSharpFile = sourceFile.GetPsiFile(CSharpLanguage.Instance) as ICSharpFile;
#endif
            if (cSharpFile == null)
            {
                return(EmptyList <RegistrationInfo> .InstanceList);
            }

            var usingStatements = cSharpFile.Imports
                                  .Where(directive => !directive.ImportedSymbolName.QualifiedName.StartsWith("System"))
                                  .Select(directive => directive.ImportedSymbolName.QualifiedName).ToList();

            IContainerInfo matchingContainer = GetMatchingContainer(usingStatements);
            if (matchingContainer == null)
            {
                return(EmptyList <RegistrationInfo> .InstanceList);
            }

            ISearchDomain searchDomain = searchDomainFactory.CreateSearchDomain(sourceFile);

            return(ScanRegistrations(matchingContainer, searchDomain));
        }
    public static void TestSetUp()
    {
        TestsHelper.SetupLogger();

        var fileBasedConfigurationParameters = new FileBasedConfigurationParameters(
            new FileBasedConfigurationFileContentsProvider(
                Path.Combine(Helpers.TestsEntryAssemblyFolder, @"DocumentationTests\AutoServiceCustom\DemoIoCConfiguration_autoServiceCustom.xml")),
            Helpers.TestsEntryAssemblyFolder,
            // LoadedAssembliesForTests is an implementation of ILoadedAssemblies that has a method
            // "IEnumerable<Assembly> GetAssemblies()" that returns list of assemblies to add as references to
            // generate dynamic assembly.
            new LoadedAssembliesForTests())
        {
            AdditionalReferencedAssemblies = new []
            {
                // List additional assemblies that should be added to dynamically generated assembly as references
                Path.Combine(Helpers.GetTestFilesFolderPath(), @"DynamicallyLoadedDlls\TestProjects.DynamicallyLoadedAssembly1.dll"),
                Path.Combine(Helpers.GetTestFilesFolderPath(), @"DynamicallyLoadedDlls\TestProjects.DynamicallyLoadedAssembly2.dll")
            },
            AttributeValueTransformers         = new[] { new FileFolderPathAttributeValueTransformer() },
            ConfigurationFileXmlDocumentLoaded = (sender, e) =>
                                                 Helpers.EnsureConfigurationDirectoryExistsOrThrow(e.XmlDocument.SelectElement("/iocConfiguration/appDataDir").GetAttribute("path"))
        };

        _containerInfo = new DiContainerBuilder.DiContainerBuilder()
                         .StartFileBasedDi(fileBasedConfigurationParameters, out _)
                         .WithoutPresetDiContainer()
                         .RegisterModules().Start();
    }
예제 #3
0
 private IEnumerable<RegistrationInfo> ScanRegistrations(IContainerInfo containerInfo)
 {
     return (from pattern in containerInfo.RegistrationPatterns
             let matchResults = patternSearcher.Search(pattern)
             from matchResult in matchResults.Where(result => result.Matched)
             from registration in pattern.GetComponentRegistrations(matchResult.MatchedElement)
             select new RegistrationInfo(registration, containerInfo.ContainerDisplayName)).ToList();
 }
예제 #4
0
 private IEnumerable <RegistrationInfo> ScanRegistrations(IContainerInfo containerInfo, ISearchDomain searchDomain)
 {
     return(from pattern in containerInfo.RegistrationPatterns
            let matchResults = patternSearcher.Search(pattern, searchDomain)
                               from matchResult in matchResults.Where(result => result.Matched)
                               from registration in pattern.GetComponentRegistrations(matchResult.MatchedElement)
                               select new RegistrationInfo(registration, containerInfo.ContainerDisplayName));
 }
 public VisualizerViewModel(IContainerInfo container)
 {
     this.container           = container;
     BuildCommand             = new RelayCommand(Build, o1 => Components.CurrentItem != null);
     ReturnToContainerCommand = new RelayCommand(o => CurrentView = View.Container, o1 => true);
     CurrentView = View.Container;
     RefreshTypes();
 }
예제 #6
0
        protected static void ClassInitializeCommon(DiImplementationType diImplementationType, Action <ConfigurationFileXmlDocumentLoadedEventArgs> configurationFileXmlDocumentLoadedEventHandler)
        {
            // JetBrains.ReSharper.TestRunner.Merged
            TestsHelper.SetupLogger();
            Log4Tests.LogLevel = LogLevel.Debug;

            _diImplementationType = diImplementationType;

            _mainLifeTimeScopeTerminatedExecuted = false;
            var diContainerBuilder = new DiContainerBuilder.DiContainerBuilder();


            var fileBasedConfigurationParameters = new FileBasedConfigurationParameters(new FileBasedConfigurationFileContentsProvider(
                                                                                            Path.Combine(Helpers.TestsEntryAssemblyFolder, "IoCConfiguration_Overview.xml")),
                                                                                        Helpers.TestsEntryAssemblyFolder, new LoadedAssembliesForTests())
            {
                AttributeValueTransformers         = new[] { new FileFolderPathAttributeValueTransformer() },
                ConfigurationFileXmlDocumentLoaded = (sender, e) =>
                {
                    Helpers.EnsureConfigurationDirectoryExistsOrThrow(e.XmlDocument.SelectElement("/iocConfiguration/appDataDir").GetAttribute("path"));

                    Helpers.ReplaceActiveDiManagerInConfigurationFile(e.XmlDocument, _diImplementationType);
                    configurationFileXmlDocumentLoadedEventHandler?.Invoke(e);
                }
            };

            _containerInfo = diContainerBuilder.StartFileBasedDi(
                fileBasedConfigurationParameters, out _)
                             .WithoutPresetDiContainer()
                             .AddAdditionalDiModules(new TestModule2())
                             .RegisterModules()
                             .Start();

            _diContainer = _containerInfo.DiContainer;

            var injectedStartupActionsHelper = _diContainer.Resolve <ClassToTestServicesInjection <IStartupAction> >();

            _startupActionsToTest = injectedStartupActionsHelper.Implementations.Where(x => x is IStartupActionState &&
                                                                                       new[]
            {
                "DynamicallyLoadedAssembly1.Implementations.StartupAction1",
                "DynamicallyLoadedAssembly1.Implementations.StartupAction2"
            }
                                                                                       .Contains(x.GetType().FullName)).ToList();

            var injectedPluginsHelper = _diContainer.Resolve <ClassToTestServicesInjection <IPlugin> >();

            _pluginsToTest = injectedPluginsHelper.Implementations.Where(x => x is IPluginState &&
                                                                         new[]
            {
                "TestPluginAssembly1.Implementations.Plugin1",
                "TestPluginAssembly2.Implementations.Plugin2"
            }
                                                                         .Contains(x.GetType().FullName)).ToList();

            _diContainer.MainLifeTimeScope.LifeTimeScopeTerminated += (sender, e) => { _mainLifeTimeScopeTerminatedExecuted = true; };
        }
예제 #7
0
        public IEnumerable <RegistrationInfo> Analyze([NotNull] IPsiSourceFile sourceFile)
        {
            IContainerInfo matchingContainer = GetMatchingContainer(sourceFile);

            if (matchingContainer == null)
            {
                return(EmptyList <RegistrationInfo> .InstanceList);
            }

            ISearchDomain searchDomain = searchDomainFactory.CreateSearchDomain(sourceFile);

            return(ScanRegistrations(matchingContainer, searchDomain));
        }
        protected static void ClassInitializeCommon(DiImplementationType diImplementationType,
                                                    Func <IContainerInfo> createContainerInfo)
        {
            TestsHelper.SetupLogger();
            Log4Tests.LogLevel = LogLevel.Debug;

            _diImplementationType = diImplementationType;

            _mainLifeTimeScopeTerminatedExecuted = false;

            _containerInfo = createContainerInfo();

            _diContainer = _containerInfo.DiContainer;

            _diContainer.MainLifeTimeScope.LifeTimeScopeTerminated += (sender, e) => { _mainLifeTimeScopeTerminatedExecuted = true; };
        }
예제 #9
0
        private static void SyncContainer(Container container, IContainerInfo schema)
        {
            // Delete child elements that have a schema id but a matching
            // one does not exist anymore.
            container.Components
                .OfType<ICollection>()
                .Where(c => !schema.Components.OfType<ICollectionInfo>().Any(i => i.SchemaId == c.SchemaId))
                .ToArray()
                .ForEach(c => c.Delete());
            container.Components
                .OfType<IElement>()
                .Where(c => !schema.Components.OfType<IElementInfo>().Any(i => i.SchemaId == c.SchemaId))
                .ToArray()
                .ForEach(c => c.Delete());

            // TODO: Delete extra child elements that are beyond the specified cardinality.
            //container.Components
            //    .GroupBy(x => x.SchemaId)
            //    .Where(x => schema.Components.Any(
            //        i => x.Key == i.Id &&
            //        (i.Cardinality == Cardinality.OneToOne || i.Cardinality == Cardinality.ZeroToOne) &&
            //        x.Count() > 1))
            //    .SelectMany(x => x.Skip(1))
            //    .ForEach(x => x.Delete());

            // TODO: auto-create elements where specified.
            //var singletonElements = schema.Components
            //    .Where(i => i.AutoCreate &&
            //        !container.Components.Any(e => e.SchemaId == i.Id))
            //    .ToArray();

            // TODO: also sync the newly created elements?
            //singletonElements.OfType<IElementInfo>().ForEach(x => element.CreateElement(e => e.DefinitionId = x.Id));
            //singletonElements.OfType<ICollectionInfo>().ForEach(x => element.CreateCollection(e => e.DefinitionId = x.Id));

            SyncComponent(container, schema);
            foreach (var component in container.Components)
            {
                var collection = component as Collection;
                var element = component as Element;

                if (collection != null)
                    SyncCollection(collection, schema.Components.OfType<ICollectionInfo>().First(x => x.SchemaId == component.SchemaId));
                else if (element != null)
                    SyncElement(element, schema.Components.OfType<IElementInfo>().First(x => x.SchemaId == component.SchemaId));
            }
        }
예제 #10
0
        private bool IsCompatibleContainer(IContainerInfo schema, Type type)
        {
            // Initial property comparison.
            if (!IsCompatibleComponent(schema, type))
                return false;

            var referenceProperties = type.GetProperties().Where(info => !info.PropertyType.IsNative());

            // Check compatibility of elements.
            if (!referenceProperties.Where(info => !info.PropertyType.IsCollection()).All(info =>
                schema.Components.OfType<IElementInfo>().Any(element =>
                    element.DefaultName == info.Name &&
                    IsCompatibleContainer(element, info.PropertyType))))
                return false;

            // Check compatibility of collections
            return referenceProperties.Where(info => info.PropertyType.IsCollection()).All(info =>
                schema.Components.OfType<ICollectionInfo>().Any(collection =>
                    collection.DefaultName == info.Name &&
                    IsCompatibleCollection(collection, info.PropertyType)));
        }
예제 #11
0
 public void AddContainer(IContainerInfo containerInfo)
 {
     knownContainers.Add(containerInfo);
 }
예제 #12
0
 public void AddContainer(IContainerInfo containerInfo)
 {
     knownContainers.Add(containerInfo);
 }