예제 #1
0
 private void Dummy2(StructureServiceProvider ssp)
 {
     #region FunctionAggregatorDeclarationCode3
     // Assume 'ssp' is variable of type Qi4CS.Core.API.Structures.StructureServiceProvider
     var service = ssp.FindService <MyFunctionality>().GetService(); // Get the reference to service composite
     var typeStr = service.GetStringFor(typeof(Object));             // 'typeStr' now is "System.Object_MySuffix"
     var strStr  = service.GetStringFor("MyTestString");             // 'strStr' now is "MyTestString_MyOtherSuffix"
     #endregion
 }
예제 #2
0
        public static void RunCompositeCreationPerformanceTest(StructureServiceProvider ssp)
        {
            Int64 t0 = TestCreationPerformanceInLoop(LOOPS, () => new AnyObject(), "Minimum C# Object creation time", "object");
            Int64 t1 = TestCreationPerformanceInLoop(LOOPS, () => ssp.NewPlainCompositeBuilder <AnyComposite>().Instantiate(), "Transient builder creation time", "composite");
            //Int64 t2 = TestCreationPerformanceInLoop( LOOPS, () => ssp.NewValueBuilder<AnyValue>().Instantiate(), "Value builder creation time", "composite" );
            Int64 t3 = TestCreationPerformanceInLoop(LOOPS, () => ssp.NewPlainCompositeBuilder <AnyObject>().Instantiate(), "Object builder creation time", "Qi4CS object");

            Console.WriteLine("Transient builder: " + (t1 / t0) + "x");
            //Console.WriteLine( "Value builder: " + ( t2 / t0 ) + "x" );
            Console.WriteLine("Object builder: " + (t3 / t0) + "x");
        }
예제 #3
0
 public virtual void SetUp()
 {
     _appDomain = Qi4CSTestUtils.CreateTestAppDomain("Qi4CS Instance Test");
     _appDomain.DoCallBack(() =>
     {
         ArchitectureType architecture = this.CreateArchitecture();
         this.SetUpArchitecture(architecture);
         var ass = ReflectionHelper.QI4CS_ASSEMBLY;
         _model  = this.CreateModel(architecture);
         _model.GenerateAndSaveAssemblies(emittingInfoCreator: Qi4CSCodeGenHelper.EmittingArgumentsCallback);
         _application       = _model.NewInstance(TestConstants.APPLICATION_NAME, TestConstants.APPLICATION_MODE, TestConstants.APPLICATION_VERSION);
         _structureServices = this.GetStructureProvider(_application);
         _application.Activate();
     });
 }
예제 #4
0
 public virtual void TearDown()
 {
     try
     {
         _appDomain.DoCallBack(() =>
         {
             if (_application != null)
             {
                 _application.Passivate();
             }
             _model             = null;
             _structureServices = null;
         });
     }
     finally
     {
         _appDomain.Dispose();
         _appDomain = null;
     }
 }
        public static void RunInvocationPerformanceTest(StructureServiceProvider ssp)
        {
            TestBase manualSimple = new TestMixin();

            TestBase manualTypedConcernMixin = new TestMixin();
            TestBase manualTypedConcernObj   = new TestTypedConcern(manualTypedConcernMixin);

            TestBase manualGenericConcernMixin = new TestMixin();
            TestBase manualGenericConcernObj   = new ManualNextInvocator(manualGenericConcernMixin);

            Int64 t0 = TestInvocationPerformanceInLoop(LOOPS, manualSimple);
            Int64 t1 = TestInvocationPerformanceInLoop(LOOPS, manualTypedConcernObj);
            Int64 t2 = TestInvocationPerformanceInLoop(LOOPS, manualGenericConcernObj);

            Int64 t3 = TestInvocationPerformanceInLoop(LOOPS, ssp.NewPlainCompositeBuilder <TestComposite>().Instantiate());
            Int64 t4 = TestInvocationPerformanceInLoop(LOOPS, ssp.NewPlainCompositeBuilder <TestWithTypedConcernComposite>().Instantiate());
            Int64 t5 = TestInvocationPerformanceInLoop(LOOPS, ssp.NewPlainCompositeBuilder <TestWithGenericConcernComposite>().Instantiate());

            Console.WriteLine("Simple: " + (t3 / t0) + "x");
            Console.WriteLine("Typed concern: " + (t4 / t1) + "x");
            Console.WriteLine("Generic concern: " + (t5 / t2) + "x");
        }
예제 #6
0
        public static void DummyMethod()
        {
            StructureServiceProvider ssp = null;
            Type myCompositeType         = null;

            #region CompositeCreationCode1
            // Acquiring CompositeBuilderInfo
            CompositeBuilderInfo <MyComposite> cbi = ssp.NewPlainCompositeBuilder <MyComposite>();

            // Acquiring CompositeBuilder, type of composite not known at compile time
            CompositeBuilder cb = ssp.NewPlainCompositeBuilder(myCompositeType); // myCompositeType is of System.Type

            // Acquiring CompositeBuilder and using multiple types to filter out possible composites
            CompositeBuilder cbm = ssp.NewPlainCompositeBuilder(new[] { typeof(MyCompositePartialType1), typeof(MyCompositePartialType2) });
            #endregion

            {
                #region CompositeCreationCode2
                MyComposite composite = cbi.Instantiate();
                #endregion
            }

            {
                #region CompositeCreationCode3
                MyComposite composite  = cb.Instantiate <MyComposite>();
                MyComposite composite2 = (MyComposite)cb.InstantiateWithType(typeof(MyComposite));
                // Both composite and composite2 will be same object.
                #endregion
            }

            {
                #region CompositeCreationCode4
                MyCompositePartialType1 composite1 = cbm.Instantiate <MyCompositePartialType1>();
                MyCompositePartialType2 composite2 = cbm.Instantiate <MyCompositePartialType2>();
                // composite1 and composite2 may be different objects.
                #endregion
            }
        }
예제 #7
0
 /// <summary>
 /// Helper to create a new <see cref="CompositeBuilder"/> from a specific <see cref="CompositeModel"/>.
 /// </summary>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <param name="model">The <see cref="CompositeModel"/> of the composite.</param>
 /// <returns>A <see cref="CompositeBuilder"/> to build instances of composites modeled by <see cref="CompositeModel"/>.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, System.Collections.Generic.IEnumerable{Type})"/> method for more exception scenarios.</remarks>
 public static CompositeBuilder NewCompositeBuilder(this StructureServiceProvider ssp, CompositeModel model)
 {
     return(ssp.NewCompositeBuilder(model.ModelType, model.PublicTypes));
 }
 /// <summary>
 /// Helper method to create new <see cref="CompositeBuilder"/> for plain composites (compositem odel type of <see cref="CompositeModelType.PLAIN"/>) with given types to be used as search criterion.
 /// </summary>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <param name="compositeTypes">The types of the plain composite.</param>
 /// <returns>A new instance of <see cref="CompositeBuilder"/> for plain composites, matching the search criteria.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/>
 public static CompositeBuilder NewPlainCompositeBuilder(this StructureServiceProvider ssp, IEnumerable <Type> compositeTypes)
 {
     return(ssp.NewCompositeBuilder(CompositeModelType.PLAIN, compositeTypes));
 }
 /// <summary>
 /// Shortcut method to create a composite of specified <see cref="CompositeModelType"/> without further setting up of <see cref="CompositeBuilder"/>.
 /// </summary>
 /// <typeparam name="TComposite">The type of the composite.</typeparam>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <param name="compositeModelType">The <see cref="CompositeModelType"/> of the composite.</param>
 /// <returns>A new instance of composite with given <see cref="CompositeModelType"/>.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> and <see cref="CompositeBuilder.InstantiateWithType(Type)"/> methods for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/>
 /// <seealso cref="CompositeBuilder.InstantiateWithType(Type)"/>
 public static TComposite NewComposite <TComposite>(this StructureServiceProvider ssp, CompositeModelType compositeModelType)
 {
     return(ssp.NewCompositeBuilder <TComposite>(compositeModelType).Instantiate());
 }
 /// <summary>
 /// Shortcut method to create a plain composite (composite with <see cref="CompositeModelType.PLAIN"/> as composite model type) without further setting up of <see cref="CompositeBuilder"/>.
 /// </summary>
 /// <typeparam name="TComposite">The type of the composite.</typeparam>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <returns>A new instance of plain composite.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> and <see cref="CompositeBuilder.InstantiateWithType(Type)"/> methods for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/>
 /// <seealso cref="CompositeBuilder.InstantiateWithType(Type)"/>
 public static TComposite NewPlainComposite <TComposite>(this StructureServiceProvider ssp)
 {
     return(NewComposite <TComposite>(ssp, CompositeModelType.PLAIN));
 }
 /// <summary>
 /// Helper method to find all suitable services using given type as search criterion.
 /// </summary>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <param name="serviceType">The type of the service.</param>
 /// <returns>All <see cref="ServiceReference"/>s matching search criterion.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/>
 /// <seealso cref="ServiceReference"/>
 public static IEnumerable <ServiceReference> FindServices(this StructureServiceProvider ssp, Type serviceType)
 {
     return(ssp.FindServices(serviceType.Singleton()));
 }
 /// <summary>
 /// Helper method to find all suitable services using single type, known at compile time, as search criterion.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <returns>All <see cref="ServiceReferenceInfo{T}"/>s matching search criterion.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/>
 /// <seealso cref="ServiceReferenceInfo{T}"/>
 public static IEnumerable <ServiceReferenceInfo <TService> > FindServices <TService>(this StructureServiceProvider ssp)
 {
     return(ssp.FindServices(typeof(TService).Singleton()).ToArray()
            .Select(sRef => new ServiceReferenceInfo <TService>(sRef)));
 }
 /// <summary>
 /// Helper method to find a first suitable <see cref="ServiceReferenceInfo{T}"/> using given type as search criterion.
 /// </summary>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <param name="serviceType">The type of the service.</param>
 /// <returns>A first <see cref="ServiceReference"/> matching search criterion.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <exception cref="InvalidOperationException">If no suitable services found.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/>
 /// <seealso cref="ServiceReference"/>
 public static ServiceReference FindService(this StructureServiceProvider ssp, Type serviceType)
 {
     return(ssp.FindServices(serviceType.Singleton()).First());
 }
 /// <summary>
 /// Helper method to find first suitable <see cref="ServiceReference"/> using given types as search criterion.
 /// </summary>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <param name="serviceTypes">The types of the service.</param>
 /// <returns>A first <see cref="ServiceReference"/> matching search criterion.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <exception cref="InvalidOperationException">If no suitable services found.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/>
 /// <seealso cref="ServiceReference"/>
 public static ServiceReference FindService(this StructureServiceProvider ssp, IEnumerable <Type> serviceTypes)
 {
     return(ssp.FindServices(serviceTypes).First());
 }
    // TODO implementing value composite model type should be done via extension
    //public static CompositeBuilderInfo<TComposite> NewValueBuilder<TComposite>( this StructureServiceProvider ssp )
    //{
    //   return ssp.NewCompositeBuilder<TComposite>( CompositeModelType.VALUE );
    //}

    //public static CompositeBuilder NewValueBuilder( this StructureServiceProvider ssp, Type compositeType )
    //{
    //   return ssp.NewCompositeBuilder( CompositeModelType.VALUE, compositeType.Singleton() );
    //}

    //public static CompositeBuilder NewValueBuilder( this StructureServiceProvider ssp, IEnumerable<Type> compositeTypes )
    //{
    //   return ssp.NewCompositeBuilder( CompositeModelType.VALUE, compositeTypes );
    //}

    /// <summary>
    /// Helper method to find a first suitable <see cref="ServiceReferenceInfo{T}"/> using given type, known at compile time, as search criterion.
    /// </summary>
    /// <typeparam name="TService">The type of the service.</typeparam>
    /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
    /// <returns>A first <see cref="ServiceReferenceInfo{T}"/> matching search criterion.</returns>
    /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
    /// <exception cref="InvalidOperationException">If no suitable services found.</exception>
    /// <remarks>
    /// See <see cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/> method for more exception scenarios.
    /// </remarks>
    /// <seealso cref="StructureServiceProvider.FindServices(IEnumerable{Type})"/>
    /// <seealso cref="ServiceReferenceInfo{T}"/>
    public static ServiceReferenceInfo <TService> FindService <TService>(this StructureServiceProvider ssp)
    {
        return(ssp.FindServices <TService>().First());
    }
예제 #16
0
        public void SetUp()
        {
            _appDomain = Qi4CSTestUtils.CreateTestAppDomain("Qi4CS Configuration test.");
            _appDomain.DoCallBack(() =>
            {
                // Typical usecase scenario, first create architecture
                var architecture = Qi4CSArchitectureFactory.NewLayeredArchitecture();

                // Add layer for all configuration composites
                var configLayer = architecture.GetOrCreateLayer("ConfigLayer");

                // Add a module for all configuration composites
                var configModule = configLayer.GetOrCreateModule("ConfigModule");

                // Assembler for configuration module
                var assembler = configModule.CompositeAssembler;

                var customSerializers = new List <XMLConfigurationSerializerHelper>();

                // IPEndPoint is not a Qi4CS composite - add custom (de)serialization support for it
                customSerializers.Add(new XMLConfigurationSerializerWithCallbacks(
                                          (obj, type) => typeof(IPEndPoint).Equals(type),
                                          (obj, type, parent) => parent.Add(new XElement("Address", ((IPEndPoint)obj).Address.ToString()), new XElement("Port", ((IPEndPoint)obj).Port.ToString())),
                                          (element, type) => typeof(IPEndPoint).Equals(type),
                                          (element, type) =>
                {
                    var addressString = element.Element("Address").Value;
                    IPAddress address;
                    if (!IPAddress.TryParse(addressString, out address))
                    {
                        address = Dns.GetHostEntry(addressString).AddressList[0];
                    }
                    return(new IPEndPoint(address, Int32.Parse(element.Element("Port").Value)));
                }
                                          ));

                // Add serialization composite
                assembler.AddXMLSerializationSupport(null, customSerializers);
                // Add composites part of the configuration
                assembler
                .NewPlainComposite()
                .OfTypes(typeof(DatabaseConfiguration));
                assembler
                .NewLayeredPlainComposite()
                .VisibleIn(Visibility.MODULE)
                .OfTypes(typeof(DatabaseSetup));

                // Add support for configuration service and instances
                assembler.AddSupportForAllConfigurationInstancesAndManager()
                .WithDefaultsFor(typeof(DatabaseConfiguration)) // Set default values for DatabaseConfiguration
                .SerializedByXML()                              // Make DatabaseConfiguration (de)serialization process use XMLConfigurationSerializer
                .LocatedInXMLDocument(CONFIG_FILE_FULL_PATH);   // Default location for DatabaseConfiguration

                // Add the test composite
                var testLayer  = architecture.GetOrCreateLayer("TestLayer");
                var testModule = testLayer.GetOrCreateModule("TestModule");
                assembler      = testModule.CompositeAssembler;
                assembler.NewLayeredPlainComposite().OfTypes(typeof(CompositeUsingConfiguration)).WithMixins(typeof(CompositeUsingConfigurationMixin));

                testLayer.UseLayers(configLayer);

                var model = architecture.CreateModel();
                model.GenerateAndSaveAssemblies(emittingInfoCreator: Qi4CSCodeGenHelper.EmittingArgumentsCallback);
                var application = model.NewInstance(TestConstants.APPLICATION_NAME, TestConstants.APPLICATION_MODE, TestConstants.APPLICATION_VERSION);
                _ssp            = assembler.GetStructureServiceProvider(application);
                application.Activate();
            });
            //var configSSP = configModule.CompositeAssembler.GetStructureServiceProvider( application );
            //var suckaObjBuilder = configSSP.NewPlainCompositeBuilder<DatabaseConfiguration>();
            //suckaObjBuilder.Prototype().DatabaseSetups = new Dictionary<String, DatabaseSetup>();
            //var localConnBuilder = configSSP.NewPlainCompositeBuilder<DatabaseSetup>();
            //localConnBuilder.Prototype().DatabaseName = "SomeDB";
            //localConnBuilder.Prototype().DatabaseConnectionInformation = new IPEndPoint( IPAddress.Loopback, 1000 );
            //suckaObjBuilder.Prototype().DatabaseSetups.Add( "Local", localConnBuilder.Instantiate() );

            //var sucka = new XElement( "DatabaseConfiguration" );
            //configSSP.FindService<XMLSerializationService>().Service.Serialize( suckaObjBuilder.Instantiate(), sucka );
        }
 /// <summary>
 /// Helper method to create new <see cref="CompositeBuilder"/> for plain composites (composite model type of <see cref="CompositeModelType.PLAIN"/>) with only one type to be used as search criterion.
 /// </summary>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <param name="compositeType">The type of the plain composite.</param>
 /// <returns>A new instance of <see cref="CompositeBuilder"/> for plain composites, matching the search criteria.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/>
 public static CompositeBuilder NewPlainCompositeBuilder(this StructureServiceProvider ssp, Type compositeType)
 {
     return(ssp.NewCompositeBuilder(CompositeModelType.PLAIN, compositeType.Singleton()));
 }
 /// <summary>
 /// Helper method to create new <see cref="CompositeBuilder"/> for plain composites (composite model type of <see cref="CompositeModelType.PLAIN"/>) with only one type, known at compile time, to be used as search criterion.
 /// </summary>
 /// <typeparam name="TComposite">The type of the plain composite.</typeparam>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/>.</param>
 /// <returns>A new instance of <see cref="CompositeBuilderInfo{T}"/> for plain composites, matching the search criteria.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/>
 /// <seealso cref="CompositeBuilderInfo{T}"/>
 public static CompositeBuilderInfo <TComposite> NewPlainCompositeBuilder <TComposite>(this StructureServiceProvider ssp)
 {
     return(ssp.NewCompositeBuilder <TComposite>(CompositeModelType.PLAIN));
 }
 /// <summary>
 /// Helper method to create new composite builder with specified <see cref="CompositeModelType"/> and only one type, known at compile time, to be used as search criteria.
 /// </summary>
 /// <typeparam name="TComposite">The type of the composite, to be used as search criterion when searching for suitable composite model.</typeparam>
 /// <param name="ssp">The <see cref="StructureServiceProvider"/></param>
 /// <param name="compositeModelType">The <see cref="CompositeModelType"/> to be used when searching for suitable composite model.</param>
 /// <returns>A new <see cref="CompositeBuilderInfo{T}"/> instance matching the search criteria.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="ssp"/> is <c>null</c>.</exception>
 /// <remarks>
 /// See <see cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/> method for more exception scenarios.
 /// </remarks>
 /// <seealso cref="StructureServiceProvider.NewCompositeBuilder(CompositeModelType, IEnumerable{Type})"/>
 /// <seealso cref="CompositeBuilderInfo{T}"/>
 public static CompositeBuilderInfo <TComposite> NewCompositeBuilder <TComposite>(this StructureServiceProvider ssp, CompositeModelType compositeModelType)
 {
     return(new CompositeBuilderInfo <TComposite>(ssp.NewCompositeBuilder(compositeModelType, typeof(TComposite).Singleton())));
 }