コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            ToggableNetworkInformation networkInfo = new ToggableNetworkInformation();

            SimpleIoc.Default.Register<INetworkInformation>(() => networkInfo);

            SimpleIoc.Default.Register<IStructuredStorage>(() => new SQLiteStructuredStorage("cache"));
            SimpleIoc.Default.Register<ISynchronizer, TimestampSynchronizer>();
            SimpleIoc.Default.Register<Func<Uri, bool>>(() => (u => true));
            //SimpleIoc.Default.Register<ICacheProvider, DisabledCacheProvider>();
            SimpleIoc.Default.Register<ICacheProvider, TimestampCacheProvider>();

            SimpleIoc.Default.Register<NetworkInformationDelegate>(() =>
            {
                return new NetworkInformationDelegate(() => networkInfo.IsOnline, b => networkInfo.IsOnline = b);
            });

            SimpleIoc.Default.Register<MainViewModel>();

            DelegatingHandler handler = new CacheHandler(SimpleIoc.Default.GetInstance<ICacheProvider>());

            // Configure your mobile service here
            MobileServiceClient MobileService = new MobileServiceClient(
                Constants.MobileServiceUrl,
                Constants.MobileServiceKey,
                handler
            );

            SimpleIoc.Default.Register<IMobileServiceClient>(() => MobileService);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            ToggableNetworkInformation networkInfo = new ToggableNetworkInformation();

            SimpleIoc.Default.Register<INetworkInformation>(() => networkInfo);

            SimpleIoc.Default.Register<ICacheProvider, TimestampCacheProvider>();

            SimpleIoc.Default.Register<IStructuredStorage, SQLiteStructuredStorage>();

            SimpleIoc.Default.Register<NetworkInformationDelegate>(() =>
            {
                return new NetworkInformationDelegate(() => networkInfo.IsOnline, b => networkInfo.IsOnline = b);
            });

            SimpleIoc.Default.Register<MainViewModel>();

            DelegatingHandler handler = new CacheHandler(SimpleIoc.Default.GetInstance<ICacheProvider>());
                        
            // This MobileServiceClient has been configured to communicate with your Mobile Service's url
            // and application key. You're all set to start working with your Mobile Service!
            MobileServiceClient MobileService = new MobileServiceClient(
                "https://YOURAPP.azure-mobile.net/",
                "YOURKEY",
                handler
            );

            SimpleIoc.Default.Register<IMobileServiceClient>(() => MobileService);
        }
コード例 #3
0
        /// <summary>
        /// Get a client pointed at the test server without request logging.
        /// </summary>
        /// <returns>The test client.</returns>
        public override Task Initialize()
        {
            string offlineRuntimeUrl = this.GetTestSetting("MobileServiceOfflineRuntimeUrl");
            string offlineRuntimeKey = this.GetTestSetting("MobileServiceOfflineRuntimeKey");
            string normalRuntimeUrl = this.GetTestSetting("MobileServiceNormalRuntimeUrl");
            string normalRuntimeKey = this.GetTestSetting("MobileServiceNormalRuntimeKey");

            this.Storage = new SQLiteStructuredStorage("cache.db");
            ToggableNetworkInformation network = new ToggableNetworkInformation();
            network.IsOnline = true;
            this.NetworkInformation = network;
            ISynchronizer synchronizer = new TimestampSynchronizer(this.Storage);
            this.CacheProvider = new TimestampCacheProvider(this.Storage, network, synchronizer, this.AreWeCachingThis);

            this.OfflineClient = new MobileServiceClient(offlineRuntimeUrl, offlineRuntimeKey, new LoggingHttpHandler(this), new CacheHandler(this.CacheProvider));

            this.NormalClient = new MobileServiceClient(normalRuntimeUrl, normalRuntimeKey, new LoggingHttpHandler(this));

            return Task.FromResult(0);
        }