Exemplo n.º 1
0
        public void CompressionDecompressionTest()
        {
            var compressedResult   = GzipUtils.Compress(InputString);
            var decompressedResult = GzipUtils.Decompress(compressedResult);

            Assert.AreEqual(InputString, decompressedResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the dictionary. If the dictionary is not found by its key and postfix, the empty dictionary is created.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="postfix">The postfix.</param>
        /// <param name="dict">The dictionary.</param>
        /// <returns></returns>
        private bool LoadDictionary(string key, string postfix, ref IDictionary <string, string> dict)
        {
            key = key.Replace("-", "_");
            bool isFound = false;

            string resourceName = $"language.{key}.{postfix}.json.gz";
            string targetManifestResourceName = this
                                                .GetType().Assembly
                                                .GetManifestResourceNames()
                                                .Where(i => i.EndsWith(resourceName)).FirstOrDefault();

            if (targetManifestResourceName != null)
            {
                using (Stream resourceStream = this.GetType().Assembly.GetManifestResourceStream(targetManifestResourceName))
                {
                    using (StreamReader streamReader = new StreamReader(resourceStream))
                    {
                        var compressedResourceValue   = streamReader.ReadToEnd();
                        var decompressedResourceValue = GzipUtils.Decompress(compressedResourceValue);

                        dict = JsonConvert.DeserializeObject <ResourceLocale>(decompressedResourceValue).Values;

                        isFound = true;
                    }
                }
            }

            if (!isFound && dict == null)
            {
                dict = new Dictionary <string, string>();
            }

            return(isFound);
        }