Exemplo n.º 1
0
        public void ReadFileCommand_ExecuteRequest_1()
        {
            int returnCode = 0;
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            ReadFileCommand         command    = new ReadFileCommand(connection)
            {
                Files =
                {
                    new FileSpecification(IrbisPath.MasterFile, "IBIS", "file.txt")
                }
            };
            ResponseBuilder builder = new ResponseBuilder()
                                      .StandardHeader(CommandCode.ReadDocument, 123, 456)
                                      .NewLine()
                                      .Append(returnCode)
                                      .NewLine();
            TestingSocket socket = (TestingSocket)connection.Socket;

            socket.Response = builder.Encode();
            ClientQuery    query    = command.CreateQuery();
            ServerResponse response = command.Execute(query);

            Assert.IsNotNull(response);
        }
        public TsFile ReadFile(string filePath)
        {
            var command = new ReadFileCommand()
            {
                FilePath = filePath
            };

            var response = this.ExecuteCommand(command);

            var result = JsonConvert.DeserializeObject <ReadFileCommandResult>(response);

            List <IStatement> ast = JsonConvert.DeserializeObject <List <IStatement> >(result.AstPayload, new JsonSerializerSettings
            {
                TypeNameHandling         = TypeNameHandling.Auto,
                NullValueHandling        = NullValueHandling.Ignore,
                MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead
            });

            return(new TsFile()
            {
                FileName = result.FileName,
                Statements = ast,
                Path = filePath
            });
        }
        public void CreateSignature(ApplicationArguments arguments)
        {
            ReadKeyFromFileCommand readPrivateKeyFromFile = fileCommandProvider.GetReadPrivateKeyFromFileCommand(arguments.PrivateKeyPath, arguments.Password);

            commandExecutor.Execute(readPrivateKeyFromFile);

            byte[] contentToSign;
            if (arguments.HasFileInput)
            {
                ReadFileCommand <byte[]> readFileToSign = fileCommandProvider.GetReadFileCommand <byte[]>(arguments.FileInput);
                commandExecutor.Execute(readFileToSign);
                contentToSign = readFileToSign.Result;
            }
            else
            {
                contentToSign = encoding.GetBytes(arguments.Input);
            }

            CreateSignatureCommand createSignature = signatureCommandProvider.GetCreateSignatureCommand(readPrivateKeyFromFile.Result, contentToSign);

            commandExecutor.Execute(createSignature);

            if (arguments.HasFileOutput)
            {
                WriteFileCommand <Signature> writeSignatureTofile = fileCommandProvider.GetWriteToFileCommand(createSignature.Result, arguments.FileOutput);
                commandExecutor.Execute(writeSignatureTofile);
                return;
            }

            WriteToStdOutCommand <Signature> writeSignatureToStdOut = fileCommandProvider.GetWriteToStdOutCommand <Signature>(createSignature.Result);

            commandExecutor.Execute(writeSignatureToStdOut);
        }
Exemplo n.º 4
0
        public void ReadFileCommand_Verify_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            ReadFileCommand         command
                = new ReadFileCommand(connection);

            Assert.IsFalse(command.Verify(false));
        }
Exemplo n.º 5
0
        public void ReadFileCommand_Construciton_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            ReadFileCommand         command
                = new ReadFileCommand(connection);

            Assert.AreSame(connection, command.Connection);
        }
Exemplo n.º 6
0
        public void ShouldSetReadFileAsFileContent()
        {
            var readFileCommand = new ReadFileCommand <byte[]>
            {
                FilePath = "foo"
            };

            commandHandler.Execute(readFileCommand);
            Assert.AreEqual(fileContent, readFileCommand.Result);
        }
Exemplo n.º 7
0
        public void ReadFileCommand_CreateQuery_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            ReadFileCommand         command    = new ReadFileCommand(connection)
            {
                Files =
                {
                    new FileSpecification(IrbisPath.MasterFile, "IBIS", "file.txt")
                }
            };
            ClientQuery query = command.CreateQuery();

            Assert.IsNotNull(query);
        }
        static void Main(string[] args)
        {
            var fileSystemReceiver = FileSystemReceiverUtil.GetFileSystemReceiver();

            var openFileCommand = new OpenFileCommand(fileSystemReceiver);

            var closeFileCommand = new CloseFileCommand(fileSystemReceiver);

            var readFileCommand = new ReadFileCommand(fileSystemReceiver);

            var writeFileCommand = new WriteFileCommand(fileSystemReceiver);

            var invoker = new FileInvoker();

            invoker.Execute(openFileCommand);

            invoker.Execute(closeFileCommand);

            invoker.Execute(new ICommand[] { openFileCommand, readFileCommand, writeFileCommand, closeFileCommand });

            Console.Read();
        }
        public void VerifySignature(ApplicationArguments arguments)
        {
            ReadKeyFromFileCommand readPublicKeyFromFile = fileCommandProvider.GetReadPublicKeyFromFileCommand(arguments.PublicKeyPath);

            commandExecutor.Execute(readPublicKeyFromFile);

            byte[] contentToVerify;
            if (arguments.HasFileInput)
            {
                ReadFileCommand <byte[]> readFileToVerify = fileCommandProvider.GetReadFileCommand <byte[]>(arguments.FileInput);
                commandExecutor.Execute(readFileToVerify);
                contentToVerify = readFileToVerify.Result;
            }
            else
            {
                contentToVerify = encoding.GetBytes(arguments.Input);
            }

            byte[] signatureToVerify;
            if (base64.IsBase64(arguments.Signature))
            {
                signatureToVerify = base64.FromBase64String(arguments.Signature);
            }
            else
            {
                ReadFileCommand <byte[]> readSignatureToVerify = fileCommandProvider.GetReadFileCommand <byte[]>(arguments.Signature);
                commandExecutor.Execute(readSignatureToVerify);

                string base64Signature = encoding.GetString(readSignatureToVerify.Result);
                signatureToVerify = base64.FromBase64String(base64Signature);
            }

            VerifySignatureCommand verifySignature = signatureCommandProvider.GetVerifySignatureCommand(readPublicKeyFromFile.Result, contentToVerify, signatureToVerify);

            commandExecutor.Execute(verifySignature);
        }
Exemplo n.º 10
0
 public void Execute(ReadFileCommand <byte[]> command)
 {
     command.Result = file.ReadAllBytes(command.FilePath);
 }
Exemplo n.º 11
0
        public MainWindowViewModel()
        {
            Rows = new ReactiveList <string>();
            _cts = new CancellationTokenSource();
            System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] UI.");

            GridViewSamplesCommand = ReactiveCommand.Create(() =>
            {
                var window         = new GridEditSample();
                window.DataContext = new GridEditSampleViewModel();
                window.ShowDialog();
            });

            ReadFileCommand = ReactiveCommand.CreateFromObservable(() => ReadFile(FileName, _cts.Token).SubscribeOn(RxApp.TaskpoolScheduler));  //this runs the observable code on the thread pool

            System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] ctor()");

            StopCommand = ReactiveCommand.Create(() =>
            {
                _cts.Cancel();
            });

            //ObserveOnDispatcher means the subscription code will run on the ui thread
            ReadFileCommand.ObserveOnDispatcher().Subscribe(
                onNext: (line) =>
            {
                _rows.Insert(0, line);
                System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] Update UI");
            },
                onCompleted: () =>
            {
                System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] Completed");
            });

            ReadFileCommand.Finally(() =>
            {
                System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] Finally");
            });

            //var fileObservable = Observable.Create<string>((observer) => ReadyFileAsync(observer, FileName, _cts.Token)).SubscribeOn(RxApp.TaskpoolScheduler);

            //ReadFileCommand = ReactiveCommand.CreateFromObservable(() => fileObservable);
            //ReadFileCommand.ObserveOnDispatcher().Subscribe((line) =>
            //{
            //    _rows.Insert(0, line);
            //    System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] {line}");
            //});

            //ReadFileCommand = ReactiveCommand.CreateFromObservable(() => ReadFile(FileName, _cts.Token)  .SubscribeOn(RxApp.TaskpoolScheduler));
            //ReadFileCommand.ObserveOnDispatcher().Subscribe((line) =>
            //    {
            //        _rows.Insert(0, line);
            //        System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] {line}");

            //    });

            //ReadFileCommand.Subscribe(
            //    onNext: line =>
            //    {
            //        try
            //        {
            //                System.Diagnostics.Debug.WriteLine($"Thread[{System.Threading.Thread.CurrentThread.ManagedThreadId}] Rows Collection Insert.");
            //                _rows.Insert(0, line);
            //        }
            //        catch (Exception ex)
            //        {
            //            MessageBox.Show(ex.ToString());
            //        }
            //    },
            //        onError: ex =>
            //        {
            //            MessageBox.Show(ex.ToString());
            //        },
            //    onCompleted: () => MessageBox.Show("Read File Completed")
            //    );


            FileName = @"d:\temp\RT Client Test Job 1.csv";
        }
Exemplo n.º 12
0
 public void Setup()
 {
     result = provider.GetReadFileCommand <object>("bazPath");
 }
 public void ShouldNotExecuteDecoratedHandlerWhenExceptionIsThrown()
 {
     command = Mock.Of <ReadFileCommand <object> >();
     Assert.Throws <ArgumentException>(() => { decorator.Execute(command); });
     decoratedHandler.Verify(h => h.Execute(command), Times.Never);
 }
 public void ShouldExecuteDecoratedHandler()
 {
     command = Mock.Of <ReadFileCommand <object> >(c => c.FilePath == "file.path");
     decorator.Execute(command);
     decoratedHandler.Verify(h => h.Execute(command));
 }