//------------------------------------------ // EXECUTION //----------------------------------------- #region Execution /// <summary> /// Executes this instance with result. /// </summary> /// <param name="resultString">The result to get.</param> /// <param name="appScope">The application scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="runtimeMode">The runtime mode to consider.</param> /// <returns>The log of execution log.</returns> public override ILog ExecuteWithResult( out string resultString, IAppScope appScope = null, IScriptVariableSet scriptVariableSet = null, RuntimeMode runtimeMode = RuntimeMode.Normal) { resultString = ""; ILog log = appScope.Check(true); if (this.Reference == null) { log.AddWarning( title: "Reference missing", description: "No reference defined in command '" + this.Key() + "'."); } else if (!log.HasErrorsOrExceptions() && this.Reference != null) { scriptVariableSet.SetValue("currentItem", this.Reference.SourceElement.GetObject()); scriptVariableSet.SetValue("currentElement", this.Reference.SourceElement); resultString = this.Reference.Get(appScope, scriptVariableSet, log)?.ToString(); } return(log); }
//------------------------------------------ // EXECUTION //----------------------------------------- #region Execution /// <summary> /// Executes this instance with result. /// </summary> /// <param name="resultString">The result to get.</param> /// <param name="appScope">The application scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="runtimeMode">The runtime mode to consider.</param> /// <returns>The log of execution log.</returns> public override ILog ExecuteWithResult( out string resultString, IAppScope appScope = null, IScriptVariableSet scriptVariableSet = null, RuntimeMode runtimeMode = RuntimeMode.Normal) { resultString = ""; ILog log = appScope.Check(false); if (!log.HasErrorsOrExceptions()) { if (string.IsNullOrEmpty(this._script)) { log.AddWarning( title: "Script missing", description: "No script defined in command '" + this.Key() + "'."); } else { appScope.ScriptInterpreter.Evaluate(this._script, out resultString, scriptVariableSet, log); } } return(log); }
public NhUnitOfWork(IAppScope scope, ICurrentUnitOfWorkProvider uowProvider) { if (scope == null) { throw new ArgumentNullException("scope"); } if (uowProvider == null) { throw new ArgumentNullException("uowProvider"); } _currentUnitOfWorkProvider = uowProvider; if (_currentUnitOfWorkProvider.Current != null) { throw new NCoreException("В текущем контексте уже открыт юнит-оф-ворк. Закройте его перед тем как открывать новый."); } _currentUnitOfWorkProvider.Current = this; Scope = scope.BeginScope(); var sessionFactory = Scope.Resolve <ISessionFactory>(); if (sessionFactory == null) { throw new NCoreException("Не удалось инициализировать UoW Nh, не удалос получить фабрику сессий"); } Session = sessionFactory.OpenSession(); }
public EfUnitOfWork(IAppScope scope, ICurrentUnitOfWorkProvider uowProvider) { if (scope == null) { throw new ArgumentNullException("scope"); } if (uowProvider == null) { throw new ArgumentNullException("uowProvider"); } _currentUnitOfWorkProvider = uowProvider; if (_currentUnitOfWorkProvider.Current != null) { throw new NCoreException("В текущем контексте уже открыт юнит-оф-ворк. Закройте его перед тем как открывать новый."); } _currentUnitOfWorkProvider.Current = this; Scope = scope.BeginScope(); var dbContextFactory = Scope.Resolve <IDbContextFactory>(); if (dbContextFactory == null) { throw new NCoreException("Не удалось инициализировать UoW EF, не удалос получить фабрику контекста подключения"); } DbContext = dbContextFactory.CreateDbContext(); }
/// <summary> /// Initializes a new instance of the <see cref="ZenCoreDependencyResolver"/> class. /// </summary> /// <param name="container">The container that nested lifetime scopes will be create from.</param> public ZenCoreDependencyResolver(IAppScope container) { if (container == null) { throw new ArgumentNullException("container"); } _container = container; }
public EmitRawUoWInterfaceImplementor(IAppScope scope) { _scope = scope; _interfaceType = typeof(TInterface); _isDisposable = _interfaceType.IsAssignableTo <IDisposable>(); }
/// <summary> /// Initializes a new instance of the <see cref="ZenCoreDependencyResolver"/> class. /// </summary> /// <param name="container">The container that nested lifetime scopes will be create from.</param> /// <param name="lifetimeScopeProvider">A <see cref="ILifetimeScopeProvider"/> implementation for /// creating new lifetime scopes.</param> /// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/> /// that adds component registations visible only in nested lifetime scopes.</param> public ZenCoreDependencyResolver(IAppScope container, ILifetimeScopeProvider lifetimeScopeProvider, Action <ContainerBuilder> configurationAction) : this(container, lifetimeScopeProvider) { if (configurationAction == null) { throw new ArgumentNullException("configurationAction"); } _configurationAction = configurationAction; }
/// <summary> /// Initializes a new instance of the <see cref="ZenCoreDependencyResolver"/> class. /// </summary> /// <param name="container">The container that nested lifetime scopes will be create from.</param> /// <param name="lifetimeScopeProvider">A <see cref="ILifetimeScopeProvider"/> implementation for /// creating new lifetime scopes.</param> public ZenCoreDependencyResolver(IAppScope container, ILifetimeScopeProvider lifetimeScopeProvider) : this(container) { if (lifetimeScopeProvider == null) { throw new ArgumentNullException("lifetimeScopeProvider"); } _lifetimeScopeProvider = lifetimeScopeProvider; }
/// <summary> /// Initializes a new instance of the <see cref="RequestLifetimeScopeProvider"/> class. /// </summary> /// <param name="container">The parent container, usually the application container.</param> public RequestLifetimeScopeProvider(IAppScope container) { if (container == null) { throw new ArgumentNullException("container"); } _container = container; RequestLifetimeHttpModule.SetLifetimeScopeProvider(this); }
/// <summary> /// Gets a nested lifetime scope that services can be resolved from. /// </summary> /// <param name="configurationAction"> /// A configuration action that will execute during lifetime scope creation. /// </param> /// <returns>A new or existing nested lifetime scope.</returns> public IAppScope GetLifetimeScope(Action <ContainerBuilder> configurationAction) { if (HttpContext.Current == null) { throw new InvalidOperationException(RequestLifetimeScopeProviderResources.HttpContextNotAvailable); } if (LifetimeScope == null) { if ((LifetimeScope = GetLifetimeScopeCore(configurationAction)) == null) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, RequestLifetimeScopeProviderResources.NullLifetimeScopeReturned, GetType().FullName)); } } return(LifetimeScope); }
public EmitUoWInterfaceImplementor(IAppScope scope, ICurrentUnitOfWorkProvider provider) { _scope = scope; _provider = provider; _interfaceType = typeof(TInterface); using (var innerScope = _scope.BeginScope()) using (var parentUow = innerScope.Resolve <IUnitOfWorkImplementation>()) { if (parentUow == null) { throw new NCoreException("Ошибка определения родительской реализации UoW"); } _parentType = parentUow.GetType(); } _scopeProperty = _parentType.GetProperty("Scope"); }
/// <summary> /// Constructor. /// </summary> /// <param name="appScope">Required: the <see cref="IAppScope.GetAppDataFolderPath"/> and /// <see cref="IAppScope.AppGuid"/> determines the location and name of the trace log file.</param> /// <param name="traceFileFactoryAssembly">Required: all trace output traced by this class /// is traced with a trace source fetched for this assembly. The assembly is not /// otherwise used here.</param> /// <param name="logFileRootLocation">Selects the root location for the trace output /// file. Defaults to <see cref="Environment.SpecialFolder.LocalApplicationData"/>. /// Notice that this argument is nullable: if this is null, then the root folder is /// <see cref="Path.GetTempPath"/>. Then, in either case, the file is then within the /// <see cref="IAppScope.GetAppDataFolderPath"/> within this root folder (and /// then any optional further subfolder specified by /// <paramref name="logFileInnerSubFolder"/>.</param> /// <param name="logFileInnerSubFolder">This can specify an optional further subfolder /// that is created within the <see cref="IAppScope.GetAppDataFolderPath"/>.</param> /// <param name="addToTraceSources">Defaults to true: this factory adds itself to /// <see cref="TraceSources"/> to configure all sources created there.</param> public LogFileFactory( IAppScope appScope, Assembly traceFileFactoryAssembly, Environment.SpecialFolder?logFileRootLocation = Environment.SpecialFolder.LocalApplicationData, string logFileInnerSubFolder = null, bool addToTraceSources = true) { AppScope = appScope ?? throw new ArgumentNullException(nameof(appScope)); TraceFileFactoryAssembly = traceFileFactoryAssembly ?? throw new ArgumentNullException(nameof(traceFileFactoryAssembly)); LogFileRootLocation = logFileRootLocation; LogFileInnerSubFolder = string.IsNullOrWhiteSpace(logFileInnerSubFolder) ? null : logFileInnerSubFolder; this.addToTraceSources = addToTraceSources; new LogFileFactoryConfig().SetPropertiesOn(this); trySetPropertiesFromConfigFile(); }
// ------------------------------------------ // EXECUTING // ------------------------------------------ #region Executing /// <summary> /// Executes this instance with result. /// </summary> /// <param name="resultString">The result to get.</param> /// <param name="appScope">The application scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="runtimeMode">The runtime mode to consider.</param> /// <returns>The log of execution log.</returns> public override ILog ExecuteWithResult( out string resultString, IAppScope appScope = null, IScriptVariableSet scriptVariableSet = null, RuntimeMode runtimeMode = RuntimeMode.Normal) { resultString = ""; ILog log = appScope.Check(true); if (string.IsNullOrEmpty(this.FileName)) { log.AddWarning( title: "File name missing", description: "No file name defined in command '" + this.Key() + "'."); } else if (!log.HasErrorsOrExceptions()) { try { Process process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.FileName = this.FileName; process.StartInfo.Arguments = this.ArgumentString; process.StartInfo.WorkingDirectory = this.WorkingDirectory; process.Start(); resultString = process.StandardOutput.ReadToEnd(); process.WaitForExit(); } catch (Exception ex) { log.AddException(ex); } } return(log); }
public EfUnitOfWork(IAppScope scope, ICurrentUnitOfWorkProvider uowProvider) { if (scope == null) throw new ArgumentNullException("scope"); if (uowProvider == null) throw new ArgumentNullException("uowProvider"); _currentUnitOfWorkProvider = uowProvider; if (_currentUnitOfWorkProvider.Current != null) throw new NCoreException("В текущем контексте уже открыт юнит-оф-ворк. Закройте его перед тем как открывать новый."); _currentUnitOfWorkProvider.Current = this; Scope = scope.BeginScope(); var dbContextFactory = Scope.Resolve<IDbContextFactory>(); if (dbContextFactory == null) throw new NCoreException("Не удалось инициализировать UoW EF, не удалос получить фабрику контекста подключения"); DbContext = dbContextFactory.CreateDbContext(); }
public EmitInterfaceImplementor(IAppScope scope) { this._scope = scope; }
/// <summary> /// Initializes a new instance of the <see cref="RequestLifetimeScopeProvider"/> class. /// </summary> /// <param name="container">The parent container, usually the application container.</param> public RequestLifetimeScopeProvider(IAppScope container) { if (container == null) throw new ArgumentNullException("container"); _container = container; RequestLifetimeHttpModule.SetLifetimeScopeProvider(this); }
/// <summary> /// Gets a nested lifetime scope that services can be resolved from. /// </summary> /// <param name="configurationAction"> /// A configuration action that will execute during lifetime scope creation. /// </param> /// <returns>A new or existing nested lifetime scope.</returns> public IAppScope GetLifetimeScope(Action<ContainerBuilder> configurationAction) { if (HttpContext.Current == null) { throw new InvalidOperationException(RequestLifetimeScopeProviderResources.HttpContextNotAvailable); } if (LifetimeScope == null) { if ((LifetimeScope = GetLifetimeScopeCore(configurationAction)) == null) throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, RequestLifetimeScopeProviderResources.NullLifetimeScopeReturned, GetType().FullName)); } return LifetimeScope; }
public NotesController(IRepository repository, IAppScope appScope) : base(appScope) { Ensure.ArgumentNotNull(repository, "repository"); _repository = repository; }
/// <summary> /// Initializes a new instance of the <see cref="ZenCoreDependencyResolver"/> class. /// </summary> /// <param name="container">The container that nested lifetime scopes will be create from.</param> /// <param name="lifetimeScopeProvider">A <see cref="ILifetimeScopeProvider"/> implementation for /// creating new lifetime scopes.</param> public ZenCoreDependencyResolver(IAppScope container, ILifetimeScopeProvider lifetimeScopeProvider) : this(container) { if (lifetimeScopeProvider == null) throw new ArgumentNullException("lifetimeScopeProvider"); _lifetimeScopeProvider = lifetimeScopeProvider; }
/// <summary> /// Initializes a new instance of the <see cref="ZenCoreDependencyResolver"/> class. /// </summary> /// <param name="container">The container that nested lifetime scopes will be create from.</param> /// <param name="lifetimeScopeProvider">A <see cref="ILifetimeScopeProvider"/> implementation for /// creating new lifetime scopes.</param> /// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/> /// that adds component registations visible only in nested lifetime scopes.</param> public ZenCoreDependencyResolver(IAppScope container, ILifetimeScopeProvider lifetimeScopeProvider, Action<ContainerBuilder> configurationAction) : this(container, lifetimeScopeProvider) { if (configurationAction == null) throw new ArgumentNullException("configurationAction"); _configurationAction = configurationAction; }
public ApplicationController(IAppScope appScope) { _appScope = appScope; CreateController(); }
//------------------------------------------ // EXECUTION //----------------------------------------- #region Execution /// <summary> /// Executes this instance with result. /// </summary> /// <param name="resultString">The result to get.</param> /// <param name="appScope">The application scope to consider.</param> /// <param name="scriptVariableSet">The script variable set to use.</param> /// <param name="runtimeMode">The runtime mode to consider.</param> /// <returns>The log of execution log.</returns> public abstract ILog ExecuteWithResult( out string resultString, IAppScope appScope = null, IScriptVariableSet scriptVariableSet = null, RuntimeMode runtimeMode = RuntimeMode.Normal);
/// <summary> /// Initializes a new instance of the <see cref="ZenCoreDependencyResolver"/> class. /// </summary> /// <param name="container">The container that nested lifetime scopes will be create from.</param> public ZenCoreDependencyResolver(IAppScope container) { if (container == null) throw new ArgumentNullException("container"); _container = container; }