コード例 #1
0
        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);
        }
コード例 #2
0
 public static async Task AddRandomMembersAsync(this ITypeTemplate template, Authentication authentication, int tryCount)
 {
     for (var i = 0; i < tryCount; i++)
     {
         await AddRandomMemberAsync(template, authentication);
     }
 }
コード例 #3
0
 public static void AddRandomMembers(this ITypeTemplate template, Authentication authentication, int tryCount)
 {
     for (var i = 0; i < tryCount; i++)
     {
         AddRandomMember(template, authentication);
     }
 }
コード例 #4
0
        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;
                    });
                }
            }
        }
コード例 #5
0
 public static async Task ModifyRandomMembersAsync(this ITypeTemplate template, Authentication authentication, int count)
 {
     for (var i = 0; i < count; i++)
     {
         await ModifyRandomMemberAsync(template, authentication);
     }
 }
コード例 #6
0
ファイル: TemplateViewModel.cs プロジェクト: sedrion/Crema
        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);
            }
        }
コード例 #7
0
 public void SetIsFlag(ITypeTemplate template, TaskContext context)
 {
     template.Dispatcher.Invoke(() =>
     {
         var isFlag = RandomUtility.NextBoolean();
         template.SetIsFlag(context.Authentication, isFlag);
     });
 }
コード例 #8
0
 public void SetComment(ITypeTemplate template, TaskContext context)
 {
     template.Dispatcher.Invoke(() =>
     {
         var comment = RandomUtility.NextString();
         template.SetComment(context.Authentication, comment);
     });
 }
コード例 #9
0
        public static ITypeMember AddRandomMember(this ITypeTemplate template, Authentication authentication)
        {
            var member = template.AddNew(authentication);

            member.InitializeRandom(authentication);
            template.EndNew(authentication, member);
            return(member);
        }
コード例 #10
0
 public void SetTypeName(ITypeTemplate template, TaskContext context)
 {
     template.Dispatcher.Invoke(() =>
     {
         var tableName = RandomUtility.NextIdentifier();
         template.SetTypeName(context.Authentication, tableName);
     });
 }
コード例 #11
0
ファイル: Extensions.cs プロジェクト: teize001/Crema
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
 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;
 }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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();
            }));
        }
コード例 #18
0
ファイル: TemplateViewModel.cs プロジェクト: sedrion/Crema
        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;
        }
コード例 #19
0
 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);
     });
 }
コード例 #20
0
        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;
            }
        }
コード例 #21
0
        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);
        }
コード例 #22
0
ファイル: TemplateViewModel.cs プロジェクト: sedrion/Crema
        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();
                });
            }
        }
コード例 #23
0
        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;
                //}
            }
        }
コード例 #24
0
        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);
        }
コード例 #25
0
ファイル: TemplateViewModel.cs プロジェクト: sedrion/Crema
        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);
        }
コード例 #26
0
 public static Task AddMemberAsync(this ITypeTemplate template, Authentication authentication, string name, long value)
 {
     return(AddMemberAsync(template, authentication, name, value, string.Empty));
 }
コード例 #27
0
 public static Task <bool> ContainsAsync(this ITypeTemplate template, string memberName)
 {
     return(template.Dispatcher.InvokeAsync(() => template.Contains(memberName)));
 }
コード例 #28
0
 public async Task SetCommentAsync(ITypeTemplate template, TaskContext context)
 {
     var authentication = context.Authentication;
     var comment        = RandomUtility.NextString();
     await template.SetCommentAsync(authentication, comment);
 }
コード例 #29
0
 public async Task SetIsFlagAsync(ITypeTemplate template, TaskContext context)
 {
     var authentication = context.Authentication;
     var isFlag         = RandomUtility.NextBoolean();
     await template.SetIsFlagAsync(authentication, isFlag);
 }
コード例 #30
0
 public async Task SetTypeNameAsync(ITypeTemplate template, TaskContext context)
 {
     var authentication = context.Authentication;
     var tableName      = RandomUtility.NextIdentifier();
     await template.SetTypeNameAsync(authentication, tableName);
 }