public UnitWorkContainer() { this.Add(ServiceActivator.Get <AddSpaceIndexerxUnitOfWork>()); this.Add(ServiceActivator.Get <RemoveSpaceIndexerxUnitOfWork>()); this.Add(ServiceActivator.Get <AddDocumentIndexerxUnitOfWork>()); this.Add(ServiceActivator.Get <RemoveSpaceIndexerxUnitOfWork>()); }
public void ExtendedActivator_ShouldThrowOnNonInterfaceArguments() { ConstructorInfo ctor = typeof(MyClass).GetConstructor(new[] { typeof(IDisposable), typeof(IList), typeof(int) }); // // Sima Get() hivas nem fog mukodni (nem interface parameter). // Assert.Throws <ArgumentException>(() => ServiceActivator.Get(ctor), Resources.INVALID_CONSTRUCTOR); // // Ne mock-oljuk az injector-t h a megfelelo kiveteleket kapjuk // using (IServiceContainer container = new ServiceContainer()) { IInjector injector = container .Factory <IDisposable>(i => new Disposable(), Lifetime.Scoped) .Factory <IList>(i => new List <object>(), Lifetime.Scoped) .CreateInjector(); // // Ez mukodne viszont nem adtuk meg a nem interface parametert. // Assert.Throws <ArgumentException>(() => ServiceActivator.GetExtended(ctor).Invoke(injector, new Dictionary <string, object>(0)), Resources.PARAMETER_NOT_AN_INTERFACE); } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { string controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; string action = filterContext.ActionDescriptor.ActionName; string actionPath = "/" + controller + "/" + action; _logger.Info("菜单高亮:" + actionPath + ";访问IP:" + CerCommon.GetIp() + "; 登录账号:" + filterContext.HttpContext.User.Identity.Name); filterContext.Controller.ViewData["CurrentMenu"] = CurrentItem; filterContext.Controller.ViewData["CurrentParentItem"] = CurrentParentItem; var cache = filterContext.HttpContext.Cache; string key = string.Format("rolefunction_{0}", ContextService.Current.GetCookieValue("role")); if (cache[key] == null) { Guid rs; if (!Guid.TryParse(ContextService.Current.GetCookieValue("role"), out rs)) { var user = ServiceActivator.Get <UserService>().GetByUserName(filterContext.HttpContext.User.Identity.Name); rs = user.RoleId; ContextService.Current.SetCookie("role", user.RoleId.ToString()); } var menus = ServiceActivator.Get <RoleFunctionService>().Get(rs); cache.Add(key, menus, new SqlCacheDependency("MonkeyCacheDependency", "BASE_ROLEFUNCTIONS"), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); } //ContextService.Current.Cache(""); filterContext.Controller.ViewData["Menus"] = cache[key]; base.OnActionExecuted(filterContext); }
protected override void DoExecute(ExecutionEvent executionEvent) { IPresetCRUDService presetCRUDService = ServiceActivator.Get <IPresetCRUDService>(); presetCRUDService.SetAsDefault(executionEvent.GetFirstSelectedTreeNavigationItem().Id, executionEvent.GetMasterTreeNavigationItem().Id); OnSuccessful(executionEvent, IdConstants.PRESET_FOLDER_ID); }
public GenerateGuidWindowModelView() : base("GenerateGuidWindowModelView") { _generateGuidService = ServiceActivator.Get <IGenerateGuidService>(); GenerateGuidDto = new GenerateGuidDto(); CloseCommand = new RelayCommand(OnCloseCommand); GenerateCommand = new RelayCommand(OnGenerateCommand, x => !IsThreadRunning); }
protected override void DoPersist(ProgressCounter progressCounter, ProjectDto projectDto) { _isDatabaseFileAlreadyExisting = IsDatabaseFileExisting(projectDto.Name); Connection.GetInstance().CreateConnection(GetPathToDatabaseFile(projectDto.Name)); _crudService = (IProjectCRUDService)ServiceActivator.Get(typeof(IProjectCRUDService)); _persister = new ProjectPersister(_crudService, progressCounter, projectDto); _persister.Persist(); }
public override void Persist() { BeforePersist(); IProjectImportService projectImportService = ServiceActivator.Get <IProjectImportService>(); projectImportService.Import(_progressCounter, GetDto()); AfterPersist(); }
protected virtual void Delete(ExecutionEvent executionEvent, Guid id) { ICRUDService <T> crudService = (ICRUDService <T>)ServiceActivator.Get(HandlerUtils.DTO_TO_SERVICE[typeof(T)]); Connection.GetInstance().StartTransaction(); crudService.Delete(id); Connection.GetInstance().EndTransaction(); }
public GenerateLiquibaseWindowModelView(TreeNavigationItem selectedTreeNavigationItem) : base("GenerateLiquibaseWindowModelView") { _generateService = ServiceActivator.Get <IGenerateLiquibaseService>(); _selectedTreeNavigationItem = selectedTreeNavigationItem; LoadCommand = new RelayCommand(OnLoadCommand); GenerateCommand = new RelayCommand(OnGenerateCommand, x => !IsThreadRunning); CloseCommand = new RelayCommand(OnCloseCommand, x => !IsThreadRunning); }
public void should_read_file_content_from_localfile() { IStorePolicy policy = ServiceActivator.Get <LocalPolicy>(); FileContentReader reader = new FileContentReader(policy); var content = reader.Read(file); Console.WriteLine(content); }
public SettingsModelView() : base("SettingsModelView") { _settingsCRUDService = ServiceActivator.Get <ISettingsCRUDService>(); LoadCommand = new RelayCommand(OnLoadCommand); SaveCommand = new RelayCommand(OnSaveCommand, x => !IsThreadRunning); CloseCommand = new RelayCommand(OnCloseCommand, x => !IsThreadRunning); }
public void Drop(TreeNavigationItem draggedTreeNavigationItem, TreeNavigationItem targetTreeNavigationItem) { Connection.GetInstance().StartTransaction(); IMoveAwareCRUDService moveAwareCRUDService = ServiceActivator.Get <IFolderCRUDService>(); moveAwareCRUDService.Move(draggedTreeNavigationItem.Id, targetTreeNavigationItem.Id); Connection.GetInstance().EndTransaction(); Publisher.GetInstance().Publish(PublishEvent.CreateDeletionEvent(draggedTreeNavigationItem.Id, draggedTreeNavigationItem.GetParentId())); Publisher.GetInstance().Publish(PublishEvent.CreateCreationEvent(draggedTreeNavigationItem.Id, targetTreeNavigationItem.GetParentId())); }
protected virtual T LoadDto(ExecutionEvent executionEvent) { ICRUDService <T> crudService = (ICRUDService <T>)ServiceActivator.Get(HandlerUtils.DTO_TO_SERVICE[typeof(T)]); Connection.GetInstance().StartTransaction(); T dto = crudService.Read(executionEvent.GetFirstSelectedTreeNavigationItem().Id); Connection.GetInstance().EndTransaction(); return(dto); }
protected override void DoExecute(ExecutionEvent executionEvent) { ICRUDService <T> crudService = (ICRUDService <T>)ServiceActivator.Get(HandlerUtils.DTO_TO_SERVICE[typeof(T)]); List <T> dtos = new List <T>(); foreach (TreeNavigationItem treeNavigationItem in GetTreeNavigationItemsFromClipboard("copy")) { dtos.Add(crudService.Read(treeNavigationItem.Id)); } //Paste(dtos); //OnSuccessful(executionEvent, affectedObjectId); }
public void should_read_file_content_from_mongo_db() { IStorePolicy policy = ServiceActivator.Get <MongoPolicy>(); string remoteFile = "sample.docx"; policy.Add(file, remoteFile); FileContentReader reader = new FileContentReader(policy); var content = reader.Read(remoteFile); Console.WriteLine(content); policy.Delete(remoteFile); }
protected override void OnStart(string[] args) { _logger.Info("Starting DocViewerService"); _listener = ServiceActivator.Get <MessageListener>(); _listener.Start(); _jobEngine = ServiceActivator.Get <JobEngine>(); _jobEngine.Start(); _logger.Info("DocViewerService is started."); }
public void Activator_ShouldResolveDependencies(Type dep1, string name1, Type dep2, string name2) { var mockDisposable = new Mock <IDisposable>(); var mockServiceFactory = new Mock <IList>(); var mockInjector = new Mock <IInjector>(MockBehavior.Strict); foreach (Func <IInjector, object> activator in GetActivators(typeof(MyClass).GetConstructor(new[] { dep1, dep2 }))) { mockInjector .Setup(i => i.Get(It.IsAny <Type>(), It.IsAny <string>())) .Returns <Type, string>((type, name) => { if (type == typeof(IDisposable) && name == name1) { return(mockDisposable.Object); } if (type == typeof(IList) && name == name2) { return(mockServiceFactory.Object); } Assert.Fail("Unknown type"); return(null); }); MyClass instance = (MyClass)activator(mockInjector.Object); Assert.That(instance, Is.Not.Null); Assert.That(instance.Dep1, Is.SameAs(mockDisposable.Object)); Assert.That(instance.Dep2, Is.SameAs(mockServiceFactory.Object)); mockInjector.Verify(i => i.Get(It.Is <Type>(t => t == typeof(IDisposable)), It.Is <string>(n => n == name1)), Times.Once); mockInjector.Verify(i => i.Get(It.Is <Type>(t => t == typeof(IList)), It.Is <string>(n => n == name2)), Times.Once); mockInjector.Verify(i => i.Get(It.IsAny <Type>(), It.IsAny <string>()), Times.Exactly(2)); mockInjector.Reset(); } IEnumerable <Func <IInjector, object> > GetActivators(ConstructorInfo ctor) { Func <IInjector, Type, object> factory = ServiceActivator.Get(ctor); yield return(injector => factory(injector, null)); Func <IInjector, IReadOnlyDictionary <string, object>, object> factoryEx = ServiceActivator.GetExtended(ctor); yield return(injector => factoryEx(injector, new Dictionary <string, object>(0))); } }
public WizardModelView(T dto) : base(typeof(WizardModelView <>).Name) { Dto = dto; FinishCommand = new RelayCommand(OnFinishCommand); CancelCommand = new RelayCommand(OnCancelCommand); InfoVisibility = Visibility.Visible; ValidationMessageVisibility = Visibility.Hidden; _crudService = (ICRUDService <T>)ServiceActivator.Get(HandlerUtils.DTO_TO_SERVICE[typeof(T)]); _persister = new BasePersister <T>(_crudService, Dto); CreateTitle(); }
public void Execute() { _logger.Debug("开始执行批量创建索引..."); try { var searchService = ServiceActivator.Get <SearchService>(); searchService.Update(ConfigurationManager.AppSettings["Segment"]); _logger.Debug("创建索引完毕!"); } catch (Exception ex) { _logger.Error(ex.StackTrace); _logger.Error(ex.Message); } }
public void Execute() { _logger.Debug("开始执行缓存重启..."); try { var cachedService = ServiceActivator.Get <ICachePolicy>(); cachedService.FlushAll(); _logger.Debug("缓存重启完毕!"); } catch (Exception ex) { _logger.Error(ex.StackTrace); _logger.Error(ex.Message); } }
public void Drop(TreeNavigationItem draggedTreeNavigationItem, TreeNavigationItem targetTreeNavigationItem) { string name = Guid.NewGuid().ToString().Substring(0, 7); ICompositeTypeElementCRUDService compositeTypeElementCRUDService = ServiceActivator.Get <ICompositeTypeElementCRUDService>(); CompositeTypeElementDto compositeTypeElementDto = new CompositeTypeElementDto(); compositeTypeElementDto.Description = name; compositeTypeElementDto.UniqueName = name; compositeTypeElementDto.RuntimeId = Guid.NewGuid(); compositeTypeElementDto.ProjectId = targetTreeNavigationItem.ProjectId; compositeTypeElementDto.OwningTypeId = targetTreeNavigationItem.Id; compositeTypeElementDto.State = State.NEW; compositeTypeElementDto.ElementTypeReference = new ReferenceString(draggedTreeNavigationItem.Id, draggedTreeNavigationItem.Name); Connection.GetInstance().StartTransaction(); compositeTypeElementDto = compositeTypeElementCRUDService.Persist(compositeTypeElementDto); Connection.GetInstance().EndTransaction(); Publisher.GetInstance().Publish(PublishEvent.CreateCreationEvent(compositeTypeElementDto.Id, compositeTypeElementDto.OwningTypeId)); }
public void Get_ShouldHandleParameterlessConstructors() { var mockInjector = new Mock <IInjector>(MockBehavior.Strict); mockInjector.Setup(i => i.Get(It.IsAny <Type>(), It.IsAny <string>())); Func <IInjector, Type, object> factory = ServiceActivator .Get(typeof(MyClass).GetConstructor(new Type[0])); Assert.That(factory, Is.Not.Null); MyClass instance = (MyClass)factory(mockInjector.Object, null); Assert.That(instance, Is.Not.Null); Assert.That(instance.Dep1, Is.Null); Assert.That(instance.Dep2, Is.Null); mockInjector.Verify(i => i.Get(It.IsAny <Type>(), It.IsAny <string>()), Times.Never); }
public void Get_ShouldSupportProxyTypes() { Type proxy = ProxyGenerator <IList <IDictionary>, MyInterceptor> .GetGeneratedType(); Func <IInjector, Type, object> factory = ServiceActivator.Get(proxy); var mockInjector = new Mock <IInjector>(MockBehavior.Strict); mockInjector .Setup(i => i.Get(typeof(IList <IDictionary>), null)) .Returns(new List <IDictionary>()); mockInjector .Setup(i => i.TryGet(typeof(IDisposable), null)) .Returns(null); Assert.DoesNotThrow(() => factory.Invoke(mockInjector.Object, typeof(IList <IDictionary>))); mockInjector.Verify(i => i.Get(typeof(IList <IDictionary>), null), Times.Once); mockInjector.Verify(i => i.TryGet(typeof(IDisposable), null), Times.Once); }
public void Handle(Message message) { var msgType = GetMessageType(message); var handlerType = GetHandlerType(msgType); var handler = ServiceActivator.Get(handlerType); message.Formatter = new XmlMessageFormatter(new[] { msgType }); var body = message.Body; try { LOGGER.DebugFormat("Handler ({0}) handle message ({1})", msgType, handlerType); handlerType.GetMethod("Handle").Invoke(handler, new[] { body }); } catch (Exception err) { LOGGER.Error("Could not invoke handle for handler: " + handlerType, err); throw; } }
protected override INavigationService CreateNavigationService() { return(ServiceActivator.Get <ICompositeTypeNavigationService>()); }
public void Get_ShouldValidate() { Assert.Throws <ArgumentException>(() => ServiceActivator.Get(typeof(IDisposable)), Resources.PARAMETER_NOT_A_CLASS); Assert.Throws <ArgumentException>(() => ServiceActivator.Get(typeof(IList <>)), Resources.PARAMETER_IS_GENERIC); Assert.Throws <ArgumentException>(() => ServiceActivator.Get(typeof(AbstractClass)), Resources.PARAMETER_IS_ABSTRACT); }
public void Get_ShouldCache() { Assert.AreSame(ServiceActivator.Get(typeof(Disposable)), ServiceActivator.Get(typeof(Disposable))); Assert.AreSame(ServiceActivator.Get(typeof(Disposable).GetApplicableConstructor()), ServiceActivator.Get(typeof(Disposable).GetApplicableConstructor())); }
protected override List <TreeNavigationItem> DoGetProposals() { ICompositeTypeNavigationService compositeTypeNavigationService = ServiceActivator.Get <ICompositeTypeNavigationService>(); return(compositeTypeNavigationService.GetAllDerivableCompositeTypes()); }
protected override void Init() { base.Init(); _settingsCRUDService = ServiceActivator.Get <ISettingsCRUDService>(); }
protected override List <TreeNavigationItem> DoGetProposals() { ICompositeTypeNavigationService compositeTypeNavigationService = ServiceActivator.Get <ICompositeTypeNavigationService>(); return(compositeTypeNavigationService.GetPresetsToCompositeTypeElement(GetDto().CompositeTypeElementId)); }