示例#1
0
        public ProjectCompositeCommandAdapter(
            ProjectCommandController projectCommandController,
            CompositeCommand <OperationContext> composite,
            OperationContext operationContext)
            : base(true, false)
        {
            // Save the operation context so we can call back into the editor.
            this.operationContext = operationContext;

            // Go through the commands and wrap each one.
            foreach (ICommand <OperationContext> command in composite.Commands)
            {
                IWrappedCommand wrappedCommand =
                    projectCommandController.WrapCommand(command, operationContext);
                Commands.Add(wrappedCommand);
            }
        }
        public void Do(
            ICommand <OperationContext> command,
            OperationContext context)
        {
            // Every command needs a full write lock on the blocks.
            using (Project.Blocks.AcquireLock(RequestLock.Write))
            {
                // Create the context for the block commands.
                var          blockContext = new BlockCommandContext(Project);
                LinePosition linePosition = context.Position.LinePosition;
                int          lineIndex    = linePosition.GetLineIndex(Project.Blocks.Count);
                Block        currentBlock = Project.Blocks[lineIndex];
                blockContext.Position = new BlockPosition(
                    currentBlock, context.Position.CharacterPosition);

                // Wrap the command with our wrappers.
                IWrappedCommand wrappedCommand = WrapCommand(command, context);

                Project.Commands.Do(wrappedCommand, blockContext);

                // Set the operation context from the block context.
                if (blockContext.Position.HasValue)
                {
                    // Grab the block position and figure out the index.
                    BlockPosition blockPosition = blockContext.Position.Value;
                    int           blockIndex    = Project.Blocks.IndexOf(blockPosition.BlockKey);

                    var position = new TextPosition(blockIndex, (int)blockPosition.TextIndex);

                    // Set the context results.
                    context.Results = new LineBufferOperationResults(position);
                }

                // Make sure we process our wrapped command.
                wrappedCommand.PostDo(context);
            }
        }
示例#3
0
 public static Task WriteToServerAsync(this IWrappedCommand cmd, DbContext context, string destinationTable, params string[] fields)
 {
     return(cmd.UseReaderAsync(x => x.WriteToServerAsync(context, destinationTable, fields)));
 }
示例#4
0
 public static void WriteToServer(this IWrappedCommand cmd, DbContext context, string destinationTable, params string[] fields)
 {
     cmd.UseReader(x => x.WriteToServer(context, destinationTable, fields));
 }
示例#5
0
 public static Task WriteToServerAsync(this IWrappedCommand cmd, DbContext context, string destinationTable, BulkOptions bulkOptions, CancellationToken cancellationToken, params string[] fields)
 {
     return(cmd.UseReaderAsync(x => x.WriteToServerAsync(context, destinationTable, bulkOptions, cancellationToken, fields)));
 }
示例#6
0
 public static Task UseReaderAsync(this IWrappedCommand cmd, Func <DbDataReader, Task> action)
 {
     return(cmd.UseReaderAsync(CancellationToken.None, action));
 }