コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            this.UnhandledException += AppUnhandledException;

            CacheProvider cache = new CacheProvider(StorageType.IsolatedStorage);
            GlobalValue.CurrentUserContext = cache.GetItem<UserContext>(CacheKey.UserContext);
        }
コード例 #3
0
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            this.UnhandledException += AppUnhandledException;

            CacheProvider cache = new CacheProvider(StorageType.IsolatedStorage);

            GlobalValue.CurrentUserContext = cache.GetItem <UserContext>(CacheKey.UserContext);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Untils.cs プロジェクト: tianzhaodong/uwp_AiJianShu
        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;
        }
コード例 #6
0
 public static NoteDetailResult ReadNoteDetial(string id)
 {
     return(cache.GetItem <NoteDetailResult>(CacheKey.NoteDetail + id));
 }