コード例 #1
0
 protected override ResourceLiteralDictionary readAllFromPlistFile(string file)
 {
     if (IPhoneUtils.GetInstance().ResourcesZipped)
     {
         // if resource is zipped, we will need to parse the file as an xml file (done in abstract class)
         return(base.readAllFromPlistFile(file));
     }
     else
     {
         ResourceLiteralDictionary result = null;
         if (this.FileExists(file))
         {
             result = new ResourceLiteralDictionary();
             NSDictionary literalDictionary = loadResourcesLiteral(file);
             foreach (NSObject key in literalDictionary.Keys)
             {
                 result.Add(key.ToString(), literalDictionary[key].ToString());
             }
             return(result);
         }
         else
         {
             // if file does not exists, means that requested locale is not supported by application
             // try then to get default locale string
             return(this.GetResourceLiterals());
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Initializes the appverse context exposing data to the WebView Javascript DOM.
        /// </summary>
        private void InitializeAppverseContext()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try {
                                #if DEBUG
                log("Before loading the main HTML, platform will expose some information directly to javascript...");
                                #endif

                IPhoneSystem systemService = (IPhoneSystem)IPhoneServiceLocator.GetInstance().GetService("system");
                AbstractI18N i18nService   = (AbstractI18N)IPhoneServiceLocator.GetInstance().GetService("i18n");
                IIo          ioService     = (IIo)IPhoneServiceLocator.GetInstance().GetService("io");

                // 1. Appverse Context (Appverse.is)
                UnityContext unityContext           = systemService.GetUnityContext();
                String       unityContextJsonString = IPhoneUtils.GetInstance().JSONSerializeObjectData(unityContext);
                unityContextJsonString = "_AppverseContext = " + unityContextJsonString;
                this.EvaluateJavascript(unityContextJsonString);

                // 2. OS Info (Appverse.OSInfo)
                OSInfo osInfo           = systemService.GetOSInfo();
                String osInfoJsonString = IPhoneUtils.GetInstance().JSONSerializeObjectData(osInfo);
                osInfoJsonString = "_OSInfo = " + osInfoJsonString;
                this.EvaluateJavascript(osInfoJsonString);

                // 3. Hardware Info (Appverse.HardwareInfo)
                HardwareInfo hwInfo           = systemService.GetOSHardwareInfo();
                String       hwInfoJsonString = IPhoneUtils.GetInstance().JSONSerializeObjectData(hwInfo);
                hwInfoJsonString = "_HwInfo = " + hwInfoJsonString;
                this.EvaluateJavascript(hwInfoJsonString);

                // 4. Get all configured localized keys (Appverse.i18n)
                Unity.Core.I18N.Locale[] supportedLocales = i18nService.GetLocaleSupported();
                String localizedStrings = "_i18n = {};  _i18n['default'] = '" + i18nService.DefaultLocale + "'; ";
                String localeLiterals   = "";
                foreach (Unity.Core.I18N.Locale supportedLocale in supportedLocales)
                {
                    ResourceLiteralDictionary literals = i18nService.GetResourceLiterals(supportedLocale);
                    String literalsJsonString          = IPhoneUtils.GetInstance().JSONSerializeObjectData(literals);
                    localeLiterals = localeLiterals + " _i18n['" + supportedLocale.ToString() + "'] = " + literalsJsonString + "; ";
                }
                localizedStrings = localizedStrings + localeLiterals;
                this.EvaluateJavascript(localizedStrings);

                // 5. Current device locale
                Unity.Core.System.Locale currentLocale = systemService.GetLocaleCurrent();
                String currentLocaleJsonString         = IPhoneUtils.GetInstance().JSONSerializeObjectData(currentLocale);
                currentLocaleJsonString = "_CurrentDeviceLocale = " + currentLocaleJsonString;
                this.EvaluateJavascript(currentLocaleJsonString);

                // 6. Configured IO services endpoints
                IOService[] services           = ioService.GetServices();
                String      servicesJsonString = "_IOServices = {}; ";
                foreach (IOService service in services)
                {
                    String serviceJson = IPhoneUtils.GetInstance().JSONSerializeObjectData(service);
                    servicesJsonString = servicesJsonString + " _IOServices['" + service.Name + "-" + IPhoneUtils.GetInstance().JSONSerializeObjectData(service.Type) + "'] = " + serviceJson + "; ";
                }
                this.EvaluateJavascript(servicesJsonString);

                IPhoneNet NetService = (IPhoneNet)IPhoneServiceLocator.GetInstance().GetService("net");
                NetService.CheckConnectivity();
                String netJsonString = "_NetworkStatus = " + NetService.getNetStatus();
                this.EvaluateJavascript(netJsonString);
            } catch (Exception ex) {
                                #if DEBUG
                log("Unable to load Appverse Context. Exception message: " + ex.Message);
                                #endif
            }

            stopwatch.Stop();
                        #if DEBUG
            log("# Time elapsed initializing Appverse Context: " + stopwatch.Elapsed);
                        #endif
        }
コード例 #3
0
ファイル: IPhoneI18N.cs プロジェクト: jioe/appverse-mobile
 protected override ResourceLiteralDictionary readAllFromPlistFile(string file)
 {
     if(IPhoneUtils.GetInstance().ResourcesZipped) {
         // if resource is zipped, we will need to parse the file as an xml file (done in abstract class)
         return base.readAllFromPlistFile(file);
     } else {
         ResourceLiteralDictionary result = null;
         if (this.FileExists (file)) {
             result = new ResourceLiteralDictionary();
             NSDictionary literalDictionary = loadResourcesLiteral(file);
             foreach(NSObject key in literalDictionary.Keys)
             {
                 result.Add(key.ToString(),literalDictionary[key].ToString());
             }
             return result;
         } else {
             // if file does not exists, means that requested locale is not supported by application
             // try then to get default locale string
             return this.GetResourceLiterals();
         }
     }
 }
コード例 #4
0
        protected virtual ResourceLiteralDictionary readAllFromPlistFile(string file)
        {
            ResourceLiteralDictionary result = null;
            if (File.Exists (file)) {
                result = new ResourceLiteralDictionary ();
                try {
                    using (XmlTextReader reader = new XmlTextReader (file)) {
                        reader.XmlResolver = null;
                        XmlDocument XmlDoc = new XmlDocument ();
                        XmlDoc.Load (reader);
                        XmlNodeList keys = XmlDoc.SelectNodes ("plist/dict/key");
                        XmlNodeList values = XmlDoc.SelectSingleNode ("plist/dict").ChildNodes;
                        for (int value = 0; value <= keys.Count - 1; value++) {
                            if (result.ContainsKey (keys [value].InnerText)) {
                                result [keys [value].InnerText] = values [value * 2 + 1].InnerText;
                            } else {
                                result.Add (keys [value].InnerText, values [value * 2 + 1].InnerText);
                            }

                        }
                    }
                } catch (Exception) {
                    result = null;
                }
            } else {
                // if file does not exists, means that requested locale is not supported by application
                // try then to get default locale string
                return GetResourceLiterals ();
            }
            return result;
        }
コード例 #5
0
		protected override ResourceLiteralDictionary readAllFromPlistFile (string file)
		{
			if(IPhoneUtils.GetInstance().ResourcesZipped) {
				// if resource is zipped, we will need to parse the file as an xml file (done in abstract class)
				return base.readAllFromPlistFile(file);
			} else {
				try
				{
					ResourceLiteralDictionary result = null;
					if (this.FileExists (file)) {
						result = new ResourceLiteralDictionary();
						NSDictionary literalDictionary = loadResourcesLiteral(file);
						foreach(NSObject key in literalDictionary.Keys)
						{
							result.Add(key.ToString(),literalDictionary[key].ToString());
						}
						return result;
					} else {
						// if file does not exists, means that requested locale is not supported by application
						// try then to get default locale string
						return this.GetResourceLiterals();
					}
				} catch(Exception ex) {
					#if DEBUG
					SystemLogger.Log(SystemLogger.Module.PLATFORM, "reading PLIST file (" + file + ")in iPhonei18N: Exception message:" + ex.Message);
					#endif
					return null;
				}
			}
		}
コード例 #6
0
        private async Task FillLanguagesDictionary()
        {

            var configFolder = await Package.Current.InstalledLocation.GetFolderAsync(AppConfigPath);
            var files = (await configFolder.GetFilesAsync()).Where(x => x.FileType.Equals(PlistExtension) && _i18NConfiguration.SupportedLanguages.Select(language => language.Language).ToList().Contains(x.DisplayName)).ToList();

            Parallel.ForEach(files, async languageFile =>
            {
                var languageFileContentDictionary = new ResourceLiteralDictionary();
                using (var fileStream = await languageFile.OpenStreamForReadAsync())
                {
                    var xDoc = XDocument.Load(fileStream);
                    if (xDoc.Root != null && xDoc.Root.HasElements)
                    {
                        var dict = xDoc.Root.Element(XName.Get(DictTag));
                        if (dict != null && dict.HasElements)
                        {
                            var elementList = dict.Descendants().ToList();
                            if (elementList.Count % 2 == 0)
                            {
                                for (var i = 0; i < elementList.Count; i += 2)
                                {
                                    var keyElement = elementList[i];
                                    var valueElement = elementList[i + 1];

                                    if (
                                        !keyElement.Name.LocalName.Equals(KeyTag,
                                            StringComparison.CurrentCultureIgnoreCase)) continue;
                                    if (!languageFileContentDictionary.ContainsKey(keyElement.Value.ToUpper()))
                                    {
                                        languageFileContentDictionary.Add(keyElement.Value.ToUpper(), valueElement.Value);
                                    }
                                }
                            }
                        }
                    }
                }
                lock (LockObj)
                {
                    _languageFilesDictionary.Add(languageFile.DisplayName.ToLower(), languageFileContentDictionary);
                }
            });
        }