/// <summary>
    /// 取得該語言的內容
    /// </summary>
    /// <param name="object">抓取的物件</param>
    /// <param name="fieldNamePrefix">抓取欄位的名稱(不包含Language的字,預設中文是沒有lng的字眼)</param>
    /// <returns></returns>
    public string GetContent(object obj, string fieldNamePrefix)
    {
        string content = string.Empty;
        string fieldName = fieldNamePrefix;
        if (!WebLanguageUtil.Language.Cht.ToString().Equals(m_SessionHelper.FrontLanguage))
        {
            fieldName += m_SessionHelper.FrontLanguage.ToUpper();
        }
        m_Log.Info("取得內容的欄位:" + fieldName);

        try
        {
            ObjectWrapper ow = new ObjectWrapper(obj);
            object value = ow.GetPropertyValue(fieldName);
            if (value != null)
            {
                content = value.ToString();
            }
        }
        catch (Exception ex)
        {
            m_Log.Debug(ex);
        }

        return content;
    }
        public static object ToDictionary(object input)
        {
            if (input == null)
                return null;

            var inputType = input.GetType();

            if (IsAtomic(inputType))
                return input;

            if (IsEnumerable(inputType))
            {
                var enumerable = input as IEnumerable<object>;
                if (enumerable == null)
                    return null;

                return new EnumerableWrapper(inputType.Name, input, enumerable.Select(ToDictionary));
            }            

            var namedDictionary = new ObjectWrapper(inputType.Name, input);

            var fields = inputType.GetFields(DefaultBindingFlags)
                .Select(x => new
                {
                    x.Name,
                    Value = x.GetValue(input)
                })
                /*.OrderBy(x => x.Name)*/;

            var properties = inputType.GetProperties(DefaultBindingFlags)
                .Select(x => new
                {
                    x.Name,
                    Value = x.GetValue(input)
                })
                /*.OrderBy(x => x.Name)*/;

            foreach (var field in fields)
                namedDictionary.Add(field.Name, ToDictionary(field.Value));

            foreach (var property in properties)
                namedDictionary.Add(property.Name, ToDictionary(property.Value));

            return namedDictionary;
        }
Example #3
0
        //This example reads player stats in Dark Souls 1 using JMemLib
        static void Main()
        {
            Console.WriteLine("JMemLib Example 1");
            Console.WriteLine("Dark Souls Stat Reader");

            Process darkSoulsProcess = null;
            while (darkSoulsProcess == null)
            {
                Process[] processes = Process.GetProcessesByName("DARKSOULS");
                if (processes.Length < 1) continue;
                darkSoulsProcess = processes[0];
            }

            IntPtr handle = Native.GetHandle(Native.PROCESS_VM_READ, darkSoulsProcess.Id);

            int baseAddress = (int)darkSoulsProcess.MainModule.BaseAddress + BaseOffset;

            Pointer gameBasePointer = new Pointer(baseAddress, handle);

            int playerBaseAddress = 0;

            //If playerBaseAddress is 0 then were not ingame
            while (playerBaseAddress == 0)
            {
                byte[] bytes = gameBasePointer.ReadByteArray(4, PlayerBaseOffset);
                playerBaseAddress = BitConverter.ToInt32(bytes, 0);
            }

            Pointer playerBasePointer = new Pointer(playerBaseAddress, handle);

            for (int i = 0; i < Stats.Length; i++)
            {
                int index = i;
                ObjectWrapper wrapper = new ObjectWrapper();
                wrapper.PropertyChanged += (sender, args) =>
                {
                    byte[] value = (byte[]) wrapper.GetValue();
                    Console.WriteLine(Stats[index] + ": " + BitConverter.ToInt32(value, 0));
                };
                playerBasePointer.ReadListener(4, new []{Offsets[i]}, true, wrapper);
            }

            Console.Read();
        }
Example #4
0
 static Navigator()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.Navigator o) =>
                                          new Navigator(o));
 }
        /// <summary>
        /// Resolves the <see cref="Spring.Objects.Factory.Config.ConstructorArgumentValues"/>
        /// of the supplied <paramref name="definition"/>.
        /// </summary>
        /// <param name="objectName">The name of the object that is being resolved by this factory.</param>
        /// <param name="definition">The rod.</param>
        /// <param name="wrapper">The wrapper.</param>
        /// <param name="cargs">The cargs.</param>
        /// <param name="resolvedValues">Where the resolved constructor arguments will be placed.</param>
        /// <returns>
        /// The minimum number of arguments that any constructor for the supplied
        /// <paramref name="definition"/> must have.
        /// </returns>
        /// <remarks>
        /// 	<p>
        /// 'Resolve' can be taken to mean that all of the <paramref name="definition"/>s
        /// constructor arguments is resolved into a concrete object that can be plugged
        /// into one of the <paramref name="definition"/>s constructors. Runtime object
        /// references to other objects in this (or a parent) factory are resolved,
        /// type conversion is performed, etc.
        /// </p>
        /// 	<p>
        /// These resolved values are plugged into the supplied
        /// <paramref name="resolvedValues"/> object, because we wouldn't want to touch
        /// the <paramref name="definition"/>s constructor arguments in case it (or any of
        /// its constructor arguments) is a prototype object definition.
        /// </p>
        /// 	<p>
        /// This method is also used for handling invocations of static factory methods.
        /// </p>
        /// </remarks>
        private int ResolveConstructorArguments(string objectName, RootObjectDefinition definition, ObjectWrapper wrapper,
                                                ConstructorArgumentValues cargs,
                                                ConstructorArgumentValues resolvedValues)
        {
//            ObjectDefinitionValueResolver valueResolver = new ObjectDefinitionValueResolver(objectFactory);
            int minNrOfArgs = cargs.ArgumentCount;

            foreach (KeyValuePair<int, ConstructorArgumentValues.ValueHolder> entry in cargs.IndexedArgumentValues)
            {
                int index = Convert.ToInt32(entry.Key);
                if (index < 0)
                {
                    throw new ObjectCreationException(definition.ResourceDescription, objectName,
                                                      "Invalid constructor agrument index: " + index);
                }
                if (index > minNrOfArgs)
                {
                    minNrOfArgs = index + 1;
                }
                ConstructorArgumentValues.ValueHolder valueHolder = entry.Value;
                string argName = "constructor argument with index " + index;
                object resolvedValue =
                    valueResolver.ResolveValueIfNecessary(objectName, definition, argName, valueHolder.Value);
                resolvedValues.AddIndexedArgumentValue(index, resolvedValue,
                                                       StringUtils.HasText(valueHolder.Type)
                                                           ? TypeResolutionUtils.ResolveType(valueHolder.Type).
                                                                 AssemblyQualifiedName
                                                           : null);
            }

            foreach (ConstructorArgumentValues.ValueHolder valueHolder in definition.ConstructorArgumentValues.GenericArgumentValues)
            {
                string argName = "constructor argument";
                object resolvedValue =
                    valueResolver.ResolveValueIfNecessary(objectName, definition, argName, valueHolder.Value);
                resolvedValues.AddGenericArgumentValue(resolvedValue,
                                                       StringUtils.HasText(valueHolder.Type)
                                                           ? TypeResolutionUtils.ResolveType(valueHolder.Type).
                                                                 AssemblyQualifiedName
                                                           : null);
            }
            foreach (KeyValuePair<string, object> namedArgumentEntry in definition.ConstructorArgumentValues.NamedArgumentValues)
            {
                string argumentName = namedArgumentEntry.Key;
                string syntheticArgumentName = "constructor argument with name " + argumentName;
                ConstructorArgumentValues.ValueHolder valueHolder =
                    (ConstructorArgumentValues.ValueHolder)namedArgumentEntry.Value;
                object resolvedValue =
                    valueResolver.ResolveValueIfNecessary(objectName, definition, syntheticArgumentName, valueHolder.Value);
                resolvedValues.AddNamedArgumentValue(argumentName, resolvedValue);
            }
            return minNrOfArgs;
        }
		/// <summary>
		/// Return an instance (possibly shared or independent) of the object
		/// managed by this factory.
		/// </summary>
		/// <returns>
		/// An instance (possibly shared or independent) of the object managed by
		/// this factory.
		/// </returns>
		/// <see cref="Spring.Objects.Factory.IFactoryObject.GetObject()"/>
		public object GetObject()
		{
			IObjectWrapper target = this.targetObjectWrapper;
			if (target == null)
			{
				// fetch the prototype object object...
				target = new ObjectWrapper(this.objectFactory[this.targetObjectName]);
			}
			object value = target.GetPropertyValue(this.propertyPath);
			if (value == null)
			{
				throw new FatalObjectException("PropertyPathFactoryObject is not allowed to return null, " +
					"but property value for path '" + this.propertyPath + "' is null.");
			}
			return value;
		}
Example #7
0
            public static ObjectWrapper AddObject(Region r, int depth, ObjectWrapper Parent)
            {

                if (r.size >= regionSizeMB * 1024 * 1024 || depth>maxDepth)
                    return null;
                byte[] Temp = new byte[Rand.Next(50, 200)];
                int size = Rand.Next(r.minObjectSize, r.maxObjectsize);
               
                bool pinned = false;
                if ((r.pinnedCount * 100.0 / (double)r.objectCount) < r.pinnedPercentage)
                {
                    pinned = true;
                    r.pinnedCount++;
                }
                int randNumber = Rand.Next(0, 20);
                bool arrayrefs = false;
                if (randNumber == 1)
                    arrayrefs = true;
                int references = Rand.Next(0, 3);
                int arrayrefCount = 0;
                if (arrayrefs)
                {
                    arrayrefCount = Rand.Next(10, 100);
                    references = Rand.Next(3, arrayrefCount);
                }


                ObjectWrapper ow = new ObjectWrapper(size, pinned, references, arrayrefs, arrayrefCount, depth);
                if (randNumber == 7)
                    ow.parent = Parent;

                if (!arrayrefs) //object has up to 3 references to other objects
                {
                    if (references > 0)
                    {
                        ow.ref1 = AddObject(r, ow.depth+1, ow);
                    }
                    if (references > 1)
                    {
                        ow.ref2 = AddObject(r, ow.depth + 1, ow);
                    }
                    if (references > 2)
                    {
                        ow.ref3 = AddObject(r, ow.depth + 1, ow);
                    }
                }
                else  //object has an array of references
                {
                    for (int i = 0; i < arrayrefCount; i++)
                    {
                        ow.arrayRefs[i] = AddObject(r, depth+1, ow);
                    }
                }
                r.size += size;


                int spaceSize = Rand.Next(r.minSpaceSize, r.maxSpaceSize);
                r.Spaces.Add(new byte[spaceSize]);

                r.size += spaceSize;
                r.objectCount++;
                EstimatedObjectCount++;
                EstimatedHeapSize += size;
                return ow;
            }
Example #8
0
        public static void PickObject(List<ObjectWrapper> Arr, int index)
        {
            ClearVisitedFlag(Arr);
            staticObject=null;
            staticIndex = 0;
            for (int i = 0; i < Arr.Count; i++)
            {
                //Console.WriteLine("in Arr, pos=" + i);
                if (staticObject != null)
                    return;
               // Console.WriteLine("now pick object in Arr, pos=" + i);
                 PickObject(Arr[i], index);
            }

            for (int i = 0; i < staticArr.Count; i++)
            {
               // Console.WriteLine("in staticArr, pos=" + i);
                if (staticObject != null)
                    return;
               // Console.WriteLine("now pick object in static Arr, pos=" + i);
                 PickObject(staticArr[i], index);
            }
        }
Example #9
0
// Generating method code for item
        public virtual NHtmlUnit.Javascript.Host.File.File Item(int index)
        {
            var arg = WObj.item(index);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Javascript.Host.File.File>(arg));
        }
Example #10
0
 static FileList()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.file.FileList o) =>
                                          new FileList(o));
 }
// Generating method code for getClassConfiguration
        public virtual NHtmlUnit.Javascript.Configuration.ClassConfiguration GetClassConfiguration(string hostClassName)
        {
            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Javascript.Configuration.ClassConfiguration>(WObj.getClassConfiguration(hostClassName)));
        }
 static AbstractJavaScriptConfiguration()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration o) =>
                                          new AbstractJavaScriptConfiguration(o));
 }
Example #13
0
 static DOMStringMap()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.dom.DOMStringMap o) =>
                                          new DOMStringMap(o));
 }
Example #14
0
 static SharedWorker()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.SharedWorker o) =>
                                          new SharedWorker(o));
 }
 static PresentationAvailability()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.media.presentation.PresentationAvailability o) =>
                                          new PresentationAvailability(o));
 }
    /// <summary>
    /// 取得該語言的內容
    /// </summary>
    /// <param name="object">抓取的物件</param>
    /// <param name="fieldNamePrefix">抓取欄位的名稱(不包含Language的字,預設中文是沒有lng的字眼)</param>
    /// <param name="dateFormate">日期格式</param>
    /// <returns></returns>
    public string GetDateContent(object obj, string fieldName, string dateFormate)
    {
        string content = string.Empty;
        m_Log.Info("取得內容的欄位:" + fieldName);

        try
        {
            ObjectWrapper ow = new ObjectWrapper(obj);
            object value = ow.GetPropertyValue(fieldName);
            //預設日期格式
            if (string.IsNullOrEmpty(dateFormate))
            {
                dateFormate = "MMMM dd, yyyy";
            }

            if (value != null)
            {
                //只有日期欄位才做
                if (ow.GetPropertyType(fieldName) == typeof(DateTime) || ow.GetPropertyType(fieldName) == typeof(DateTime?))
                {
                    //中文格式一種,其他語言一種,目前是兩個都設定一樣
                    if (WebLanguageUtil.Language.Cht.ToString().Equals(m_SessionHelper.FrontLanguage))
                    {
                        DateTime dateTime = (DateTime)value;
                        content = dateTime.ToString(dateFormate, new System.Globalization.CultureInfo("en-us"));
                        //content = dateTime.ToString(dateFormate, new System.Globalization.CultureInfo("zh-tw"));
                    }
                    else
                    {
                        DateTime dateTime = (DateTime)value;
                        content = dateTime.ToString(dateFormate, new System.Globalization.CultureInfo("en-us"));
                    }
                }
                //else if (ow.GetPropertyType(fieldName) == typeof(DateTime?))
                //{
                //}
            }
        }
        catch (Exception ex)
        {
            m_Log.Debug(ex);
        }

        return content;
    }
Example #17
0
 static SvgFePointLight()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.svg.SvgFePointLight o) =>
                                          new SvgFePointLight(o));
 }
		public SignalEventArgs (ObjectWrapper wrapper, Signal signal): base (wrapper)
		{
			this.signal = signal;
		}
Example #19
0
// Generating method code for getCellAt
        public virtual NHtmlUnit.Html.HtmlTableCell GetCellAt(int rowIndex, int columnIndex)
        {
            var arg = WObj.getCellAt(rowIndex, columnIndex);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Html.HtmlTableCell>(arg));
        }
Example #20
0
        public static void ClearVisitedFlag(ObjectWrapper o)
        {
            if (!o.visited)
            {
                return;
            }
            else
                o.visited = false;

            if (o.ref1 != null)
                ClearVisitedFlag(o.ref1);
            if (o.ref2 != null)
                ClearVisitedFlag(o.ref2);
            if (o.ref3 != null)
                ClearVisitedFlag(o.ref3);
            if (o.arrayRefs != null)
            {
                for (int i = 0; i < o.arrayRefs.Length; i++)
                {
                    if (o.arrayRefs[i] != null)
                    {
                        ClearVisitedFlag(o.arrayRefs[i]);
                    }
                }
            }
           
        }
Example #21
0
// Generating method code for getRow
        public virtual NHtmlUnit.Html.HtmlTableRow GetRow(int index)
        {
            var arg = WObj.getRow(index);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Html.HtmlTableRow>(arg));
        }
Example #22
0
        /*
        static void AddReference(ObjectWrapper parent, ObjectWrapper child)
        {
            //find an empty position to add a reference in the parent
            //else use a random position
            int position = GetRandomNumber(maxRef);
            for (int i = 0; i < maxRef; i++)
            {
                if (parent.objRef[i] == null)
                {
                    position = i;
                    break;
                }
            }

            parent.objRef[position] = child;

        }
         * */

        public static int Main(string[] args)
        {
            //            if (Environment.Is64BitProcess)
            pointerSize = 8;

            stopWatch.Start();

            for (int i = 0; i < 3; i++)
            {
                currentCollections[i] = 0;
            }

            if (!ParseArgs(args))
                return 101;
            dummyObject = new ObjectWrapper(0, 0, true, 0);

            objectCollection = new ObjArray();
            objectCollection.Init(objCount);
            //One thread is in charge of updating the object age
            Thread thrd = new Thread(UpdateObjectAge);
            thrd.Start();
            //another thread is removing expired objects
            Thread thrd2 = new Thread(RemoveExpiredObjects);
            thrd2.Start();
            //another thread is removing weak references to dead objects
            Thread thrd3 = new Thread(RemoveWeakReferences);
            thrd3.Start();

            // Run the test.
            for (int i = 0; i < numThreads; ++i)
            {
                Thread thread = new Thread(RunTest);


                threadList.Add(thread);
                thread.Start(i);
            }

            foreach (Thread t in threadList)
            {
                t.Join();
            }
            testDone = true;

            return 100;
        }
Example #23
0
// Generating method code for getRowById
        public virtual NHtmlUnit.Html.HtmlTableRow GetRowById(string id)
        {
            var arg = WObj.getRowById(id);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Html.HtmlTableRow>(arg));
        }
Example #24
0
		protected void GenerateSetPacking (GeneratorContext ctx, CodeExpression parentVar, CodeExpression childVar, ObjectWrapper containerChildWrapper)
		{
			Gtk.Container.ContainerChild cc = containerChildWrapper.Wrapped as Gtk.Container.ContainerChild;
			ClassDescriptor klass = containerChildWrapper.ClassDescriptor;
			
			// Generate a variable that holds the container child
			
			string contChildVar = ctx.NewId ();
			CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (cc.GetType().ToGlobalTypeRef (), contChildVar);
			varDec.InitExpression = new CodeCastExpression ( 
				cc.GetType ().ToGlobalTypeRef (),
				new CodeIndexerExpression (parentVar, childVar)
			);
			
			CodeVariableReferenceExpression var = new CodeVariableReferenceExpression (contChildVar);
			
			// Set the container child properties

			ctx.Statements.Add (varDec);
			int count = ctx.Statements.Count;
			
			foreach (ItemGroup group in klass.ItemGroups) {
				foreach (ItemDescriptor item in group) {
					PropertyDescriptor prop = item as PropertyDescriptor;
					if (prop == null || !prop.IsRuntimeProperty)
						continue;
					GenerateChildPropertySet (ctx, var, klass, prop, cc);
				}
			}
			
			if (ctx.Statements.Count == count) {
				ctx.Statements.Remove (varDec);
			}
		}
Example #25
0
 static CustomEvent()
 {
     ObjectWrapper.RegisterWrapperCreator(([email protected] o) =>
                                          new CustomEvent(o));
 }
        /// <summary>
        /// Instantiate an object instance using a named factory method.
        /// </summary>
        /// <remarks>
        /// <p>
        /// The method may be static, if the <paramref name="definition"/>
        /// parameter specifies a class, rather than a
        /// <see cref="Spring.Objects.Factory.IFactoryObject"/> instance, or an
        /// instance variable on a factory object itself configured using Dependency
        /// Injection.
        /// </p>
        /// <p>
        /// Implementation requires iterating over the static or instance methods
        /// with the name specified in the supplied <paramref name="definition"/>
        /// (the method may be overloaded) and trying to match with the parameters.
        /// We don't have the types attached to constructor args, so trial and error
        /// is the only way to go here.
        /// </p>
        /// </remarks>
        /// <param name="name">
        /// The name associated with the supplied <paramref name="definition"/>.
        /// </param>
        /// <param name="definition">
        /// The definition describing the instance that is to be instantiated.
        /// </param>
        /// <param name="arguments">
        /// Any arguments to the factory method that is to be invoked.
        /// </param>
        /// <returns>
        /// The result of the factory method invocation (the instance).
        /// </returns>
        public virtual IObjectWrapper InstantiateUsingFactoryMethod(string name, RootObjectDefinition definition, object[] arguments)
        {
            ObjectWrapper wrapper = new ObjectWrapper();
            Type factoryClass = null;
            bool isStatic = true;


            ConstructorArgumentValues cargs = definition.ConstructorArgumentValues;
            ConstructorArgumentValues resolvedValues = new ConstructorArgumentValues();
            int expectedArgCount = 0;

            // we don't have arguments passed in programmatically, so we need to resolve the
            // arguments specified in the constructor arguments held in the object definition...
            if (arguments == null || arguments.Length == 0)
            {
                expectedArgCount = cargs.ArgumentCount;
                ResolveConstructorArguments(name, definition, wrapper, cargs, resolvedValues);
            }
            else
            {
                // if we have constructor args, don't need to resolve them...
                expectedArgCount = arguments.Length;
            }


            if (StringUtils.HasText(definition.FactoryObjectName))
            {
                // it's an instance method on the factory object's class...
                factoryClass = objectFactory.GetObject(definition.FactoryObjectName).GetType();
                isStatic = false;
            }
            else
            {
                // it's a static factory method on the object class...
                factoryClass = definition.ObjectType;
            }

            GenericArgumentsHolder genericArgsInfo = new GenericArgumentsHolder(definition.FactoryMethodName);
            IList<MethodInfo> factoryMethodCandidates = FindMethods(genericArgsInfo.GenericMethodName, expectedArgCount, isStatic, factoryClass);

            bool autowiring = (definition.AutowireMode == AutoWiringMode.Constructor);

            // try all matching methods to see if they match the constructor arguments...
            for (int i = 0; i < factoryMethodCandidates.Count; i++)
            {
                MethodInfo factoryMethodCandidate = factoryMethodCandidates[i];
                if (genericArgsInfo.ContainsGenericArguments)
                {
                    string[] unresolvedGenericArgs = genericArgsInfo.GetGenericArguments();
                    if (factoryMethodCandidate.GetGenericArguments().Length != unresolvedGenericArgs.Length)
                        continue;

                    Type[] paramTypes = new Type[unresolvedGenericArgs.Length];
                    for (int j = 0; j < unresolvedGenericArgs.Length; j++)
                    {
                        paramTypes[j] = TypeResolutionUtils.ResolveType(unresolvedGenericArgs[j]);
                    }
                    factoryMethodCandidate = factoryMethodCandidate.MakeGenericMethod(paramTypes);
                }
                if (arguments == null || arguments.Length == 0)
                {
                    Type[] paramTypes = ReflectionUtils.GetParameterTypes(factoryMethodCandidate.GetParameters());
                    // try to create the required arguments...
                    UnsatisfiedDependencyExceptionData unsatisfiedDependencyExceptionData = null;
                    ArgumentsHolder args = CreateArgumentArray(name, definition, resolvedValues, wrapper, paramTypes,
                                                               factoryMethodCandidate, autowiring, out unsatisfiedDependencyExceptionData);
                    if (args == null)
                    {
                        arguments = null;
                        // if we failed to match this method, keep
                        // trying new overloaded factory methods...
                        continue;
                    }
                    else
                    {
                        arguments = args.arguments;
                    }
                }

                // if we get here, we found a usable candidate factory method - check, if arguments match
                //arguments = (arguments.Length == 0 ? null : arguments);
                if (ReflectionUtils.GetMethodByArgumentValues(new MethodInfo[] { factoryMethodCandidate }, arguments) == null)
                {
                    continue;
                }

                object objectInstance = instantiationStrategy.Instantiate(definition, name, objectFactory, factoryMethodCandidate, arguments);
                wrapper.WrappedInstance = objectInstance;

                #region Instrumentation

                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format(CultureInfo.InvariantCulture, "Object '{0}' instantiated via factory method [{1}].", name, factoryMethodCandidate));
                }

                #endregion

                return wrapper;
            }



            // if we get here, we didn't match any method...
            throw new ObjectDefinitionStoreException(
                    string.Format(CultureInfo.InvariantCulture, "Cannot find matching factory method '{0} on Type [{1}].", definition.FactoryMethodName,
                                  factoryClass));
        }
Example #27
0
 static HtmlHeading4()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.html.HtmlHeading4 o) =>
                                          new HtmlHeading4(o));
 }
Example #28
0
 public void Remove(ObjectWrapper wrapper)
 {
     HashSet<ObjectWrapper> wrappers;
     if (_elementToWrappers.TryGetValue(wrapper.Element, out wrappers))
     {
         wrappers.Remove(wrapper);
         if(wrappers.Count == 0)
         {
             _elementToWrappers.Remove(wrapper.Element);
         }
     }
 }
Example #29
0
// Generating method code for getEnclosingElement
        public virtual NHtmlUnit.Html.HtmlElement GetEnclosingElement(string tagName)
        {
            var arg = WObj.getEnclosingElement(tagName);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Html.HtmlElement>(arg));
        }
Example #30
0
 static HtmlListItem()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.html.HtmlListItem o) =>
                                          new HtmlListItem(o));
 }
Example #31
0
// Generating method code for type
        public virtual NHtmlUnit.IPage Type(System.Char c)
        {
            var arg = WObj.type(c);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.IPage>(arg));
        }
Example #32
0
// Generating method code for type
        public virtual NHtmlUnit.IPage Type(int keyCode)
        {
            var arg = WObj.type(keyCode);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.IPage>(arg));
        }
Example #33
0
// Generating method code for type
        public virtual NHtmlUnit.IPage Type(NHtmlUnit.Html.Keyboard keyboard)
        {
            var arg = WObj.type((com.gargoylesoftware.htmlunit.html.Keyboard)keyboard.WrappedObject);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.IPage>(arg));
        }
Example #34
0
        public void ReadListener(int bufferSize, int[] offsets,bool isBackground, ObjectWrapper objectWrapper)
        {
            Thread t = new Thread(() =>
            {
                while (!_stopped)
                {

                    if (_alive)
                    {
                        byte[] bytes = ReadByteArray(bufferSize, offsets);
                        objectWrapper.SetValue(bytes);
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }

                    Thread.Sleep(10);

                }
            }) { IsBackground = isBackground };
            t.Start();
        }
Example #35
0
// Generating method code for getOneHtmlElementByAttribute
        public virtual NHtmlUnit.Html.HtmlElement GetOneHtmlElementByAttribute(string elementName, string attributeName, string attributeValue)
        {
            var arg = WObj.getOneHtmlElementByAttribute(elementName, attributeName, attributeValue);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Html.HtmlElement>(arg));
        }
Example #36
0
		internal void SetOwner (ObjectWrapper owner)
		{
			this.owner = owner;
		}
Example #37
0
// Generating method code for appendChildIfNoneExists
        public virtual NHtmlUnit.Html.HtmlElement AppendChildIfNoneExists(string tagName)
        {
            var arg = WObj.appendChildIfNoneExists(tagName);

            return(ObjectWrapper.CreateWrapper <NHtmlUnit.Html.HtmlElement>(arg));
        }
Example #38
0
 /// <summary>
 /// Get the <see cref="Spring.Objects.Support.ISortDefinition"/>'s property
 /// value for the given object.
 /// </summary>
 /// <param name="obj">The object to get the property value for.</param>
 /// <returns>The property value.</returns>
 private object GetPropertyValue(object obj)
 {
     object propertyValue = null;
     if (obj != null)
     {
         IObjectWrapper ow = (IObjectWrapper) this.cachedObjectWrappers[obj];
         if (ow == null)
         {
             ow = new ObjectWrapper(obj);
             this.cachedObjectWrappers.Add(obj, ow);
         }
         try
         {
             propertyValue = ow.GetPropertyValue(this.sortDefinition.Property);
         }
         catch (InvalidPropertyException)
         {
             // the property doesn't exist in the first place, so let exception through...
             throw;
         }
         catch (ObjectsException ex)
         {
             // if a nested property cannot be read, simply return null...
             if (logger.IsDebugEnabled)
             {
                 logger.Debug("Could not access property - treating as null for sorting.", ex);
             }
         }
     }
     return propertyValue;
 }
Example #39
0
 static HtmlCenter()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.html.HtmlCenter o) =>
                                          new HtmlCenter(o));
 }
Example #40
0
        public static void PickObject(ObjectWrapper o, int index)
        {
            if (o.visited)
            {
                return;
            }
            o.visited = true;
       //    Console.WriteLine("Try Pick object" + staticIndex);
  
            if(staticObject != null)
                return;
            if (staticIndex == index)
            {
             //   Console.WriteLine("Object {0}; found for index {1}", o.m_dataSize, staticIndex);
                staticObject = o;
                return;
            }
           
            staticIndex++;


            if (o.ref1 != null && staticObject == null)
                PickObject(o.ref1, index);
            if (o.ref2 != null && staticObject == null)
                PickObject(o.ref2, index);
            if (o.ref3 != null && staticObject == null)
                PickObject(o.ref3, index);
            if (o.arrayRefs != null && staticObject == null)
            {
                for (int i = 0; i < o.arrayRefs.Length; i++)
                {
                    if (o.arrayRefs[i] != null && staticObject == null)
                        PickObject(o.arrayRefs[i], index);
                }
            }
        }
 static MozMobileMessageManager()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.moz.MozMobileMessageManager o) =>
                                          new MozMobileMessageManager(o));
 }
Example #42
0
        //counts the pinned refernces of this objects
        public static int CountPinnedReferences(ObjectWrapper o)
        {
            if (o.visited)
            {
                return 0;
            }
            else
                o.visited=true;
            int count = 0;
            if (o.m_pinned)
                count = 1;

            if (o.ref1 != null)
                count += CountPinnedReferences(o.ref1);
            if (o.ref2 != null)
                count += CountPinnedReferences(o.ref2);
            if (o.ref3 != null)
                count += CountPinnedReferences(o.ref3);
            if (o.arrayRefs != null)
            {
                for (int i = 0; i < o.arrayRefs.Length; i++)
                {
                    if (o.arrayRefs[i] != null)
                    {
                        count += CountPinnedReferences(o.arrayRefs[i]);
                    }
                }
            }
            return count;
        }
Example #43
0
        public void GetMethodDescriptionAndObject(Type type, IntPtr selector, bool is_static, IntPtr obj, ref IntPtr mthis, IntPtr desc)
        {
            var sel = new Selector(selector);
            var res = GetMethodNoThrow(type, type, sel.Name, is_static);

            if (res == null)
            {
                throw ErrorHelper.CreateError(8006, "Failed to find the selector '{0}' on the type '{1}'", sel.Name, type.FullName);
            }

            if (res.IsInstanceCategory)
            {
                mthis = IntPtr.Zero;
            }
            else
            {
                var nsobj = Runtime.GetNSObject(obj, Runtime.MissingCtorResolution.ThrowConstructor1NotFound, true, selector, ObjectWrapper.Convert(res.Method));
                mthis = ObjectWrapper.Convert(nsobj);
                if (res.Method.ContainsGenericParameters)
                {
                    res.WriteUnmanagedDescription(desc, Runtime.FindClosedMethod(nsobj.GetType(), res.Method));
                    return;
                }
            }

            res.WriteUnmanagedDescription(desc);
        }
Example #44
0
        //This is because Random is not thread safe and it stops returning a random number after a while 
        //public static int GetRandomNumber(int min, int max)
        //{
        //    lock(objLock)
        //    {
        //        return RandomObj.Next(min, max);
        //    }
        //}
        private static ObjectWrapper CreateObject()
        {
            bool isLOHObject = false;
            //pick a random value for the lifespan, from the min/max lifespan interval
            int lifeSpan = Rand.Next(minLife, maxLife);

            //decide the data size for this object

            int size = 0;
            for (int i = 0; i < SIZEBUCKET_COUNT; i++)
            {
                //First find what bucket to assign
                //find current percentage for bucket i; if smaller than target percentage, assign to this bucket
                if ((float)current_bucketObjCount[i] * 100.0F / (float)current_TotalObjCount < sizeBuckets[i].percentage)
                {
                    size = Rand.Next(sizeBuckets[i].minsize, sizeBuckets[i].maxsize);
                    //Console.WriteLine("bucket={0}, size {1}", i, size);
                    current_bucketObjCount[i]++;
                    break;
                }
            }
            if (size == 0)  //buckets are full; assign to LOH
            {
                isLOHObject = true;
                size = Rand.Next(85000, 130000);
                current_LOHObjects++;
                //Console.WriteLine("LOH " + size);
            }
            int references = Rand.Next(1, maxRef);

            //decide if to make this object pinned 
            bool pin = false;

            if ((LOHpin && isLOHObject) || !LOHpin)
            {
                float pinPercentage;
                if (LOHpin)
                {
                    pinPercentage = (float)current_pinObjCount * 100.0F / (float)current_LOHObjects;
                }
                else
                {
                    pinPercentage = (float)current_pinObjCount * 100.0F / (float)current_TotalObjCount;
                }
                if (pinPercentage < percentPinned)
                {
                    pin = true;
                    current_pinObjCount++;
                }
            }



            ObjectWrapper myNewObject;
            myNewObject = new ObjectWrapper(lifeSpan, size, pin, references);
            current_TotalObjCount++;
            /*
            lock (objLock)
            {
                Console.WriteLine("Created object with: ");
                Console.WriteLine("datasize= " + size);
                Console.WriteLine("lifetime= " + lifeSpan);
                Console.WriteLine("pinned= " + pin);
            }
             */

            WR_All.Add(myNewObject);


            return myNewObject;
        }
Example #45
0
 static HtmlTableHeaderCell()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.html.HtmlTableHeaderCell o) =>
                                          new HtmlTableHeaderCell(o));
 }
Example #46
0
 public void SetObjectAt(ObjectWrapper o, int index)
 {
     if (index >= _size)
     {
         Console.WriteLine("AddObjectAt " + index + " index is out of bounds");
     }
     _array[index] = o;
 }
Example #47
0
 static XMLDOMNodeList()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLDOMNodeList o) =>
                                          new XMLDOMNodeList(o));
 }
		public SignalChangedEventArgs (ObjectWrapper wrapper, Signal oldSignal, Signal signal): base (wrapper, signal)
		{
			this.oldSignal = oldSignal;
		}
Example #49
0
// Generating method code for item
        public virtual NHtmlUnit.W3C.Dom.INode Item(int index)
        {
            return(ObjectWrapper.CreateWrapper <NHtmlUnit.W3C.Dom.INode>(WObj.item(index)));
        }
		/// <summary>
		/// Instantiate an instance of the object described by the supplied
		/// <paramref name="definition"/> from the supplied <paramref name="factory"/>,
		/// injecting methods as appropriate.
		/// </summary>
		/// <remarks>
		/// <p>
		/// This method dynamically generates a subclass that supports method
		/// injection for the supplied <paramref name="definition"/>. It then
		/// instantiates an new instance of said type using the constructor
		/// identified by the supplied <paramref name="ctorParameterTypes"/>,
		/// passing the supplied <paramref name="arguments"/> to said
		/// constructor. It then manually injects (generic) method replacement
		/// and method lookup instances (of <see cref="System.Type"/>
		/// <see cref="Spring.Objects.Factory.Support.IMethodReplacer"/>) into
		/// the new instance: those methods that are 'method-injected' will
		/// then delegate to the approriate
		/// <see cref="Spring.Objects.Factory.Support.IMethodReplacer"/>
		/// instance to effect the actual method injection.
		/// </p>
		/// </remarks>
		/// <param name="definition">
		/// The definition of the object that is to be instantiated.
		/// </param>
		/// <param name="objectName">
		/// The name associated with the object definition. The name can be the
		/// <see lang="null"/> or zero length string if we're autowiring an
		/// object that doesn't belong to the supplied
		/// <paramref name="factory"/>.
		/// </param>
		/// <param name="factory">
		/// The owning <see cref="Spring.Objects.Factory.IObjectFactory"/>
		/// </param>
		/// <param name="ctorParameterTypes">
		/// The parameter <see cref="System.Type"/>s to use to find the
		/// appropriate constructor to invoke.
		/// </param>
		/// <param name="arguments">
		/// The aguments that are to be passed to the appropriate constructor
		/// when the object is being instantiated.
		/// </param>
		/// <returns>
		/// A new instance of the <see cref="System.Type"/> defined by the
		/// supplied <paramref name="definition"/>.
		/// </returns>
		private object DoInstantiate(
			RootObjectDefinition definition, string objectName, IObjectFactory factory, Type[] ctorParameterTypes, object[] arguments)
		{
			Type type = GetGeneratedType(objectName, definition);
			object instance = type.GetConstructor(ctorParameterTypes).Invoke(arguments);
			IObjectWrapper wrapper = new ObjectWrapper(instance);
			wrapper.SetPropertyValue(
				MethodInjectingTypeBuilder.MethodReplacementPropertyName,
				new DelegatingMethodReplacer(definition, factory));
			wrapper.SetPropertyValue(
				MethodInjectingTypeBuilder.MethodLookupPropertyName,
				new LookupMethodReplacer(definition, factory));
			return instance;
		}
Example #51
0
 static TextTrackCue()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.media.TextTrackCue o) =>
                                          new TextTrackCue(o));
 }
        /// <summary>
        /// Gets the constructor instantiation info given the object definition.
        /// </summary>
        /// <param name="objectName">Name of the object.</param>
        /// <param name="rod">The RootObjectDefinition</param>
        /// <param name="chosenCtors">The explicitly chosen ctors.</param>
        /// <param name="explicitArgs">The explicit chose ctor args.</param>
        /// <returns>A ConstructorInstantiationInfo containg the specified constructor in the RootObjectDefinition or
        /// one based on type matching.</returns>
        public ConstructorInstantiationInfo GetConstructorInstantiationInfo(string objectName, RootObjectDefinition rod,
                                                  ConstructorInfo[] chosenCtors, object[] explicitArgs)
        {

            ObjectWrapper wrapper = new ObjectWrapper();

            ConstructorInfo constructorToUse = null;
            object[] argsToUse = null;

            if (explicitArgs != null)
            {
                argsToUse = explicitArgs;
            }
            else
            {
                //TODO performance optmization on cached ctors.
            }


            // Need to resolve the constructor.
            bool autowiring = (chosenCtors != null ||
                               rod.ResolvedAutowireMode == AutoWiringMode.Constructor);
            ConstructorArgumentValues resolvedValues = null;

            int minNrOfArgs = 0;
            if (explicitArgs != null)
            {
                minNrOfArgs = explicitArgs.Length;
            }
            else
            {
                ConstructorArgumentValues cargs = rod.ConstructorArgumentValues;
                resolvedValues = new ConstructorArgumentValues();
                minNrOfArgs = ResolveConstructorArguments(objectName, rod, wrapper, cargs, resolvedValues);
            }
            // Take specified constructors, if any.            
            ConstructorInfo[] candidates = (chosenCtors != null
                                                ? chosenCtors
                                                : AutowireUtils.GetConstructors(rod, 0));
            AutowireUtils.SortConstructors(candidates);
            int minTypeDiffWeight = Int32.MaxValue;

            for (int i = 0; i < candidates.Length; i++)
            {
                ConstructorInfo candidate = candidates[i];
                Type[] paramTypes = ReflectionUtils.GetParameterTypes(candidate.GetParameters());
                if (constructorToUse != null && argsToUse.Length > paramTypes.Length)
                {
                    // already found greedy constructor that can be satisfied, so
                    // don't look any further, there are only less greedy constructors left...
                    break;
                }
                if (paramTypes.Length < minNrOfArgs)
                {
                    throw new ObjectCreationException(rod.ResourceDescription, objectName,
                                  string.Format(CultureInfo.InvariantCulture,
                                                "'{0}' constructor arguments specified but no matching constructor found "
                                                + "in object '{1}' (hint: specify argument indexes, names, or "
                                                + "types to avoid ambiguities).", minNrOfArgs, objectName));
                }
                ArgumentsHolder args = null;

                if (resolvedValues != null)
                {
                    UnsatisfiedDependencyExceptionData unsatisfiedDependencyExceptionData = null;
                    // Try to resolve arguments for current constructor

                    //need to check for null as indicator of no ctor arg match instead of using exceptions for flow
                    //control as in the Java implementation
                    args = CreateArgumentArray(objectName, rod, resolvedValues, wrapper, paramTypes, candidate,
                                                autowiring, out unsatisfiedDependencyExceptionData);
                    if (args == null)
                    {
                        if (i == candidates.Length - 1 && constructorToUse == null)
                        {
                            throw new UnsatisfiedDependencyException(rod.ResourceDescription,
                                            objectName,
                                            unsatisfiedDependencyExceptionData.ParameterIndex,
                                            unsatisfiedDependencyExceptionData.ParameterType,
                                            unsatisfiedDependencyExceptionData.ErrorMessage);
                        }
                        // try next constructor...
                        continue;
                    }
                }
                else
                {
                    // Explicit arguments given -> arguments length must match exactly
                    if (paramTypes.Length != explicitArgs.Length)
                    {
                        continue;
                    }
                    args = new ArgumentsHolder(explicitArgs);

                }
                int typeDiffWeight = args.GetTypeDifferenceWeight(paramTypes);
                // Choose this constructor if it represents the closest match.
                if (typeDiffWeight < minTypeDiffWeight)
                {
                    constructorToUse = candidate;
                    argsToUse = args.arguments;
                    minTypeDiffWeight = typeDiffWeight;
                }

            }


            if (constructorToUse == null)
            {
                throw new ObjectCreationException(rod.ResourceDescription, objectName, "Could not resolve matching constructor.");
            }

            return new ConstructorInstantiationInfo(constructorToUse, argsToUse);

            
        }
Example #53
0
 static MouseEvent()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.MouseEvent o) =>
                                          new MouseEvent(o));
 }
        /// <summary>
        /// Create an array of arguments to invoke a constructor or static factory method,
        /// given the resolved constructor arguments values.
        /// </summary>
        /// <remarks>When return value is null the out parameter UnsatisfiedDependencyExceptionData will contain
        /// information for use in throwing a UnsatisfiedDependencyException by the caller.  This avoids using
        /// exceptions for flow control as in the original implementation.</remarks>
        private ArgumentsHolder CreateArgumentArray(string objectName, RootObjectDefinition rod, ConstructorArgumentValues resolvedValues, ObjectWrapper wrapper, Type[] paramTypes, MethodBase methodOrCtorInfo, bool autowiring, out UnsatisfiedDependencyExceptionData unsatisfiedDependencyExceptionData)
        {
            string methodType = (methodOrCtorInfo is ConstructorInfo) ? "constructor" : "factory method";
            unsatisfiedDependencyExceptionData = null;

            ArgumentsHolder args = new ArgumentsHolder(paramTypes.Length);
            ISet usedValueHolders = new HybridSet();
            IList autowiredObjectNames = new LinkedList();
            bool resolveNecessary = false;

            ParameterInfo[] argTypes = methodOrCtorInfo.GetParameters();

            for (int paramIndex = 0; paramIndex < paramTypes.Length; paramIndex++)
            {
                Type paramType = paramTypes[paramIndex];

                string parameterName = argTypes[paramIndex].Name;
                // If we couldn't find a direct match and are not supposed to autowire,
                // let's try the next generic, untyped argument value as fallback:
                // it could match after type conversion (for example, String -> int).               
                ConstructorArgumentValues.ValueHolder valueHolder = null;
                if (resolvedValues.GetNamedArgumentValue(parameterName) != null)
                {
                    valueHolder = resolvedValues.GetArgumentValue(parameterName, paramType, usedValueHolders);
                }
                else
                {
                    valueHolder = resolvedValues.GetArgumentValue(paramIndex, paramType, usedValueHolders);
                }


                if (valueHolder == null && !autowiring)
                {
                    valueHolder = resolvedValues.GetGenericArgumentValue(null, usedValueHolders);
                }
                if (valueHolder != null)
                {
                    // We found a potential match - let's give it a try.
                    // Do not consider the same value definition multiple times!
                    usedValueHolders.Add(valueHolder);
                    args.rawArguments[paramIndex] = valueHolder.Value;
                    try
                    {
                        object originalValue = valueHolder.Value;
                        object convertedValue = TypeConversionUtils.ConvertValueIfNecessary(paramType, originalValue, null);
                        args.arguments[paramIndex] = convertedValue;

                        //?
                        args.preparedArguments[paramIndex] = convertedValue;
                    }
                    catch (TypeMismatchException ex)
                    {
                        //To avoid using exceptions for flow control, this is not a cost in Java as stack trace is lazily created.
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                   "Could not convert {0} argument value [{1}] to required type [{2}] : {3}",
                                   methodType, valueHolder.Value,
                                   paramType, ex.Message);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);
                        return null;
                    }
                }
                else
                {
                    // No explicit match found: we're either supposed to autowire or
                    // have to fail creating an argument array for the given constructor.
                    if (!autowiring)
                    {
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                  "Ambiguous {0} argument types - " +
                                  "Did you specify the correct object references as {0} arguments?",
                                  methodType);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);

                        return null;
                    }
                    try
                    {
                        MethodParameter param = MethodParameter.ForMethodOrConstructor(methodOrCtorInfo, paramIndex);
                        object autowiredArgument = ResolveAutoWiredArgument(param, objectName, autowiredObjectNames);
                        args.rawArguments[paramIndex] = autowiredArgument;
                        args.arguments[paramIndex] = autowiredArgument;
                        args.preparedArguments[paramIndex] = new AutowiredArgumentMarker();
                        resolveNecessary = true;
                    }
                    catch (ObjectsException ex)
                    {
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, ex.Message);

                        return null;
                    }

                }
            }
            foreach (string autowiredObjectName in autowiredObjectNames)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Autowiring by type from object name '" + objectName +
                         "' via " + methodType + " to object named '" + autowiredObjectName + "'");
                }
            }


            return args;

        }
Example #55
0
 static HTMLLabelElement()
 {
     ObjectWrapper.RegisterWrapperCreator((com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLabelElement o) =>
                                          new HTMLLabelElement(o));
 }
        /// <summary>
        /// "autowire constructor" (with constructor arguments by type) behavior.  
        /// Also applied if explicit constructor argument values are specified,
        /// matching all remaining arguments with objects from the object factory.
        /// </summary>
        /// <para>
        /// This corresponds to constructor injection: In this mode, a Spring
        /// object factory is able to host components that expect constructor-based
        /// dependency resolution.
        /// </para>
        /// <param name="objectName">Name of the object.</param>
        /// <param name="rod">The merged object definition for the object.</param>
        /// <param name="chosenCtors">The chosen chosen candidate constructors (or <code>null</code> if none).</param>
        /// <param name="explicitArgs">The explicit argument values passed in programmatically via the getBean method,
        /// or <code>null</code> if none (-> use constructor argument values from object definition)</param>
        /// <returns>An IObjectWrapper for the new instance</returns>
        public IObjectWrapper AutowireConstructor(string objectName, RootObjectDefinition rod,
                                                  ConstructorInfo[] chosenCtors, object[] explicitArgs)
        {

            ObjectWrapper wrapper = new ObjectWrapper();

            ConstructorInstantiationInfo constructorInstantiationInfo = GetConstructorInstantiationInfo(
                objectName, rod, chosenCtors, explicitArgs);

            wrapper.WrappedInstance = instantiationStrategy.Instantiate(rod, objectName, this.objectFactory,
                    constructorInstantiationInfo.ConstructorInfo, constructorInstantiationInfo.ArgInstances);

            #region Instrumentation

            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format(CultureInfo.InvariantCulture, "Object '{0}' instantiated via constructor [{1}].", objectName, constructorInstantiationInfo.ConstructorInfo));
            }

            #endregion

            return wrapper;
        }
Example #57
0
 public void Add(ObjectWrapper wrapper)
 {
     HashSet<ObjectWrapper> wrappers;
     if(!_elementToWrappers.TryGetValue(wrapper.Element, out wrappers))
     {
         wrappers = new HashSet<ObjectWrapper>();
         _elementToWrappers.Add(wrapper.Element, wrappers);
     }
     wrappers.Add(wrapper);
 }