Example #1
0
        public void TestReadInMemory()
        {
            var          serializer      = new LanguagePackSerializer();
            LanguagePack dictionary      = new LanguagePack(description, languageDictionary);
            LanguagePack splitDictionary = new LanguagePack(description, languageSplitDictionary);

            using (Stream stream = new MemoryStream())
            {
                serializer.Serialize(stream, dictionary);

                stream.Seek(0, SeekOrigin.Begin);
                var pack = serializer.DeserializeSplit(stream);

                CheckIsSame(dictionary, pack);
            }

            using (Stream stream = new MemoryStream())
            {
                serializer.Serialize(stream, splitDictionary);

                stream.Seek(0, SeekOrigin.Begin);
                var pack = serializer.DeserializePack(stream);

                CheckIsSame(splitDictionary, pack);
            }
        }
Example #2
0
        private void ReadTest(Stream stream, LanguagePack pack1)
        {
            var serializer = new LanguagePackSerializer();

            var pack2 = serializer.DeserializePack(stream);

            CheckIsSame(pack1.Description, pack2.Description);
            CheckIsSame(pack1.LanguageDictionary, pack2.LanguageDictionary);
        }
 /// <summary>
 /// 尝试读取到语言包,不返回异常;
 /// </summary>
 private bool TryDeserializePack(LanguagePackSerializer packSerializer, ILanguagePackInfo info, out LanguagePack languagePack)
 {
     using (var stream = info.GetInputStream())
     {
         try
         {
             if (IsReadAsSplitPack)
             {
                 languagePack = packSerializer.DeserializeSplit(stream);
             }
             else
             {
                 languagePack = packSerializer.DeserializePack(stream);
             }
             return(true);
         }
         catch (Exception ex)
         {
             Debug.LogWarning(string.Format("读取语言包[{0}]时失败!{1}", info, ex));
             languagePack = default(LanguagePack);
             return(false);
         }
     }
 }