コード例 #1
0
ファイル: ValidatorImpl.cs プロジェクト: lendak/warchain
 public void AddTransaction(Transaction tr)
 {
     _val.AddTransaction(tr);
 }
コード例 #2
0
        static void PopulateSingleValidatorFromExcel(BlockChainLib.ProofOfStake.Validator validator, string pathToExcel, int sleepMiliseconds = 0)
        {
            Console.WriteLine(DateTime.Now.ToString() + " - Populate single validator - Start.");
            using (var stream = File.Open(pathToExcel, FileMode.Open, FileAccess.Read))
            {
                // Auto-detect format, supports:
                //  - Binary Excel files (2.0-2003 format; *.xls)
                //  - OpenXml Excel files (2007 format; *.xlsx)

                /*ExcelReaderConfiguration erc = new ExcelReaderConfiguration()
                 * {
                 *  // Gets or sets the encoding to use when the input XLS lacks a CodePage
                 *  // record, or when the input CSV lacks a BOM and does not parse as UTF8.
                 *  // Default: cp1252 (XLS BIFF2-5 and CSV only)
                 *  FallbackEncoding = Encoding.GetEncoding(1252),
                 *
                 *
                 *  // Gets or sets an array of CSV separator candidates. The reader
                 *  // autodetects which best fits the input data. Default: , ; TAB | #
                 *  // (CSV only)
                 *  AutodetectSeparators = new char[] { ',', ';', '\t', '|', '#' },
                 *
                 *  // Gets or sets a value indicating whether to leave the stream open after
                 *  // the IExcelDataReader object is disposed. Default: false
                 *  LeaveOpen = false,
                 *
                 *  // Gets or sets a value indicating the number of rows to analyze for
                 *  // encoding, separator and field count in a CSV. When set, this option
                 *  // causes the IExcelDataReader.RowCount property to throw an exception.
                 *  // Default: 0 - analyzes the entire file (CSV only, has no effect on other
                 *  // formats)
                 *  AnalyzeInitialCsvRows = 0,
                 * };*/

                using (var reader = ExcelReaderFactory.CreateReader(stream))
                {
                    uint counter = 0;

                    do
                    {
                        while (reader.Read())
                        {
                            if (counter == 0)
                            {
                                continue;               // skip first row
                            }
                            if ((counter > 0) && (counter % NUMBER_OF_TRANSACTIONS_IN_BLOCK == 0))
                            {
                                validator.FinalizeBlock(); // create blocks of 10000 document validations
                                //Console.WriteLine("Block finalized at article count {0}", counter);
                            }

                            DateTime dtTransactionDate = DateTime.Now;
                            //FormattableString message = $"{{ \"url_hash\": { reader.GetString(1)}, \"article_hash\": {reader.GetString(2)}, \"transaction_date\": { dtTransactionDate.ToString() }";
                            //Transaction tr = new Transaction(validator, message.ToString(), dtTransactionDate);

                            BlockChainLib.WARChain.WARCTransaction tr = new BlockChainLib.WARChain.WARCTransaction(validator, "", dtTransactionDate, BigInteger.Parse(reader.GetString(1), System.Globalization.NumberStyles.HexNumber), BigInteger.Parse(reader.GetString(2), System.Globalization.NumberStyles.HexNumber));

                            //Console.WriteLine("Hashes for (URL, article) = ({0}, {1})", reader.GetString(1), reader.GetString(2));
                            //Console.WriteLine(message.ToString());
                            validator.AddTransaction(tr);

                            if (sleepMiliseconds > 0)
                            {
                                Thread.Sleep(sleepMiliseconds);
                            }

                            counter++;
                        }
                    } while (reader.NextResult());

                    // The result of each spreadsheet is in result.Tables
                }

                Console.WriteLine(DateTime.Now.ToString() + " - Populate single validator - End.");
            }
        }