public async void Init() { if (Project == null) { Helper.Notify("当前项目为空,请在左侧菜单选择“项目”节点", NotificationType.Error); return; } List <CodeModule> entities = new List <CodeModule>(); await _provider.ExecuteScopedWorkAsync(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); entities = contract.CodeModules.Where(m => m.ProjectId == Project.Id).OrderBy(m => m.Order).ToList(); return(Task.CompletedTask); }); Modules.Clear(); foreach (CodeModule entity in entities) { ModuleViewModel model = _provider.GetRequiredService <ModuleViewModel>(); model = entity.MapTo(model); model.Project = Project; Modules.Add(model); } Helper.Output($"模块列表刷新成功,共{Modules.Count}个模块"); }
private static async Task <CodeEntity> GetOrAddEntity(IDataContract contract, Guid moduleId, CodeEntity en) { CodeEntity entity = contract.CodeEntities.FirstOrDefault(m => m.ModuleId == moduleId && m.Name == en.Name && m.Display == en.Display); if (entity != null) { return(entity); } CodeEntityInputDto dto = new CodeEntityInputDto() { Name = en.Name, Display = en.Display, PrimaryKeyTypeFullName = en.PrimaryKeyTypeFullName, Icon = en.Icon, Listable = en.Listable, Addable = en.Addable, Updatable = en.Updatable, Deletable = en.Deletable, IsDataAuth = en.IsDataAuth, HasCreatedTime = en.HasCreatedTime, HasLocked = en.HasLocked, HasSoftDeleted = en.HasSoftDeleted, HasCreationAudited = en.HasCreationAudited, HasUpdateAudited = en.HasUpdateAudited, IsLocked = en.IsLocked, ModuleId = moduleId }; await contract.UpdateCodeEntities(dto); entity = contract.CodeEntities.First(m => m.ModuleId == moduleId && m.Name == en.Name && m.Display == en.Display); return(entity); }
public async void Init() { if (Entity == null) { Helper.Notify("当前实体为空,请在左侧菜单选择一个“实体”节点", NotificationType.Error); return; } List <CodeProperty> properties = new List <CodeProperty>(); await _provider.ExecuteScopedWork(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); properties = contract.CodeProperties.Where(m => m.EntityId == Entity.Id).OrderBy(m => m.Order).ToList(); return(Task.CompletedTask); }); Properties.Clear(); foreach (CodeProperty property in properties) { PropertyViewModel model = _provider.GetRequiredService <PropertyViewModel>(); model = property.MapTo(model); model.Entity = Entity; Properties.Add(model); } Helper.Output($"实体“{Entity.Display}”的属性列表刷新成功,共{Properties.Count}个属性"); }
public async void Init() { if (Module == null) { Helper.Notify("当前模块为空,请在左侧菜单选择一个“模块”节点", NotificationType.Error); return; } List <CodeEntity> entities = new List <CodeEntity>(); await _provider.ExecuteScopedWorkAsync(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); entities = contract.CodeEntities.Where(m => m.ModuleId == Module.Id).OrderBy(m => m.Order).ToList(); return(Task.CompletedTask); }); Entities.Clear(); foreach (CodeEntity entity in entities) { EntityViewModel model = _provider.GetRequiredService <EntityViewModel>(); model = entity.MapTo(model); model.Module = Module; Entities.Add(model); } Helper.Output($"模块“{Module.Display}”的实体列表刷新成功,共{Entities.Count}个实体"); }
public async void Save() { if (!CanSave) { Helper.Notify("模板信息验证失败", NotificationType.Warning); return; } for (int i = 0; i < Templates.Count; i++) { Templates[i].Order = i + 1; } CodeTemplateInputDto[] dtos = Templates.Select(m => m.MapTo <CodeTemplateInputDto>()).ToArray(); OperationResult <CodeTemplate[]> result = null; await _provider.ExecuteScopedWorkAsync(async provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); result = await contract.UpdateCodeTemplates(dtos); }); Helper.Notify(result); if (!result.Succeeded) { return; } Init(); }
public async void Delete() { if (IsSystem) { Helper.Notify($"模板“{Name}”是系统模板,不能删除", NotificationType.Error); return; } if (MessageBox.Show($"是否删除模板“{Name}”?", "请确认", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel) { return; } OperationResult result = null; await _provider.ExecuteScopedWorkAsync(async provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); result = await contract.DeleteCodeTemplates(Id); }); Helper.Notify(result); if (!result.Succeeded) { return; } TemplateListViewModel list = IoC.Get <TemplateListViewModel>(); list.Init(); }
private TestCase <T> BuildTestCase <T>(ILocalDataSource <IEnumerable <T> > localDataSource, bool withContractSource = true, IComparer <T> keyComparer = null, IComparer <T> valueComparer = null) { IDataContract <T> dataContract = null; if (withContractSource) { dataContract = Substitute.For <IDataContract <T> >(); dataContract.IncrementalChanges.Returns(true); } IBlockTree blockTree = Substitute.For <IBlockTree>(); IReceiptFinder receiptsFinder = Substitute.For <IReceiptFinder>(); receiptsFinder.Get(Arg.Any <Block>()).Returns(Array.Empty <TxReceipt>()); return(new TestCase <T>() { DataContract = dataContract, BlockTree = blockTree, ReceiptFinder = receiptsFinder, ContractDataStore = keyComparer == null ? (IContractDataStore <T>) new ContractDataStoreWithLocalData <T>(new HashSetContractDataStoreCollection <T>(), dataContract, blockTree, receiptsFinder, LimboLogs.Instance, localDataSource) : new DictionaryContractDataStore <T>(new SortedListContractDataStoreCollection <T>(keyComparer, valueComparer), dataContract, blockTree, receiptsFinder, LimboLogs.Instance, localDataSource) }); }
private static async Task <CodeForeign> GetOrAddForeign(IDataContract contract, Guid entityId, CodeForeign fore) { CodeForeign foreign = contract.CodeForeigns.FirstOrDefault(m => m.EntityId == entityId && m.SelfNavigation == fore.SelfNavigation); if (foreign != null) { return(foreign); } CodeForeignInputDto dto = new CodeForeignInputDto() { SelfNavigation = fore.SelfNavigation, SelfForeignKey = fore.SelfForeignKey, OtherEntity = fore.OtherEntity, OtherNavigation = fore.OtherNavigation, IsRequired = fore.IsRequired, DeleteBehavior = fore.DeleteBehavior, ForeignRelation = fore.ForeignRelation, EntityId = entityId }; await contract.UpdateCodeForeigns(dto); foreign = contract.CodeForeigns.First(m => m.EntityId == entityId && m.SelfNavigation == fore.SelfNavigation); return(foreign); }
public async void EditSave() { MainViewModel main = IoC.Get <MainViewModel>(); if (!await ValidateAsync()) { await main.Notify("项目信息验证失败", NotificationType.Warning); return; } CodeProjectInputDto dto = this.MapTo <CodeProjectInputDto>(); OperationResult result = null; await _serviceProvider.ExecuteScopedWorkAsync(async provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); result = dto.Id == default ? await contract.CreateCodeProjects(dto) : await contract.UpdateCodeProjects(dto); }); Helper.Notify(result); if (!result.Succeeded) { return; } ProjectListViewModel list = main.ProjectList; list.EditingModel = null; list.IsShowEdit = false; list.Init(); }
private static ContractDataStore <T, TCollection> CreateContractDataStore( TCollection collection, IDataContract <T> dataContract, IBlockTree blockTree, IReceiptFinder receiptFinder, ILogManager logManager) => new ContractDataStore <T, TCollection>(collection, dataContract, blockTree, receiptFinder, logManager);
public void Init() { if (Project == null) { Helper.Notify("当前项目为空,请先通过菜单“项目-项目管理”加载项目", NotificationType.Error); return; } ProjectTemplateViewModel[] models = new ProjectTemplateViewModel[0]; _provider.ExecuteScopedWork(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); models = contract.CodeProjectTemplates.Where(m => m.ProjectId == Project.Id).OrderBy(m => m.Template.Order).Select(m => new ProjectTemplateViewModel(_provider) { Id = m.Id, ProjectId = m.ProjectId, TemplateId = m.TemplateId, IsLocked = m.IsLocked, TemplateName = m.Template.Name }).ToArray(); }); ProjectTemplates.Clear(); foreach (ProjectTemplateViewModel model in models) { ProjectTemplates.Add(model); } }
public void Init() { if (Project == null) { Helper.Notify("当前项目为空,请先通过菜单“项目-项目管理”加载项目", NotificationType.Error); return; } CodeProject[] projects = null; _provider.ExecuteScopedWork(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); projects = contract.GetCodeProject(m => m.Name == Project.Name); }); if (projects == null) { Helper.Notify($"名称为“{Project.Name}”的项目信息不存在", NotificationType.Error); return; } MenuItems.Clear(); foreach (CodeProject project in projects) { MenuItems.Add(ToMenu(project)); } }
private static async void Method11() { Console.WriteLine("请输入代码模板:"); string input = Console.ReadLine(); CodeProject project = null; CodeTemplate template = null; await _provider.ExecuteScopedWorkAsync(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); CodeProject[] projects = contract.GetCodeProject(m => true); project = projects[0]; template = contract.CodeTemplates.FirstOrDefault(m => m.Name == input); return(Task.CompletedTask); }); if (template == null) { Console.WriteLine($"模板 {input} 不存在"); return; } ICodeGenerator generator = _provider.GetService <ICodeGenerator>(); //var model = project.Modules.First().Entities.First(); //var model = project.Modules.First(); var model = project; CodeFile file = await generator.GenerateCode(template, model); File.WriteAllText(@"D:\Temp\11.txt", file.SourceCode); Console.WriteLine(file.SourceCode); }
public DictionaryContractDataStore( DictionaryBasedContractDataStoreCollection <T> collection, IDataContract <T> dataContract, IBlockProcessor blockProcessor, ILogManager logManager) : this(CreateContractDataStore(collection, dataContract, blockProcessor, logManager)) { }
protected internal ContractDataStore(TCollection collection, IDataContract <T> dataContract, IBlockProcessor blockProcessor, ILogManager logManager) { Collection = collection; _dataContract = dataContract ?? throw new ArgumentNullException(nameof(dataContract)); _blockProcessor = blockProcessor ?? throw new ArgumentNullException(nameof(blockProcessor));; _logger = logManager?.GetClassLogger <ContractDataStore <T, TCollection> >() ?? throw new ArgumentNullException(nameof(logManager)); _blockProcessor.BlockProcessed += OnBlockProcessed; }
/// <summary> /// Initializes a new instance of the <see cref="T:WannaChain.Core.WannaChainNode`1"/> class. /// </summary> /// <param name="dataContract">Data contract.</param> /// <param name="blockContract">Block contract.</param> public WannaChainNode(IDataContract <TData> dataContract, IBlockContract <TData> blockContract) { this.dataContract = dataContract; this.blockContract = blockContract; Chains = new List <Block <TData> >(); }
protected internal ContractDataStore(TCollection collection, IDataContract <T> dataContract, IBlockTree blockTree, IReceiptFinder receiptFinder, ILogManager logManager) { Collection = collection; _dataContract = dataContract ?? throw new ArgumentNullException(nameof(dataContract)); _receiptFinder = receiptFinder ?? throw new ArgumentNullException(nameof(receiptFinder)); _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); _logger = logManager?.GetClassLogger <ContractDataStore <T, TCollection> >() ?? throw new ArgumentNullException(nameof(logManager)); blockTree.NewHeadBlock += OnNewHead; }
protected internal ContractDataStore(IContractDataStoreCollection <T> collection, IDataContract <T> dataContract, IBlockTree blockTree, IReceiptFinder receiptFinder, ILogManager logManager) { Collection = collection == null || collection is ThreadSafeContractDataStoreCollectionDecorator <T>?collection : new ThreadSafeContractDataStoreCollectionDecorator <T>(collection); _dataContract = dataContract ?? throw new ArgumentNullException(nameof(dataContract)); _receiptFinder = receiptFinder ?? throw new ArgumentNullException(nameof(receiptFinder)); _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); _logger = logManager?.GetClassLogger <ContractDataStore <T> >() ?? throw new ArgumentNullException(nameof(logManager)); blockTree.NewHeadBlock += OnNewHead; }
public DictionaryContractDataStore( TCollection collection, IDataContract <T> dataContract, IBlockTree blockTree, IReceiptFinder receiptFinder, ILogManager logManager) : this(CreateContractDataStore(collection, dataContract, blockTree, receiptFinder, logManager)) { }
private string[] GetPropNames(Expression <Func <CodeProperty, bool> > exp) { string[] props = new string[0]; _provider.ExecuteScopedWork(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); props = contract.CodeProperties.Where(exp).Select(m => m.Name).ToArray(); }); return(props); }
public DictionaryContractDataStore( DictionaryBasedContractDataStoreCollection <T> collection, IDataContract <T> dataContract, IBlockProcessor blockProcessor, ILogManager logManager, ILocalDataSource <IEnumerable <T> > localDataSource) : this(localDataSource == null ? CreateContractDataStore(collection, dataContract, blockProcessor, logManager) : CreateContractDataStoreWithLocalData(collection, dataContract, blockProcessor, logManager, localDataSource)) { }
public SheduleViewModel() { CurrentNavigation = TypeForm.SheduleForm; textBoxCountPerson = new TextBox(); textBoxDate = new TextBox(); contract = new DataContract(); InsertParametersToTableShedule = new RelayCommand(AddValueToSheduleTable); }
private static ContractDataStoreWithLocalData <T, DictionaryBasedContractDataStoreCollection <T> > CreateContractDataStoreWithLocalData( DictionaryBasedContractDataStoreCollection <T> collection, IDataContract <T> dataContract, IBlockProcessor blockProcessor, ILogManager logManager, ILocalDataSource <IEnumerable <T> > localDataSource) => new ContractDataStoreWithLocalData <T, DictionaryBasedContractDataStoreCollection <T> >( collection, dataContract ?? new EmptyDataContract <T>(), blockProcessor, logManager, localDataSource);
protected internal ContractDataStoreWithLocalData( TCollection collection, IDataContract <T> dataContract, IBlockProcessor blockProcessor, ILogManager logManager, ILocalDataSource <IEnumerable <T> > localDataSource) : base(collection, dataContract, blockProcessor, logManager) { _localDataSource = localDataSource ?? throw new ArgumentNullException(nameof(localDataSource)); _localDataSource.Changed += OnChanged; LoadLocalData(); }
public DictionaryContractDataStore( TCollection collection, IDataContract <T> dataContract, IBlockTree blockTree, IReceiptFinder receiptFinder, ILogManager logManager, ILocalDataSource <IEnumerable <T> > localDataSource) : this(localDataSource == null ? CreateContractDataStore(collection, dataContract, blockTree, receiptFinder, logManager) : CreateContractDataStoreWithLocalData(collection, dataContract, blockTree, receiptFinder, logManager, localDataSource)) { }
public IDataContract DoSmthWithClass(IDataContract dataContract) { EventLog tmpEventLog = new EventLog(); tmpEventLog.Source = "Test WCF"; tmpEventLog.WriteEntry(string.Format("BusinessLogic.DoSmthWithClass({0})", dataContract.StringField), EventLogEntryType.Information); dataContract.StringField = !string.IsNullOrEmpty(dataContract.StringField) ? dataContract.StringField + "+" + dataContract.StringField : "null"; return(dataContract); }
public ContractDataStoreWithLocalData( IContractDataStoreCollection <T> collection, IDataContract <T> dataContract, IBlockTree blockTree, IReceiptFinder receiptFinder, ILogManager logManager, ILocalDataSource <IEnumerable <T> > localDataSource) : base(collection, dataContract ?? new EmptyDataContract <T>(), blockTree, receiptFinder, logManager) { _localDataSource = localDataSource ?? throw new ArgumentNullException(nameof(localDataSource)); _localDataSource.Changed += OnChanged; LoadLocalData(); }
private string[] GetEntities() { ProjectViewModel project = IoC.Get <MenuViewModel>().Project; ModuleListViewModel moduleList = IoC.Get <ModuleListViewModel>(); List <string> list = new List <string>() { "OSharp.Core.EntityInfos.EntityInfo", "OSharp.Core.Functions.Function", "OSharp.Core.Systems.KeyValue" }; list.AddRange(new[] { "Identity.Entities.LoginLog", "Identity.Entities.Organization", "Identity.Entities.Role", "Identity.Entities.RoleClaim", "Identity.Entities.User", "Identity.Entities.UserClaim", "Identity.Entities.UserDetail", "Identity.Entities.UserLogin", "Identity.Entities.UserRole", "Identity.Entities.UserToken", "Security.Entities.EntityRole", "Security.Entities.EntityUser", "Security.Entities.Module", "Security.Entities.ModuleFunction", "Security.Entities.ModuleRole", "Security.Entities.ModuleUser", "Systems.Entities.AuditEntity", "Systems.Entities.AuditOperation", "Systems.Entities.AuditProperty" }.Select(m => $"{project.NamespacePrefix}.{m}")); if (moduleList != null) { if (_project == null) { IServiceProvider rootProvider = IoC.Get <IServiceProvider>(); MenuViewModel menu = rootProvider.GetRequiredService <MenuViewModel>(); rootProvider.ExecuteScopedWork(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); _project = contract.GetCodeProject(m => m.Name == menu.Project.Name).First(); }); } list.AddRange(_project.Modules.SelectMany(m => m.Entities.Select(n => $"{project.NamespacePrefix}.{m.Name}.Entities.{n.Name}")) .OrderBy(m => m)); } return(list.Distinct().ToArray()); }
private static ContractDataStoreWithLocalData <T, TCollection> CreateContractDataStoreWithLocalData( TCollection collection, IDataContract <T> dataContract, IBlockTree blockTree, IReceiptFinder receiptFinder, ILogManager logManager, ILocalDataSource <IEnumerable <T> > localDataSource) => new ContractDataStoreWithLocalData <T, TCollection>( collection, dataContract ?? new EmptyDataContract <T>(), blockTree, receiptFinder, logManager, localDataSource);
public async void Generate() { if (Project == null) { Helper.Notify("当前项目为空,无法生成代码,请先通过菜单“项目-项目管理”加载项目", NotificationType.Error); return; } CodeProject project = null; CodeTemplate[] templates = new CodeTemplate[0]; _provider.ExecuteScopedWork(provider => { IDataContract contract = provider.GetRequiredService <IDataContract>(); project = contract.GetCodeProject(m => m.Name == Project.Name).FirstOrDefault(); templates = contract.CodeProjectTemplates.Where(m => m.ProjectId == project.Id && !m.IsLocked).Select(m => m.Template).ToArray(); }); if (project == null) { Helper.Notify($"名称为“{Project.Name}”的项目信息不存在", NotificationType.Error); return; } if (templates.Length == 0) { Helper.Notify($"项目“{project.GetName()}”的模板数量为0,请先通过菜单“项目-项目模板管理”添加模板", NotificationType.Error); return; } CodeFile[] codeFiles; var progress = await Helper.Main.ShowProgressAsync("请稍候", "正在生成代码,请稍候"); await Task.Run(async() => { try { ICodeGenerator generator = _provider.GetRequiredService <ICodeGenerator>(); codeFiles = await generator.GenerateCodes(templates, project); await progress.CloseAsync(); } catch (Exception ex) { await progress.CloseAsync(); Helper.Notify($"代码生成失败:{ex.Message}", NotificationType.Error); return; } SaveToFiles(codeFiles); }); }