public TestWindow(Program.Logger _logger) { StackPanel sp1 = null; StackPanel sp2 = null; EventHandler<Program.LogData> _LoggerLogAdded = (sender, e) => ((Action)(() => { TextBlock tb = new TextBlock(); tb.Text = e.Text; tb.Foreground = e.Kind == Program.LogData.LogKind.error ? Brushes.Red : Brushes.White; tb.Margin = new Thickness(0.0, 10.0, 0.0, 10.0); sp2.Children.Add(tb); })).BeginExecuteInUIThread(); Loaded += (sender, e) => { Grid grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition()); ScrollViewer sv1 = new ScrollViewer(); sv1.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; sv1.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; sv1.SetValue(Grid.RowProperty, 0); sv1.SetValue(Grid.ColumnProperty, 0); sp1 = new StackPanel(); sp1.Background = Brushes.Black; ScrollViewer sv2 = new ScrollViewer(); sv2.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; sv2.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; sv2.SetValue(Grid.RowProperty, 1); sv2.SetValue(Grid.ColumnProperty, 0); sp2 = new StackPanel(); sp2.Background = Brushes.Black; sv1.Content = sp1; sv2.Content = sp2; TextBox tb = new TextBox(); tb.SetValue(Grid.RowProperty, 2); tb.SetValue(Grid.ColumnProperty, 0); grid.Children.Add(sv1); grid.Children.Add(sv2); grid.Children.Add(tb); Content = grid; Console.SetOut(new TextBlockStreamWriter(sp1)); _logger.LogAdded += _LoggerLogAdded; //SimulationWindow sw = new SimulationWindow(); //sw.ShowDialog(); this.StartTask(string.Empty, string.Empty, () => { //string testPrivateRsaParameters; //using (RSACryptoServiceProvider rsacsp = new RSACryptoServiceProvider(2048)) // testPrivateRsaParameters = rsacsp.ToXmlString(true); //RealInboundChennel ric = new RealInboundChennel(7777, RsaKeySize.rsa2048, 100); //ric.Accepted += (sender2, e2) => //{ // this.StartTask("", "", () => // { // e2.WriteBytes(BitConverter.GetBytes(true)); // bool b = BitConverter.ToBoolean(e2.ReadBytes(), 0); // SessionChannel sc = e2.NewSession(); // sc.WriteBytes(BitConverter.GetBytes(true)); // sc.Close(); // //e2.Close(); // }); // //e2.Close(); // //Console.WriteLine(""); //}; //ric.RequestAcceptanceStart(); //AutoResetEvent are = new AutoResetEvent(false); //SocketChannel socketc = null; //RealOutboundChannel roc = new RealOutboundChannel(IPAddress.Loopback, 7777, RsaKeySize.rsa2048, testPrivateRsaParameters); //roc.Connected += (sender2, e2) => //{ // socketc = e2; // socketc.Sessioned += (sender3, e3) => // { // bool b3 = BitConverter.ToBoolean(e3.ReadBytes(), 0); // Console.WriteLine(""); // }; // are.Set(); // //e2.Close(); // //Console.WriteLine("connected"); //}; //roc.RequestConnection(); //are.WaitOne(); //bool b2 = BitConverter.ToBoolean(socketc.ReadBytes(), 0); //socketc.WriteBytes(BitConverter.GetBytes(true)); //socketc.Close(); //CirculatedInteger ci = new CirculatedInteger(5); //Console.WriteLine(ci.GetForward(0)); //Console.WriteLine(ci.GetForward(1)); //Console.WriteLine(ci.GetForward(2)); //Console.WriteLine(ci.GetForward(3)); //Console.WriteLine(ci.GetForward(4)); //Console.WriteLine(ci.GetForward(5)); //Console.WriteLine(ci.GetForward(6)); //Console.WriteLine(ci.GetBackward(0)); //Console.WriteLine(ci.GetBackward(1)); //Console.WriteLine(ci.GetBackward(2)); //Console.WriteLine(ci.GetBackward(3)); //Console.WriteLine(ci.GetBackward(4)); //Console.WriteLine(ci.GetBackward(5)); //Console.WriteLine(ci.GetBackward(6)); Secp256k1KeyPair<Sha256Hash> secp256k1KeyPair = new Secp256k1KeyPair<Sha256Hash>(true); Sha256Ripemd160Hash address = new Sha256Ripemd160Hash(secp256k1KeyPair.pubKey.pubKey); TransactionInput ti1 = new TransactionInput(); ti1.LoadVersion1(0, 0, 0); TransactionOutput to1 = new TransactionOutput(); to1.LoadVersion0(address, new Creacoin(50m)); CoinbaseTransaction ct1 = new CoinbaseTransaction(); ct1.LoadVersion0(new TransactionOutput[] { to1 }); byte[] ctBytes1 = ct1.ToBinary(); CoinbaseTransaction ct2 = SHAREDDATA.FromBinary<CoinbaseTransaction>(ctBytes1); TransferTransaction tt1 = new TransferTransaction(); tt1.LoadVersion1(new TransactionInput[] { ti1 }, new TransactionOutput[] { to1 }); tt1.Sign(new TransactionOutput[] { to1 }, new DSAPRIVKEYBASE[] { secp256k1KeyPair.privKey }); byte[] ttBytes1 = tt1.ToBinary(); TransferTransaction tt2 = SHAREDDATA.FromBinary<TransferTransaction>(ttBytes1); ResTransactions rt1 = new ResTransactions(new Transaction[] { ct1, tt1 }); byte[] rtBytes1 = rt1.ToBinary(); ResTransactions rt2 = SHAREDDATA.FromBinary<ResTransactions>(rtBytes1); byte[] test1 = SHAREDDATA.ToBinary<Transaction>(ct2); CoinbaseTransaction ct3 = SHAREDDATA.FromBinary<Transaction>(test1) as CoinbaseTransaction; byte[] test2 = SHAREDDATA.ToBinary<Transaction>(tt2); TransferTransaction tt3 = SHAREDDATA.FromBinary<Transaction>(test2) as TransferTransaction; //string pathBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //New.BlockManagerDB bmdb = new New.BlockManagerDB(pathBase); //New.BlockDB blkdb = new New.BlockDB(pathBase); //New.BlockFilePointersDB bfpdb = new New.BlockFilePointersDB(pathBase); //New.BlockManager bm = new New.BlockManager(bmdb, blkdb, bfpdb); //New.TestBlock block1 = new New.TestBlock(1); //bm.AddMainBlock(block1); //bm.AddMainBlock(block1); //Test10NodesInv(); //TestDHT(); //bool isFirst = true; //int portNumber = 0; //CreaNode cnlt = null; //tb.KeyDown += (sender2, e2) => //{ // if (e2.Key != Key.Enter) // return; // if (isFirst) // { // portNumber = int.Parse(tb.Text); // FirstNodeInfosDatabase fnidb = new FirstNodeInfosDatabase(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); // cnlt = new CreaNode((ushort)portNumber, 0, "test", fnidb); // cnlt.Start(); // cnlt.ReceivedNewChat += (sender3, e3) => // { // this.ConsoleWriteLine(e3.Message); // }; // isFirst = false; // return; // } // Chat chat = new Chat(); // chat.LoadVersion0(portNumber.ToString(), tb.Text); // chat.Sign(secp256k1KeyPair.privKey); // cnlt.DiffuseNewChat(chat); //}; }); }; Closed += (sender, e) => { _logger.LogAdded -= _LoggerLogAdded; string fileText = string.Empty; foreach (var child in sp1.Children) fileText += (child as TextBlock).Text + Environment.NewLine; File.AppendAllText(Path.Combine(new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName, "LogTest.txt"), fileText); }; }
public TestWindow(Program.Logger _logger) { StackPanel sp1 = null; StackPanel sp2 = null; EventHandler <Program.LogData> _LoggerLogAdded = (sender, e) => ((Action)(() => { TextBlock tb = new TextBlock(); tb.Text = e.Text; tb.Foreground = e.Kind == Program.LogData.LogKind.error ? Brushes.Red : Brushes.White; tb.Margin = new Thickness(0.0, 10.0, 0.0, 10.0); sp2.Children.Add(tb); })).BeginExecuteInUIThread(); Loaded += (sender, e) => { Grid grid = new Grid(); grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition()); ScrollViewer sv1 = new ScrollViewer(); sv1.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; sv1.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; sv1.SetValue(Grid.RowProperty, 0); sv1.SetValue(Grid.ColumnProperty, 0); sp1 = new StackPanel(); sp1.Background = Brushes.Black; ScrollViewer sv2 = new ScrollViewer(); sv2.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; sv2.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; sv2.SetValue(Grid.RowProperty, 1); sv2.SetValue(Grid.ColumnProperty, 0); sp2 = new StackPanel(); sp2.Background = Brushes.Black; sv1.Content = sp1; sv2.Content = sp2; TextBox tb = new TextBox(); tb.SetValue(Grid.RowProperty, 2); tb.SetValue(Grid.ColumnProperty, 0); grid.Children.Add(sv1); grid.Children.Add(sv2); grid.Children.Add(tb); Content = grid; Console.SetOut(new TextBlockStreamWriter(sp1)); _logger.LogAdded += _LoggerLogAdded; //SimulationWindow sw = new SimulationWindow(); //sw.ShowDialog(); this.StartTask(string.Empty, string.Empty, () => { //string testPrivateRsaParameters; //using (RSACryptoServiceProvider rsacsp = new RSACryptoServiceProvider(2048)) // testPrivateRsaParameters = rsacsp.ToXmlString(true); //RealInboundChennel ric = new RealInboundChennel(7777, RsaKeySize.rsa2048, 100); //ric.Accepted += (sender2, e2) => //{ // this.StartTask("", "", () => // { // e2.WriteBytes(BitConverter.GetBytes(true)); // bool b = BitConverter.ToBoolean(e2.ReadBytes(), 0); // SessionChannel sc = e2.NewSession(); // sc.WriteBytes(BitConverter.GetBytes(true)); // sc.Close(); // //e2.Close(); // }); // //e2.Close(); // //Console.WriteLine(""); //}; //ric.RequestAcceptanceStart(); //AutoResetEvent are = new AutoResetEvent(false); //SocketChannel socketc = null; //RealOutboundChannel roc = new RealOutboundChannel(IPAddress.Loopback, 7777, RsaKeySize.rsa2048, testPrivateRsaParameters); //roc.Connected += (sender2, e2) => //{ // socketc = e2; // socketc.Sessioned += (sender3, e3) => // { // bool b3 = BitConverter.ToBoolean(e3.ReadBytes(), 0); // Console.WriteLine(""); // }; // are.Set(); // //e2.Close(); // //Console.WriteLine("connected"); //}; //roc.RequestConnection(); //are.WaitOne(); //bool b2 = BitConverter.ToBoolean(socketc.ReadBytes(), 0); //socketc.WriteBytes(BitConverter.GetBytes(true)); //socketc.Close(); //CirculatedInteger ci = new CirculatedInteger(5); //Console.WriteLine(ci.GetForward(0)); //Console.WriteLine(ci.GetForward(1)); //Console.WriteLine(ci.GetForward(2)); //Console.WriteLine(ci.GetForward(3)); //Console.WriteLine(ci.GetForward(4)); //Console.WriteLine(ci.GetForward(5)); //Console.WriteLine(ci.GetForward(6)); //Console.WriteLine(ci.GetBackward(0)); //Console.WriteLine(ci.GetBackward(1)); //Console.WriteLine(ci.GetBackward(2)); //Console.WriteLine(ci.GetBackward(3)); //Console.WriteLine(ci.GetBackward(4)); //Console.WriteLine(ci.GetBackward(5)); //Console.WriteLine(ci.GetBackward(6)); Secp256k1KeyPair <Sha256Hash> secp256k1KeyPair = new Secp256k1KeyPair <Sha256Hash>(true); Sha256Ripemd160Hash address = new Sha256Ripemd160Hash(secp256k1KeyPair.pubKey.pubKey); TransactionInput ti1 = new TransactionInput(); ti1.LoadVersion1(0, 0, 0); TransactionOutput to1 = new TransactionOutput(); to1.LoadVersion0(address, new Creacoin(50m)); CoinbaseTransaction ct1 = new CoinbaseTransaction(); ct1.LoadVersion0(new TransactionOutput[] { to1 }); byte[] ctBytes1 = ct1.ToBinary(); CoinbaseTransaction ct2 = SHAREDDATA.FromBinary <CoinbaseTransaction>(ctBytes1); TransferTransaction tt1 = new TransferTransaction(); tt1.LoadVersion1(new TransactionInput[] { ti1 }, new TransactionOutput[] { to1 }); tt1.Sign(new TransactionOutput[] { to1 }, new DSAPRIVKEYBASE[] { secp256k1KeyPair.privKey }); byte[] ttBytes1 = tt1.ToBinary(); TransferTransaction tt2 = SHAREDDATA.FromBinary <TransferTransaction>(ttBytes1); ResTransactions rt1 = new ResTransactions(new Transaction[] { ct1, tt1 }); byte[] rtBytes1 = rt1.ToBinary(); ResTransactions rt2 = SHAREDDATA.FromBinary <ResTransactions>(rtBytes1); byte[] test1 = SHAREDDATA.ToBinary <Transaction>(ct2); CoinbaseTransaction ct3 = SHAREDDATA.FromBinary <Transaction>(test1) as CoinbaseTransaction; byte[] test2 = SHAREDDATA.ToBinary <Transaction>(tt2); TransferTransaction tt3 = SHAREDDATA.FromBinary <Transaction>(test2) as TransferTransaction; //string pathBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //New.BlockManagerDB bmdb = new New.BlockManagerDB(pathBase); //New.BlockDB blkdb = new New.BlockDB(pathBase); //New.BlockFilePointersDB bfpdb = new New.BlockFilePointersDB(pathBase); //New.BlockManager bm = new New.BlockManager(bmdb, blkdb, bfpdb); //New.TestBlock block1 = new New.TestBlock(1); //bm.AddMainBlock(block1); //bm.AddMainBlock(block1); //Test10NodesInv(); //TestDHT(); //bool isFirst = true; //int portNumber = 0; //CreaNode cnlt = null; //tb.KeyDown += (sender2, e2) => //{ // if (e2.Key != Key.Enter) // return; // if (isFirst) // { // portNumber = int.Parse(tb.Text); // FirstNodeInfosDatabase fnidb = new FirstNodeInfosDatabase(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); // cnlt = new CreaNode((ushort)portNumber, 0, "test", fnidb); // cnlt.Start(); // cnlt.ReceivedNewChat += (sender3, e3) => // { // this.ConsoleWriteLine(e3.Message); // }; // isFirst = false; // return; // } // Chat chat = new Chat(); // chat.LoadVersion0(portNumber.ToString(), tb.Text); // chat.Sign(secp256k1KeyPair.privKey); // cnlt.DiffuseNewChat(chat); //}; }); }; Closed += (sender, e) => { _logger.LogAdded -= _LoggerLogAdded; string fileText = string.Empty; foreach (var child in sp1.Children) { fileText += (child as TextBlock).Text + Environment.NewLine; } File.AppendAllText(Path.Combine(new FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName, "LogTest.txt"), fileText); }; }