Ejemplo n.º 1
0
        //Dispatch cards to be encoded to an encoder selected by command line option. then stitch them together in a stringbuilder.
        public string EncodeCardCollection(CardCollection cardCollection, EncodingFormats encodingFormat)
        {
            var outputBuilder = new StringBuilder();
            var encoder       = InstanciateEncoder(encodingFormat);

            if (ShuffleFields && encodingFormat == EncodingFormats.scfdivineFormat)
            {
                Console.WriteLine("This format cannot be shuffled");
                ShuffleFields = false;
            }

            if (IncludeFlavorText && encodingFormat == EncodingFormats.MtgEncoderFormat)
            {
                ((MtgEncodeFormatEncoder)encoder).IncludeFlavorText = IncludeFlavorText;
            }

            foreach (var card in cardCollection.Cards)
            {
                var cardOutput = encoder.EncodeCard(card);

                if (string.IsNullOrWhiteSpace(cardOutput))
                {
                    continue;
                }

                if (ShuffleFields)
                {
                    cardOutput = ShuffleCardFields(cardOutput);
                }

                outputBuilder.Append($"{cardOutput}\n\n");
            }

            return(outputBuilder.ToString());
        }
Ejemplo n.º 2
0
    public static string GetFormatCode(EncodingFormats format)
    {
        if (format == EncodingFormats.ASCII)
        {
            return(ASCIIFormatCode);
        }

        return(Base64FormatCode);
    }
Ejemplo n.º 3
0
 public static string ConvertBytesToString(byte[] encodedBytes, EncodingFormats format)
 {
     if (format == EncodingFormats.Base64)
     {
         return(Convert.ToBase64String(encodedBytes));
     }
     else
     {
         return(Encoding.ASCII.GetString(encodedBytes));
     }
 }
Ejemplo n.º 4
0
 public static byte[] GetBytesFromString(string original, EncodingFormats format)
 {
     if (format == EncodingFormats.Base64)
     {
         return(Convert.FromBase64String(original));
     }
     else
     {
         return(Encoding.ASCII.GetBytes(original));
     }
 }
Ejemplo n.º 5
0
        //Return an encoder based on the requested decodingFormat
        private IDecoderInterface InstanciateDecoder(EncodingFormats decodingFormat)
        {
            switch (decodingFormat)
            {
            case EncodingFormats.scfdivineFormat:
                return(new scfdivineFormatDecoder());

            case EncodingFormats.MtgEncoderFormat:
            default:
                return(new MtgEncodeFormatDecoder());
            }
        }
Ejemplo n.º 6
0
        //Return an encoder based on the requested encodingFormat
        public IEncoderInterface InstanciateEncoder(EncodingFormats encodingFormat)
        {
            switch (encodingFormat)
            {
            case EncodingFormats.scfdivineFormat:
                return(new scfdivineFormatEncoder());

            case EncodingFormats.MtgEncoderFormat:
            default:
                return(new MtgEncodeFormatEncoder());
            }
        }
Ejemplo n.º 7
0
        //Dispatch lines to be decoded to a decoder selected by decodingFormat
        public CardCollection DecodeString(string inputData, EncodingFormats decodingFormat)
        {
            PotentialCards = 0;
            ActualCards    = 0;

            var cardCollection = new CardCollection();
            var decoder        = InstanciateDecoder(decodingFormat);

            if (string.IsNullOrWhiteSpace(inputData))
            {
                Console.WriteLine("Input contained no data.");
                return(cardCollection);
            }

            using (StringReader reader = new StringReader(inputData))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    PotentialCards++;
                    var card = decoder.DecodeCard(line);

                    if (card != null)
                    {
                        ActualCards++;
                        SetAdditionalData(card);
                        cardCollection.Cards.Add(card);

                        _ConsoleLog.VerboseWriteLine(card + Environment.NewLine);
                    }
                    else
                    {
                        _ConsoleLog.VerboseWriteLine($"Dud: '{line}'" + Environment.NewLine);
                    }
                }
            }

            return(cardCollection);
        }
Ejemplo n.º 8
0
 public StringUtilities(EncodingFormats format)
 {
     EncodingFormat = format;
 }
Ejemplo n.º 9
0
 public StringEncoder(EncodingFormats format)
 {
     this.EncodingFormat = format;
     m_byteShift         = 53;
 }