Esempio n. 1
0
        }                     //end dump

        public static void export()
        {
            Console.Out.WriteLine("");
            Banker bank = new Banker(fileUtils);

            int[] bankTotals    = bank.countCoins(bankFolder);
            int[] frackedTotals = bank.countCoins(frackedFolder);
            int[] partialTotals = bank.countCoins(partialFolder);
            Console.Out.WriteLine("  Your Bank Inventory:");
            int grandTotal = (bankTotals[0] + frackedTotals[0] + partialTotals[0]);

            showCoins();
            // state how many 1, 5, 25, 100 and 250
            int exp_1   = 0;
            int exp_5   = 0;
            int exp_25  = 0;
            int exp_100 = 0;
            int exp_250 = 0;

            //Warn if too many coins
            Console.WriteLine(bankTotals[1] + frackedTotals[1] + bankTotals[2] + frackedTotals[2] + bankTotals[3] + frackedTotals[3] + bankTotals[4] + frackedTotals[4] + bankTotals[5] + frackedTotals[5] + partialTotals[1] + partialTotals[2] + partialTotals[3] + partialTotals[4] + partialTotals[5]);
            if (((bankTotals[1] + frackedTotals[1]) + (bankTotals[2] + frackedTotals[2]) + (bankTotals[3] + frackedTotals[3]) + (bankTotals[4] + frackedTotals[4]) + (bankTotals[5] + frackedTotals[5]) + partialTotals[1] + partialTotals[2] + partialTotals[3] + partialTotals[4] + partialTotals[5]) > 1000)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("Warning: You have more than 1000 Notes in your bank. Stack files should not have more than 1000 Notes in them.");
                Console.Out.WriteLine("Do not export stack files with more than 1000 notes. .");
                Console.ForegroundColor = ConsoleColor.White;
            }//end if they have more than 1000 coins

            Console.Out.WriteLine("  Do you want to export your CloudCoin to (1)jpgs or (2) stack (JSON) file?");
            int file_type = reader.readInt(1, 2);

            // 1 jpg 2 stack
            if ((bankTotals[1] + frackedTotals[1]) > 0)
            {
                Console.Out.WriteLine("  How many 1s do you want to export?");
                exp_1 = reader.readInt(0, (bankTotals[1] + frackedTotals[1] + partialTotals[1]));
            }

            // if 1s not zero
            if ((bankTotals[2] + frackedTotals[2]) > 0)
            {
                Console.Out.WriteLine("  How many 5s do you want to export?");
                exp_5 = reader.readInt(0, (bankTotals[2] + frackedTotals[2] + partialTotals[2]));
            }

            // if 1s not zero
            if ((bankTotals[3] + frackedTotals[3] > 0))
            {
                Console.Out.WriteLine("  How many 25s do you want to export?");
                exp_25 = reader.readInt(0, (bankTotals[3] + frackedTotals[3] + partialTotals[3]));
            }

            // if 1s not zero
            if ((bankTotals[4] + frackedTotals[4]) > 0)
            {
                Console.Out.WriteLine("  How many 100s do you want to export?");
                exp_100 = reader.readInt(0, (bankTotals[4] + frackedTotals[4] + partialTotals[4]));
            }

            // if 1s not zero
            if ((bankTotals[5] + frackedTotals[5]) > 0)
            {
                Console.Out.WriteLine("  How many 250s do you want to export?");
                exp_250 = reader.readInt(0, (bankTotals[5] + frackedTotals[5] + partialTotals[5]));
            }

            // if 1s not zero
            // move to export
            Exporter exporter = new Exporter(fileUtils);

            if (file_type == 1)
            {
                Console.Out.WriteLine("  Tag your jpegs with 'random' to give them a random number.");
            }
            Console.Out.WriteLine("  What tag will you add to the file name?");
            String tag = reader.readString();

            //Console.Out.WriteLine(("Exporting to:" + exportFolder));
            if (file_type == 1)
            {
                exporter.writeJPEGFiles(exp_1, exp_5, exp_25, exp_100, exp_250, tag);
                // stringToFile( json, "test.txt");
            }
            else
            {
                exporter.writeJSONFile(exp_1, exp_5, exp_25, exp_100, exp_250, tag);
            }

            // end if type jpge or stack
            Console.Out.WriteLine("  Exporting CloudCoins Completed.");
        }         // end export One
Esempio n. 2
0
        public static void ExportCoins()
        {
            Console.Out.WriteLine("  Do you want to export your CloudCoin to (1)jpgs , (2) stack (JSON) , (3) QR Code (4) 2D Bar code (5) CSV file?");
            int file_type = reader.readInt(1, 5);

            int exp_1   = 0;
            int exp_5   = 0;
            int exp_25  = 0;
            int exp_100 = 0;
            int exp_250 = 0;

            if (onesTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 1s do you want to export?");
                exp_1 = reader.readInt(0, (onesTotalCount));
            }

            // if 1s not zero
            if (fivesTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 5s do you want to export?");
                exp_5 = reader.readInt(0, (fivesTotalCount));
            }

            // if 1s not zero
            if ((qtrTotalCount > 0))
            {
                Console.Out.WriteLine("  How many 25s do you want to export?");
                exp_25 = reader.readInt(0, (qtrTotalCount));
            }

            // if 1s not zero
            if (hundredsTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 100s do you want to export?");
                exp_100 = reader.readInt(0, (hundredsTotalCount));
            }

            // if 1s not zero
            if (twoFiftiesTotalCount > 0)
            {
                Console.Out.WriteLine("  How many 250s do you want to export?");
                exp_250 = reader.readInt(0, (twoFiftiesTotalCount));
            }

            Console.Out.WriteLine("  What tag will you add to the file name?");
            String tag = reader.readString();

            int totalSaved = exp_1 + (exp_5 * 5) + (exp_25 * 25) + (exp_100 * 100) + (exp_250 * 250);
            List <CloudCoin> totalCoins = IFileSystem.bankCoins.ToList();

            totalCoins.AddRange(IFileSystem.frackedCoins);


            var onesToExport = (from x in totalCoins
                                where x.denomination == 1
                                select x).Take(exp_1);
            var fivesToExport = (from x in totalCoins
                                 where x.denomination == 5
                                 select x).Take(exp_5);
            var qtrToExport = (from x in totalCoins
                               where x.denomination == 25
                               select x).Take(exp_25);
            var hundredsToExport = (from x in totalCoins
                                    where x.denomination == 100
                                    select x).Take(exp_100);
            var twoFiftiesToExport = (from x in totalCoins
                                      where x.denomination == 250
                                      select x).Take(exp_250);
            List <CloudCoin> exportCoins = onesToExport.ToList();

            exportCoins.AddRange(fivesToExport);
            exportCoins.AddRange(qtrToExport);
            exportCoins.AddRange(hundredsToExport);
            exportCoins.AddRange(twoFiftiesToExport);

            // Export Coins as jPeg Images
            if (file_type == 1)
            {
                String filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + "");
                if (File.Exists(filename))
                {
                    // tack on a random number if a file already exists with the same tag
                    Random rnd     = new Random();
                    int    tagrand = rnd.Next(999);
                    filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + "");
                }//end if file exists

                foreach (var coin in exportCoins)
                {
                    string OutputFile    = FS.ExportFolder + coin.FileName + tag + ".jpg";
                    bool   fileGenerated = FS.WriteCoinToJpeg(coin, FS.GetCoinTemplate(coin), OutputFile, "");
                    if (fileGenerated)
                    {
                        updateLog("CloudCoin exported as Jpeg to " + OutputFile);
                    }
                }

                FS.RemoveCoins(exportCoins, FS.BankFolder);
                FS.RemoveCoins(exportCoins, FS.FrackedFolder);
            }

            // Export Coins as Stack
            if (file_type == 2)
            {
                String filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + "");
                if (File.Exists(filename))
                {
                    // tack on a random number if a file already exists with the same tag
                    Random rnd     = new Random();
                    int    tagrand = rnd.Next(999);
                    filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + "");
                }//end if file exists

                FS.WriteCoinsToFile(exportCoins, filename, ".stack");
                FS.RemoveCoins(exportCoins, FS.BankFolder);
                FS.RemoveCoins(exportCoins, FS.FrackedFolder);
            }

            // Export Coins as QR Code
            if (file_type == 3)
            {
                foreach (var coin in exportCoins)
                {
                    string OutputFile    = FS.ExportFolder + coin.FileName + ".qr" + tag + ".jpg";
                    bool   fileGenerated = FS.WriteCoinToQRCode(coin, OutputFile, tag);
                    if (fileGenerated)
                    {
                        updateLog("CloudCoin Exported as QR code to " + OutputFile);
                    }
                }

                FS.RemoveCoins(exportCoins, FS.BankFolder);
                FS.RemoveCoins(exportCoins, FS.FrackedFolder);
            }

            // Export Coins as 2D Bar code - PDF417
            if (file_type == 4)
            {
                foreach (var coin in exportCoins)
                {
                    string OutputFile    = FS.ExportFolder + coin.FileName + ".qr" + tag + ".jpg";
                    bool   fileGenerated = FS.WriteCoinToBARCode(coin, OutputFile, tag);
                    if (fileGenerated)
                    {
                        updateLog("CloudCoin Exported as Bar code to " + OutputFile);
                    }
                }

                FS.RemoveCoins(exportCoins, FS.BankFolder);
                FS.RemoveCoins(exportCoins, FS.FrackedFolder);
            }
            if (file_type == 5)
            {
                String filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ".csv");
                if (File.Exists(filename))
                {
                    // tack on a random number if a file already exists with the same tag
                    Random rnd     = new Random();
                    int    tagrand = rnd.Next(999);
                    filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + "");
                }//end if file exists

                var csv   = new StringBuilder();
                var coins = exportCoins;

                var    headerLine     = string.Format("sn,denomination,nn,");
                string headeranstring = "";
                for (int i = 0; i < CloudCoinCore.Config.NodeCount; i++)
                {
                    headeranstring += "an" + (i + 1) + ",";
                }

                // Write the Header Record
                csv.AppendLine(headerLine + headeranstring);

                // Write the Coin Serial Numbers
                foreach (var coin in coins)
                {
                    string anstring = "";
                    for (int i = 0; i < CloudCoinCore.Config.NodeCount; i++)
                    {
                        anstring += coin.an[i] + ",";
                    }
                    var newLine = string.Format("{0},{1},{2},{3}", coin.sn, coin.denomination, coin.nn, anstring);
                    csv.AppendLine(newLine);
                }
                File.WriteAllText(filename, csv.ToString());


                //FS.WriteCoinsToFile(exportCoins, filename, ".s");
                FS.RemoveCoins(exportCoins, FS.BankFolder);
                FS.RemoveCoins(exportCoins, FS.FrackedFolder);
            }
        }