public void performance() { using (IServiceContext childContext = BeanContext.CreateService(typeof(IocPerformanceTestModule))) { Assert.AssertEquals(50000, childContext.GetObjects <TestBean>().Count); } }
public IProgress StartProgress() { IBeanContextHolder <IProgressDispatcherIntern> childSP = progressDispatcherTL.Value; if (childSP == null) { IBeanContextHolder <IProgressDispatcherIntern> progressDispatcher = BeanContext.CreateService <IProgressDispatcherIntern>(typeof(ProgressDispatcherModule)); progressDispatcherTL.Value = progressDispatcher; } return(((ProgressDispatcher)childSP.GetTypedValue()).StartProgress()); }
protected virtual IServiceContext StartIntern(IBackgroundWorkerParamDelegate <IBeanContextFactory> content) { writeLock.Lock(); try { if (Log.DebugEnabled) { Log.Debug("Looking for existing child context..."); } IServiceContext childContext = GetChildContext(); if (childContext == null || childContext.IsDisposed) { if (Log.DebugEnabled) { Log.Debug("No valid child context found. Creating new child context"); } IBackgroundWorkerParamDelegate <IBeanContextFactory> rpd = new IBackgroundWorkerParamDelegate <IBeanContextFactory>(delegate(IBeanContextFactory beanContextFactory) { if (content != null) { content.Invoke(beanContextFactory); } beanContextFactory.RegisterBean <ChildContextFoot>().PropertyValue("ContextHandle", this); }); if (ContextFactory != null) { childContext = ContextFactory.CreateChildContext(rpd); } else { childContext = BeanContext.CreateService(rpd); } SetChildContext(childContext); childContexts.Add(childContext); } else if (Log.DebugEnabled) { Log.Debug("Existing child context found and valid"); } IList <IUpwakingBean> upwakingBeans = childContext.GetImplementingObjects <IUpwakingBean>(); for (int a = 0, size = upwakingBeans.Count; a < size; a++) { upwakingBeans[a].WakeUp(); } return(childContext); } finally { writeLock.Unlock(); } }
public virtual void Execute(object parameter) { IServiceContext childContext = BeanContext.CreateService(delegate(IBeanContextFactory bcf) { if (SelectedItemContainerBean != null) { bcf.RegisterExternalBean(SelectedItemContainerBean, parameter); } }, EditModuleType); bool success = false; try { EventHandler eventHandler = new EventHandler(delegate(Object sender, EventArgs e) { ChildWindow childWindow = childContext.GetService <ChildWindow>(PopupWindowBean); bool?dialogResult = childWindow.DialogResult; if (!dialogResult.HasValue || !dialogResult.Value) { Object editedItem = null; if (parameter is IModelMultiContainer <T> ) { editedItem = ((IModelSingleContainer <T>)parameter).Value; } else { editedItem = parameter; } RevertChangesHelper.RevertChanges(editedItem); return; } }); childContext.Link(eventHandler).To(PopupWindowBean, ChildWindowEvents.Closed); success = true; } catch (Exception ex) { Log.Error(ex); throw; } finally { if (!success) { childContext.Dispose(); } } }
public Object ProcessWrite(IPostProcessWriter writer) { ISet <Object> substitutedEntities = writer.SubstitutedEntities; if (substitutedEntities.Count == 0) { return(null); } IDisposableCache childCache = CacheFactory.Create(CacheFactoryDirective.NoDCE, "XmlMerge"); IServiceContext mergeContext = BeanContext.CreateService(delegate(IBeanContextFactory childContextFactory) { childContextFactory.RegisterBean(typeof(MergeHandle)).Autowireable <MergeHandle>().PropertyValue("Cache", childCache); }); try { IDictionary <Object, Int32> mutableToIdMap = writer.MutableToIdMap; IObjRefHelper objRefHelper = ObjRefHelper; MergeHandle mergeHandle = mergeContext.GetService <MergeHandle>(); IList <Object> toMerge = new List <Object>(substitutedEntities.Count); foreach (Object entity in substitutedEntities) { toMerge.Add(entity); IObjRef ori = objRefHelper.EntityToObjRef(entity); mergeHandle.objToOriDict.Add(entity, ori); Int32 id = mutableToIdMap[entity]; mutableToIdMap.Add(ori, id); } ICUDResult cudResult = MergeController.MergeDeep(toMerge, mergeHandle); if (cudResult.AllChanges.Count != 0) { return(cudResult); } else { return(null); } } finally { mergeContext.Dispose(); } }
public virtual void Execute(object parameter) { IServiceContext childContext = BeanContext.CreateService(CreateModuleType); bool success = false; try { EventHandler eventHandler = new EventHandler(delegate(Object sender, EventArgs e) { ChildWindow childWindow = childContext.GetService <ChildWindow>(PopupWindowBean); bool?dialogResult = childWindow.DialogResult; if (!dialogResult.HasValue || !dialogResult.Value) { return; } IModelSingleContainer <T> singleContainer = childContext.GetService <IModelSingleContainer <T> >(); T newItem = singleContainer.Value; if (parameter is IGenericViewModel <T> ) { ((IGenericViewModel <T>)parameter).InsertAt(0, newItem); } else if (parameter is IModelMultiContainer <T> ) { ((IModelMultiContainer <T>)parameter).Values.Insert(0, newItem); } else if (parameter is IModelSingleContainer <T> ) { ((IModelSingleContainer <T>)parameter).Value = newItem; } else if (parameter is IList <T> ) { ((IList <T>)parameter).Insert(0, newItem); } else if (parameter is T) { parameter = newItem; } else { String errorString = "parameter for create command can not hold an item of type " + newItem.GetType().ToString(); Log.Error(errorString); throw new ArgumentException(errorString); } }); childContext.Link(eventHandler).To(PopupWindowBean, ChildWindowEvents.Closed); success = true; } catch (Exception ex) { Log.Error(ex); throw; } finally { if (!success) { childContext.Dispose(); } } }
//[TestInitialize] public void InitManually() { base.InitManually(GetType()); childContext = BeanContext.CreateService(typeof(LinkContainerTestModule)); testRegistry = childContext.GetService <ITestRegistry>(); }