public Shipper GetShipper(string name) { // Yet another argument for AOP here... // Could pull this information from the downstream LoggedCommand class by using a StackFrame but this is very brittle and who wants to play with a StackFrame anyway? using (LogContext.PushProperty("CallingType", "MyDataAccess")) { using (LogContext.PushProperty("CallingMethod", "GetShipper")) { Shipper shipper = CacheProvider.GetItem <Shipper>(name); if (shipper != null) { return(shipper); } shipper = _connection.Query <Shipper>( "SELECT ShipperId, CompanyName, Phone FROM Shippers WHERE CompanyName = @name", new { name }).SingleOrDefault(); if (shipper != null) { CacheProvider.PutItem(name, shipper); } return(shipper); } } }
public App() { this.InitializeComponent(); this.Suspending += OnSuspending; this.UnhandledException += AppUnhandledException; CacheProvider cache = new CacheProvider(StorageType.IsolatedStorage); GlobalValue.CurrentUserContext = cache.GetItem<UserContext>(CacheKey.UserContext); }
public App() { this.InitializeComponent(); this.Suspending += OnSuspending; this.UnhandledException += AppUnhandledException; CacheProvider cache = new CacheProvider(StorageType.IsolatedStorage); GlobalValue.CurrentUserContext = cache.GetItem <UserContext>(CacheKey.UserContext); }
private static async Task <bool> WeiboShare(string url, string text) { CacheProvider cache = new CacheProvider(StorageType.IsolatedStorage); if (GlobalValue.CurrentWeiboUserInfo == null) { GlobalValue.CurrentWeiboUserInfo = cache.GetItem <UserInfo>(CacheKey.WeiboUser) ?? new UserInfo(); } byte[] image = await new HttpClient().GetByteArrayAsync(url); bool shareResult = false; try { WeiboClient client = new WeiboClient(GlobalValue.CurrentWeiboUserInfo); await client.LoginAsync(); WeiboResult result; if (!string.IsNullOrEmpty(url)) { result = await client.ShareImageAsync(image, text); } else { result = await client.ShareTextAsync(text); } GlobalValue.CurrentWeiboUserInfo = client.UserInfo; cache.UpdateItem(CacheKey.WeiboUser, GlobalValue.CurrentWeiboUserInfo); shareResult = true; } catch { shareResult = false; } return(shareResult); }
private static async Task<bool> WeiboShare(string url, string text) { CacheProvider cache = new CacheProvider(StorageType.IsolatedStorage); if (GlobalValue.CurrentWeiboUserInfo == null) { GlobalValue.CurrentWeiboUserInfo = cache.GetItem<UserInfo>(CacheKey.WeiboUser) ?? new UserInfo(); } byte[] image = await new HttpClient().GetByteArrayAsync(url); bool shareResult = false; try { WeiboClient client = new WeiboClient(GlobalValue.CurrentWeiboUserInfo); await client.LoginAsync(); WeiboResult result; if (!string.IsNullOrEmpty(url)) { result = await client.ShareImageAsync(image, text); } else { result = await client.ShareTextAsync(text); } GlobalValue.CurrentWeiboUserInfo = client.UserInfo; cache.UpdateItem(CacheKey.WeiboUser, GlobalValue.CurrentWeiboUserInfo); shareResult = true; } catch { shareResult = false; } return shareResult; }
public static NoteDetailResult ReadNoteDetial(string id) { return(cache.GetItem <NoteDetailResult>(CacheKey.NoteDetail + id)); }