コード例 #1
0
        public String GetMultiLanguageStringAttributeById(ServiceAttributeId id, LanguageBaseItem language)
        {
            if (language == null)
            {
                throw new ArgumentNullException("language");
            }
            ServiceAttributeId actualId = CreateLanguageBasedAttributeId(id, language.AttributeIdBase);
            ServiceAttribute   attr     = GetAttributeById(actualId);
            ServiceElement     element  = attr.Value;
            // (No need to check that element is of type TextString, that's handled inside the following).
            String str = element.GetValueAsString(language);

            return(str);
        }
コード例 #2
0
        private static void DumpString(System.IO.TextWriter writer, int depth, ServiceElement element, LanguageBaseItem langBase)
        {
            if (langBase != null)
            {
                try {
                    String value = element.GetValueAsString(langBase);
                    writer.WriteLine("{0}: [{1}] '{2}'", element.ElementType, langBase.NaturalLanguage, value);
                } catch (NotSupportedException ex) {
                    System.Diagnostics.Debug.Assert(ex.Message != null);
                    System.Diagnostics.Debug.Assert(ex.Message.StartsWith("Unrecognized character encoding"));
                    writer.WriteLine("{0}: Failure: {1}", element.ElementType, ex.Message);
                }
            }
            else
            {
                try {
                    String hack = element.GetValueAsStringUtf8();
                    if (hack.IndexOf((char)0) != -1)
                    {
                        throw new
#if !WinCE
                              System.Text.DecoderFallbackException
#else
                              // NETCF doesn't support DecoderFallbackException this what the docs say.
                              ArgumentException
#endif
                                  ("EEEEE contains nulls!  UTF-16?!");
                    }
                    writer.WriteLine("{0} (guessing UTF-8): '{1}'", element.ElementType, hack);
                } catch (
                    // TODO ! What exception thrown by UTF8Encoding on NETCF?
#if !WinCE
                    System.Text.DecoderFallbackException
#else
                    // NETCF doesn't support DecoderFallbackException this what the docs say.
                    ArgumentException
#endif
                    ) {
                    writer.WriteLine("{0} (Unknown/bad encoding):", element.ElementType);
                    var arr = (byte[])element.Value;
                    var str = BitConverter.ToString(arr);
                    WritePrefix(writer, depth); // On another line.
                    writer.WriteLine("Length: {0}, >>{1}<<", arr.Length, str);
                }//try
            }
        }
コード例 #3
0
        private static void DumpString(System.IO.TextWriter writer, int depth, ServiceElement element, LanguageBaseItem langBase)
        {
            if (langBase != null) {
                try {
                    String value = element.GetValueAsString(langBase);
                    writer.WriteLine("{0}: [{1}] '{2}'", element.ElementType, langBase.NaturalLanguage, value);
                } catch (NotSupportedException ex) {
                    System.Diagnostics.Debug.Assert(ex.Message != null);
                    System.Diagnostics.Debug.Assert(ex.Message.StartsWith("Unrecognized character encoding"));
                    writer.WriteLine("{0}: Failure: {1}", element.ElementType, ex.Message);
                }
            } else {
                try {
                    String hack = element.GetValueAsStringUtf8();
                    writer.WriteLine("{0} (guessing UTF-8): '{1}'", element.ElementType, hack);
                } catch (
                    // TODO ! What exception thrown by UTF8Encoding on NETCF?
#if ! WinCE
                    System.Text.DecoderFallbackException
#else
                    // NETCF doesn't support DecoderFallbackException this what the docs say.
                    ArgumentException
#endif
                ) {
                    writer.WriteLine("{0} (Unknown/bad encoding):", element.ElementType);
                }//try
            }
        }