/// <summary>
        /// 分配角色
        /// </summary>
        public async void RelateRoles(Wrap <UserInfo> user)
        {
            this.Busy();

            RelateRoleViewModel viewModel = ResolveMediator.Resolve <RelateRoleViewModel>();
            await viewModel.Load(user.Model.Number);

            this.Idle();

            await this._windowManager.ShowDialogAsync(viewModel);
        }
Beispiel #2
0
        //Public

        #region # 保存任务 —— static void Store(ICrontab crontab)
        /// <summary>
        /// 保存任务
        /// </summary>
        /// <param name="crontab">定时任务</param>
        public static void Store(ICrontab crontab)
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }
                crontabStore.Store(crontab);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 关联权限
        /// </summary>
        /// <param name="menu">菜单</param>
        public async void RelateAuthorities(Models.Menu menu)
        {
            this.Busy();

            RelateAuthorityViewModel viewModel = ResolveMediator.Resolve <RelateAuthorityViewModel>();
            await viewModel.Load(menu.Id);

            this.Idle();

            await this._windowManager.ShowDialogAsync(viewModel);
        }
 /// <summary>
 /// 挂起领域事件
 /// </summary>
 /// <typeparam name="T">领域事件源类型</typeparam>
 /// <param name="eventSource">领域事件源</param>
 public static void Suspend <T>(T eventSource) where T : class, IEvent
 {
     using (IEventStore eventStorer = ResolveMediator.Resolve <IEventStore>())
     {
         using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled))
         {
             eventStorer.Suspend(eventSource);
             scope.Complete();
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// 创建菜单
        /// </summary>
        public async void CreateMenu()
        {
            AddViewModel viewModel = ResolveMediator.Resolve <AddViewModel>();

            viewModel.Load(this.InfoSystems);
            bool?result = await this._windowManager.ShowDialogAsync(viewModel);

            if (result == true)
            {
                await this.ReloadMenus();
            }
        }
Beispiel #6
0
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="menu">菜单</param>
        public async void UpdateMenu(Models.Menu menu)
        {
            UpdateViewModel viewModel = ResolveMediator.Resolve <UpdateViewModel>();

            viewModel.Load(menu);
            bool?result = await this._windowManager.ShowDialogAsync(viewModel);

            if (result == true)
            {
                await this.ReloadMenus();
            }
        }
        /// <summary>
        /// 修改权限
        /// </summary>
        /// <param name="authority">权限</param>
        public async void UpdateAuthority(Wrap <AuthorityInfo> authority)
        {
            UpdateViewModel viewModel = ResolveMediator.Resolve <UpdateViewModel>();

            viewModel.Load(authority.Model);
            bool?result = await this._windowManager.ShowDialogAsync(viewModel);

            if (result == true)
            {
                await this.ReloadAuthorities();
            }
        }
        public void Init()
        {
            if (!ResolveMediator.ContainerBuilt)
            {
                IServiceCollection builder = ResolveMediator.GetServiceCollection();
                builder.RegisterConfigs();

                ResolveMediator.Build();
            }

            ScheduleMediator.Clear();
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //初始化依赖注入容器
            InitContainer();

            MainWindow mainWindow = ResolveMediator.Resolve <MainWindow>();

            Application.Run(mainWindow);
        }
        /// <summary>
        /// 重置私钥
        /// </summary>
        public async void ResetPrivateKey(Wrap <UserInfo> user)
        {
            ResetPrivateKeyViewModel viewModel = ResolveMediator.Resolve <ResetPrivateKeyViewModel>();

            viewModel.Load(user.Model);
            bool?result = await this._windowManager.ShowDialogAsync(viewModel);

            if (result == true)
            {
                await this.ReloadUsers();
            }
        }
        /// <summary>
        /// 调度任务
        /// </summary>
        /// <param name="crontab">定时任务</param>
        public static void Schedule(ICrontab crontab)
        {
            #region # 验证

            if (crontab.ExecutionStrategy == null)
            {
                throw new InvalidOperationException("执行策略不可为空!");
            }

            #endregion

            //调度任务
            Type crontabType = crontab.GetType();
            IEnumerable <ICrontabExecutor> crontabSchedulers = CrontabExecutorFactory.GetCrontabExecutorsFor(crontabType);
            foreach (ICrontabExecutor scheduler in crontabSchedulers)
            {
                JobKey jobKey = new JobKey(crontab.Id);

                if (!_Scheduler.CheckExists(jobKey).Result)
                {
                    Type       jobType    = scheduler.GetType();
                    JobBuilder jobBuilder = JobBuilder.Create(jobType);

                    //设置任务数据
                    IDictionary <string, object> dictionary = new Dictionary <string, object>();
                    dictionary.Add(crontab.Id, crontab);
                    jobBuilder.SetJobData(new JobDataMap(dictionary));

                    //创建任务明细
                    IJobDetail jobDetail = jobBuilder.WithIdentity(jobKey).Build();

                    //创建触发器
                    ITrigger trigger = GetTrigger(crontab.ExecutionStrategy);

                    //为调度者添加任务明细与触发器
                    _Scheduler.ScheduleJob(jobDetail, trigger).Wait();

                    //开始调度
                    _Scheduler.Start().Wait();
                }
                else
                {
                    _Scheduler.ResumeJob(jobKey).Wait();
                }
            }

            //保存任务
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                crontab.Status = CrontabStatus.Scheduled;
                crontabStore?.Store(crontab);
            }
        }
        /// <summary>
        /// 打开飞窗
        /// </summary>
        /// <param name="type">飞窗类型</param>
        /// <returns>飞窗</returns>
        public FlyoutBase OpenFlyout(Type type)
        {
            //验证
            if (!type.IsSubclassOf(typeof(FlyoutBase)))
            {
                throw new InvalidCastException("给定类型不是飞窗!");
            }

            this.Flyout = (FlyoutBase)ResolveMediator.Resolve(type);
            this.Flyout.Open();

            return(this.Flyout);
        }
        /// <summary>
        /// 注册依赖注入解析者
        /// </summary>
        /// <param name="httpConfiguration">Http配置</param>
        public static void RegisterDependencyResolver(this HttpConfiguration httpConfiguration)
        {
            //初始化依赖注入容器
            if (!ResolveMediator.ContainerBuilt)
            {
                IServiceCollection builder = ResolveMediator.GetServiceCollection();
                builder.RegisterConfigs();

                ResolveMediator.Build();
            }

            httpConfiguration.DependencyResolver = new WebApiDependencyResolver();
        }
        /// <summary>
        /// 初始化信息系统
        /// </summary>
        /// <param name="infoSystem">信息系统</param>
        public async void InitInfoSystem(Wrap <InfoSystemInfo> infoSystem)
        {
            InitViewModel viewModel = ResolveMediator.Resolve <InitViewModel>();

            viewModel.Load(infoSystem.Model);

            bool?result = await this._windowManager.ShowDialogAsync(viewModel);

            if (result == true)
            {
                await this.ReloadInfoSystems();
            }
        }
Beispiel #15
0
        /// <summary>
        /// 获取任务
        /// </summary>
        /// <typeparam name="T">定时任务类型</typeparam>
        /// <param name="crontabId">定时任务Id</param>
        /// <returns>定时任务</returns>
        /// <remarks>需要CrontabStore持久化支持</remarks>
        public static T GetCrontab <T>(string crontabId) where T : ICrontab
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }

                T crontab = crontabStore.Get <T>(crontabId);

                return(crontab);
            }
        }
Beispiel #16
0
        /// <summary>
        /// 创建服务建造者
        /// </summary>
        public IServiceCollection CreateBuilder(IServiceCollection services)
        {
            IServiceCollection builder = ResolveMediator.GetServiceCollection();

            foreach (ServiceDescriptor serviceDescriptor in services)
            {
                builder.Add(serviceDescriptor);
            }

            builder.RegisterConfigs();
            ResolveMediator.Build();

            return(builder);
        }
        /// <summary>
        /// 打开文档
        /// </summary>
        /// <typeparam name="T">文档类型</typeparam>
        /// <returns>文档</returns>
        public T OpenDocument <T>() where T : DocumentBase
        {
            DocumentBase document = this.Documents.SingleOrDefault(x => x.GetType().FullName == typeof(T).FullName);

            if (document == null)
            {
                document = ResolveMediator.Resolve <T>();
                this.Documents.Add(document);
            }

            document.Open();

            return((T)document);
        }
Beispiel #18
0
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="crontabId">定时任务Id</param>
        public static void Remove(string crontabId)
        {
            JobKey jobKey = new JobKey(crontabId);

            if (_Scheduler.CheckExists(jobKey).Result)
            {
                _Scheduler.DeleteJob(jobKey).Wait();
            }

            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                crontabStore?.Remove(crontabId);
            }
        }
Beispiel #19
0
        /// <summary>
        /// 获取全部任务列表
        /// </summary>
        /// <returns>定时任务列表</returns>
        /// <remarks>需要CrontabStore持久化支持</remarks>
        public static IList <ICrontab> FindAll()
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }

                IList <ICrontab> crontabs = crontabStore.FindAll();

                return(crontabs);
            }
        }
Beispiel #20
0
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="crontab">定时任务</param>
        public static void Remove <T>(T crontab) where T : class, ICrontab
        {
            JobKey jobKey = new JobKey(crontab.Id);

            if (_Scheduler.CheckExists(jobKey).Result)
            {
                _Scheduler.DeleteJob(jobKey).Wait();
            }

            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                crontabStore?.Remove(crontab);
            }
        }
Beispiel #21
0
        /// <summary>
        /// 执行中间件
        /// </summary>
        public async Task Invoke(HttpContext context)
        {
            try
            {
                //初始化SessionId
                Initializer.InitSessionId();

                await this._next.Invoke(context);
            }
            finally
            {
                //清理依赖注入范围容器
                ResolveMediator.Dispose();
            }
        }
        /// <summary>
        /// 执行中间件
        /// </summary>
        public override async Task Invoke(IOwinContext context)
        {
            try
            {
                //初始化SessionId
                Initializer.InitSessionId();

                await base.Next.Invoke(context);
            }
            finally
            {
                //清理依赖注入范围容器
                ResolveMediator.Dispose();
            }
        }
Beispiel #23
0
        /// <summary>
        /// 命令执行者
        /// </summary>
        /// <param name="commandType">命令类型</param>
        /// <returns>命令执行者</returns>
        public static object GetCommandExecutorFor(Type commandType)
        {
            #region # 验证类型

            if (!typeof(ICommand).IsAssignableFrom(commandType))
            {
                throw new InvalidOperationException(string.Format("类型\"{0}\"不实现命令基接口!", commandType.FullName));
            }

            #endregion

            Type executorType = typeof(ICommandExecutor <>).MakeGenericType(commandType);

            return(ResolveMediator.Resolve(executorType));
        }
        public void Init()
        {
            //初始化依赖注入容器
            if (!ResolveMediator.ContainerBuilt)
            {
                IServiceCollection serviceCollection = ResolveMediator.GetServiceCollection();
                serviceCollection.RegisterConfigs();
                ResolveMediator.Build();
            }

            DbSession dbSession = new DbSession(GlobalSetting.WriteConnectionString);

            dbSession.Database.CreateIfNotExists();

            this._unitOfWork = ResolveMediator.Resolve <IUnitOfWorkStub>();
        }
        /// <summary>
        /// 主活动创建事件
        /// </summary>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            Forms.Init(this, savedInstanceState);

            //初始化应用程序
            Startup startup = ResolveMediator.Resolve <Startup>();

            base.LoadApplication(startup);

            //注册未处理异常事件
            AndroidEnvironment.UnhandledExceptionRaiser += this.OnAndroidException;
            AppDomain.CurrentDomain.UnhandledException  += this.OnAppDomainException;
        }
        /// <summary>
        /// 配置应用程序
        /// </summary>
        protected override void Configure()
        {
            //配置自动更新服务
            AutoUpdater.Start(FrameworkSection.Setting.AutoUpdateService.Value);

            //初始化依赖注入容器
            if (!ResolveMediator.ContainerBuilt)
            {
                IServiceCollection serviceCollection = ResolveMediator.GetServiceCollection();
                serviceCollection.RegisterConfigs();
#if NETCOREAPP3_1_OR_GREATER
                serviceCollection.RegisterServiceModels();
#endif
                ResolveMediator.Build();
            }
        }
Beispiel #27
0
        /// <summary>
        /// 注销登录
        /// </summary>
        public async void Logout()
        {
            MessageBoxResult result = MessageBox.Show("确定要注销吗?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                //清空Session
                MembershipMediator.SetLoginInfo(null);

                //跳转到登录窗体
                LoginViewModel loginViewModel = ResolveMediator.Resolve <LoginViewModel>();
                await this._windowManager.ShowWindowAsync(loginViewModel);

                //关闭当前窗口
                await base.TryCloseAsync();
            }
        }
        /// <summary>
        /// 获取定时任务执行者实例列表
        /// </summary>
        /// <param name="crontabType">定时任务类型</param>
        /// <returns>定时任务执行者列表</returns>
        public static IEnumerable <ICrontabExecutor> GetCrontabExecutorsFor(Type crontabType)
        {
            #region # 验证类型

            if (!typeof(ICrontab).IsAssignableFrom(crontabType))
            {
                throw new InvalidOperationException($"类型\"{crontabType.FullName}\"不实现定时任务基接口!");
            }

            #endregion

            Type schedulerType = typeof(ICrontabExecutor <>).MakeGenericType(crontabType);
            IEnumerable <object>           schedulerInstances = ResolveMediator.ResolveAll(schedulerType);
            IEnumerable <ICrontabExecutor> schedulers         = schedulerInstances.Select(handler => (ICrontabExecutor)handler);

            return(schedulers);
        }
Beispiel #29
0
        /// <summary>
        /// 异常恢复
        /// </summary>
        /// <remarks>需要CrontabStore持久化支持</remarks>
        public static void Recover()
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }

                IList <ICrontab>       crontabs          = crontabStore.FindAll();
                IEnumerable <ICrontab> scheduledCrontabs = crontabs.Where(x => x.Status == CrontabStatus.Scheduled);
                foreach (ICrontab crontab in scheduledCrontabs)
                {
                    Schedule(crontab);
                }
            }
        }
Beispiel #30
0
        /// <summary>
        /// 恢复全部任务
        /// </summary>
        /// <remarks>需要CrontabStore持久化支持</remarks>
        public static void ResumeAll()
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }

                IList <ICrontab> crontabs = crontabStore.FindAll();

                foreach (ICrontab crontab in crontabs)
                {
                    ScheduleMediator.Schedule(crontab);
                }
            }
        }