Пример #1
0
        /// <summary>
        /// Create an instance of content which contains both string and binary data representation
        /// </summary>
        public Content(ContentId id,
                       NLSMap name,
                       string stringContent,
                       byte[] binaryContent,
                       string contentType,
                       LangInfo?lang             = null,
                       string attachmentFileName = null,
                       string createUser         = null,
                       string modifyUser         = null,
                       DateTime?createDate       = null,
                       DateTime?modifyDate       = null)
        {
            if (!id.IsAssigned)
            {
                throw new CmsException($"{StringConsts.ARGUMENT_ERROR} {nameof(Content)}.ctor(id.!IsAssigned)");
            }
            m_Id            = id;
            m_Name          = name;
            m_StringContent = stringContent;
            m_BinaryContent = binaryContent;

            if (m_StringContent == null && m_BinaryContent == null)
            {
                throw new CmsException($"{StringConsts.ARGUMENT_ERROR} {nameof(Content)}.ctor(stringContent==null && binaryContent==null)");
            }

            m_ContentType        = contentType.NonBlank(nameof(contentType));
            m_Language           = LangInfo.Default(lang);
            m_AttachmentFileName = attachmentFileName;
            m_ETag       = getETag(m_ContentType, m_StringContent, m_BinaryContent);
            m_CreateDate = createDate;
            m_ModifyDate = modifyDate;
            m_CreateUser = createUser;
            m_ModifyUser = modifyUser;
        }
Пример #2
0
        public void NLSMap_Get_NameAndDescr()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}, rus: { d: 'On Zeleniy'}}";

            var nls = new NLSMap(content);

            var nand = nls.Get(NLSMap.GetParts.NameAndDescription);

            Aver.AreEqual("Cucumber - It is green", nand);

            nand = nls.Get(NLSMap.GetParts.NameAndDescription, "deu");
            Aver.AreEqual("Gurke - Es ist grün", nand);

            nand = nls.Get(NLSMap.GetParts.NameAndDescription, "XXX");
            Aver.AreEqual("Cucumber - It is green", nand);

            nand = nls.Get(NLSMap.GetParts.NameAndDescription, "YYY", concat: "::");
            Aver.AreEqual("Cucumber::It is green", nand);

            nand = nls.Get(NLSMap.GetParts.NameAndDescription, "rus");
            Aver.AreEqual("On Zeleniy", nand);

            nand = nls.Get(NLSMap.GetParts.NameAndDescription, "XXX", dfltLangIso: "ZZZ");
            Aver.IsNull(nand);
        }
Пример #3
0
        public void NLSMap_Get_DescrAndName()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}, rus: { d: 'On Zeleniy'}}";

            var nls = new NLSMap(content);

            var dan = nls.Get(NLSMap.GetParts.DescriptionAndName);

            Aver.AreEqual("It is green - Cucumber", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "deu");
            Aver.AreEqual("Es ist grün - Gurke", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "XXX");
            Aver.AreEqual("It is green - Cucumber", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "YYY", concat: "::");
            Aver.AreEqual("It is green::Cucumber", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "rus");
            Aver.AreEqual("On Zeleniy", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "XXX", dfltLangIso: "ZZZ");
            Aver.IsNull(dan);
        }
Пример #4
0
        public void Equality_4()
        {
            var nls  = new NLSMap("{eng: {n: 'namE', d: 'descr'}}");
            var nls2 = new NLSMap("{eng: {d: 'descr',          n: 'Name' }}");

            Aver.IsFalse(nls.Equals(nls2));
            Aver.IsFalse(nls2.Equals(nls));
        }
Пример #5
0
        public void Equality_1_0()
        {
            var nls  = new NLSMap(new NLSMap.NDPair[0]);
            var nls2 = new NLSMap(new NLSMap.NDPair[0]);

            Aver.IsTrue(nls.Equals(nls2));
            Aver.AreEqual(nls.GetHashCode(), nls2.GetHashCode());
        }
Пример #6
0
        public void Equality_5()
        {
            var nls  = new NLSMap("{enG: {n: 'name', d: 'descr'}}");
            var nls2 = new NLSMap("{eng: {d: 'descr',          n: 'name' }}");

            Aver.IsFalse(nls.Equals(nls2));
            Aver.IsFalse(nls2.Equals(nls));
            Aver.AreNotEqual(nls.GetHashCode(), nls2.GetHashCode());
        }
Пример #7
0
        public void Equality_7()
        {
            var nls  = new NLSMap("{eng: {n: 'name', d: 'descr'}, rus: {n: 'i', d: 'o'}, chi: {n: '1', d: '2'}}");
            var nls2 = new NLSMap("{rus: {n: 'i',    d: 'o'},  eng: {d: 'descr',          n: 'name' }}");

            Aver.IsFalse(nls.Equals(nls2));
            Aver.IsFalse(nls2.Equals(nls));
            Aver.AreNotEqual(nls.GetHashCode(), nls2.GetHashCode());
        }
Пример #8
0
        public void Equality_6()
        {
            var nls  = new NLSMap("{eng: {n: 'name', d: 'descr'}, rus: {n: 'i', d: 'o'}}");
            var nls2 = new NLSMap("{  eng: {d: 'descr',          n: 'name' },       rus: {n: 'i',    d: 'o'} }");

            Aver.IsTrue(nls.Equals(nls2));
            Aver.IsTrue(nls2.Equals(nls));
            Aver.AreEqual(nls.GetHashCode(), nls2.GetHashCode());
        }
Пример #9
0
        public void NLSMap_OverrideByEmpty1()
        {
            var nls1 = new NLSMap();

            var content2 = "{eng: {n: 'Cacamber',d: 'It is brown'}, rus: {n: 'Ogurez', d: 'On zeleniy'}}";
            var nls2     = new NLSMap(content2);

            var nls = nls1.OverrideBy(nls2);

            Aver.AreEqual(2, nls.Count);
            Aver.AreEqual("Cacamber", nls["eng"].Name);
            Aver.AreEqual(null, nls["deu"].Name);
            Aver.AreEqual("Ogurez", nls["rus"].Name);
        }
Пример #10
0
        public void NLSMap_OverrideByEmpty2()
        {
            var content1 = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";
            var nls1     = new NLSMap(content1);

            var nls2 = new NLSMap();

            var nls = nls1.OverrideBy(nls2);

            Aver.AreEqual(2, nls.Count);
            Aver.AreEqual("Cucumber", nls["eng"].Name);
            Aver.AreEqual("Gurke", nls["deu"].Name);
            Aver.AreEqual(null, nls["rus"].Name);
        }
Пример #11
0
        public void NLSMap_Basic1_String()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}}";

            var nls = new NLSMap(content);

            Aver.IsTrue(nls["eng"].IsAssigned);
            Aver.IsFalse(nls["rus"].IsAssigned);

            Aver.AreEqual("Cucumber", nls["eng"].Name);
            Aver.AreEqual(null, nls["rus"].Name);

            Aver.AreEqual("It is green", nls["eng"].Description);
            Aver.AreEqual(null, nls["rus"].Description);
        }
Пример #12
0
        public void NLSMap_Basic1_Config()
        {
            var content = "nls{ eng{n='Cucumber' d='It is green'}}".AsLaconicConfig();

            var nls = new NLSMap(content);

            Aver.IsTrue(nls["eng"].IsAssigned);
            Aver.IsFalse(nls["rus"].IsAssigned);

            Aver.AreEqual("Cucumber", nls["eng"].Name);
            Aver.AreEqual(null, nls["rus"].Name);

            Aver.AreEqual("It is green", nls["eng"].Description);
            Aver.AreEqual(null, nls["rus"].Description);
        }
Пример #13
0
        public void NLSMap_Basic1_WithRoot()
        {
            var content = @"{""nls"": {""eng"": {""n"": ""Cucumber"",""d"": ""It is green""}}}";

            var nls = new NLSMap(content);

            Assert.IsTrue(nls["eng"].IsAssigned);
            Assert.IsFalse(nls["rus"].IsAssigned);

            Assert.AreEqual("Cucumber", nls["eng"].Name);
            Assert.AreEqual(null, nls["rus"].Name);

            Assert.AreEqual("It is green", nls["eng"].Description);
            Assert.AreEqual(null, nls["rus"].Description);
        }
Пример #14
0
        public void NLSMap_OverrideBy()
        {
            var content1 = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";
            var nls1     = new NLSMap(content1);

            var content2 = "{eng: {n: 'Cacamber',d: 'It is brown'}, rus: {n: 'Ogurez', d: 'On zeleniy'}}";
            var nls2     = new NLSMap(content2);

            var nls = nls1.OverrideBy(nls2);

            Aver.AreEqual(3, nls.Count);
            Aver.AreEqual("Cacamber", nls["eng"].Name);
            Aver.AreEqual("Gurke", nls["deu"].Name);
            Aver.AreEqual("Ogurez", nls["rus"].Name);
        }
Пример #15
0
        public void NLSMap_Basic()
        {
            var content = "eng{n='Cucumber' d='It is green'} deu{n='Gurke' d='Es ist grün'}";

            var nls = new NLSMap(content);

            Assert.IsTrue(nls["eng"].IsAssigned);
            Assert.IsTrue(nls["deu"].IsAssigned);
            Assert.IsFalse(nls["rus"].IsAssigned);

            Assert.AreEqual("Cucumber", nls["eng"].Name);
            Assert.AreEqual("Gurke", nls["deu"].Name);

            Assert.AreEqual("It is green", nls["eng"].Description);
            Assert.AreEqual("Es ist grün", nls["deu"].Description);
        }
Пример #16
0
        public override void Write(NLSMap map)
        {
            if (map.m_Data == null)
            {
                this.Write((int)0);
                return;
            }

            this.Write(map.m_Data.Count);
            foreach (var kvp in map.m_Data)
            {
                this.Write(kvp.Key);
                this.Write(kvp.Value.Name);
                this.Write(kvp.Value.Description);
            }
        }
Пример #17
0
        public void NLSMap_Basic2()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            Aver.IsTrue(nls["eng"].IsAssigned);
            Aver.IsTrue(nls["deu"].IsAssigned);
            Aver.IsFalse(nls["rus"].IsAssigned);

            Aver.AreEqual("Cucumber", nls["eng"].Name);
            Aver.AreEqual("Gurke", nls["deu"].Name);

            Aver.AreEqual("It is green", nls["eng"].Description);
            Aver.AreEqual("Es ist grün", nls["deu"].Description);
        }
Пример #18
0
        public void NLSMap_JSONSerializationRoundtrip()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var json = nls.ToJson();

            json.See();

            var nls2 = new NLSMap(json);

            Aver.AreEqual(2, nls2.Count);
            Aver.AreEqual("Cucumber", nls2["eng"].Name);
            Aver.AreEqual("Gurke", nls2["deu"].Name);
            Aver.AreEqual(null, nls["rus"].Name);
        }
Пример #19
0
        public override void Write(NLSMap map)
        {
            if (map.m_Data == null)
            {
                this.Write((ushort)0);
                return;
            }

            this.Write((ushort)map.m_Data.Length);
            for (var i = 0; i < map.m_Data.Length; i++)
            {
                var nd = map.m_Data[i];
                this.Write(nd.ISO);
                this.Write(nd.Name);
                this.Write(nd.Description);
            }
        }
Пример #20
0
        public void NLSMap_SerializeAll()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var json = nls.ToJson();

            json.See();

            dynamic read = json.JsonToDynamic();

            Aver.IsNotNull(read);

            Aver.AreEqual("Cucumber", read.eng.n);
            Aver.AreEqual("Gurke", read.deu.n);
        }
Пример #21
0
        public void NLSMap_SerializeAll()
        {
            var content = "eng{n='Cucumber' d='It is green'} deu{n='Gurke' d='Es ist grün'}";

            var nls = new NLSMap(content);

            var json = nls.ToJSON();

            Console.WriteLine(json);

            dynamic read = json.JSONToDynamic();

            Assert.IsNotNull(read);

            Assert.AreEqual("Cucumber", read.eng.n);
            Assert.AreEqual("Gurke", read.deu.n);
        }
Пример #22
0
        public void NLSMap_SerializeAll()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var json = nls.ToJSON();

            Console.WriteLine(json);

            dynamic read = json.JSONToDynamic();

            Aver.IsNotNull(read);

            Aver.AreEqual("Cucumber", read.ENG.n);
            Aver.AreEqual("Gurke", read.DEU.n);
        }
Пример #23
0
        public override void Write(NLSMap map)
        {
            if (map.m_Data == null)
            {
                this.Write((ushort)0);
                return;
            }

            this.Write((ushort)map.m_Data.Length);
            for (var i = 0; i < map.m_Data.Length; i++)
            {
                var nd = map.m_Data[i];
                this.Write((byte)((nd.ISO & 0xff0000) >> 16));
                this.Write((byte)((nd.ISO & 0x00ff00) >> 08));
                this.Write((byte)((nd.ISO & 0xFF)));
                this.Write(nd.Name);
                this.Write(nd.Description);
            }
        }
Пример #24
0
        public void NLSMap()
        {
            using (var ms = new MemoryStream())
            {
                var r = SlimFormat.Instance.MakeReadingStreamer();
                var w = SlimFormat.Instance.MakeWritingStreamer();

                r.BindStream(ms);
                w.BindStream(ms);

                var map = new NLSMap(
                    @"nls{
            eng{n='Cream>Serum>Day' d='Daily Serum Care'}
            rus{n='Крем>Серум>Дневной' d='Дневной Уход Серум'}
            deu{n='Ein Drek'}
          }".AsLaconicConfig(handling: ConvertErrorHandling.Throw));

                w.Write(map);

                ms.Position = 0;

                var map2 = r.ReadNLSMap();

                Aver.IsNotNull(map2);
                Aver.AreEqual(3, map2.Count);
                Aver.AreEqual("Cream>Serum>Day", map2["eng"].Name);
                Aver.AreEqual("Крем>Серум>Дневной", map2["rus"].Name);
                Aver.AreEqual("Ein Drek", map2["deu"].Name);

                Aver.AreEqual("Daily Serum Care", map2["eng"].Description);
                Aver.AreEqual("Дневной Уход Серум", map2["rus"].Description);
                Aver.AreEqual(null, map2["deu"].Description);

                ms.Position = 0;
                NLSMap nullmap = new NLSMap();
                w.Write(nullmap);
                ms.Position = 0;

                var map3 = r.ReadNLSMap();
                Aver.IsNull(map3.m_Data);
                Aver.AreEqual(0, map3.Count);
            }
        }
Пример #25
0
        public void NLSMap_Get_Name()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var name = nls.Get(NLSMap.GetParts.Name);

            Aver.AreEqual("Cucumber", name);

            name = nls.Get(NLSMap.GetParts.Name, "deu");
            Aver.AreEqual("Gurke", name);

            name = nls.Get(NLSMap.GetParts.Name, "XXX");
            Aver.AreEqual("Cucumber", name);

            name = nls.Get(NLSMap.GetParts.Name, "XXX", dfltLangIso: "ZZZ");
            Aver.IsNull(name);
        }
Пример #26
0
        public void NLSMap_Get_Descr()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var descr = nls.Get(NLSMap.GetParts.Description);

            Aver.AreEqual("It is green", descr);

            descr = nls.Get(NLSMap.GetParts.Description, "deu");
            Aver.AreEqual("Es ist grün", descr);

            descr = nls.Get(NLSMap.GetParts.Description, "XXX");
            Aver.AreEqual("It is green", descr);

            descr = nls.Get(NLSMap.GetParts.Description, "XXX", dfltLangIso: "ZZZ");
            Aver.IsNull(descr);
        }
Пример #27
0
        public void _NLSMap()
        {
            using (var ms = new MemoryStream())
            {
                var r = SlimFormat.Instance.MakeReadingStreamer();
                var w = SlimFormat.Instance.MakeWritingStreamer();

                r.BindStream(ms);
                w.BindStream(ms);

                NLSMap?map = new NLSMap(
                    @"nls{
                    eng{n='Cream>Serum>Day' d='Daily Serum Care'}
                    rus{n='Крем>Серум>Дневной' d='Дневной Уход Серум'}
                    deu{n='Ein Drek'}
                  }".AsLaconicConfig(handling: ConvertErrorHandling.Throw));

                w.Write(map);

                ms.Position = 0;

                var map2 = r.ReadNullableNLSMap();

                Aver.IsTrue(map2.HasValue);
                Aver.AreEqual(3, map2.Value.Count);
                Aver.AreEqual("Cream>Serum>Day", map2.Value["eng"].Name);
                Aver.AreEqual("Крем>Серум>Дневной", map2.Value["rus"].Name);
                Aver.AreEqual("Крем>Серум>Дневной", map2.Value[CoreConsts.ISOA_LANG_RUSSIAN].Name);
                Aver.AreEqual("Ein Drek", map2.Value["deu"].Name);
                Aver.AreEqual("Ein Drek", map2.Value[CoreConsts.ISOA_LANG_GERMAN].Name);



                ms.Position = 0;
                NLSMap?nullmap = null;
                w.Write(nullmap);
                ms.Position = 0;

                var map3 = r.ReadNullableNLSMap();
                Aver.IsFalse(map3.HasValue);
            }
        }
Пример #28
0
        public void NLSMap_SerializeOnlyOneNoneExisting()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var options = new JsonWritingOptions {
                NLSMapLanguageISO = CoreConsts.ISOA_LANG_RUSSIAN, Purpose = JsonSerializationPurpose.UIFeed
            };
            var json = nls.ToJson(options);

            json.See();

            dynamic read = json.JsonToDynamic();

            Aver.IsNotNull(read);

            Aver.AreEqual("Cucumber", read.n);
            Aver.AreEqual("It is green", read.d);
        }
Пример #29
0
        public void NLSMap_SerializeOnlyOneNoneExisting()
        {
            var content = "{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);


            var options = new JSONWritingOptions {
                NLSMapLanguageISO = "rus", Purpose = JSONSerializationPurpose.UIFeed
            };
            var json = nls.ToJSON(options);

            Console.WriteLine(json);

            dynamic read = json.JSONToDynamic();

            Aver.IsNotNull(read);

            Aver.AreEqual("Cucumber", read.n);
            Aver.AreEqual("It is green", read.d);
        }
Пример #30
0
        public void NLS_Root()
        {
            using (var ms = new MemoryStream())
            {
                var s = new SlimSerializer();

                var dIn = new NLSMap("eng{n='name' d='description'} rus{n='имя' d='описание'}".AsLaconicConfig());

                s.Serialize(ms, dIn);
                ms.Seek(0, SeekOrigin.Begin);

                var dOut = (NLSMap)s.Deserialize(ms);

                Aver.AreEqual(2, dOut.Count);
                Aver.AreEqual("name", dOut.Get(NLSMap.GetParts.Name, "eng"));
                Aver.AreEqual("имя", dOut.Get(NLSMap.GetParts.Name, "rus"));

                Aver.AreEqual("description", dOut.Get(NLSMap.GetParts.Description, "eng"));
                Aver.AreEqual("описание", dOut.Get(NLSMap.GetParts.Description, "rus"));
            }
        }
Пример #31
0
        public void NLS_Array()
        {
            using (var ms = new MemoryStream())
              {
            var s = new SlimSerializer();

            var dIn = new NLSMap[]{
                        new NLSMap("eng{n='name' d='description'} rus{n='имя' d='описание'}".AsLaconicConfig()),
                        new NLSMap("eng{n='color' d='of product'} rus{n='zvet' d='producta'}".AsLaconicConfig()),
                        new NLSMap("eng{n='size' d='of item'} rus{n='razmer' d='tovara'}".AsLaconicConfig())
                      };

            s.Serialize(ms, dIn);
            ms.Seek(0, SeekOrigin.Begin);

            var dOut = (NLSMap[])s.Deserialize(ms);

            Assert.IsNotNull(dOut);

            Assert.AreEqual( 3, dOut.Length);

            Assert.AreEqual( "name",        dOut[0].Get(NLSMap.GetParts.Name, "eng"));
            Assert.AreEqual( "имя",         dOut[0].Get(NLSMap.GetParts.Name, "rus"));
            Assert.AreEqual( "description", dOut[0].Get(NLSMap.GetParts.Description, "eng"));
            Assert.AreEqual( "описание",    dOut[0].Get(NLSMap.GetParts.Description, "rus"));

            Assert.AreEqual( "color",      dOut[1].Get(NLSMap.GetParts.Name, "eng"));
            Assert.AreEqual( "zvet",       dOut[1].Get(NLSMap.GetParts.Name, "rus"));
            Assert.AreEqual( "of product", dOut[1].Get(NLSMap.GetParts.Description, "eng"));
            Assert.AreEqual( "producta",   dOut[1].Get(NLSMap.GetParts.Description, "rus"));

            Assert.AreEqual( "size",    dOut[2].Get(NLSMap.GetParts.Name, "eng"));
            Assert.AreEqual( "razmer",  dOut[2].Get(NLSMap.GetParts.Name, "rus"));
            Assert.AreEqual( "of item", dOut[2].Get(NLSMap.GetParts.Description, "eng"));
            Assert.AreEqual( "tovara",  dOut[2].Get(NLSMap.GetParts.Description, "rus"));
              }
        }
Пример #32
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Basic2_WithRoot()
        {
            var content=@"{""nls"": {""eng"": {""n"": ""Cucumber"",""d"": ""It is green""}, ""deu"": {""n"": ""Gurke"", ""d"": ""Es ist grün""}}}";

            var nls = new NLSMap(content);

            Assert.IsTrue (nls["eng"].IsAssigned);
            Assert.IsTrue (nls["deu"].IsAssigned);
            Assert.IsFalse(nls["rus"].IsAssigned);

            Assert.AreEqual("Cucumber", nls["eng"].Name);
            Assert.AreEqual("Gurke", nls["deu"].Name);

            Assert.AreEqual("It is green", nls["eng"].Description);
            Assert.AreEqual("Es ist grün", nls["deu"].Description);
        }
Пример #33
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Get_Descr()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var descr = nls.Get(NLSMap.GetParts.Description);
            Assert.AreEqual("It is green", descr);

            descr = nls.Get(NLSMap.GetParts.Description, "deu");
            Assert.AreEqual("Es ist grün", descr);

            descr = nls.Get(NLSMap.GetParts.Description, "XXX");
            Assert.AreEqual("It is green", descr);

            descr = nls.Get(NLSMap.GetParts.Description, "XXX", dfltLangIso: "ZZZ");
            Assert.IsNull(descr);
        }
Пример #34
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Get_Name()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var name = nls.Get(NLSMap.GetParts.Name);
            Assert.AreEqual("Cucumber", name);

            name = nls.Get(NLSMap.GetParts.Name, "deu");
            Assert.AreEqual("Gurke", name);

            name = nls.Get(NLSMap.GetParts.Name, "XXX");
            Assert.AreEqual("Cucumber", name);

            name = nls.Get(NLSMap.GetParts.Name, "XXX", dfltLangIso: "ZZZ");
            Assert.IsNull(name);
        }
Пример #35
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Get_DescrAndName()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}, rus: { d: 'On Zeleniy'}}";

            var nls = new NLSMap(content);

            var dan = nls.Get(NLSMap.GetParts.DescriptionAndName);
            Assert.AreEqual("It is green - Cucumber", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "deu");
            Assert.AreEqual("Es ist grün - Gurke", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "XXX");
            Assert.AreEqual("It is green - Cucumber", dan);

             dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "YYY", concat: "::");
            Assert.AreEqual("It is green::Cucumber", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "rus");
            Assert.AreEqual("On Zeleniy", dan);

            dan = nls.Get(NLSMap.GetParts.DescriptionAndName, "XXX", dfltLangIso: "ZZZ");
            Assert.IsNull(dan);
        }
Пример #36
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_SerializeAll()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var json = nls.ToJSON();
            Console.WriteLine(json);

            dynamic read = json.JSONToDynamic();
            Assert.IsNotNull(read);

            Assert.AreEqual("Cucumber", read.eng.n);
            Assert.AreEqual("Gurke", read.deu.n);
        }
Пример #37
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Get_NameOrDescr()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}, rus: { d: 'On Zeleniy'}}";

            var nls = new NLSMap(content);

            var nord = nls.Get(NLSMap.GetParts.NameOrDescription);
            Assert.AreEqual("Cucumber", nord);

            nord = nls.Get(NLSMap.GetParts.NameOrDescription, "deu");
            Assert.AreEqual("Gurke", nord);

            nord = nls.Get(NLSMap.GetParts.NameOrDescription, "XXX");
            Assert.AreEqual("Cucumber", nord);

            nord = nls.Get(NLSMap.GetParts.NameOrDescription, "rus");
            Assert.AreEqual("On Zeleniy", nord);

            nord = nls.Get(NLSMap.GetParts.NameOrDescription, "XXX", dfltLangIso: "ZZZ");
            Assert.IsNull(nord);
        }
Пример #38
0
        public void _NLSMap()
        {
            using(var ms = new MemoryStream())
                    {
                        var r = SlimFormat.Instance.MakeReadingStreamer();
                        var w = SlimFormat.Instance.MakeWritingStreamer();

                        r.BindStream(ms);
                        w.BindStream(ms);

                        NLSMap? map = new NLSMap(
                @"nls{
                    eng{n='Cream>Serum>Day' d='Daily Serum Care'}
                    rus{n='Крем>Серум>Дневной' d='Дневной Уход Серум'}
                    deu{n='Ein Drek'}
                  }".AsLaconicConfig(handling: ConvertErrorHandling.Throw));

                        w.Write(map);

                        ms.Position = 0;

                        var map2 = r.ReadNullableNLSMap();

                        Assert.IsTrue(map2.HasValue);
                        Assert.AreEqual(3, map2.Value.Count);
                        Assert.AreEqual("Cream>Serum>Day", map2.Value["ENG"].Name);
                        Assert.AreEqual("Крем>Серум>Дневной", map2.Value["rus"].Name);
                        Assert.AreEqual("Ein Drek", map2.Value["dEu"].Name);

                        ms.Position = 0;
                        NLSMap? nullmap = null;
                        w.Write(nullmap);
                        ms.Position = 0;

                        var map3 = r.ReadNullableNLSMap();
                        Assert.IsFalse( map3.HasValue );
                    }
        }
Пример #39
0
        public void NLSMap()
        {
            using(var ms = new MemoryStream())
            {
                var r = SlimFormat.Instance.MakeReadingStreamer();
                var w = SlimFormat.Instance.MakeWritingStreamer();

                r.BindStream(ms);
                w.BindStream(ms);

                var map = new NLSMap(
            @"nls{
            eng{n='Cream>Serum>Day' d='Daily Serum Care'}
            rus{n='Крем>Серум>Дневной' d='Дневной Уход Серум'}
            deu{n='Ein Drek'}
              }".AsLaconicConfig(handling: ConvertErrorHandling.Throw));

                w.Write(map);

                ms.Position = 0;

                var map2 = r.ReadNLSMap();

                Assert.IsNotNull(map2);
                Assert.AreEqual(3, map2.Count);
                Assert.AreEqual("Cream>Serum>Day", map2["ENG"].Name);
                Assert.AreEqual("Крем>Серум>Дневной", map2["rus"].Name);
                Assert.AreEqual("Ein Drek", map2["dEu"].Name);

                Assert.AreEqual("Daily Serum Care", map2["ENG"].Description);
                Assert.AreEqual("Дневной Уход Серум", map2["rus"].Description);
                Assert.AreEqual(null, map2["dEu"].Description);

                ms.Position = 0;
                NLSMap nullmap = new NLSMap();
                w.Write(nullmap);
                ms.Position = 0;

                var map3 = r.ReadNLSMap();
                Assert.IsNull( map3.m_Data);
                Assert.AreEqual(0 , map3.Count);

            }
        }
Пример #40
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Basic2()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            Assert.IsTrue (nls["eng"].IsAssigned);
            Assert.IsTrue (nls["deu"].IsAssigned);
            Assert.IsFalse(nls["rus"].IsAssigned);

            Assert.AreEqual("Cucumber", nls["eng"].Name);
            Assert.AreEqual("Gurke", nls["deu"].Name);

            Assert.AreEqual("It is green", nls["eng"].Description);
            Assert.AreEqual("Es ist grün", nls["deu"].Description);
        }
Пример #41
0
        public void NLS_Root()
        {
            using (var ms = new MemoryStream())
              {
            var s = new SlimSerializer();

            var dIn = new NLSMap("eng{n='name' d='description'} rus{n='имя' d='описание'}".AsLaconicConfig());

            s.Serialize(ms, dIn);
            ms.Seek(0, SeekOrigin.Begin);

            var dOut = (NLSMap)s.Deserialize(ms);

            Assert.AreEqual( 2, dOut.Count);
            Assert.AreEqual( "name", dOut.Get(NLSMap.GetParts.Name, "eng"));
            Assert.AreEqual( "имя", dOut.Get(NLSMap.GetParts.Name, "rus"));

            Assert.AreEqual( "description", dOut.Get(NLSMap.GetParts.Description, "eng"));
            Assert.AreEqual( "описание", dOut.Get(NLSMap.GetParts.Description, "rus"));
              }
        }
Пример #42
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_SerializeOnlyOneNoneExisting()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}}";

            var nls = new NLSMap(content);

            var options = new JSONWritingOptions{ NLSMapLanguageISO = "rus", Purpose = JSONSerializationPurpose.UIFeed};
            var json = nls.ToJSON(options);
            Console.WriteLine(json);

            dynamic read = json.JSONToDynamic();
            Assert.IsNotNull(read);

            Assert.AreEqual("Cucumber", read.n);
            Assert.AreEqual("It is green", read.d);
        }
Пример #43
0
 public override void Write(NLSMap? value)
 {
     if (value.HasValue)
         {
           this.Write(true);
           Write(value.Value);
           return;
         }
         this.Write(false);
 }
Пример #44
0
        public override void Write(NLSMap map)
        {
            if (map.m_Data==null)
            {
              this.Write((int)0);
              return;
            }

            this.Write(map.m_Data.Count);
            foreach(var kvp in map.m_Data)
            {
              this.Write(kvp.Key);
              this.Write(kvp.Value.Name);
              this.Write(kvp.Value.Description);
            }
        }
Пример #45
0
 public abstract void Write(NLSMap? map);
Пример #46
0
        public override NLSMap ReadNLSMap()
        {
            var cnt = this.ReadInt();
            var result = new NLSMap(cnt>0);
            if (cnt<=0) return result;
            for(var i=0; i<cnt; i++)
            {
              var key = this.ReadString();
              if (key==null)
                throw new NFXIOException(StringConsts.SLIM_STREAM_CORRUPTED_ERROR + "ReadNLSMap(): key==null");
              var name = this.ReadString();
              var descr = this.ReadString();
              result.m_Data[key] = new NLSMap.NDPair(name, descr);
            }

            return result;
        }
Пример #47
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Get_DescrOrName()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}, deu: {n: 'Gurke', d: 'Es ist grün'}, rus: { d: 'On Zeleniy'}}";

            var nls = new NLSMap(content);

            var dorn = nls.Get(NLSMap.GetParts.DescriptionOrName);
            Assert.AreEqual("It is green", dorn);

            dorn = nls.Get(NLSMap.GetParts.DescriptionOrName, "deu");
            Assert.AreEqual("Es ist grün", dorn);

            dorn = nls.Get(NLSMap.GetParts.DescriptionOrName, "XXX");
            Assert.AreEqual("It is green", dorn);

            dorn = nls.Get(NLSMap.GetParts.DescriptionOrName, "rus");
            Assert.AreEqual("On Zeleniy", dorn);

            dorn = nls.Get(NLSMap.GetParts.DescriptionOrName, "XXX", dfltLangIso: "ZZZ");
            Assert.IsNull(dorn);
        }
Пример #48
0
Файл: JSON.cs Проект: yhhno/nfx
        public void NLSMap_Basic1()
        {
            var content="{eng: {n: 'Cucumber',d: 'It is green'}}";

            var nls = new NLSMap(content);

            Assert.IsTrue (nls["eng"].IsAssigned);
            Assert.IsFalse(nls["rus"].IsAssigned);

            Assert.AreEqual("Cucumber", nls["eng"].Name);
            Assert.AreEqual(null, nls["rus"].Name);

            Assert.AreEqual("It is green", nls["eng"].Description);
            Assert.AreEqual(null, nls["rus"].Description);
        }