Exemple #1
0
        public Task ReloadSolutionRemotelyTask(ISolutionItem item)
        {
            var itemName = solutionItemNameRegistry.GetName(item);

            return(taskRunner.ScheduleTask($"Reload {itemName} on server",
                                           async progress =>
            {
                var commands = remoteCommandGenerator.GenerateCommand(item);
                var reduced = remoteConnectorService.Merge(commands);

                if (reduced.Count == 0)
                {
                    progress.ReportFinished();
                    return;
                }

                try
                {
                    for (int i = 0; i < reduced.Count; ++i)
                    {
                        progress.Report(i, reduced.Count, reduced[i].GenerateCommand());
                        await remoteConnectorService.ExecuteCommand(reduced[i]);
                    }
                }
                catch (CouldNotConnectToRemoteServer)
                {
                    // we are fine with that
                }

                progress.ReportFinished();
            }));
        }
    public (ICommand, string) GenerateCommand(string metaColumn, DatabaseEntity entity, DatabaseKey realKey)
    {
        if (metaColumn.StartsWith("table:"))
        {
            var parts = metaColumn.Substring(6).Split(';');
            if (parts.Length < 2)
            {
                throw new NotSupportedException("Invalid table meta column: " + metaColumn + ". Expected `table:<tableName>;<condition>(;<keys>)?`");
            }
            var table     = parts[0];
            var condition = parts[1];
            var keyParts  = parts.Length == 3 ? parts[2].Split(',') : new string[] {};
            return(new DelegateCommand(
                       () =>
            {
                var newCondition = entity.FillTemplate(condition);
                tableEditorPickerService.ShowTable(table, newCondition, keyParts.Length == 0 ? null : new DatabaseKey(keyParts.Select(entity.GetTypedValueOrThrow <long>))).ListenErrors();
            }), "Open");
        }
        if (metaColumn.StartsWith("tableByKey:"))
        {
            var table = metaColumn.Substring(11, metaColumn.IndexOf(";") - 11);
            var key   = metaColumn.Substring(metaColumn.IndexOf(";") + 1);
            return(new DelegateCommand(() =>
            {
                tableEditorPickerService.ShowTable(table, null, new DatabaseKey(entity.GetTypedValueOrThrow <long>(key))).ListenErrors();
            }), "Open");
        }
        if (metaColumn.StartsWith("one2one:"))
        {
            var table = metaColumn.Substring(8);
            return(new DelegateCommand(
                       () =>
            {
                tableEditorPickerService.ShowForeignKey1To1(table, entity.Key).ListenErrors();
            }, () => !entity.Phantom), "Open");
        }
        if (metaColumn.StartsWith("invoke:"))
        {
            var command = metaColumn.Substring(7);
            return(new AsyncAutoCommand(
                       () =>
            {
                var result = entity.FillTemplate(command);
                return remoteConnectorService.ExecuteCommand(new AnonymousRemoteCommand(result));
            }, () => !entity.Phantom), "Invoke");
        }

        return(new AlwaysDisabledCommand(), "(invalid)");
    }