This class represents the parse.com Language class (for purposes of generating json)
 internal string LanguageId(LanguageDescriptor lang)
 {
     var getLang = MakeGetRequest(ClassesLanguagePath);
     getLang.AddParameter("where", lang.Json, ParameterType.QueryString);
     var response = Client.Execute(getLang);
     if (response.StatusCode != HttpStatusCode.OK)
         return null;
     dynamic json = JObject.Parse(response.Content);
     if (json == null || json.results.Count < 1)
         return null;
     return json.results[0].objectId;
 }
 /// <summary>
 /// Get the language pointers we need to refer to a sequence of languages.
 /// If matching languages don't exist they will be created (requires user to be logged in)
 /// </summary>
 /// <param name="languages"></param>
 /// <returns></returns>
 internal ParseDotComObjectPointer[] GetLanguagePointers(LanguageDescriptor[] languages)
 {
     var result = new ParseDotComObjectPointer[languages.Length];
     for (int i = 0; i < languages.Length; i++)
     {
         var lang = languages[i];
         var id = LanguageId(lang);
         if (id == null)
         {
             var language = CreateLanguage(lang);
             id = language["objectId"].Value;
         }
         result[i] = new ParseDotComObjectPointer() {ClassName = "language", ObjectId = id};
     }
     return result;
 }
 public bool LanguageExists(LanguageDescriptor lang)
 {
     return LanguageCount(lang) > 0;
 }
        public dynamic CreateLanguage(LanguageDescriptor lang)
        {
            if (!LoggedIn)
                throw new ApplicationException();
            var request = MakePostRequest(ClassesLanguagePath);
            var langjson = lang.Json;
            request.AddParameter("application/json", langjson, ParameterType.RequestBody);
            var response = Client.Execute(request);
            if (response.StatusCode != HttpStatusCode.Created)
            {
                var message = new StringBuilder();

                message.AppendLine("Request.Json: " + langjson);
                message.AppendLine("Response.Code: " + response.StatusCode);
                message.AppendLine("Response.Uri: " + response.ResponseUri);
                message.AppendLine("Response.Description: " + response.StatusDescription);
                message.AppendLine("Response.Content: " + response.Content);
                throw new ApplicationException(message.ToString());
            }
            return JObject.Parse(response.Content);
        }
 internal LanguageDescriptor[] MakeLanguageUploadData(string[] isoCodes)
 {
     var result = new LanguageDescriptor[isoCodes.Length];
     for (int i = 0; i < isoCodes.Length; i++)
     {
         var code = isoCodes[i];
         string name = Language1Name;
         if (code != Language1Iso639Code)
             _lookupIsoCode.GetBestLanguageName(code, out name);
         string ethCode;
         LanguageSubtag data;
         if (!StandardSubtags.RegisteredLanguages.TryGet(code.ToLowerInvariant(), out data))
             ethCode = code;
         else
         {
             ethCode = data.Iso3Code;
             if (string.IsNullOrEmpty(ethCode))
                 ethCode = code;
         }
         result[i] = new LanguageDescriptor() { IsoCode = code, Name = name, EthnologueCode = ethCode };
     }
     return result;
 }
Esempio n. 6
0
 void VerifyLangData(LanguageDescriptor lang, string code, string name, string ethCode)
 {
     Assert.That(lang.IsoCode, Is.EqualTo(code));
     Assert.That(lang.Name, Is.EqualTo(name));
     Assert.That(lang.EthnologueCode, Is.EqualTo(ethCode));
 }