コード例 #1
0
    /// <summary>
    /// Retrieve string value with given key and language, and replace with wildcards
    /// </summary>
    /// <param name="sEnum"></param>
    /// <param name="lEnum"></param>
    /// <param name="wildcards"></param>
    /// <returns></returns>
    public static string GetString(LEnum lEnum, SEnum sEnum, string[] wildcards)
    {
        string line = dictionary[lEnum][sEnum];

        if (NumberOfMarkups(line) == wildcards.Length)
        {
            for (int count = 0; count < wildcards.Length; count++)
            {
                line = line.Substring(0, line.IndexOf(markUp, StringComparison.Ordinal)) + wildcards[count] + line.Substring(line.IndexOf(markUp, StringComparison.Ordinal) + markUp.Length);
            }
            return(line);
        }
        return("Number of wildcards does not match number of spaces available");
    }
コード例 #2
0
    //public static void UnBinarize()
    //{
    //    string allText;

    //    using (var read = new StreamReader(@"assets/binary.csv"))
    //    {
    //        allText = read.ReadToEnd();
    //    }

    //    var filepath = "binary.csv";

    //    using (StreamWriter writer = new StreamWriter(new FileStream(filepath, FileMode.Create, FileAccess.Write)))
    //    {
    //        writer.WriteLine(Binary.Base64Decode(allText));
    //    }
    //}

    /// <summary>
    /// Create dictionary by reading from the binary file
    /// </summary>
    public static void Ingest()
    {
        List <string> lang = new List <string>();
        //UnBinarize();
        var stream = new MemoryStream();
        var writer = new StreamWriter(stream);

        using (var reader = new StreamReader(outputFilePath))
        {
            reader.BaseStream.Position = 0;
            reader.DiscardBufferedData();

            string allStrings = reader.ReadToEnd();

            writer.Write(Binary.Base64Decode(allStrings));
            writer.Flush();
            stream.Position = 0;
        }

        using (CachedCsvReader csv = new CachedCsvReader(new StreamReader(stream), true))
        {
            int fieldCount = csv.FieldCount;

            string[] headers = csv.GetFieldHeaders();

            for (int count = 1; count < headers.Length; count++)
            {
                lang.Add(headers[count]);
            }

            for (int count = 0; count < lang.Count; count++)
            {
                csv.MoveTo(-1);

                LEnum lEnum = (LEnum)Enum.Parse(typeof(LEnum), lang[count]);
                Dictionary <SEnum, string> StringDict = new Dictionary <SEnum, string>();

                while (csv.ReadNextRecord())
                {
                    SEnum sEnum = (SEnum)Enum.Parse(typeof(SEnum), csv[0]);
                    StringDict.Add(sEnum, csv[count + 1]);
                }

                dictionary.Add(lEnum, StringDict);
            }
        }
    }
コード例 #3
0
 /// <summary>
 /// Retrieve string value with given key and lang
 /// </summary>
 /// <param name="sEnum"></param>
 /// <param name="lEnum"></param>
 /// <returns></returns>
 public static string GetString(LEnum lEnum, SEnum sEnum)
 {
     return(dictionary[lEnum][sEnum]);
 }