SfSdk.Providers.LanguageResourceProvider.GetResources C# (CSharp) Method

GetResources() public method

Downloads the english language resources.
/// When no network connection is available ///
public GetResources ( Uri serverUri ) : string>.Dictionary
serverUri System.Uri
return string>.Dictionary
        public override Dictionary<SF, string> GetResources(Uri serverUri)
        {
            if (serverUri == null) throw new ArgumentNullException("serverUri");

            var uri = new Uri(serverUri, "lang/sfgame_en.txt");
            var url = uri.ToString();

            Func<string> fillResourceDict = () =>
            {
                try
                {
                    using (var wc = new WebClient())
                    {
                        var randomizedUri = new Uri(uri,
                            "?rnd=" + Random.NextDouble().ToString("N" + 16, CultureInfo.GetCultureInfo("en-US")));
                        return wc.DownloadString(randomizedUri);
                    }
                }
                catch (WebException)
                {
                    throw new NotImplementedException("Network connection lost.");
                }
            };
            return GetResources(url, fillResourceDict);
        }

Usage Example

Ejemplo n.º 1
0
        public void GetResourcesThrowsExceptionWithoutNetworkConnection()
        {
            TestHelpers.Disconnect();

            // Arrange
            var sut = new LanguageResourceProvider();
            Action getResources = () => sut.GetResources(TestConstants.ValidServerUri);

            // Act / Assert
            getResources.ShouldThrow<NotImplementedException>().Where(e => e.Message == "Network connection lost.");

            TestHelpers.Connect();
        }
LanguageResourceProvider