コード例 #1
0
        //[DebuggerStepThrough]
        ////[DebuggerHidden]
        public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder, UsesInstance uses)
        {
            var    injectionContext = new InjectionContext(compositeInstance, uses, stateHolder);
            object mixin            = this.injectedObjectBuilder.NewInstance(injectionContext);

            return(mixin);
        }
コード例 #2
0
        public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
        {
            Object result;

            RoleMapHolder.ROLE_MAPS.Value.Peek().TryGetRole <Object>(((RoleAttribute)model.InjectionScope).Name, targetType, out result);
            return(result);
        }
コード例 #3
0
        public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
        {
            Object result = null;

            if (targetType.IsAssignableFrom(typeof(CollectionsFactory)))
            {
                result = instance.StructureOwner.Application.CollectionsFactory;
            }
            else if (targetType.IsAssignableFrom(typeof(ApplicationSPI)))
            {
                result = instance.StructureOwner.Application;
            }
            else if (targetType.IsAssignableFrom(typeof(StructureServiceProviderSPI)))
            {
                result = this.GetStructureServiceProvider(instance, model, targetType);
            }
            else if (targetType.IsAssignableFrom(typeof(UsesProviderQuery)))
            {
                result = instance.UsesContainer;
            }
            else if (targetType.IsAssignableFrom(typeof(CompositeModel)) || targetType.IsAssignableFrom(typeof(ServiceCompositeModel)))
            {
                result = instance.ModelInfo.Model;
            }
            else if (targetType.IsAssignableFrom(typeof(CompositeInstance)))
            {
                result = instance;
            }
            else
            {
                result = this.ProvideNonStandardInjection(instance, model, targetType);
            }
            return(result);
        }
コード例 #4
0
        public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
        {
            InvocationInfo invocationInfo = instance.InvocationInfo;
            Object         result;

            if (Object.Equals(typeof(MethodInfo), targetType))
            {
                result = invocationInfo.CompositeMethod;
            }
            else if (Object.Equals(typeof(CompositeMethodModel), targetType))
            {
                result = invocationInfo.FragmentMethodModel.CompositeMethod;
            }
            else if (typeof(AbstractFragmentMethodModel).IsAssignableFrom(targetType))
            {
                result = invocationInfo.FragmentMethodModel;
            }
            else
            {
                AttributeHolder holder = instance.ModelInfo.CompositeMethodAttributeHolders[invocationInfo.FragmentMethodModel.CompositeMethod.MethodIndex];
                if (typeof(Attribute).IsAssignableFrom(targetType))
                {
                    ListQuery <Attribute> list;
                    holder.AllAttributes.TryFindInTypeDictionarySearchBottommostType(targetType, out list);
                    result = list.FirstOrDefault();
                }
                else // target type must be attribute holder
                {
                    result = holder;
                }
            }

            return(result);
        }
コード例 #5
0
        public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
        {
            Object retVal;

            instance.Composites.TryGetValue(targetType, out retVal);
            return(retVal);
        }
コード例 #6
0
ファイル: InjectionContext.cs プロジェクト: attila3453/alsing
 // For mixins
 //[DebuggerStepThrough]
 ////[DebuggerHidden]
 public InjectionContext(CompositeInstance compositeInstance, UsesInstance uses, StateHolder state)
 {
     this.CompositeInstance = compositeInstance;
     this.ModuleInstance = compositeInstance.ModuleInstance;
     this.Uses = uses;
     this.State = state;
     this.Next = null;
     this.ProxyHandler = null;
 }
コード例 #7
0
 // For mixins
 //[DebuggerStepThrough]
 ////[DebuggerHidden]
 public InjectionContext(CompositeInstance compositeInstance, UsesInstance uses, StateHolder state)
 {
     this.CompositeInstance = compositeInstance;
     this.ModuleInstance    = compositeInstance.ModuleInstance;
     this.Uses         = uses;
     this.State        = state;
     this.Next         = null;
     this.ProxyHandler = null;
 }
コード例 #8
0
ファイル: MixinsModel.cs プロジェクト: attila3453/alsing
 //[DebuggerStepThrough]
 ////[DebuggerHidden]
 public void NewMixins(CompositeInstance compositeInstance, UsesInstance uses, StateHolder stateHolder, object[] mixins)
 {
     int i = 0;
     foreach (MixinModel mixinModel in this.mixinModels)
     {
         object mixin = mixinModel.NewInstance(compositeInstance, stateHolder, uses);
         mixins[i++] = mixin;
     }
 }
コード例 #9
0
        //[DebuggerStepThrough]
        ////[DebuggerHidden]
        public void NewMixins(CompositeInstance compositeInstance, UsesInstance uses, StateHolder stateHolder, object[] mixins)
        {
            int i = 0;

            foreach (MixinModel mixinModel in this.mixinModels)
            {
                object mixin = mixinModel.NewInstance(compositeInstance, stateHolder, uses);
                mixins[i++] = mixin;
            }
        }
コード例 #10
0
        //[DebuggerStepThrough]
        ////[DebuggerHidden]
        public object Invoke(object proxy, MethodInfo method, object[] args)
        {
            if (method.Name == "ToString")
            {
                return(this.owner.ServiceModel.ToString());
            }
            CompositeInstance instance = this.owner.GetInstance();

            return(instance.Invoke(proxy, method, args));
        }
コード例 #11
0
        public T NewInstance()
        {
            StateHolder instanceState = this.state == null?this.transientModel.NewInitialState() : this.transientModel.NewState(this.state);

            this.transientModel.State.CheckConstraints(instanceState);

            CompositeInstance compositeInstance = this.transientModel.NewCompositeInstance(this.moduleInstance, this.uses ?? UsesInstance.NoUses, instanceState);

            return((T)compositeInstance.Proxy);
        }
コード例 #12
0
        public K PrototypeFor <K>()
        {
            // Instantiate given value type
            if (this.prototypeInstance == null)
            {
                this.prototypeInstance = this.transientModel.NewCompositeInstance(this.moduleInstance, this.Uses, this.State);
            }

            return((K)this.prototypeInstance.NewProxy(typeof(K)));
        }
コード例 #13
0
        public T Prototype()
        {
            // Instantiate proxy for given composite interface

            if (this.prototypeInstance == null)
            {
                this.prototypeInstance = this.transientModel.NewCompositeInstance(this.moduleInstance, this.Uses, this.State);
            }

            return((T)this.prototypeInstance.Proxy);
        }
コード例 #14
0
        public virtual CompositeInstance GetCompositeInstance(Object compositeOrFragment)
        {
            ArgumentValidator.ValidateNotNull("Composite or fragment", compositeOrFragment);
            CompositeInstance instance = null;

            this._compositeModelTypeSupport.Values.FirstOrDefault(support => support.TryGetInstanceFromCompositeOrFragment(compositeOrFragment, out instance));
            if (instance == null)
            {
                throw new ArgumentException("Given argument " + compositeOrFragment + " is not valid composite or fragment.");
            }
            return(instance);
        }
コード例 #15
0
        public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
        {
            var    scope = model.InjectionScope;
            Object result;

            if (typeof(CompositeState).IsAssignableFrom(targetType))
            {
                result = instance.State;
            }
            else
            {
                var attribute           = (StateAttribute)scope;
                var isCompositeProperty = typeof(CompositeProperty).IsAssignableFrom(targetType);
                var prop = this.FindSuitable <CompositeProperty, PropertyInfo>(
                    instance.State.Properties.Values,
                    attribute.DeclaringType,
                    attribute.ElementName,
                    GetActualTargetType <CompositeProperty>(targetType),
                    cProp => cProp.ReflectionInfo,
                    pInfo => pInfo.PropertyType
                    );
                if (prop != null)
                {
                    result = isCompositeProperty ? prop : prop.PropertyValueAsObject;
                }
                else
                {
                    var isCompositeEvent = typeof(CompositeEvent).IsAssignableFrom(targetType);
                    var evt = this.FindSuitable <CompositeEvent, EventInfo>(
                        instance.State.Events.Values,
                        attribute.DeclaringType,
                        attribute.ElementName,
                        GetActualTargetType <CompositeEvent>(targetType),
                        cEvent => cEvent.ReflectionInfo,
                        eventInfo => eventInfo.EventHandlerType
                        );
                    if (evt != null)
                    {
                        result = isCompositeEvent ? evt : evt.InvokeActionAsObject;
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
コード例 #16
0
        public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
        {
            KeyedRoleMap roleMap = RoleMapHolder.INVOCATION_DATA.Value.RoleMap;
            Object       result;

            if (roleMap.ThisHasRole(targetType))
            {
                result = roleMap.Get <Object>(targetType);
            }
            else
            {
                FunctionInvocationDataAttribute attr = (FunctionInvocationDataAttribute)model.InjectionScope;
                result = attr.GetFactory(targetType).NewInvocationData();
                roleMap.Set(result);
            }
            return(result);
        }
コード例 #17
0
    /// <summary>
    /// Gets reference to composite of given type.
    /// </summary>
    /// <param name="instance">The <see cref="CompositeInstance"/>.</param>
    /// <param name="compositeType">The type of the composite. If it is <see cref="Object"/>, then composite reference of one of the public types is returned.</param>
    /// <returns>The reference to composite of type <paramref name="compositeType"/>.</returns>
    /// <exception cref="NullReferenceException">If <paramref name="instance"/> is <c>null</c>.</exception>
    /// <exception cref="ArgumentNullException">If <paramref name="compositeType"/> is <c>null</c>.</exception>
    /// <exception cref="ArgumentException">If composite of given type is not found.</exception>
    public static Object GetCompositeForType(this CompositeInstance instance, Type compositeType)
    {
        ArgumentValidator.ValidateNotNull("Composite type", compositeType);
        Object result;

        if (Object.Equals(typeof(Object), compositeType))
        {
            result = instance.Composites.Values.FirstOrDefault(composite => instance.ModelInfo.Model.PublicTypes.Any(pType => pType.GetGenericDefinitionIfContainsGenericParameters().IsAssignableFrom_IgnoreGenericArgumentsForGenericTypes(composite.GetType())));
        }
        else
        {
            instance.Composites.TryGetValue(compositeType, out result);
        }
        if (result == null)
        {
            throw new ArgumentException("Did not found composites of type " + compositeType + ".");
        }
        return(result);
    }
コード例 #18
0
        public object ProvideInjection(InjectionContext context, InjectionAttribute attribute, Type fieldType)
        {
            object obj = context.Uses.UseForType(fieldType);

            if (obj != null)
            {
                return(obj);
            }

            ModuleInstance moduleInstance = context.ModuleInstance;

            TransientFinder compositeFinder = moduleInstance.FindCompositeModel(fieldType);

            if (compositeFinder.Model != null)
            {
                CompositeInstance compositeInstance = compositeFinder.Model.NewCompositeInstance(moduleInstance, context.Uses, context.State);
                context.Uses.Use(compositeInstance);
                return(compositeInstance.Proxy);
            }

            return(null);
        }
コード例 #19
0
        /**
         * <summary>Generates a single classification instance of the WSD problem for the given word of the given sentence. If the
         * word has not been labeled with sense tag yet, the method returns null. In the WSD problem, the system also
         * generates and stores all possible sense labels for the current instance. In this case, a classification
         * instance will not have all labels in the dataset, but some subset of it.</summary>
         * <param name="sentence">Input sentence.</param>
         * <param name="wordIndex">The index of the word in the sentence.</param>
         * <returns>Classification instance.</returns>
         */
        public override Instance GenerateInstanceFromSentence(Sentence sentence, int wordIndex)
        {
            var possibleSynSets =
                ((AnnotatedSentence.AnnotatedSentence)sentence).ConstructSynSets(_wordNet, _fsm, wordIndex);
            var word       = (AnnotatedWord)sentence.GetWord(wordIndex);
            var classLabel = word.GetSemantic();

            if (classLabel == null || possibleSynSets.Count == 0)
            {
                return(null);
            }

            var current             = new CompositeInstance(classLabel);
            var possibleClassLabels = new List <string>();

            foreach (var synSet in possibleSynSets)
            {
                possibleClassLabels.Add(synSet.GetId());
            }

            current.SetPossibleClassLabels(possibleClassLabels);
            AddAttributes(current, sentence, wordIndex);
            return(current);
        }
コード例 #20
0
 public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
 {
     return(_holder == null ? _holder2 : _holder);
 }
コード例 #21
0
        public virtual Boolean TryGetInstanceFromCompositeOrFragment(Object composite, out CompositeInstance instance)
        {
            var cType       = composite.GetType();
            var codeGenInfo = this._modelScopeSupport.CodeGenerationInfo;
            var result      = cType.GetAssembly().GetCustomAttributes( ).OfType <Qi4CSGeneratedAssemblyAttribute>().Any();

            if (result)
            {
                var field = composite.GetType()
#if WINDOWS_PHONE_APP
                            .GetTypeInfo().GetDeclaredField(codeGenInfo.CompositeInstanceFieldName)
#else
                            .GetField(codeGenInfo.CompositeInstanceFieldName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly)
#endif
                ;
                result = field != null;
                if (result && codeGenInfo.CompositeInstanceFieldType.IsAssignableFrom(field.FieldType))
                {
                    instance = (CompositeInstance)field.GetValue(composite);
                }
                else
                {
                    instance = null;
                }
            }
            else
            {
                instance = null;
            }
            return(result);
        }
コード例 #22
0
 //[DebuggerStepThrough]
 ////[DebuggerHidden]
 public object Invoke(MixinsInstance mixins, CompositeInstance compositeInstance, object proxy, MethodInfo method, object[] args, ModuleInstance moduleInstance)
 {
     return this.compositeMethodsModel.Invoke(mixins, proxy, method, args, moduleInstance);
 }
コード例 #23
0
 /// <summary>
 /// Gets reference to composite of given type, when type is known at compile time.
 /// </summary>
 /// <typeparam name="TComposite">The type of the composite referece.</typeparam>
 /// <param name="instance">The <see cref="CompositeInstance"/>.</param>
 /// <returns>The reference to composite of type <typeparamref name="TComposite"/>, when type is known at compile time.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="instance"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">If composite of given type is not found.</exception>
 public static TComposite GetCompositeForType <TComposite>(this CompositeInstance instance)
 {
     return((TComposite)GetCompositeForType(instance, typeof(TComposite)));
 }
コード例 #24
0
        /// <summary>
        /// Creates a new instance of <see cref="CompositeModelInstantiationArgs"/>.
        /// </summary>
        /// <param name="instance">The <see cref="CompositeInstance"/> of the composite that was instantiated.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="instance"/> is <c>null</c>.</exception>
        public CompositeModelInstantiationArgs(CompositeInstance instance)
        {
            ArgumentValidator.ValidateNotNull("Composite instance", instance);

            this._instance = instance;
        }
コード例 #25
0
 public Object ProvideInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
 {
     return(((CompositeInstanceImpl)instance).CreateOrGetConcernInvocationBase(targetType));
 }
コード例 #26
0
        /// <summary>
        /// Creates a new instance of <see cref="ServiceActivationArgs"/>.
        /// </summary>
        /// <param name="service">The <see cref="CompositeInstance"/> of the service composite.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <c>null</c>.</exception>
        public ServiceActivationArgs(CompositeInstance service)
        {
            ArgumentValidator.ValidateNotNull("Service", service);

            this._service = service;
        }
コード例 #27
0
        /**
         * <summary> Constructor for generating a new {@link DataSet} from given {@link File}.</summary>
         *
         * <param name="file">{@link File} to generate {@link DataSet} from.</param>
         */
        public DataSet(string fileName)
        {
            var i = 0;

            _instances  = new InstanceList.InstanceList();
            _definition = new DataDefinition();
            var input = new StreamReader(fileName);

            while (!input.EndOfStream)
            {
                var instanceText = input.ReadLine();
                var attributes   = instanceText.Split(",");
                if (i == 0)
                {
                    for (var j = 0; j < attributes.Length - 1; j++)
                    {
                        try
                        {
                            double.Parse(attributes[j]);
                            _definition.AddAttribute(AttributeType.CONTINUOUS);
                        }
                        catch (Exception)
                        {
                            _definition.AddAttribute(AttributeType.DISCRETE);
                        }
                    }
                }
                else
                {
                    if (attributes.Length != _definition.AttributeCount() + 1)
                    {
                        continue;
                    }
                }

                Instance.Instance instance;
                if (!attributes[attributes.Length - 1].Contains(";"))
                {
                    instance = new Instance.Instance(attributes[attributes.Length - 1]);
                }
                else
                {
                    var labels = attributes[attributes.Length - 1].Split(";");
                    instance = new CompositeInstance(labels);
                }

                for (var j = 0; j < attributes.Length - 1; j++)
                {
                    switch (_definition.GetAttributeType(j))
                    {
                    case AttributeType.CONTINUOUS:
                        instance.AddAttribute(new ContinuousAttribute(double.Parse(attributes[j])));
                        break;

                    case AttributeType.DISCRETE:
                        instance.AddAttribute(new DiscreteAttribute(attributes[j]));
                        break;
                    }
                }

                if (instance.AttributeSize() == _definition.AttributeCount())
                {
                    _instances.Add(instance);
                }

                i++;
            }

            input.Close();
        }
 protected override SPI.Instance.StructureServiceProviderSPI GetStructureServiceProvider(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
 {
     return(((SingletonApplication)instance.StructureOwner).StructureServices);
 }
コード例 #29
0
ファイル: MixinModel.cs プロジェクト: attila3453/alsing
 public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder)
 {
     return this.NewInstance(compositeInstance, stateHolder, UsesInstance.NoUses);
 }
コード例 #30
0
ファイル: MixinModel.cs プロジェクト: attila3453/alsing
 //[DebuggerStepThrough]
 ////[DebuggerHidden]
 public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder, UsesInstance uses)
 {
     var injectionContext = new InjectionContext(compositeInstance, uses, stateHolder);
     object mixin = this.injectedObjectBuilder.NewInstance(injectionContext);
     return mixin;
 }
コード例 #31
0
 internal void InvokeAfterPassivation(CompositeInstance instance)
 {
     this.AfterPassivation.InvokeEventIfNotNull(evt => evt(this, new ServiceActivationArgs(instance)));
 }
コード例 #32
0
 protected abstract StructureServiceProviderSPI GetStructureServiceProvider(CompositeInstance instance, AbstractInjectableModel model, Type targetType);
コード例 #33
0
 public object NewInstance(CompositeInstance compositeInstance, StateHolder stateHolder)
 {
     return(this.NewInstance(compositeInstance, stateHolder, UsesInstance.NoUses));
 }
コード例 #34
0
 protected virtual Object ProvideNonStandardInjection(CompositeInstance instance, AbstractInjectableModel model, Type targetType)
 {
     return(null);
 }
コード例 #35
0
 internal void InvokeCompositeInstantiated(CompositeInstance instance)
 {
     this.CompositeInstantiated.InvokeEventIfNotNull(evt => evt(this, new CompositeModelInstantiationArgs(instance)));
 }