示例#1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            #region Set IdentityManager Referer
            // Get URL
            string appUrl = HtmlPage.Document.DocumentUri.ToString();

            // Remove query string
            Uri appUri = new Uri(appUrl);
            if (!string.IsNullOrEmpty(appUri.Query))
            {
                appUrl = appUrl.Replace(appUri.Query, "");
            }

            if (appUrl.ToLower().Contains("index.htm"))
            {
                appUrl = appUrl.Substring(0, appUrl.Length - 9);
            }

            // Set referer
            IdentityManager.Current.TokenGenerationReferer = Uri.EscapeUriString(appUrl);
            #endregion

            var result = WebRequest.RegisterPrefix("http://", ArcGISTokenWebRequestProvider.Instance);
            result = WebRequest.RegisterPrefix("https://", ArcGISTokenWebRequestProvider.Instance);

            // Check if Language Culture is supported
            string cultureName = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString();
            ESRI.ArcGIS.Mapping.Core.SatelliteResources.Xap resourceXap = new ESRI.ArcGIS.Mapping.Core.SatelliteResources.Xap();
            if (!resourceXap.IsSupportedLanguage(cultureName))
            {
                cultureName = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
                if (!resourceXap.IsSupportedLanguage(cultureName)) // Region only lang.
                {
                    StartupAfterGettingResources(sender, e);       //Not supported, so call StartupAfterGettingResources
                    return;
                }
            }
            // Load satellite resource file if it exist.
            string resourceUri = string.Format("/Culture/Xaps/{0}{1}", cultureName, Application.Current.Host.Source.AbsolutePath);// insert language path
            int    indexXap    = Application.Current.Host.Source.AbsolutePath.LastIndexOf('/');
            if (indexXap > 0)
            { // resources is a sub-folder of site.
                string sitePath = Application.Current.Host.Source.AbsolutePath.Substring(0, indexXap);
                string resXap   = Application.Current.Host.Source.AbsolutePath.Substring(indexXap + 1);
                resourceUri = string.Format("{0}/Culture/Xaps/{1}/{2}", sitePath, cultureName, resXap);
            }
            resourceUri = resourceUri.Replace(".xap", ".resources.xap");//update filename
            if (resourceUri.Contains("?"))
            {
                resourceUri = resourceUri.Substring(0, resourceUri.IndexOf("?", StringComparison.Ordinal));                            //remove parameters.
            }
            resourceXap.Load(resourceUri, delegate { StartupAfterGettingResources(sender, e); });
            // update the RTLHelper instance
            RTLHelper helper = Application.Current.Resources["RTLHelper"] as RTLHelper;
            Debug.Assert(helper != null);
            if (helper != null)
            {
                helper.UpdateFlowDirection();
            }
        }
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            #region Set IdentityManager Referer
                // Get URL
                string appUrl = HtmlPage.Document.DocumentUri.ToString();

                // Remove query string
                Uri appUri = new Uri(appUrl);
                if (!string.IsNullOrEmpty(appUri.Query))
                    appUrl = appUrl.Replace(appUri.Query, "");

                if (appUrl.ToLower().Contains("default.aspx"))
                    appUrl = appUrl.Substring(0, appUrl.Length - 12);

                // Set referer
                IdentityManager.Current.TokenGenerationReferer = Uri.EscapeUriString(appUrl);
            #endregion

            // use Silverlight client HTTP handling instead of browser handling
            var result = WebRequest.RegisterPrefix("http://", ArcGISTokenWebRequestProvider.Instance);
            result = WebRequest.RegisterPrefix("https://", ArcGISTokenWebRequestProvider.Instance);

            // Check if Language Culture is supported
            string cultureName = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString();
            ESRI.ArcGIS.Mapping.Core.SatelliteResources.Xap resourceXap = new ESRI.ArcGIS.Mapping.Core.SatelliteResources.Xap();
            if (!resourceXap.IsSupportedLanguage(cultureName))
            {
                cultureName = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
                if (!resourceXap.IsSupportedLanguage(cultureName)) // Region only lang.
                {
                    StartupAfterGettingResources(sender, e);	//Not supported, so call StartupAfterGettingResources
                    return;
                }
            }
            // Load satellite resource file if it exist.
            string resourceUri = string.Format("/Culture/Xaps/{0}{1}", cultureName, Application.Current.Host.Source.AbsolutePath);// insert language path
            int indexXap = Application.Current.Host.Source.AbsolutePath.LastIndexOf('/');
            if (indexXap > 0)
            { // resources is a sub-folder of site.
                string sitePath = Application.Current.Host.Source.AbsolutePath.Substring(0, indexXap);
                string resXap = Application.Current.Host.Source.AbsolutePath.Substring(indexXap + 1);
                resourceUri = string.Format("{0}/Culture/Xaps/{1}/{2}", sitePath, cultureName, resXap);
            }
            resourceUri = resourceUri.Replace(".xap", ".resources.xap");//update filename
            if (resourceUri.Contains("?")) resourceUri = resourceUri.Substring(0, resourceUri.IndexOf("?", StringComparison.Ordinal)); //remove parameters. 
            resourceXap.Load(resourceUri, delegate { StartupAfterGettingResources(sender, e); });

            RTLHelper helper = Application.Current.Resources["RTLHelper"] as RTLHelper;
            Debug.Assert(helper != null);
            if (helper != null)
                helper.UpdateFlowDirection();
        }