public static TemplateTerminal Create(Authentication authentication, ITypeTemplate template, string prompt) { var serviceProvider = template.Dispatcher.Invoke(() => template.Type as IServiceProvider); var commands = (serviceProvider.GetService(typeof(IEnumerable <ITemplateCommand>)) as IEnumerable <ITemplateCommand>); var commandContext = new TemplateCommandContext(authentication, template, commands); var terminal = new TemplateTerminal(commandContext, prompt) { Postfix = "$ " }; foreach (var item in commands) { if (item is SaveCommand saveCommand) { saveCommand.CloseAction = () => terminal.Cancel(); } else if (item is CancelCommand cancelCommand) { cancelCommand.CloseAction = () => terminal.Cancel(); } } return(terminal); }
public static async Task AddRandomMembersAsync(this ITypeTemplate template, Authentication authentication, int tryCount) { for (var i = 0; i < tryCount; i++) { await AddRandomMemberAsync(template, authentication); } }
public static void AddRandomMembers(this ITypeTemplate template, Authentication authentication, int tryCount) { for (var i = 0; i < tryCount; i++) { AddRandomMember(template, authentication); } }
protected async override void OnDeactivate(bool close) { base.OnDeactivate(close); try { if (this.template != null) { await this.template.Dispatcher.InvokeAsync(() => { this.template.CancelEdit(this.authentication); }); } } catch (Exception e) { CremaLog.Error(e); } finally { if (this.template != null) { await this.template.Dispatcher.InvokeAsync(() => { this.template.EditEnded -= Template_EditEnded; this.template.EditCanceled -= Template_EditCanceled; this.template.Changed -= Template_Changed; this.template = null; }); } } }
public static async Task ModifyRandomMembersAsync(this ITypeTemplate template, Authentication authentication, int count) { for (var i = 0; i < count; i++) { await ModifyRandomMemberAsync(template, authentication); } }
public async void Change() { try { this.BeginProgress(this.IsNew ? Resources.Message_Creating : Resources.Message_Changing); await this.template.Dispatcher.InvokeAsync(() => { this.template.EndEdit(this.authentication); this.template.EditEnded -= Template_EditEnded; this.template.EditCanceled -= Template_EditCanceled; this.template.Changed -= Template_Changed; }); this.domain = null; this.template = null; this.isModified = false; this.EndProgress(); this.TryClose(true); } catch (Exception e) { this.EndProgress(); AppMessageBox.ShowError(e); } }
public void SetIsFlag(ITypeTemplate template, TaskContext context) { template.Dispatcher.Invoke(() => { var isFlag = RandomUtility.NextBoolean(); template.SetIsFlag(context.Authentication, isFlag); }); }
public void SetComment(ITypeTemplate template, TaskContext context) { template.Dispatcher.Invoke(() => { var comment = RandomUtility.NextString(); template.SetComment(context.Authentication, comment); }); }
public static ITypeMember AddRandomMember(this ITypeTemplate template, Authentication authentication) { var member = template.AddNew(authentication); member.InitializeRandom(authentication); template.EndNew(authentication, member); return(member); }
public void SetTypeName(ITypeTemplate template, TaskContext context) { template.Dispatcher.Invoke(() => { var tableName = RandomUtility.NextIdentifier(); template.SetTypeName(context.Authentication, tableName); }); }
public static void AddMember(this ITypeTemplate template, Authentication authentication, string name, long value, string comment) { var member = template.AddNew(authentication); member.SetName(authentication, name); member.SetValue(authentication, value); member.SetComment(authentication, comment); template.EndNew(authentication, member); }
public static async Task <ITypeMember> AddRandomMemberAsync(this ITypeTemplate template, Authentication authentication) { var member = await template.AddNewAsync(authentication); await member.InitializeRandomAsync(authentication); await template.EndNewAsync(authentication, member); return(member); }
protected TemplateViewModel(Authentication authentication, ITypeTemplate template, bool isNew) { this.authentication = authentication; this.IsNew = isNew; this.Template = template; this.Template.EditEnded += Template_EditEnded; this.Template.EditCanceled += Template_EditCanceled; this.Template.Changed += Template_Changed; this.DisplayName = Resources.Title_EditTypeTemplate; }
public static async Task AddMemberAsync(this ITypeTemplate template, Authentication authentication, string name, long value, string comment) { var member = await template.AddNewAsync(authentication); await member.SetNameAsync(authentication, name); await member.SetValueAsync(authentication, value); if (comment != string.Empty) { await member.SetCommentAsync(authentication, comment); } await template.EndNewAsync(authentication, member); }
public static async Task InitializeRandomAsync(this ITypeTemplate template, Authentication authentication) { var typeName = RandomUtility.NextIdentifier(); await template.SetTypeNameAsync(authentication, typeName); if (RandomUtility.Within(50) == true) { await template.SetIsFlagAsync(authentication, RandomUtility.NextBoolean()); } if (RandomUtility.Within(50) == true) { await template.SetCommentAsync(authentication, RandomUtility.NextString()); } await template.AddRandomMembersAsync(authentication); }
public static void InitializeRandom(this ITypeTemplate template, Authentication authentication) { var typeName = RandomUtility.NextIdentifier(); template.SetTypeName(authentication, typeName); if (RandomUtility.Within(50) == true) { template.SetIsFlag(authentication, RandomUtility.NextBoolean()); } if (RandomUtility.Within(50) == true) { template.SetComment(authentication, RandomUtility.NextString()); } template.AddRandomMembers(authentication); }
private Task <ITable[]> GetTablesAsync(ITypeTemplate template, Func <ITable, bool> predicate) { return(template.Dispatcher.InvokeAsync(() => { var type = template.Type; var typePath = type.Path; var tables = type.GetService(typeof(ITableCollection)) as ITableCollection; var query = from item in tables from columnInfo in item.TableInfo.Columns where columnInfo.DataType == typePath select item; return query.Distinct().Where(predicate).ToArray(); })); }
protected async override void OnDeactivate(bool close) { base.OnDeactivate(close); if (this.template != null) { await this.template.Dispatcher.InvokeAsync(() => { this.template.CancelEdit(this.authentication); this.template.EditEnded -= Template_EditEnded; this.template.EditCanceled -= Template_EditCanceled; this.template.Changed -= Template_Changed; }); } this.template = null; }
public static void ClassInit(TestContext context) { app = new CremaBootstrapper(); app.Initialize(context, nameof(ITypeTemplate_DispatcherTest)); cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost; cremaHost.Dispatcher.Invoke(() => { authentication = cremaHost.Start(); dataBase = cremaHost.DataBases.Random(); dataBase.Load(authentication); dataBase.Enter(authentication); dataBase.TypeContext.AddRandomItems(authentication); template = dataBase.TypeContext.Types.Random().Template; template.BeginEdit(authentication); member = template.AddNew(authentication); }); }
public TypeTemplateDescriptor(Authentication authentication, ITypeTemplate template, DescriptorTypes descriptorTypes, object owner) : base(authentication, template, descriptorTypes) { this.template = template; this.owner = owner ?? this; this.template.Dispatcher.VerifyAccess(); this.domain = this.template.Domain; if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true) { this.template.EditBegun += Template_EditBegun; this.template.EditEnded += Template_EditEnded; this.template.EditCanceled += Template_EditCanceled; this.template.Changed += Template_Changed; this.template.Type.TypeInfoChanged += Type_TypeInfoChanged; } }
public static ITypeTemplate CreateAddNew(this ITypeTemplate template, Authentication authentication, string typeName, long value, int?index = null) { var type = template.AddNew(authentication); type.SetName(authentication, typeName); type.SetValue(authentication, value); if (index != null) { type.SetIndex(authentication, index.Value); } template.EndNew(authentication, type); return(template); }
private async void Template_EditCanceled(object sender, EventArgs e) { if (e is DomainDeletedEventArgs ex) { this.template.EditEnded -= Template_EditEnded; this.template.EditCanceled -= Template_EditCanceled; this.template.Changed -= Template_Changed; this.template = null; await this.Dispatcher.InvokeAsync(() => { this.flashService?.Flash(); AppMessageBox.ShowInfo(Resources.Message_ExitEditByUser_Format, ex.UserID); this.TryClose(); }); } }
public TemplateCommandContext(Authentication authentication, ITypeTemplate template, IEnumerable <ITemplateCommand> commands) : base(commands.Select(item => item.Command), Enumerable.Empty <ICommandProvider>()) { this.authentication = authentication; this.template = template; foreach (var item in commands) { if (item is TemplateCommandBase command) { command.CommandContext = this; } //else if (item is ConsoleCommandMethodBase commandMethod) //{ // commandMethod.CommandContext = this; //} } }
private bool CanEdit(ITypeTemplate template) { var type = template.Type; var tables = type.GetService(typeof(ITableCollection)) as ITableCollection; var query = from table in tables from column in table.TableInfo.Columns where column.DataType == type.Path where table.TableState != TableState.None select table; if (query.Any() == true) { return(false); } return(true); }
public async override void CanClose(Action <bool> callback) { if (this.template == null || this.IsModified == false) { callback(true); return; } var result = AppMessageBox.ConfirmCreateOnClosing(); if (result == null) { return; } if (this.template != null && result == true) { this.BeginProgress(this.IsNew ? Resources.Message_Creating : Resources.Message_Changing); try { await this.template.Dispatcher.InvokeAsync(() => { this.template.EndEdit(this.authentication); this.template.EditEnded -= Template_EditEnded; this.template.EditCanceled -= Template_EditCanceled; this.template.Changed -= Template_Changed; }); this.template = null; this.EndProgress(); } catch (Exception e) { AppMessageBox.ShowError(e); this.EndProgress(); return; } } this.DialogResult = result.Value; callback(true); }
public static Task AddMemberAsync(this ITypeTemplate template, Authentication authentication, string name, long value) { return(AddMemberAsync(template, authentication, name, value, string.Empty)); }
public static Task <bool> ContainsAsync(this ITypeTemplate template, string memberName) { return(template.Dispatcher.InvokeAsync(() => template.Contains(memberName))); }
public async Task SetCommentAsync(ITypeTemplate template, TaskContext context) { var authentication = context.Authentication; var comment = RandomUtility.NextString(); await template.SetCommentAsync(authentication, comment); }
public async Task SetIsFlagAsync(ITypeTemplate template, TaskContext context) { var authentication = context.Authentication; var isFlag = RandomUtility.NextBoolean(); await template.SetIsFlagAsync(authentication, isFlag); }
public async Task SetTypeNameAsync(ITypeTemplate template, TaskContext context) { var authentication = context.Authentication; var tableName = RandomUtility.NextIdentifier(); await template.SetTypeNameAsync(authentication, tableName); }