Exemplo n.º 1
0
        /// <summary>
        /// 将Cookie反序列化为ShopMobileView
        /// </summary>
        /// <param name="CookieName">CookieName</param>
        public static RecentView CookieToShopMobileView(string cookieName)
        {
            if (HasCookie(cookieName))
            {
                cookieName = SetRecentViewCookie();
            }

            string StrCart = GetCookie(cookieName);

            if (StrCart == "" || StrCart == string.Empty)
            {
                return(null);
            }

            string StrViewNew = GetCookie(cookieName);

            byte[] byt = Convert.FromBase64String(StrViewNew);

            RecentView SvNew = null;

            using (Stream smNew = new MemoryStream(byt, 0, byt.Length))
            {
                IFormatter fmNew = new BinaryFormatter();
                SvNew = (RecentView)fmNew.Deserialize(smNew);
            }
            if (SvNew == null)
            {
                return(null);
            }
            else
            {
                return(SvNew);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 将ShopMobileView写入Cookie
        /// </summary>
        /// <param name="sv">商品模型实体</param>
        /// <param name="cookieName"></param>
        /// <returns></returns>
        public static void RecentViewToCookie(RecentView smv, string cookieName)
        {
            if (HasCookie(cookieName))
            {
                cookieName = SetRecentViewCookie();
            }

            IFormatter fm         = new BinaryFormatter();
            string     StrCartNew = string.Empty;

            using (MemoryStream ms = new MemoryStream())
            {
                fm.Serialize(ms, smv);
                byte[] byt = new byte[ms.Length];
                byt        = ms.ToArray();
                StrCartNew = Convert.ToBase64String(byt);
                ms.Flush();
            }
            WriteCookie(cookieName, StrCartNew, 30);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 将ShopMobileView写入Cookie
        /// </summary>
        /// <param name="sv">商品模型实体</param>
        /// <param name="cookieName"></param>
        /// <returns></returns>
        public static void RecentViewToCookie(RecentView smv, string cookieName)
        {
            if (HasCookie(cookieName))
                cookieName = SetRecentViewCookie();

            IFormatter fm = new BinaryFormatter();
            string StrCartNew = string.Empty;
            using (MemoryStream ms = new MemoryStream())
            {
                fm.Serialize(ms, smv);
                byte[] byt = new byte[ms.Length];
                byt = ms.ToArray();
                StrCartNew = Convert.ToBase64String(byt);
                ms.Flush();
            }
            WriteCookie(cookieName, StrCartNew, 30);
        }