示例#1
0
 private SerializationContext(ContextMode contextMode, IStreamSource streamSource, SerializerMode serializerMode, BackgroundStream parentStream)
 {
     ContextMode       = contextMode;
     StreamSource      = Argument.NotNull(streamSource, nameof(streamSource));
     SerializerMode    = Argument.NotNull(serializerMode, nameof(serializerMode));
     _backgroundStream = Argument.NotNull(parentStream, nameof(parentStream));
 }
示例#2
0
        public SerializationContext?GetSubContext([CanBeNull] string relativeFile, ContextMode contextMode)
        {
            if (relativeFile == null)
            {
                return(this);
            }

            if (_childContexts.TryGetValue(relativeFile, out var context))
            {
                return(context);
            }

            var streamSource = StreamSource.OpenSideLocation(relativeFile);

            if (streamSource == null)
            {
                return(null);
            }
            if (_backgroundStream == null)
            {
                return(null);
            }

            context = new SerializationContext(contextMode, streamSource, SerializerMode, _backgroundStream);
            _childContexts[relativeFile] = context;

            return(context);
        }
示例#3
0
 public SerializationContext(ContextMode contextMode, IStreamSource streamSource, SerializerMode serializerMode)
 {
     ContextMode       = contextMode;
     StreamSource      = Argument.NotNull(streamSource, nameof(streamSource));
     SerializerMode    = Argument.NotNull(serializerMode, nameof(serializerMode));
     _backgroundStream = new BackgroundStream();
 }
 /// <summary>
 /// Configures the database context to the given mode
 /// </summary>
 public static void SetContextMode(this DbContext dbContext, ContextMode mode)
 {
     dbContext.Configuration.ProxyCreationEnabled     = mode.HasFlag(ContextMode.ProxyOnly);
     dbContext.Configuration.LazyLoadingEnabled       = mode.HasFlag(ContextMode.LazyLoading);
     dbContext.Configuration.AutoDetectChangesEnabled = mode.HasFlag(ContextMode.ChangeTracking);
     dbContext.Configuration.ValidateOnSaveEnabled    = true;
 }
        /// <inheritdoc />
        public DbContext CreateContext(IDatabaseConfig config, ContextMode mode)
        {
            var context = (DbContext)Activator.CreateInstance(_contextType, BuildConnectionString(config));

            context.SetContextMode(mode);
            return(context);
        }
示例#6
0
        /// <summary>
        /// Gets the drawing context.
        /// </summary>
        /// <param name="contextId">A context id like 2d.</param>
        /// <returns>An object that defines the drawing context.</returns>
        public IRenderingContext GetContext(String contextId)
        {
            if (_current != null && _current.ContextId.Equals(contextId, StringComparison.OrdinalIgnoreCase))
            {
                return(_current);
            }

            var renderService = Owner.Options.GetService <IRenderingService>();

            if (renderService == null)
            {
                return(null);
            }

            var context = renderService.CreateContext(contextId);

            if (context != null)
            {
                context.Host = this;
                _mode        = GetModeFrom(contextId);
                _current     = context;
            }

            return(context);
        }
示例#7
0
        public void SetContext(string game, ContextMode mode)
        {
            Game = game;
            Mode = mode;

            OnContextChange?.Invoke(this, new ContextChangeEventArgs(game, mode));
        }
        /// <summary>
        /// Gets the drawing context.
        /// </summary>
        /// <param name="contextId">A context id like 2d.</param>
        /// <returns>An object that defines the drawing context.</returns>
        public IRenderingContext GetContext(String contextId)
        {
            if (_current == null || contextId.Isi(_current.ContextId))
            {
                foreach (var renderService in _renderServices)
                {
                    if (renderService.IsSupportingContext(contextId))
                    {
                        var context = renderService.CreateContext(this, contextId);

                        if (context != null)
                        {
                            _mode    = GetModeFrom(contextId);
                            _current = context;
                        }

                        return(context);
                    }
                }

                return(null);
            }

            return(_current);
        }
 public SerializationContext(ContextMode contextMode, [NotNull] IStreamSource streamSource, SerializerMode serializerMode)
 {
     ContextMode = contextMode;
     StreamSource = streamSource;
     SerializerMode = serializerMode;
     _backgroundStream = new BackgroundStream();
 }
示例#10
0
        /// <summary>
        /// Gets the drawing context.
        /// </summary>
        /// <param name="contextId">A context id like 2d.</param>
        /// <returns>An object that defines the drawing context.</returns>
        public IRenderingContext GetContext(String contextId)
        {
            if (_current == null || contextId.Isi(_current.ContextId))
            {
                var renderServices = Owner.Options.GetServices<IRenderingService>();

                foreach (var renderService in renderServices)
                {
                    if (renderService.IsSupportingContext(contextId))
                    {
                        var context = renderService.CreateContext(this, contextId);

                        if (context != null)
                        {
                            _mode = GetModeFrom(contextId);
                            _current = context;
                        }

                        return context;
                    }
                }

                return null;
            }

            return _current;

        }
示例#11
0
        public override IContent Route(UrlBuilder urlBuilder, ContextMode contextMode)
        {
            // Attempts to parse content ID from the path.
            // This only works with URLs generated with the GetUrl method, where the URL is the content ID.
            // If contentRepository is provided, load the content from there, otherwise return BasicContent.

            int id;

            if (int.TryParse(urlBuilder.Path, out id))
            {
                var contentLink = new ContentReference(id);
                if (contentRepository != null)
                {
                    return(contentRepository.Get <IContent>(contentLink));
                }
                else
                {
                    return new BasicContent {
                               ContentLink = contentLink
                    }
                };
            }

            return(null);
        }
 private SerializationContext(ContextMode contextMode, [NotNull] IStreamSource streamSource,
                              SerializerMode serializerMode, [NotNull] BackgroundStream parentStream)
 {
     ContextMode = contextMode;
     StreamSource = streamSource;
     SerializerMode = serializerMode;
     _backgroundStream = parentStream;
 }
示例#13
0
        public void SetContext(ContextGame game, ContextMode mode)
        {
            currentGame = game;
            currentMode = mode;

            if (OnContextChange != null)
            {
                OnContextChange(this, new ContextChangeEventArgs(game, mode));
            }
        }
示例#14
0
        /// <inheritdoc />
        public TContext Create <TContext>(IDatabaseConfig config, ContextMode contextMode) where TContext : DbContext
        {
            var connection = string.IsNullOrEmpty(_instanceId)
                ? Effort.DbConnectionFactory.CreatePersistent(Guid.NewGuid().ToString())
                : Effort.DbConnectionFactory.CreatePersistent(_instanceId);

            // Create instance of context
            var context = (TContext)Activator.CreateInstance(typeof(TContext), connection);

            // Override initializer of MoryxDbContext: Create database if not exists
            Database.SetInitializer(new CreateDatabaseIfNotExists <TContext>());

            return(context);
        }
示例#15
0
        /// <inheritdoc />
        public TContext Create <TContext>(IDatabaseConfig config, ContextMode contextMode) where TContext : DbContext
        {
            var wrapper = _knownModels.FirstOrDefault(k => k.DbContextType == typeof(TContext));

            if (wrapper == null)
            {
                throw new InvalidOperationException("Unknown model");
            }

            var configurator = wrapper.Configurator;

            return(config != null
                ? (TContext)configurator.CreateContext(config, contextMode)
                : (TContext)configurator.CreateContext(contextMode));
        }
示例#16
0
        /// <summary>
        /// Changes the context the element is related to the given one.
        /// </summary>
        /// <param name="context">The new context.</param>
        public void SetContext(IRenderingContext context)
        {
            if (_mode != ContextMode.None && _mode != ContextMode.Indirect)
            {
                throw new DomException(DomError.InvalidState);
            }
            else if (context.IsFixed)
            {
                throw new DomException(DomError.InvalidState);
            }

            context.Host = this;
            _current     = context;
            _mode        = ContextMode.Indirect;
        }
示例#17
0
        /// <summary>
        /// Gets the drawing context.
        /// </summary>
        /// <param name="contextId">A context id like 2d.</param>
        /// <returns>An object that defines the drawing context.</returns>
        public IRenderingContext GetContext(String contextId)
        {
            if (_current != null && contextId.Isi(_current.ContextId))
                return _current;

            var renderService = Owner.Options.GetService<IRenderingService>();

            if (renderService == null)
                return null;

            var context = renderService.CreateContext(this, contextId);

            if (context != null)
            {
                _mode = GetModeFrom(contextId);
                _current = context;
            }

            return context;
        }
示例#18
0
        /// <summary>
        /// Gets the drawing context.
        /// </summary>
        /// <param name="contextId">A context id like 2d.</param>
        /// <returns>An object that defines the drawing context.</returns>
        public IRenderingContext GetContext(String contextId)
        {
            if (_current != null && _current.ContextId.Equals(contextId, StringComparison.OrdinalIgnoreCase))
                return _current;

            var renderService = Owner.Options.GetService<IRenderingService>();

            if (renderService == null)
                return null;

            var context = renderService.CreateContext(this, contextId);

            if (context != null)
            {
                _mode = GetModeFrom(contextId);
                _current = context;
            }

            return context;
        }
示例#19
0
        /// <summary>
        /// Gets the drawing context.
        /// </summary>
        /// <param name="contextId">A context id like 2d.</param>
        /// <returns>An object that defines the drawing context.</returns>
        public IRenderingContext GetContext(String contextId)
        {
            if (_current != null && contextId.Isi(_current.ContextId))
            {
                return(_current);
            }

            var renderService = Owner.Options.GetService <IRenderingService>();

            if (renderService == null)
            {
                return(null);
            }

            var context = renderService.CreateContext(this, contextId);

            if (context != null)
            {
                _mode    = GetModeFrom(contextId);
                _current = context;
            }

            return(context);
        }
示例#20
0
 /// <summary>
 /// Возвращает контекст доверенного подключения (без пароля или Integrated Security)
 /// </summary>
 /// <param name="mode">Тип подключения.</param>
 /// <param name="serverNameORPath">Название сервера или директория расположения файла базы.</param>
 /// <param name="dataBaseName">Название базы или имя базы без расширения, расширение берётся из типа подключения.</param>
 /// <returns></returns>
 public abstract MainContext GetContext(ContextMode mode, String serverNameORPath, String dataBaseName);
 /// <inheritdoc />
 public IUnitOfWork <TContext> Create(ContextMode contextMode) =>
 _internalFactory.Create(contextMode);
 public void SetContextMode(ContextMode contextMode)
 {
     this.contextMode = contextMode;
 }
示例#23
0
 protected void EnterContext(ContextMode mode)
 {
     _contextStack.Push(mode);
 }
示例#24
0
 protected void EnterContext(ContextMode mode)
 {
     _contextStack.Push(mode);
 }
示例#25
0
        public void SetContext(ContextGame game, ContextMode mode)
        {
            currentGame = game;
            currentMode = mode;

            if (OnContextChange != null) { OnContextChange(this, new ContextChangeEventArgs(game, mode)); }
        }
示例#26
0
 /// <summary>
 /// Displays the context menu
 /// </summary>
 /// <param name="mode">Display mode</param>
 /// <param name="data">User data</param>
 private void SetContext(ContextMode mode, object data = null)
 {
     Context_Mode = mode;
     Context_Data = data;
 }
示例#27
0
 public ContextChangeEventArgs(ContextGame game, ContextMode mode)
 {
     this.GameContext = game;
     this.ModeContext = mode;
 }
示例#28
0
 public void SetContext(ContextMode mode)
 {
     SetContext(currentGame, mode);
 }
示例#29
0
 /// <inheritdoc />
 public TContext Create <TContext>(ContextMode contextMode) where TContext : DbContext =>
 Create <TContext>(null, contextMode);
 /// <inheritdoc />
 public TContext Create(IDatabaseConfig config, ContextMode contextMode)
 {
     return(Manager.Create <TContext>(config, contextMode));
 }
 /// <inheritdoc />
 public TContext Create(ContextMode contextMode)
 {
     return(Manager.Create <TContext>(contextMode));
 }
示例#32
0
 public ContextChangeEventArgs(string game, ContextMode mode)
 {
     GameContext = game;
     ModeContext = mode;
 }
 /// <summary>
 /// Creates a new HTML canvas element.
 /// </summary>
 public HtmlCanvasElement(Document owner, String prefix = null)
     : base(owner, TagNames.Canvas, prefix)
 {
     _renderServices = owner.Context.GetServices <IRenderingService>();
     _mode           = ContextMode.None;
 }
 protected SerializerBase(ObjectBuilder builder, SimpleMapper <TContext> mapper, ContextMode contextMode)
 {
     _builder     = Argument.NotNull(builder, nameof(builder));
     _mapper      = Argument.NotNull(mapper, nameof(mapper));
     _contextMode = contextMode;
 }
 //custom constructor to initialize the context with specific connection string and backend configuration
 public FluentModel(string connectionStringName, BackendConfiguration backendConfiguration, FluentModelMetadataSource metadataSource, ContextMode contextMode)
     : base(connectionStringName, backendConfiguration, metadataSource)
 {
     this.mode = contextMode;
 }
示例#36
0
 /// <summary>
 /// Hides the context menu
 /// </summary>
 private void ResetContext()
 {
     Context_Data = null;
     Context_Mode = ContextMode.None;
 }
示例#37
0
        /// <summary>
        /// Changes the context the element is related to the given one.
        /// </summary>
        /// <param name="context">The new context.</param>
        public void SetContext(IRenderingContext context)
        {
            if (_mode != ContextMode.None && _mode != ContextMode.Indirect)
                throw new DomException(DomError.InvalidState);
            else if (context.IsFixed)
                throw new DomException(DomError.InvalidState);

            context.Host = this;
            _current = context;
            _mode = ContextMode.Indirect;
        }
示例#38
0
 public override IContent Route(UrlBuilder urlBuilder, ContextMode contextMode)
 {
     return(_defaultUrlResolver.Route(urlBuilder, contextMode));
 }
示例#39
0
 /// <summary>
 /// Creates a new HTML canvas element.
 /// </summary>
 public HtmlCanvasElement(Document owner, String prefix = null)
     : base(owner, Tags.Canvas, prefix)
 {
     _mode = ContextMode.None;
 }
示例#40
0
 /// <summary>
 /// Creates a new HTML canvas element.
 /// </summary>
 public HtmlCanvasElement(Document owner, String prefix = null)
     : base(owner, Tags.Canvas, prefix)
 {
     _mode = ContextMode.None;
 }
示例#41
0
        /// <inheritdoc />
        public IUnitOfWork <TContext> Create(IDatabaseConfig config, ContextMode contextMode)
        {
            var context = _manager.Create <TContext>(config, contextMode);

            return(new UnitOfWork <TContext>(context, Repositories));
        }
 /// <inheritdoc />
 public IUnitOfWork <TContext> Create(IDatabaseConfig config, ContextMode contextMode) =>
 _internalFactory.Create(config, contextMode);
示例#43
0
 public void SetContext(ContextMode mode)
 {
     SetContext(Game, mode);
 }
示例#44
0
 /// <inheritdoc />
 public DbContext CreateContext(IDatabaseConfig config, ContextMode mode)
 {
     throw new NotSupportedException("Not supported by " + nameof(NullModelConfigurator));
 }
        public SerializationContext GetSubContext([CanBeNull] string relativeFile, ContextMode contextMode)
        {
            if (relativeFile == null) return this;

            SerializationContext context;
            if (_childContexts.TryGetValue(relativeFile, out context)) return context;

            IStreamSource streamSource = StreamSource.OpenSideLocation(relativeFile);
            if (streamSource == null) return null;

            context = new SerializationContext(contextMode, streamSource, SerializerMode, _backgroundStream);
            _childContexts[relativeFile] = context;

            return context;
        }