コード例 #1
0
ファイル: ReferenceCommand.cs プロジェクト: bindopen/BindOpen
        //------------------------------------------
        // 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);
        }
コード例 #2
0
ファイル: ScriptCommand.cs プロジェクト: bindopen/BindOpen
        //------------------------------------------
        // 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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
ファイル: EfUnitOfWork.cs プロジェクト: Vitala/NCore
        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();
        }
コード例 #5
0
 /// <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;
 }
コード例 #6
0
        public EmitRawUoWInterfaceImplementor(IAppScope scope)
        {
            _scope = scope;

            _interfaceType = typeof(TInterface);

            _isDisposable = _interfaceType.IsAssignableTo <IDisposable>();
        }
コード例 #7
0
 /// <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;
 }
コード例 #8
0
 /// <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;
 }
コード例 #9
0
 /// <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);
 }
コード例 #10
0
        /// <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);
        }
コード例 #11
0
        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");
        }
コード例 #12
0
 /// <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();
 }
コード例 #13
0
ファイル: ShellCommand.cs プロジェクト: bindopen/BindOpen
        // ------------------------------------------
        // 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);
        }
コード例 #14
0
ファイル: EfUnitOfWork.cs プロジェクト: Vitala/NCore
        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();
        }
コード例 #15
0
 public EmitInterfaceImplementor(IAppScope scope)
 {
     this._scope = scope;
 }
コード例 #16
0
 /// <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);
 }
コード例 #17
0
        /// <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;
        }
コード例 #18
0
 public NotesController(IRepository repository, IAppScope appScope)
     : base(appScope)
 {
     Ensure.ArgumentNotNull(repository, "repository");
     _repository = repository;
 }
コード例 #19
0
 /// <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;
 }
コード例 #20
0
 /// <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;
 }
コード例 #21
0
 public ApplicationController(IAppScope appScope)
 {
     _appScope = appScope;
     CreateController();
 }
コード例 #22
0
ファイル: Command.cs プロジェクト: bindopen/BindOpen
        //------------------------------------------
        // 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);
コード例 #23
0
 /// <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;
 }