Exemplo n.º 1
0
 private static void DumpString(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) {
             Debug.Assert(ex.Message != null);
             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 System.Text.DecoderFallbackException("EEEEE contains nulls!  UTF-16?!");
             }
             writer.WriteLine("{0} (guessing UTF-8): '{1}'", element.ElementType, hack);
         } catch (System.Text.DecoderFallbackException) {
             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
     }
 }
Exemplo n.º 2
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);
        }