예제 #1
0
 public void AddToCache <T>(IBarrel barrel, string key, IEnumerable <T> data)
 {
     if (data.Any())
     {
         barrel.Add(key: key, data: data, expireIn: DefaultTimeSpan);
     }
 }
예제 #2
0
 static DataService()
 {
     Barrel.ApplicationId = AppInfo.PackageName;
     barrel     = Barrel.Create(FileSystem.AppDataDirectory);
     myCI       = new CultureInfo("en-US");
     myCWR      = myCI.DateTimeFormat.CalendarWeekRule;
     myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
 }
예제 #3
0
        public GithubDataStore(HttpClient httpClient, IConnectivity connectivity, IBarrel barrel, ILogger <GithubDataStore> logger)
        {
            _httpClient   = httpClient;
            _connectivity = connectivity;
            _barrel       = barrel;
            _logger       = logger;

            httpClient.BaseAddress = new Uri(baseUrl);
        }
 public DataService()
 {
     client = new HttpClient()
     {
         BaseAddress = new Uri(App.BaseUrl)
     };
     Barrel.ApplicationId = AppInfo.PackageName;
     barrel = Barrel.Create(FileSystem.AppDataDirectory);
 }
예제 #5
0
        public static T Get <T>(this IBarrel source, string key, T defaultValue)
        {
            if (string.IsNullOrWhiteSpace(key) || !source.Exists(key))
            {
                return(defaultValue);
            }

            return(source.Get <T>(key));
        }
예제 #6
0
 static DataService()
 {
     Barrel.ApplicationId = AppInfo.PackageName;
     Debug.WriteLine(AppInfo.PackageName);
     _barrel     = Barrel.Create(FileSystem.AppDataDirectory);
     _myCI       = new CultureInfo("ja-JP");
     _myCWR      = _myCI.DateTimeFormat.CalendarWeekRule;
     _myFirstDOW = _myCI.DateTimeFormat.FirstDayOfWeek;
 }
예제 #7
0
        public void Setup()
        {
            Barrel.UniqueId = "com.refractored.monkeycache";
            url             = "http://montemagno.com/monkeys.json";
            barrel          = Barrel.Current;

            json    = @"[{""Name"":""Baboon"",""Location"":""Africa & Asia"",""Details"":""Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae."",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/9\/96\/Portrait_Of_A_Baboon.jpg\/314px-Portrait_Of_A_Baboon.jpg"",""Population"":10000},{""Name"":""Capuchin Monkey"",""Location"":""Central & South America"",""Details"":""The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus."",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/4\/40\/Capuchin_Costa_Rica.jpg\/200px-Capuchin_Costa_Rica.jpg"",""Population"":23000},{""Name"":""Blue Monkey"",""Location"":""Central and East Africa"",""Details"":""The blue monkey or diademed monkey is a species of Old World monkey native to Central and East Africa, ranging from the upper Congo River basin east to the East African Rift and south to northern Angola and Zambia"",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/8\/83\/BlueMonkey.jpg\/220px-BlueMonkey.jpg"",""Population"":12000},{""Name"":""Squirrel Monkey"",""Location"":""Central & South America"",""Details"":""The squirrel monkeys are the New World monkeys of the genus Saimiri. They are the only genus in the subfamily Saimirinae. The name of the genus Saimiri is of Tupi origin, and was also used as an English name by early researchers."",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/2\/20\/Saimiri_sciureus-1_Luc_Viatour.jpg\/220px-Saimiri_sciureus-1_Luc_Viatour.jpg"",""Population"":11000},{""Name"":""Golden Lion Tamarin"",""Location"":""Brazil"",""Details"":""The golden lion tamarin also known as the golden marmoset, is a small New World monkey of the family Callitrichidae."",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/8\/87\/Golden_lion_tamarin_portrait3.jpg\/220px-Golden_lion_tamarin_portrait3.jpg"",""Population"":19000},{""Name"":""Howler Monkey"",""Location"":""South America"",""Details"":""Howler monkeys are among the largest of the New World monkeys. Fifteen species are currently recognised. Previously classified in the family Cebidae, they are now placed in the family Atelidae."",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/0\/0d\/Alouatta_guariba.jpg\/200px-Alouatta_guariba.jpg"",""Population"":8000},{""Name"":""Japanese Macaque"",""Location"":""Japan"",""Details"":""The Japanese macaque, is a terrestrial Old World monkey species native to Japan. They are also sometimes known as the snow monkey because they live in areas where snow covers the ground for months each"",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/c\/c1\/Macaca_fuscata_fuscata1.jpg\/220px-Macaca_fuscata_fuscata1.jpg"",""Population"":1000},{""Name"":""Mandrill"",""Location"":""Southern Cameroon, Gabon, Equatorial Guinea, and Congo"",""Details"":""The mandrill is a primate of the Old World monkey family, closely related to the baboons and even more closely to the drill. It is found in southern Cameroon, Gabon, Equatorial Guinea, and Congo."",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/7\/75\/Mandrill_at_san_francisco_zoo.jpg\/220px-Mandrill_at_san_francisco_zoo.jpg"",""Population"":17000},{""Name"":""Proboscis Monkey"",""Location"":""Borneo"",""Details"":""The proboscis monkey or long-nosed monkey, known as the bekantan in Malay, is a reddish-brown arboreal Old World monkey that is endemic to the south-east Asian island of Borneo."",""Image"":""http:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/e\/e5\/Proboscis_Monkey_in_Borneo.jpg\/250px-Proboscis_Monkey_in_Borneo.jpg"",""Population"":15000},{""Name"":""Sebastian"",""Location"":""Seattle"",""Details"":""This little trouble maker lives in Seattle with James and loves traveling on adventures with James and tweeting @MotzMonkeys. He by far is an Android fanboy and is getting ready for the new Nexus 6P!"",""Image"":""http:\/\/www.refractored.com\/images\/sebastian.jpg"",""Population"":1},{""Name"":""Henry"",""Location"":""Phoenix"",""Details"":""An adorable Monkey who is traveling the world with Heather and live tweets his adventures @MotzMonkeys. His favorite platform is iOS by far and is excited for the new iPhone 6s!"",""Image"":""http:\/\/www.refractored.com\/images\/henry.jpg"",""Population"":1}]";
            monkeys = JsonConvert.DeserializeObject <IEnumerable <Monkey> >(json);
        }
예제 #8
0
        private IBarrel GetCurrent()
        {
            IBarrel current = null;

            //if(cur=="Version")
            current = fileVersion;

            //if (cur == "Edicion") current = fileEdicion;
            return(current);
        }
예제 #9
0
        public void SetCacheDirectoryAfterInitialize()
        {
            IBarrel barrel = null;
            var     folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            SetupBarrel(ref barrel);
            barrel.EmptyAll();

            BarrelUtils.SetBaseCachePath(folder);
        }
예제 #10
0
 public MainPageViewModel(
     INavigationService navigationService,
     IBarrel barrel,
     IDeviceService deviceService)
     : base(navigationService)
 {
     _navigationService = navigationService;
     _barrel            = barrel;
     _deviceService     = deviceService;
     Title = "News Feed";
 }
예제 #11
0
 public VideoInfoRepository(
     Models.NiconicoSession niconicoSession,
     NicoVideoProvider nicoVideoProvider,
     IScheduler scheduler,
     IBarrel barrel
     )
     : base(niconicoSession)
 {
     _nicoVideoProvider = nicoVideoProvider;
     _scheduler         = scheduler;
     _barrel            = barrel;
 }
예제 #12
0
 public GithubService()
 {
     BarrelSQL.ApplicationId = "com.refractored.monkeycachetestlite";
     Sql = BarrelSQL.Current;
     SerializerSettings = new JsonSerializerSettings
     {
         ContractResolver     = new CamelCasePropertyNamesContractResolver(),
         DateTimeZoneHandling = DateTimeZoneHandling.Utc,
         NullValueHandling    = NullValueHandling.Ignore,
         TypeNameHandling     = TypeNameHandling.None
     };
 }
예제 #13
0
        protected RestServiceBase(string apiBaseUrl, IBarrel cacheBarrel)
        {
            _httpClient = new HttpClient()
            {
                BaseAddress = new Uri(apiBaseUrl)
            };

            _httpClient.DefaultRequestHeaders.Accept.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            this._cacheBarrel = cacheBarrel;
        }
예제 #14
0
        public DataService()
        {
            client = new HttpClient()
            {
                BaseAddress = new Uri(App.BaseUrl)
            };

            Barrel.ApplicationId = AppInfo.PackageName;
            barrel     = Barrel.Create(FileSystem.AppDataDirectory);
            myCI       = new CultureInfo("en-US");
            myCWR      = myCI.DateTimeFormat.CalendarWeekRule;
            myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
        }
예제 #15
0
        public static T GetOrCreate <T>(this IBarrel barrel, string key, T defaultValue, TimeSpan timeSpan = default)
        {
            if (string.IsNullOrWhiteSpace(key) || !barrel.Exists(key))
            {
                if (timeSpan == default)
                {
                    timeSpan = TimeSpan.MaxValue;
                }
                barrel.Add(key, defaultValue, timeSpan);
                return(defaultValue);
            }

            return(barrel.Get <T>(key));
        }
예제 #16
0
        public Covid19JapanApiManager()
        {
            //HttpClientの生成
            //Covid19JapanApiManagerクラスはDependencyService経由でインスタンスを取得するので
            //1回しか生成されないので大丈夫.
            this._httpClient = new HttpClient
            {
                BaseAddress = new Uri("https://covid19-japan-web-api.now.sh/api/v1/")
            };

            //MonkeyCacheの初期化
            Barrel.ApplicationId = AppInfo.PackageName;
            this._barrel         = Barrel.Create(FileSystem.AppDataDirectory);
        }
예제 #17
0
        public MonkeyCacheActiveDirectoryProvider(IActiveDirectoryProvider activeDirectoryProvider, string applicationId, double expiryLengthDays = 1.0, bool refresh = false) : base(activeDirectoryProvider)
        {
            Barrel.ApplicationId = applicationId;
            _barrel           = Barrel.Current;
            _expiryLengthDays = expiryLengthDays;

            if (refresh)
            {
                _barrel.EmptyAll();
            }
            else
            {
                _barrel.EmptyExpired();
            }
        }
    private void Awake()
    {
        com = new FMODCom("BarrelExplosion");
        rb  = GetComponent <Rigidbody>();
        switch (barrelType)
        {
        case BarrelType.InstantBarrel:
            barrel = new InstantBarrel(transform);
            break;

        case BarrelType.DelayedBarrel:
            barrel = new DelayedBarrel(startExplodeTimer);
            break;
        }
        explode = Explode;
    }
예제 #19
0
        public MainPage()
        {
            InitializeComponent();

            //SetupCache
            BarrelLite.ApplicationId = _applicationIdLiteDB;
            BarrelFile.ApplicationId = _applicationIdFileStore;
            BarrelSQL.ApplicationId  = _applicationIdSqlite;
            _sql  = BarrelSQL.Current;
            _lite = BarrelLite.Current;
            _file = BarrelFile.Current;

            //Event Handlers
            ButtonLoad.Clicked    += ButtonLoad_Clicked;
            ButtonSave.Clicked    += ButtonSave_Clicked;
            ButtonExpired.Clicked += ButtonExpired_Clicked;
        }
예제 #20
0
        private IBarrel GetCurrent()
        {
            IBarrel current = null;

            if (UseFileStore.IsToggled)
            {
                current = _file;
            }
            else if (UseLiteDB.IsToggled)
            {
                current = _lite;
            }
            else
            {
                current = _sql;
            }

            return(current);
        }
예제 #21
0
        public MainPage()
        {
            InitializeComponent();


            ButtonLoad.Clicked += ButtonLoad_Clicked;
            ButtonSave.Clicked += ButtonSave_Clicked;

            BarrelLite.ApplicationId = "com.refractored.monkeycachetestlite";
            BarrelFile.ApplicationId = "com.refractored.monkeycachetestfile";
            BarrelSQL.ApplicationId  = "com.refractored.monkeycachetestsql";


            sql  = BarrelSQL.Current;
            lite = BarrelLite.Current;
            file = BarrelFile.Current;


            ButtonExpired.Clicked += ButtonExpired_Clicked;
        }
예제 #22
0
        public static async Task <IList <Url> > GetAllShortURLs()
        {
            var json = string.Empty;

            Barrel.ApplicationId = "GoogleUrl";
            IBarrel        barrel     = Barrel.Current;
            UserCredential credential = await Authenticate();

            UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = "UrlShortener.ShortenURL sample",
                //ApiKey = ""
            });

            if (!Barrel.Current.IsExpired(service.BaseUri))
            {
                return(JsonConvert.DeserializeObject <IList <Url> >(Barrel.Current.Get(service.BaseUri)));
            }
            else
            {
                List <Url> fullList = new List <Url>();

                // Get All Short URLs

                UrlHistory response = service.Url.List().Execute();
                fullList.AddRange(response.Items);
                while (response.NextPageToken != null)
                {
                    var request = service.Url.List();
                    request.StartToken = response.NextPageToken;
                    //UrlHistory result = request.Execute();
                    response = request.Execute(); // service.Url.List().Execute();
                    fullList.AddRange(response.Items);
                }
                Barrel.Current.Add(service.BaseUri, fullList, TimeSpan.FromDays(1));
                // Display response
                return(fullList);
            }
        }
예제 #23
0
        public MainViewModel(INavigationService navigationService, IPageDialogService dialogService, IEventAggregator eventAggregator, IBarrel barrel, ITeamsService teamService) : base(navigationService, dialogService)
        {
            Title = "Main view";

            _barrel          = barrel;
            _teamService     = teamService;
            _eventAggregator = eventAggregator;

            PanelCommand            = new DelegateCommand(() => IsPanelVisible = !IsPanelVisible);
            ShowLoadingCommand      = new DelegateCommand(async() => await ShowLoading());
            GoToPlayersViewCommand  = new DelegateCommand(async() => await GoToPlayersView());
            ClearCacheCommand       = new DelegateCommand(() => _barrel.EmptyAll());
            CrashCommand            = new DelegateCommand(async() => await Crash());
            NavigateToDetailCommand = new DelegateCommand(async() => await NavigateToDetail());
            SignInCommand           = new DelegateCommand(async() => await SignIn());
            SignOutCommand          = new DelegateCommand(async() => await SignOut());

            _eventAggregator.GetEvent <MyEvent>()?.Subscribe(async() =>
            {
                await DialogService.DisplayAlertAsync("Notification", "Show notification", "Ok");
            });
        }
예제 #24
0
        private IBarrel GetCurrent()
        {
            IBarrel current = null;

            if (UseSQLite.IsToggled)
            {
                current = sql;
            }
            else if (UseFileStore.IsToggled)
            {
                current = file;
            }
            else if (UseLiteDB.IsToggled)
            {
                current = lite;
            }
            else
            {
                current = sql;                //fallback
            }
            return(current);
        }
예제 #25
0
 public BarrelCacheProvider(IBarrel barrel)
 {
     _barrel = barrel ?? throw new ArgumentNullException(nameof(barrel));
 }
예제 #26
0
        /// <summary>
        /// Send a cached requests
        /// </summary>
        /// <param name="http">Http client ot use</param>
        /// <param name="barrel">Barrel to use for cache</param>
        /// <param name="req">request to send</param>
        /// <param name="expireIn">expire in</param>
        /// <param name="forceUpdate">If we should force the update or not</param>
        /// <param name="throttled">If throttled or not</param>
        /// <returns>The new or cached response.</returns>
        public static async Task <string> SendCachedAsync(this HttpClient http, IBarrel barrel, HttpRequestMessage req, TimeSpan expireIn, bool forceUpdate = false, bool throttled = true)
        {
            var url = req.RequestUri.ToString();

            var contents = barrel.Get <string>(url);
            var eTag     = barrel.GetETag(url);

            if (!forceUpdate && !string.IsNullOrEmpty(contents) && !barrel.IsExpired(url))
            {
                return(contents);
            }

            var etag = eTag ?? null;

            if (throttled)
            {
                await getThrottle.WaitAsync();
            }

            HttpResponseMessage r;
            string c = null;

            try {
                if (!forceUpdate && !string.IsNullOrEmpty(etag) && !string.IsNullOrEmpty(contents))
                {
                    req.Headers.IfNoneMatch.Clear();
                    req.Headers.IfNoneMatch.Add(new EntityTagHeaderValue(etag));
                }

                r = await http.SendAsync(req);

                if (r.StatusCode == HttpStatusCode.NotModified)
                {
                    if (string.IsNullOrEmpty(contents))
                    {
                        throw new IndexOutOfRangeException($"Cached value missing for HTTP request: {url}");
                    }

                    return(contents);
                }

                c = await r.Content.ReadAsStringAsync();
            } finally {
                if (throttled)
                {
                    getThrottle.Release();
                }
            }

            if (r.StatusCode == HttpStatusCode.OK)
            {
                // Cache it?
                var newEtag = r.Headers.ETag != null ? r.Headers.ETag.Tag : null;
                if (!string.IsNullOrEmpty(newEtag) && newEtag != etag)
                {
                    barrel.Add(url, c, expireIn, newEtag);
                }

                return(c);
            }
            else
            {
                throw new HttpCacheRequestException(r.StatusCode, "HTTP Cache Request Failed");
            }
        }
예제 #27
0
        /// <summary>
        /// Get a cahced item via web request.
        /// </summary>
        /// <param name="barrel">Barrel to use for cache</param>
        /// <param name="url">Url to query</param>
        /// <param name="timeout">Timeout to use</param>
        /// <param name="expireIn">Set the item to expire in</param>
        /// <param name="forceUpdate">Force an update from the server</param>
        /// <param name="throttled">If the request should be throttled</param>
        /// <returns>The cached or new active item.</returns>
        public Task <string> GetCachedAsync(IBarrel barrel, string url, TimeSpan timeout, TimeSpan expireIn, bool forceUpdate = false, bool throttled = true)
        {
            var client = CreateClient(timeout);

            return(client.SendCachedAsync(barrel, new HttpRequestMessage(HttpMethod.Get, url), expireIn, forceUpdate, throttled));
        }
예제 #28
0
 void SetupBarrel(ref IBarrel barrel)
 {
     Barrel.ApplicationId = "com.refractored.monkeyfile";
     barrel = Barrel.Current;
 }
예제 #29
0
 public PlaylistService(IBarrel barrel)
 {
     _barrel = barrel ?? throw new ArgumentNullException(nameof(barrel));
 }
예제 #30
0
 public SettingsService(IBarrel barrel, IMediaManager mediaManager)
 {
     _mediaManager = mediaManager ?? throw new ArgumentNullException(nameof(mediaManager));
     _barrel       = barrel ?? throw new ArgumentNullException(nameof(barrel));
 }