Пример #1
0
 public static void AddDbContextOptions <TDbContext>(this IServiceCollection services) where TDbContext : DbContext
 {
     services.AddScoped <DbContextOptions <TDbContext> >(sp =>
     {
         IConnectionHolder holder       = sp.GetService <IConnectionHolder>();
         IDatabaseConfiguring configure = sp.GetService <IDatabaseConfiguring>();
         DbContextOptionsBuilder <TDbContext> optBuilder = new DbContextOptionsBuilder <TDbContext>();
         configure.OnConfiguring(optBuilder, holder.DbConnection);
         return(optBuilder.Options);
     });
 }
Пример #2
0
 public void OnConnected(IConnectionHolder <OPCServer> aConnectionHolder)
 {
     logger.Info("Подключен " + aConnectionHolder.GetHolderName());
     try {
         if (!kppConnector.IsInitialized())
         {
             kppConnector.Initialize();
         }
         checkTimer.Start();
     }
     catch (Exception ex) {
         logger.Error("Ошибка при инициализации kppConnector: " + ex.Message);
     }
 }
Пример #3
0
        /// <summary>
        /// Returns the next message, if any.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="connectionHolder">The connection.</param>
        /// <param name="noMessageFoundActon">The no message found action.</param>
        /// <returns>
        /// A message if one is found; null otherwise
        /// </returns>
        public IReceivedMessageInternal GetMessage(IMessageContext context, IConnectionHolder <SqlConnection, SqlTransaction, SqlCommand> connectionHolder,
                                                   Action <IConnectionHolder <SqlConnection, SqlTransaction, SqlCommand> > noMessageFoundActon)
        {
            //if stopping, exit now
            if (_cancelToken.Tokens.Any(t => t.IsCancellationRequested))
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //check for a specific MessageID to pull
            IMessageId messageId = null;
            var        rpc       = context.Get(_configuration.HeaderNames.StandardHeaders.RpcContext);

            if (rpc?.MessageId != null && rpc.MessageId.HasValue)
            {
                messageId = rpc.MessageId;
            }

            //ask for the next message, or a specific message if we have a messageID
            var receivedTransportMessage =
                _receiveMessage.Handle(new ReceiveMessageQuery <SqlConnection, SqlTransaction>(connectionHolder.Connection,
                                                                                               connectionHolder.Transaction, messageId, _configuration.Routes));

            //if no message (null) run the no message action and return
            if (receivedTransportMessage == null)
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //set the message ID on the context for later usage
            context.MessageId = receivedTransportMessage.MessageId;

            //if we are holding open transactions, we need to update the status table in a separate call
            //When not using held transactions, this is part of the de-queue statement and so not needed here

            //TODO - we could consider using a task to update the status table
            //the status table drives nothing internally, however it may drive external processes
            //because of that, we are not returning the message until the status table is updated.
            //we could make this a configurable option in the future?
            if (_configuration.Options().EnableHoldTransactionUntilMessageCommitted&&
                _configuration.Options().EnableStatusTable)
            {
                _setStatusCommandHandler.Handle(
                    new SetStatusTableStatusCommand(
                        (long)receivedTransportMessage.MessageId.Id.Value, QueueStatuses.Processing));
            }
            return(receivedTransportMessage);
        }
 /// <summary>
 /// Clean up the message context when processing is done
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="connectionHolder">The connection.</param>
 private void ContextCleanup(IMessageContext context, IConnectionHolder <SqlConnection, SqlTransaction, SqlCommand> connectionHolder)
 {
     if (!_configuration.Options().EnableHoldTransactionUntilMessageCommitted)
     {
         context.Commit   -= ContextOnCommit;
         context.Rollback -= ContextOnRollback;
     }
     else
     {
         context.Commit   -= ContextOnCommitTransaction;
         context.Rollback -= ContextOnRollbackTransaction;
     }
     context.Cleanup -= Context_Cleanup;
     _disposeConnection(connectionHolder);
 }
Пример #5
0
        /// <summary>
        /// Returns the next message, if any.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="connectionHolder">The connection.</param>
        /// <param name="noMessageFoundActon">The no message found action.</param>
        /// <param name="routes">The routes.</param>
        /// <returns>
        /// A message if one is found; null otherwise
        /// </returns>
        public IReceivedMessageInternal GetMessage(IMessageContext context, IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> connectionHolder,
                                                   Action <IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> > noMessageFoundActon, List <string> routes)
        {
            //if stopping, exit now
            if (_cancelToken.Tokens.Any(t => t.IsCancellationRequested))
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //ask for the next message
            var receivedTransportMessage =
                _receiveMessage.Handle(new ReceiveMessageQuery <NpgsqlConnection, NpgsqlTransaction>(connectionHolder.Connection,
                                                                                                     connectionHolder.Transaction, routes));

            return(ProcessMessage(receivedTransportMessage, connectionHolder, context, noMessageFoundActon));
        }
Пример #6
0
        /// <summary>
        /// Returns the next message, if any.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="connectionHolder">The connection.</param>
        /// <param name="noMessageFoundActon">The no message found action.</param>
        /// <param name="routes">The routes.</param>
        /// <returns>
        /// A message if one is found; null otherwise
        /// </returns>
        public IReceivedMessageInternal GetMessage(IMessageContext context, IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> connectionHolder,
                                                   Action <IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> > noMessageFoundActon, List <string> routes)
        {
            //if stopping, exit now
            if (_cancelToken.Tokens.Any(t => t.IsCancellationRequested))
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //check for a specific MessageID to pull
            IMessageId messageId = null;
            var        rpc       = context.Get(_configuration.HeaderNames.StandardHeaders.RpcContext);

            if (rpc?.MessageId != null && rpc.MessageId.HasValue)
            {
                messageId = rpc.MessageId;
            }

            //ask for the next message, or a specific message if we have a messageID
            var receivedTransportMessage =
                _receiveMessage.Handle(new ReceiveMessageQuery <NpgsqlConnection, NpgsqlTransaction>(connectionHolder.Connection,
                                                                                                     connectionHolder.Transaction, messageId, routes));

            //if no message (null) run the no message action and return
            if (receivedTransportMessage == null)
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //set the message ID on the context for later usage
            context.MessageId = receivedTransportMessage.MessageId;

            //we need to update the status table here, as we don't do it as part of the de-queue
            if (_configuration.Options().EnableStatusTable)
            {
                _setStatusCommandHandler.Handle(
                    new SetStatusTableStatusCommand(
                        (long)receivedTransportMessage.MessageId.Id.Value, QueueStatuses.Processing));
            }
            return(receivedTransportMessage);
        }
Пример #7
0
        private IReceivedMessageInternal ProcessMessage(IReceivedMessageInternal receivedTransportMessage,
                                                        IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> connectionHolder,
                                                        IMessageContext context,
                                                        Action <IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> > noMessageFoundActon)
        {
            //if no message (null) run the no message action and return
            if (receivedTransportMessage == null)
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //set the message ID on the context for later usage
            context.SetMessageAndHeaders(receivedTransportMessage.MessageId, receivedTransportMessage.Headers);

            //we need to update the status table here, as we don't do it as part of the de-queue
            if (_configuration.Options().EnableStatusTable)
            {
                _setStatusCommandHandler.Handle(
                    new SetStatusTableStatusCommand <long>(
                        (long)receivedTransportMessage.MessageId.Id.Value, QueueStatuses.Processing));
            }
            return(receivedTransportMessage);
        }
Пример #8
0
        /// <summary>
        /// Returns the next message, if any.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="connectionHolder">The connection.</param>
        /// <param name="noMessageFoundActon">The no message found action.</param>
        /// <param name="routes">The routes.</param>
        /// <returns>
        /// A message if one is found; null otherwise
        /// </returns>
        public async Task <IReceivedMessageInternal> GetMessageAsync(IMessageContext context, IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> connectionHolder,
                                                                     Action <IConnectionHolder <NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand> > noMessageFoundActon, List <string> routes)
        {
            //if stopping, exit now
            if (_cancelToken.Tokens.Any(t => t.IsCancellationRequested))
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //ask for the next message, or a specific message if we have a messageID
            var receivedTransportMessage = await
                                           _receiveMessageAsync.Handle(new ReceiveMessageQueryAsync <NpgsqlConnection, NpgsqlTransaction>(connectionHolder.Connection,
                                                                                                                                          connectionHolder.Transaction, routes)).ConfigureAwait(false);

            return(ProcessMessage(receivedTransportMessage, connectionHolder, context, noMessageFoundActon));
        }
 public DataAccessObject(IConnectionHolder connectionHolder)
 {
     _connectionHolder = connectionHolder;
 }
Пример #10
0
 public TransactionManager(IConnectionHolder connectionHolder)
 {
     _connectionHolder = connectionHolder;
 }
Пример #11
0
        /// <summary>
        /// Returns the next message, if any.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="connectionHolder">The connection.</param>
        /// <param name="noMessageFoundActon">The no message found action.</param>
        /// <returns>
        /// A message if one is found; null otherwise
        /// </returns>
        public async Task <IReceivedMessageInternal> GetMessageAsync(IMessageContext context, IConnectionHolder <SqlConnection, SqlTransaction, SqlCommand> connectionHolder,
                                                                     Action <IConnectionHolder <SqlConnection, SqlTransaction, SqlCommand> > noMessageFoundActon)
        {
            //if stopping, exit now
            if (_cancelToken.Tokens.Any(t => t.IsCancellationRequested))
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //ask for the next message
            var receivedTransportMessage = await
                                           _receiveMessageAsync.Handle(new ReceiveMessageQueryAsync <SqlConnection, SqlTransaction>(connectionHolder.Connection,
                                                                                                                                    connectionHolder.Transaction, _configuration.Routes)).ConfigureAwait(false);

            //if no message (null) run the no message action and return
            if (receivedTransportMessage == null)
            {
                noMessageFoundActon(connectionHolder);
                return(null);
            }

            //set the message ID on the context for later usage
            context.SetMessageAndHeaders(receivedTransportMessage.MessageId, receivedTransportMessage.Headers);

            //if we are holding open transactions, we need to update the status table in a separate call
            //When not using held transactions, this is part of the de-queue statement and so not needed here

            //TODO - we could consider using a task to update the status table
            //the status table drives nothing internally, however it may drive external processes
            //because of that, we are not returning the message until the status table is updated.
            //we could make this a configurable option in the future?
            if (_configuration.Options().EnableHoldTransactionUntilMessageCommitted&&
                _configuration.Options().EnableStatusTable)
            {
                _setStatusCommandHandler.Handle(
                    new SetStatusTableStatusCommand(
                        (long)receivedTransportMessage.MessageId.Id.Value, QueueStatuses.Processing));
            }
            return(receivedTransportMessage);
        }
Пример #12
0
 public void OnDisconnected(IConnectionHolder <OracleConnection> aConnectionHolder)
 {
     logger.Info("Отключен " + aConnectionHolder.GetHolderName());
 }
Пример #13
0
 public void OnConnected(IConnectionHolder <OracleConnection> aConnectionHolder)
 {
     logger.Info("Подключен " + aConnectionHolder.GetHolderName());
     TryStoreBufferedValues();
 }
Пример #14
0
        public static void UseZKEACMS(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddMvc(option =>
            {
                option.ModelBinderProviders.Insert(0, new WidgetTypeModelBinderProvider());
                option.ModelMetadataDetailsProviders.Add(new DataAnnotationsMetadataProvider());
            })
            .AddControllersAsServices()
            .AddJsonOptions(option => { option.SerializerSettings.DateFormatString = "yyyy-MM-dd"; })
            .SetCompatibilityVersion(CompatibilityVersion.Latest);

            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.TryAddScoped <IApplicationContextAccessor, ApplicationContextAccessor>();
            services.TryAddScoped <IApplicationContext, CMSApplicationContext>();
            services.TryAddSingleton <IRouteProvider, RouteProvider>();

            services.AddTransient <IRouteDataProvider, PaginationRouteDataProvider>();
            services.AddTransient <IRouteDataProvider, PostIdRouteDataProvider>();
            services.AddTransient <IRouteDataProvider, CategoryRouteDataProvider>();
            services.AddTransient <IRouteDataProvider, HtmlRouteDataProvider>();

            services.TryAddSingleton <IAdminMenuProvider, AdminMenuProvider>();
            services.TryAddTransient <IWidgetActivator, DefaultWidgetActivator>();
            services.TryAddTransient <ICarouselItemService, CarouselItemService>();
            services.TryAddTransient <ICarouselService, CarouselService>();
            services.TryAddTransient <INavigationService, NavigationService>();

            services.TryAddTransient <IDashboardProviderService, DashboardProviderService>();
            services.AddTransient <IDashboardPartDriveService, DashboardWelcomePartService>();
            services.AddTransient <IDashboardPartDriveService, DashboardEventLogPartService>();

            services.TryAddTransient <IDataArchivedService, DataArchivedService>();
            services.TryAddTransient <IExtendFieldService, ExtendFieldService>();
            services.TryAddTransient <INotifyService, NotifyService>();
            services.AddTransient <IUserCenterLinksProvider, UserCenterLinksProvider>();
            services.TryAddTransient <ILayoutService, LayoutService>();
            services.TryAddTransient <ILayoutHtmlService, LayoutHtmlService>();
            services.TryAddTransient <IMediaService, MediaService>();
            services.TryAddTransient <IPageService, PageService>();
            services.TryAddTransient <IApplicationSettingService, ApplicationSettingService>();
            services.TryAddTransient <IThemeService, ThemeService>();
            services.TryAddTransient <IWidgetTemplateService, WidgetTemplateService>();
            services.TryAddTransient <IWidgetBasePartService, WidgetBasePartService>();
            services.TryAddTransient <IZoneService, ZoneService>();
            services.TryAddTransient <Rule.IRuleService, Rule.RuleService>();

            services.AddScoped <IOnModelCreating, EntityFrameWorkModelCreating>();

            services.AddTransient <Easy.Notification.ISmtpProvider, SmtpProvider>();
            services.AddTransient <IPackageInstaller, ThemePackageInstaller>();
            services.AddTransient <IPackageInstaller, WidgetPackageInstaller>();
            services.AddTransient <IPackageInstaller, FilePackageInstaller>();
            services.AddTransient <IPackageInstaller, DataDictionaryPackageInstaller>();
            services.AddTransient <IPackageInstallerProvider, PackageInstallerProvider>();
            services.AddTransient <IEventViewerService, EventViewerService>();

            services.ConfigureCache <IEnumerable <WidgetBase> >();
            services.ConfigureCache <IEnumerable <ZoneEntity> >();
            services.ConfigureCache <IEnumerable <LayoutHtml> >();

            services.ConfigureMetaData <ArticleEntity, ArticleEntityMeta>();
            services.ConfigureMetaData <ArticleType, ArtycleTypeMetaData>();
            services.ConfigureMetaData <BreadcrumbWidget, BreadcrumbWidgetMetaData>();
            services.ConfigureMetaData <CarouselEntity, CarouselEntityMetaData>();
            services.ConfigureMetaData <CarouselWidget, CarouselWidgetMetaData>();
            services.ConfigureMetaData <CarouselItemEntity, CarouselItemEntityMeta>();
            services.ConfigureMetaData <HtmlWidget, HtmlWidgetMetaData>();
            services.ConfigureMetaData <ImageWidget, ImageWidgetMedaData>();
            services.ConfigureMetaData <NavigationEntity, NavigationEntityMeta>();
            services.ConfigureMetaData <NavigationWidget, NavigationWidgetMetaData>();
            services.ConfigureMetaData <ScriptWidget, ScriptWidgetMetaData>();
            services.ConfigureMetaData <StyleSheetWidget, StyleSheetWidgetMetaData>();
            services.ConfigureMetaData <VideoWidget, VideoWidgetMetaData>();
            services.ConfigureMetaData <DataArchived.DataArchived, DataArchivedMetaData>();
            services.ConfigureMetaData <ExtendFieldEntity, ExtendFieldEntityMetaData>();
            services.ConfigureMetaData <LayoutEntity, LayoutEntityMetaData>();
            services.ConfigureMetaData <MediaEntity, MediaEntityMetaData>();
            services.ConfigureMetaData <PageEntity, PageMetaData>();
            services.ConfigureMetaData <ProductEntity, ProductMetaData>();
            services.ConfigureMetaData <ProductCategory, ProductCategoryMetaData>();
            services.ConfigureMetaData <ProductImage, ProductImageMetaData>();
            services.ConfigureMetaData <ApplicationSetting, ApplicationSettingMedaData>();
            services.ConfigureMetaData <ThemeEntity, ThemeEntityMetaData>();
            services.ConfigureMetaData <ZoneEntity, ZoneEntityMetaData>();
            services.ConfigureMetaData <Rule.Rule, Rule.RuleMetaData>();
            services.ConfigureMetaData <Rule.RuleItem, Rule.RuleItemMetaData>();
            services.ConfigureMetaData <SmtpSetting, SmtpSettingMetaData>();
            services.ConfigureMetaData <Robots, RobotsMetaData>();

            services.Configure <NavigationWidget>(option =>
            {
                option.DataSourceLinkTitle = "导航";
                option.DataSourceLink      = "~/admin/Navigation";
            });

            services.Configure <CarouselWidget>(option =>
            {
                option.DataSourceLinkTitle = "焦点图";
                option.DataSourceLink      = "~/admin/Carousel";
            });
            #region 数据库配置
            services.AddSingleton <IDbConnectionPool, SimpleDbConnectionPool>();
            //池的配置:
            //MaximumRetained规定池的容量(常态最大保有数量)。
            //MaximumRetained为0时,相当于不使用DbConnection池,
            //但因为在Request期间Connection是保持打开的,所以对许多场合还是有性能改善的。
            services.AddSingleton(new DbConnectionPool.Options()
            {
                MaximumRetained = 128
            });
            //提供在Request期间租、还DbConnection的支持
            services.AddScoped <IConnectionHolder, TransientConnectionHolder>();
            services.AddScoped <DbContextOptions <CMSDbContext> >(sp =>
            {
                //租一个DbConnection(将在Request完成后还回,因为其Lifetime为Scoped类型)
                IConnectionHolder holder       = sp.GetService <IConnectionHolder>();
                IDatabaseConfiguring configure = sp.GetService <IDatabaseConfiguring>();
                DbContextOptionsBuilder <CMSDbContext> optBuilder = new DbContextOptionsBuilder <CMSDbContext>();
                configure.OnConfiguring(optBuilder, holder.DbConnection);
                return(optBuilder.Options);
            });
            services.AddDbContext <CMSDbContext>(ServiceLifetime.Scoped);
            services.AddScoped <EasyDbContext>((provider) => provider.GetService <CMSDbContext>());
            services.AddSingleton(configuration.GetSection("Database").Get <DatabaseOption>());
            #endregion

            services.UseEasyFrameWork(configuration);
            foreach (IPluginStartup item in services.LoadAvailablePlugins())
            {
                item.Setup(services);
            }
            foreach (KeyValuePair <string, Type> item in WidgetBase.KnownWidgetService)
            {
                services.TryAddTransient(item.Value);
            }
            foreach (KeyValuePair <string, Type> item in WidgetBase.KnownWidgetModel)
            {
                services.TryAddTransient(item.Value);
            }

            services.Configure <AuthorizationOptions>(options =>
            {
                PermissionKeys.Configure(options);
                KnownRequirements.Configure(options);
            });

            services.AddAuthentication(DefaultAuthorizeAttribute.DefaultAuthenticationScheme)
            .AddCookie(DefaultAuthorizeAttribute.DefaultAuthenticationScheme, o =>
            {
                o.LoginPath        = new PathString("/Account/Login");
                o.AccessDeniedPath = new PathString("/Error/Forbidden");
            })
            .AddCookie(CustomerAuthorizeAttribute.CustomerAuthenticationScheme, option =>
            {
                option.LoginPath = new PathString("/Account/Signin");
            });
        }
 public AuthRoleRepository(IConnectionHolder conn) : base(conn)
 {
 }
Пример #16
0
 /// <summary>
 /// 初始化仓储
 /// </summary>
 /// <param name="connectionHolder"></param>
 /// <param name="repoXmlProvider"></param>
 /// <param name="exceptionHandler"></param>
 /// <param name="throws"></param>
 public RepositoryBase(IConnectionHolder connectionHolder, RepoXmlProvider repoXmlProvider = null, SqlEx.Core.Core.SqlExExceptionHandler exceptionHandler = null, bool throws = true)
     : this(connectionHolder.Connection, repoXmlProvider, exceptionHandler, throws)
 {
     ConnectionHolder = connectionHolder;
 }
Пример #17
0
 public RepositoryMysql(IConnectionHolder connectionHolder, RepoXmlProvider repoXmlProvider = null, SqlEx.Core.Core.SqlExExceptionHandler exceptionHandler = null, bool throws = true)
     : base(connectionHolder, repoXmlProvider, exceptionHandler, throws)
 {
 }
Пример #18
0
 /// <summary>
 /// 初始化仓储
 /// </summary>
 /// <param name="repoXmlProvider"></param>
 /// <param name="exceptionHandler"></param>
 /// <param name="throws"></param>
 /// <param name="connectionHolder"></param>
 public RepositoryPg(IConnectionHolder connectionHolder, RepoXmlProvider repoXmlProvider = null, MsSql.Core.Core.DapperExExceptionHandler exceptionHandler = null, bool throws = true)
     : base(connectionHolder, repoXmlProvider, exceptionHandler, throws)
 {
 }
Пример #19
0
 public void SetHolder(IConnectionHolder holder)
 {
     this.holder = holder;
 }
Пример #20
0
 public void OnDisconnected(IConnectionHolder <OPCServer> aConnectionHolder)
 {
     logger.Info("Отключен " + aConnectionHolder.GetHolderName());
     checkTimer.Stop();
 }
Пример #21
0
 public JsonCacheRepository(IConnectionHolder conn) : base(conn)
 {
 }