示例#1
0
        private static void GetLocalesCallback(IAsyncResult asyncResult)
        {
            // DebugLog.WriteLine("GetLocalesCallback()");
            try
            {
                // DebugLog.WriteLine("    get request");
                var request = (HttpWebRequest)asyncResult.AsyncState;
                // DebugLog.WriteLine("    get response");
                var response = (HttpWebResponse)request.EndGetResponse(asyncResult);
                // DebugLog.WriteLine("    get stream");
                var responseStream = response.GetResponseStream();

                bool persist = true;
                // If disk version is newer than online version, don't persist.  This
                // should only happen when a user is adding a new language.  In this
                // case we want ehm to be able to modify their local copy.
                DateTime lastModTime = Storage4.GetLastWriteTimeUtc(LocalesFilePath, StorageSource.UserSpace);
#if NETFX_CORE
                // For WindowsStore build .LastModified is not supported so just always persist file.
                if (true)
#else
                if (lastModTime > response.LastModified)
#endif
                {
                    persist = false;
                }

                // DebugLog.WriteLine("    persist : " + persist.ToString());

                if (persist)
                {
                    // DebugLog.WriteLine("    Populating from XML stream.");
                    PopulatesLocalesFromXmlStream(responseStream, persist);
                }
                else
                {
                    // DebugLog.WriteLine("    Getting from file.");
                    GetLocalesFromFile();
                }
            }
            catch (Exception e)
            {
                // Keep the compiler quiet when LOCALES_DEBUG not defined.
                if (e != null)
                {
                    // DebugLog.WriteException(e, "GetLocalesCallback()");
                }
#if LOCALES_DEBUG
                LocalesDebugPrint("Exception thrown in GetLocalesCallback()\n" + e.ToString());
#endif
            }
            finally
            {
                if (_locales == null)
                {
                    // DebugLog.WriteLine("    Safe get from file.");
                    SafeGetLocalesFromFile();
                }
            }
        }
        /// <summary>
        /// Load current options data.
        /// </summary>
        /// <returns></returns>
        private static XmlOptionsData Load()
        {
            XmlOptionsData xmlData = null;

            Stream stream = null;

            DateTime xmlFileTime = new DateTime();//used to compare against InstallLanguage.txt

            try
            {
                // Try the real filename first.
                string xmlFileName = FileName();

                if (Storage4.FileExists(xmlFileName, StorageSource.All))
                {
                    xmlFileTime = Storage4.GetLastWriteTimeUtc(xmlFileName, StorageSource.All);
                    stream      = Storage4.OpenRead(xmlFileName, StorageSource.All);
                    XmlSerializer serializer = new XmlSerializer(typeof(XmlOptionsData));
                    xmlData = serializer.Deserialize(stream) as XmlOptionsData;
                }
                else
                {
                    // If not there, try the back compat version.
                    xmlFileName = BackCompatFileName();

                    if (Storage4.FileExists(xmlFileName, StorageSource.All))
                    {
                        xmlFileTime = Storage4.GetLastWriteTimeUtc(xmlFileName, StorageSource.All);
                        stream      = Storage4.OpenRead(xmlFileName, StorageSource.All);
                        XmlSerializer serializer = new XmlSerializer(typeof(XmlOptionsData));
                        xmlData = serializer.Deserialize(stream) as XmlOptionsData;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            if (stream != null)
            {
                Storage4.Close(stream);
            }

            //Check for override of language.
            if (xmlData != null && Storage4.FileExists(InstalledLanguageFileName(), StorageSource.All))
            {
                var langFileTime = Storage4.GetLastWriteTimeUtc(InstalledLanguageFileName(), StorageSource.All);
                //If InstallerLanguage.txt is later than selected language.
                if (langFileTime > xmlFileTime)
                {
                    //Update language to match newly installed version.
                    xmlData.langauge = GetInstallerLanguageOrDefault();
                    Save();
                }
            }

            return(xmlData);
        }   // end of Load()
示例#3
0
            public DateTime?LastUpdated(string language)
            {
                var resourcePath = Path.Combine(LanguageDir, language, Name);

                if (Storage4.FileExists(resourcePath, StorageSource.All))
                {
                    return(Storage4.GetLastWriteTimeUtc(resourcePath, StorageSource.All));
                }
                return(null);
            }