コード例 #1
0
        public async Task <DictionaryVersionResponse> GetDictionaryVersion()
        {
            DictionaryVersionResponse version = new DictionaryVersionResponse();
            var dictionaryResponse            = await deliveryService.GetDictionaryVersion();

            if (dictionaryResponse.IsSuccess)
            {
                version = JsonConvert.DeserializeObject <DictionaryVersionResponse>(dictionaryResponse.Content);
            }
            return(version);
        }
コード例 #2
0
 /// <summary>
 /// UpdateDictionary
 /// </summary>
 /// <returns></returns>
 public static Task UpdateDictionary(string countryCode)
 {
     return(Task.Run(async() =>
     {
         try
         {
             if (Interlocked.CompareExchange(ref isDownloading, 1, 0) == 0)
             {
                 //await _syncLock.WaitAsync();
                 isDownloading = 1;
                 bool needUpdate = false;
                 string dictionaryPath = Path.Combine(GlobalAccess.DirectoryService.GetAppRootPath(), Constants.DICITIONARY_DB_NAME + countryCode + Constants.DICITIONARY_EXTENSION_NAME);
                 DictionaryVersionResponse version = await dictionaryDomainService.GetDictionaryVersion();
                 Dictionary <String, String> versionPool = new Dictionary <string, string>();
                 versionPool.Add(CountryEnum.AU.ToString(), version.AU ?? defaultVersion);
                 versionPool.Add(CountryEnum.NZ.ToString(), version.NZ ?? defaultVersion);
                 versionPool.Add(CountryEnum.SG.ToString(), version.SG ?? defaultVersion);
                 versionPool.Add(CountryEnum.HK.ToString(), version.HK ?? defaultVersion);
                 versionPool.Add(CountryEnum.JP.ToString(), version.JP ?? defaultVersion);
                 versionPool.Add(CountryEnum.MY.ToString(), version.MY ?? defaultVersion);
                 CountryEnum dictionaryLocation = (CountryEnum)Enum.Parse(typeof(CountryEnum), countryCode);
                 string currentDictionaryVersion = defaultVersion;
                 double versionDouble = 0.0;
                 bool isVersionDouble = Double.TryParse(versionPool[countryCode], out versionDouble);
                 if (versionPool[countryCode].Equals(defaultVersion) || !isVersionDouble || String.IsNullOrEmpty(GlobalAccess.Instance.CurrentUserInfo.Country.DictionaryUrl))
                 {
                     needUpdate = false;
                 }
                 else if (!await GlobalAccess.DirectoryService.FileExists(dictionaryPath))
                 {
                     needUpdate = true;
                 }
                 else
                 {
                     Settings st = null;
                     string versionLocal = String.Empty;
                     st = settingsAccess.GetDictionaryVersion(dictionaryLocation, Constants.GLOBAL_SETTING_MAIL, Constants.GLOBAL_SETTING_COUNTRY_CODE);
                     if (st != null)
                     {
                         versionLocal = st.Value;
                         double versionLocalDouble = 0.0;
                         bool isversionLocalDouble = Double.TryParse(versionLocal, out versionLocalDouble);
                         if (isversionLocalDouble && (String.IsNullOrEmpty(versionLocal.Trim()) || versionDouble > versionLocalDouble))
                         {
                             needUpdate = true;
                         }
                     }
                     else
                     {
                         needUpdate = true;
                     }
                 }
                 if (needUpdate)
                 {
                     try
                     {
                         currentDictionaryVersion = versionPool[countryCode];
                         await dictionaryDomainService.DownloadDictionary(GlobalAccess.Instance.CurrentUserInfo.Country.DictionaryUrl, Constants.DICITIONARY_DB_NAME + countryCode + Constants.DICITIONARY_EXTENSION_NAME);
                         settingsAccess.UpdateDictionaryVersion(currentDictionaryVersion, dictionaryLocation, Constants.GLOBAL_SETTING_MAIL, Constants.GLOBAL_SETTING_COUNTRY_CODE);
                     }
                     catch (Exception e)
                     {
                         isDownloading = 0;
                         settingsAccess.UpdateDictionaryVersion(defaultVersion, dictionaryLocation, Constants.GLOBAL_SETTING_MAIL, Constants.GLOBAL_SETTING_COUNTRY_CODE);
                         Logger.Log("Download Dictionary Failed : " + e.Message);
                         //if (AUTO_RETRY_TIMES >= 0)
                         //{
                         //    AUTO_RETRY_TIMES--;
                         //    Logger.Log("Download Dictionary Failed : " + e.Message + " Retry : " + (6 - AUTO_RETRY_TIMES).ToString());
                         //    UpdateDictionary();
                         //}
                     }
                 }
                 //AUTO_RETRY_TIMES = 5;
                 isDownloading = 0;
             }
         }
         catch (Exception ex)
         {
             isDownloading = 0;
             Logger.Log("Update Dictionary Failed : " + ex.Message);
             //if (AUTO_RETRY_TIMES >= 0)
             //{
             //    AUTO_RETRY_TIMES--;
             //    Logger.Log("Update Dictionary Failed : " + ex.Message + " Retry : " + (6 - AUTO_RETRY_TIMES).ToString());
             //    UpdateDictionary();
             //}
         }
         finally
         {
             //_syncLock.Release();
         }
     }));
 }