protected async override void OnExecute(object parameter)
        {
            try
            {
                if (parameter is ISelector selector && selector.SelectedItem is ListBoxItemViewModel viewModel && viewModel.Target is ITableItem tableItem)
                {
                    if (viewModel is IInfoProvider provider)
                    {
                        var props     = provider.Info;
                        var revision  = (string)props["Revision"];
                        var tableName = await tableItem.Dispatcher.InvokeAsync(() => tableItem.Name);

                        var dialog = new CommonSaveFileDialog();
                        dialog.Filters.Add(new CommonFileDialogFilter("excel file", "*.xlsx"));
                        dialog.DefaultFileName  = $"{tableName}_{revision}";
                        dialog.DefaultExtension = "xlsx";

                        if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                        {
                            var dataSet = await tableItem.GetDataSetAsync(this.authenticator, revision);

                            var writer = new SpreadsheetWriter(dataSet);
                            writer.Write(dialog.FileName);
                            await AppMessageBox.ShowAsync(Resources.Message_Exported);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                await AppMessageBox.ShowErrorAsync(e);
            }
        }
        protected async override void OnExecute(object parameter)
        {
            if (this.cremaAppHost.GetService(typeof(IDataBase)) is IDataBase dataBase)
            {
                var viewModel = parameter as TreeViewItemViewModel;

                var query = from item in viewModel.Items
                            where item.Target is ITable
                            let table = item.Target as ITable
                                        select table;

                var paths = await dataBase.Dispatcher.InvokeAsync(() =>
                {
                    return(query.Where(item => item.VerifyAccessType(this.authenticator, AccessType.Guest)).
                           Select(item => item.Path).
                           Distinct().
                           ToArray());
                });

                if (paths.Any() == false)
                {
                    await AppMessageBox.ShowAsync(Resources.Message_NoneTablesToExport);
                }
                else
                {
                    var dialog = await ExportViewModel.CreateInstanceAsync(this.authenticator, this.cremaAppHost, paths);

                    if (dialog != null)
                    {
                        await dialog.ShowDialogAsync();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public async static Task <bool> DeleteAsync(Authentication authentication, IDataBaseDescriptor descriptor)
        {
            if (descriptor.Target is IDataBase dataBase)
            {
                if (await new DeleteViewModel().ShowDialogAsync() != true)
                {
                    return(false);
                }

                try
                {
                    await dataBase.DeleteAsync(authentication);

                    await AppMessageBox.ShowAsync(Resources.Message_Deleted);

                    return(true);
                }
                catch (Exception e)
                {
                    await AppMessageBox.ShowErrorAsync(e);

                    return(false);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Exemplo n.º 4
0
        public async Task ImportAsync()
        {
            this.cancelToken = new CancellationTokenSource();
            this.CanImport   = false;

            try
            {
                this.BeginProgress(Resources.Message_Importing);
                var tableNames = this.selectedImporter.GetTableNames();
                var dataSet    = new CremaDataSet()
                {
                    SignatureDateProvider = new SignatureDateProvider(this.authentication.ID),
                };
                await this.dataBase.Dispatcher.InvokeAsync(() => this.CreateTables(dataSet, tableNames));

                await Task.Run(() => this.selectedImporter.Import(dataSet));

                await this.dataBase.ImportAsync(this.authentication, dataSet, this.Comment);

                this.configs.Commit(this);
                await AppMessageBox.ShowAsync(Resources.Message_Imported);
            }
            catch (Exception e)
            {
                await AppMessageBox.ShowErrorAsync(e);
            }
            finally
            {
                this.EndProgress();
                this.CanImport   = true;
                this.cancelToken = null;
            }
        }
Exemplo n.º 5
0
        public async Task CopyAsync()
        {
            await new ProgressAction(this)
            {
                BeginMessage = Resources.Message_CopingDataBase,
                Try          = async() =>
                {
                    await this.dataBase.CloneAsync(this.authentication, this.DataBaseName, this.Comment, string.Empty);

                    await this.TryCloseAsync(true);

                    await AppMessageBox.ShowAsync(Resources.Message_CopiedDataBase);
                }
            }.RunAsync();
        }
Exemplo n.º 6
0
        public async Task CreateAsync()
        {
            await new ProgressAction(this)
            {
                BeginMessage = Resources.Message_CreatingNewDataBase,
                Try          = async() =>
                {
                    await this.DataBaseContext.AddNewDataBaseAsync(this.authentication, this.DataBaseName, this.Comment);

                    await this.TryCloseAsync(true);

                    await AppMessageBox.ShowAsync(Resources.Message_CreatedNewDataBase);
                }
            }.RunAsync();
        }
Exemplo n.º 7
0
        public async Task CreateAsync()
        {
            try
            {
                this.BeginProgress(Resources.Message_NewUser);
                await this.category.AddNewUserAsync(this.authentication, this.ID, this.Password, this.UserName, this.Authority);

                this.EndProgress();
                await this.TryCloseAsync(true);

                await AppMessageBox.ShowAsync(Resources.Message_NewUserComplete);
            }
            catch (Exception e)
            {
                this.EndProgress();
                await AppMessageBox.ShowErrorAsync(e);
            }
        }
Exemplo n.º 8
0
        public override async Task DeleteAsync()
        {
            try
            {
                this.BeginProgress(Resources.Message_Deleting);
                await this.OnDeleteAsync();

                this.EndProgress();
                await this.TryCloseAsync(true);

                await AppMessageBox.ShowAsync(Resources.Message_Deleted);
            }
            catch (Exception e)
            {
                this.EndProgress();
                await AppMessageBox.ShowErrorAsync(e);
            }
        }
Exemplo n.º 9
0
        public async Task CopyAsync()
        {
            try
            {
                this.BeginProgress(Resources.Message_CopingType);
                await this.type.CopyAsync(this.authentication, this.NewName, this.CategoryPath);

                this.EndProgress();
                await this.TryCloseAsync(true);

                await AppMessageBox.ShowAsync(Resources.Message_TypeCopied);
            }
            catch (Exception e)
            {
                this.EndProgress();
                await AppMessageBox.ShowErrorAsync(e);
            }
        }
Exemplo n.º 10
0
        protected async override void OnExecute(object parameter)
        {
            var dialog = new SelectDataBaseViewModel(this.authenticator, this.cremaAppHost, (s) => DataBaseDescriptorUtility.IsLoaded(this.authenticator, s) == false);

            if (await dialog.ShowDialogAsync() != true)
            {
                return;
            }
            if (DataBaseDescriptorUtility.IsLoaded(this.authenticator, dialog.SelectedItem) == true)
            {
                await AppMessageBox.ShowAsync("현재 사용중인 데이터베이스는 삭제할 수 없습니다.");

                return;
            }
            if (await new DeleteViewModel().ShowDialogAsync() != true)
            {
                return;
            }
            await DataBaseUtility.DeleteAsync(this.authenticator, dialog.SelectedItem);
        }
Exemplo n.º 11
0
        private async void Users_MessageReceived(object sender, MessageEventArgs e)
        {
            var message     = e.Message;
            var messageType = e.MessageType;
            var sendUserID  = e.UserID;
            var userIDs     = e.Items.Select(item => item.ID).ToArray();

            if (messageType == MessageType.Notification)
            {
                if (e.UserID != this.authenticator.ID && (userIDs.Any() == false || userIDs.Any(item => item == this.authenticator.ID) == true))
                {
                    await this.Dispatcher.InvokeAsync(() =>
                    {
                    });

                    var title = string.Format(Resources.Title_AdministratorMessage_Format, sendUserID);
                    if (this.cremaAppHost.GetService(typeof(IFlashService)) is IFlashService flashService)
                    {
                        flashService.Flash();
                    }
                    await AppMessageBox.ShowAsync(message, title, MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else if (messageType == MessageType.None)
            {
                if (e.UserID != this.authenticator.ID)
                {
                    var userContext = this.cremaAppHost.GetService(typeof(IUserContext)) as IUserContext;
                    var dialog      = await ViewMessageViewModel.CreateInstanceAsync(this.authenticator, userContext, message, sendUserID);

                    if (dialog != null)
                    {
                        await dialog.ShowDialogAsync();
                    }
                }
            }
        }
Exemplo n.º 12
0
        public async Task CreateRepositoryAsync()
        {
            var dialog = new CommonOpenFileDialog()
            {
                IsFolderPicker = true,
            };

            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                var basePath = dialog.FileName;
                var isEmpty  = DirectoryUtility.IsEmpty(basePath);
                if (isEmpty == false)
                {
                    await AppMessageBox.ShowAsync("대상 경로는 비어있지 않습니다.");

                    return;
                }

                CremaBootstrapper.CreateRepository(this.service, basePath, "git", "xml");
                await AppMessageBox.ShowAsync("저장소를 생성했습니다.");

                this.BasePath = basePath;
            }
        }
Exemplo n.º 13
0
        protected override async void OnExecute(object parameter)
        {
            var tableDescriptor = parameter as ITableDescriptor;
            var table           = tableDescriptor.Target;
            var tableName       = tableDescriptor.TableInfo.Name;

            var dataBaseName = await this.SelectDataBaseAsync();

            if (dataBaseName == null)
            {
                return;
            }

            var dataSet1 = await this.PreviewOtherTableAsync(dataBaseName, tableName);

            if (dataSet1 != null)
            {
                var dataSet2 = await table.GetDataSetAsync(this.authenticator, null);

                var dataSet = new DiffDataSet(dataSet1, dataSet2)
                {
                    Header1 = $"{dataBaseName}: {tableName}",
                    Header2 = $"{this.cremaAppHost.DataBaseName}: {tableName}",
                };

                var dialog = new DiffDataTableViewModel(dataSet.Tables.First())
                {
                    DisplayName = Resources.Title_CompareWithOtherDataBase,
                };
                await dialog.ShowDialogAsync();
            }
            else
            {
                await AppMessageBox.ShowAsync(string.Format(Resources.Message_TableNotFound_Format, tableName));
            }
        }
Exemplo n.º 14
0
 protected async override void OnExecute(object parameter)
 {
     await AppMessageBox.ShowAsync("OK", MessageBoxButton.OK, MessageBoxImage.Information);
 }
Exemplo n.º 15
0
 protected async override void OnExecute(object parameter)
 {
     var viewModel = parameter as TreeViewItemViewModel;
     var items     = viewModel.Items.OfType <ITypeDescriptor>().Select(item => item.Name);
     await AppMessageBox.ShowAsync(string.Join(Environment.NewLine, items));
 }