Пример #1
0
        public virtual ActionResult TempFile()
        {
            var entry = new JsonResultEntry();

            try
            {
                if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                {
                    var postFile       = Request.Files[0];
                    var repositoryPath = new RepositoryPath(Repository);
                    var tempPath       = Kooboo.Web.Url.UrlUtility.Combine(repositoryPath.VirtualPath, "Temp");
                    Kooboo.IO.IOUtility.EnsureDirectoryExists(Server.MapPath(tempPath));

                    var fileUrl = Kooboo.Web.Url.UrlUtility.Combine(tempPath, UniqueIdGenerator.GetInstance().GetBase32UniqueId(24) + Path.GetExtension(postFile.FileName));

                    postFile.SaveAs(Server.MapPath(fileUrl));
                    entry.Model = Url.Content(fileUrl);
                }
                else
                {
                    entry.SetFailed().AddMessage("It is not a valid image file.".Localize());
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
Пример #2
0
        public virtual MembershipUser ForgotPassword(Kooboo.CMS.Membership.Models.Membership membership, string userName)
        {
            var membershipUser = new MembershipUser()
            {
                Membership = membership, UserName = userName
            }.AsActual();
            List <DataViolationItem> violations = new List <DataViolationItem>();

            if (membershipUser == null)
            {
                violations.Add(new DataViolationItem("UserName", userName, "The member does not exists."));
            }
            if (violations.Count > 0)
            {
                throw new DataViolationException(violations);
            }

            var activateCode = UniqueIdGenerator.GetInstance().GetBase32UniqueId(10);

            membershipUser.ActivateCode = activateCode;

            _provider.Update(membershipUser, membershipUser);

            return(membershipUser);
        }
Пример #3
0
        public virtual ActionResult ImageCrop()
        {
            var data = new JsonResultData(ModelState);

            data.RunWithTry((resultData) =>
            {
                if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                {
                    var postFile       = Request.Files[0];
                    var repositoryPath = new RepositoryPath(Repository);
                    var tempPath       = Kooboo.Web.Url.UrlUtility.Combine(repositoryPath.VirtualPath, "Temp");
                    Kooboo.IO.IOUtility.EnsureDirectoryExists(Server.MapPath(tempPath));

                    var fileUrl = Kooboo.Web.Url.UrlUtility.Combine(tempPath, UniqueIdGenerator.GetInstance().GetBase32UniqueId(24) + Path.GetExtension(postFile.FileName));

                    postFile.SaveAs(Server.MapPath(fileUrl));
                    resultData.Model = new { ImageUrl = Url.Content(fileUrl), PreviewUrl = this.Url.Action("ResizeImage", "Resource", new { siteName = Site.FullName, url = fileUrl, area = "", width = 600, height = 400, preserverAspectRatio = true, quality = 80 }) };
                }
                else
                {
                    resultData.AddErrorMessage("It is not a valid image file.".Localize());
                }
            });

            return(Json(data));
        }
Пример #4
0
        public PageDesignContent(PagePosition pos)
            : base()
        {
            if (pos == null)
            {
                throw new ArgumentNullException();
            }

            if (string.IsNullOrEmpty(pos.PagePositionId))
            {
                //pos.PagePositionId = Guid.NewGuid().ToString();
                pos.PagePositionId = UniqueIdGenerator.GetInstance().GetBase32UniqueId(5);
            }

            this.Position = pos;

            //this.TagName = "li";

            this.ClassName = "pagedesign-content";

            this.Parameter.Add("Name", PageDesignContent.Code(this.ToString()));

            this.Parameter.Add("PagePositionId", PageDesignContent.Code(pos.PagePositionId));

            this.Parameter.Add("Order", pos.Order.ToString());

            this.Parameter.Add("Type", this.GetTypeKey());
        }
Пример #5
0
        public void GetBase32UniqueIdTest()
        {
            var b1 = new byte[16];

            for (int i = 0; i < 16; i++)
            {
                b1[i] = 0;
            }
            string id = UniqueIdGenerator.GetInstance().GetBase32UniqueId(b1, 26);

            Assert.AreEqual(26, id.Length);
            Assert.AreEqual(new string( '2', 26 ), id);

            b1 = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF };
            id = UniqueIdGenerator.GetInstance().GetBase32UniqueId(b1, 26);
            System.Diagnostics.Trace.WriteLine(id);
            Assert.AreEqual(26, id.Length);
            Assert.AreEqual("ZZZZZZ", id.Substring(20, 6));

            id = UniqueIdGenerator.GetInstance().GetBase32UniqueId(b1, 6);
            System.Diagnostics.Trace.WriteLine(id);
            Assert.AreEqual(6, id.Length);
            Assert.AreEqual("ZZZZZZ", id);

            id = UniqueIdGenerator.GetInstance().GetBase32UniqueId(18);
            System.Diagnostics.Trace.WriteLine(id);
            Assert.AreEqual(18, id.Length);

            var id2 = UniqueIdGenerator.GetInstance().GetBase32UniqueId(18);

            System.Diagnostics.Trace.WriteLine(id2);
            Assert.AreEqual(18, id2.Length);

            Assert.AreNotEqual(id, id2);
        }
Пример #6
0
        public void GetNextTest()
        {
            var b1 = new byte[16];

            for (int i = 0; i < 16; i++)
            {
                b1[i] = 0;
            }
            UniqueIdGenerator.GetInstance().GetNext(b1);
            Assert.IsTrue(Array.Exists(b1, b => b != 0));                 // This could be false every billion years or so
        }
Пример #7
0
        public void GetBase32UniqueIdDupeTest()
        {
            var alreadySeen = new Dictionary <string, string>(1000000);

            System.Diagnostics.Trace.WriteLine("Allocated");
            for (int i = 0; i < 1000000; i++)
            {
                var id = UniqueIdGenerator.GetInstance().GetBase32UniqueId(12);
                Assert.IsTrue(!alreadySeen.ContainsKey(id));
                alreadySeen.Add(id, id);
            }
        }
Пример #8
0
        public virtual MembershipUser Create(Kooboo.CMS.Membership.Models.Membership membership, string userName, string email, string password, bool isApproved, string culture, string timeZoneId, string passwordQuestion = null,
                                             string passwordAnswer = null, string[] membershipGroups = null, Dictionary <string, string> profiles = null, string comment = null)
        {
            membership = membership.AsActual();

            MembershipUser membershipUser = new MembershipUser()
            {
                Membership = membership
            };

            membershipUser.UserName = userName;
            List <DataViolationItem> violations = new List <DataViolationItem>();

            if (membershipUser.AsActual() != null)
            {
                violations.Add(new DataViolationItem("UserName", userName, "DuplicateUserName"));
            }
            if (_provider.QueryUserByEmail(membership, email) != null)
            {
                violations.Add(new DataViolationItem("Email", email, "DuplicateEmail"));
            }
            if (violations.Count > 0)
            {
                throw new DataViolationException(violations);
            }

            if (!string.IsNullOrEmpty(email))
            {
                membershipUser.Email = email;
            }
            membershipUser.Culture          = culture;
            membershipUser.TimeZoneId       = timeZoneId;
            membershipUser.PasswordQuestion = passwordQuestion;
            membershipUser.PasswordAnswer   = passwordAnswer;
            membershipUser.Comment          = comment;
            membershipUser.IsApproved       = isApproved;
            if (!membershipUser.IsApproved)
            {
                string activateCode = UniqueIdGenerator.GetInstance().GetBase32UniqueId(10);
                membershipUser.ActivateCode = activateCode;
            }
            membershipUser.UtcCreationDate  = DateTime.UtcNow;
            membershipUser.Profiles         = profiles;
            membershipUser.MembershipGroups = membershipGroups;

            SetPassword(membership, membershipUser, password);


            _provider.Add(membershipUser);

            return(_provider.Get(membershipUser));
        }
Пример #9
0
        public TVTStaff(TVTPerson person, TVTPersonFunction function, int?index = null)
        {
            if (person == null)
            {
                throw new ArgumentNullException();
            }

            Id       = "S" + UniqueIdGenerator.GetInstance().GetBase32UniqueId(9).Insert(4, "_");
            Person   = person;
            Function = function;
            if (index.HasValue)
            {
                Index = index.Value;
            }
        }
Пример #10
0
        /// <summary>
        /// Empties the cart and creates a new Guid
        /// </summary>
        public void Destroy()
        {
            CartSession = null;
            Versions    = null;

            // deletes shopping cart from db and returns items to warehouse
            ApplicationContext.Current.Carts.DeleteShoppingCart(CartID);

            // generates a new id
            Guid g = Guid.NewGuid();
            UniqueIdGenerator unique = UniqueIdGenerator.GetInstance();
            string            cartId = unique.GetBase32UniqueId(g.ToByteArray(), 20).ToLower();

            CartID = cartId;
            DataBind(null);
            NeedRefresh(null, null);
        }
Пример #11
0
        public TVTNewsEffect(TVTNewsEffectType type, string param1 = null, string param2 = null, string param3 = null)
        {
            Id               = "E" + UniqueIdGenerator.GetInstance().GetBase32UniqueId(9).Insert(4, "_");
            this.Type        = type;
            EffectParameters = new List <string>();
            Chance           = 100;

            if (!string.IsNullOrEmpty(param1))
            {
                EffectParameters.Add(param1);
            }

            if (!string.IsNullOrEmpty(param2))
            {
                EffectParameters.Add(param2);
            }

            if (!string.IsNullOrEmpty(param3))
            {
                EffectParameters.Add(param3);
            }
        }
Пример #12
0
        public GlobSession Login(string usercode, string password)
        {
            try
            {
                var user = this.Get(new SysUser()
                {
                    Code = usercode
                });



                if (user != null && SecurityUtils.VerifyHashedPassword(user.Password, password))
                {
                    var service = ServiceFactory.GetService <GlobSession>() as GlobSessionManager;


                    var session = new GlobSession()
                    {
                        SessionId = UniqueIdGenerator.GetInstance().GetBase32UniqueId(16),
                        UserId    = user.Code,
                    };

                    service.Add(session);
                    return(session);
                }


                //failed
                return(null);
            }
            catch (Exception ex)
            {
                var paramList = new ParamLogUtility(() => usercode, () => password).GetParamList();
                throw new ServiceException(ex, paramList);
            }
        }
Пример #13
0
 public TVTNewsEffect()
 {
     Id = "E" + UniqueIdGenerator.GetInstance().GetBase32UniqueId(9).Insert(4, "_");
     EffectParameters = new List <string>();
     Chance           = 100;
 }
Пример #14
0
        public string Insert(ORDERS Order, bool FrontEnd, bool SaveContext = true)
        {
            string retString = String.Empty;

            //if there is any used bonus, decrease the remainder
            if (Order.ORDER_BONUS.Count > 0)
            {
                BONUS bonus;
                foreach (ORDER_BONUS bon in Order.ORDER_BONUS)
                {
                    bonus = _bonusDAO.GetById(bon.BonusID);

                    // object must be detached from context, otherwise Version field for concurrency check will not be updated!!!
                    Context.BONUS.Detach(bonus);

                    // using the version that was initially retrieved from db
                    // if another user modified this record an OptimisticConcurrencyException will be raised
                    if (bon.Value > bonus.ValueRemainder)
                    {
                        //TODO think what to do with version
                        //bonus.Version = bon.BONUS.Version;
                        throw new System.Data.OptimisticConcurrencyException("Bonus not sufficient.");
                    }
                    bonus.ValueRemainder -= bon.Value;

                    _bonusDAO.Update(bonus);
                    bon.BONUS = null;
                }
            }

            CUSTOMER customer = _customerDAO.GetById(Order.CustomerID.Value);

            // for electronic payments insert directly
            if ((Order.PAYMENT.Type == (int)PaymentType.PP && Order.PAYMENT.PAYPAL_PAYMENT.TransactionStatus == "Completed") ||
                (Order.PAYMENT.Type == (int)PaymentType.EP && Order.PAYMENT.EASYPAY_PAYMENT.TransactionStatus == "Success") ||
                (Order.PAYMENT.Type == (int)PaymentType.CA && !FrontEnd && Order.Completed))
            {
                if (!customer.FirstBuy.HasValue || !customer.FirstBuy.Value)
                {
                    // set first buy of user
                    customer.FirstBuy = true;
                    _customerDAO.Update(customer, true, false);

                    // first buy of this customer & invited by someone
                    if (customer.InvitedFrom.HasValue)
                    {
                        insertCustomerBonus(customer);
                        retString = "Bonus added to inviter " + customer.CUSTOMER2.Email;
                        Util.Mailer.SendBonus(customer, customer.CUSTOMER2.Email, Configuration.BonusValue + " € bonus per ju ne FZone");
                    }
                }
            }
            Guid g = Guid.NewGuid();
            UniqueIdGenerator unique = UniqueIdGenerator.GetInstance();
            string            vNum   = unique.GetBase32UniqueId(g.ToByteArray(), 20).ToLower();

            Order.VerificationNumber = vNum;
            _orderDAO.Insert(Order);

            // payment
            if (Order.PAYMENT != null)
            {
                Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT, EntityState.Added);
                if (Order.PAYMENT.Type == (int)PaymentType.CA)
                {
                    Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT.CASH_PAYMENT, System.Data.EntityState.Added);
                }
                else if (Order.PAYMENT.Type == (int)PaymentType.PP)
                {
                    Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT.PAYPAL_PAYMENT, System.Data.EntityState.Added);
                }
                else if (Order.PAYMENT.Type == (int)PaymentType.EP)
                {
                    Context.ObjectStateManager.ChangeObjectState(Order.PAYMENT.EASYPAY_PAYMENT, System.Data.EntityState.Added);
                }
            }

            if (SaveContext)
            {
                Context.SaveChanges();
            }
            return(retString);
        }
Пример #15
0
 public override void GenerateGuid()
 {
     Id = "M" + UniqueIdGenerator.GetInstance().GetBase32UniqueId(9).Insert(4, "_");
 }
Пример #16
0
 public static string GenerateNewGuid()
 {
     return(UniqueIdGenerator.GetInstance().GetBase32UniqueId(16));
 }
Пример #17
0
 public TVTStaff()
 {
     Id = "S" + UniqueIdGenerator.GetInstance().GetBase32UniqueId(9).Insert(4, "_");
 }
Пример #18
0
        protected void lnkAddToBasket_Click(object sender, EventArgs e)
        {
            string CartID = String.Empty;

            Guid g = Guid.NewGuid();
            UniqueIdGenerator unique = UniqueIdGenerator.GetInstance();
            string            cartId = unique.GetBase32UniqueId(g.ToByteArray(), 20).ToLower();

            if (CartSession == null || CartSession.Count == 0)
            {
                CartID      = cartId;
                CartSession = new List <SessionCart>();
            }
            else
            {
                List <SessionCart> cSession    = CartSession.OrderByDescending(c => c.DateAdded).ToList();
                SessionCart        sessionCart = cSession.First();
                if (sessionCart.DateAdded.AddMinutes(Configuration.CartExpirationValue) < DateTime.Now)
                {
                    RefreshCart();
                    CartID = cartId;
                }
                else
                {
                    CartID = CartSession.First().Id;
                }
            }

            SHOPPING_CART cart = new SHOPPING_CART();

            cart.ID         = CartID;
            cart.FrontEnd   = true;
            cart.CampaignID = CampaignID;
            cart.CustomerID = CurrentCustomer.Id;
            cart.DateAdded  = DateTime.Now;
            cart.ProductID  = ProductID;
            int num = 0;

            if (!Int32.TryParse(ddlSize.SelectedValue, out num))
            {
                return;
            }
            cart.ProdAttrID = num;

            num = 0;
            if (!Int32.TryParse(ddlQuantity.SelectedValue, out num) || num == 0)
            {
                return;
            }
            cart.Quantity = num;



            // the versions list of lists is created each time the product popup is shown, and destroyed each time it is closed
            if (Version != null)
            {
                cart.ProductAttributeVersion = Version;
            }
            else
            {
                throw new ApplicationException("Session is compromised! Cannot proceed.");
            }

            SessionCart sC;

            try
            {
                // already in the cart
                if (CartSession != null && CartSession.Count > 0 && (sC = CartSession.Find(c => c.ProductAttributeId == cart.ProdAttrID)) != null)
                {
                    // sum with old quantity
                    cart.Quantity += sC.Quantity;
                    ApplicationContext.Current.Carts.Update(cart, sC.Quantity);

                    // updating session with last quantity and last prod-attr version
                    sC.Quantity = cart.Quantity;
                    sC.ProductAttributeVersion = cart.ProductAttributeVersion;
                }
                else
                {
                    ApplicationContext.Current.Carts.Insert(cart);
                    sC = new SessionCart(cart);
                    CartSession.Add(sC);
                }
                TotalAmount = ApplicationContext.Current.Carts.GetShoppingCartTotalAmount(CartID);
            }
            catch (Exception ex)
            {
                //TODO log error
                Log(ex, ex.Message, ex.StackTrace, "Product.AddToCart");

                List <int>        qtyList;
                PRODUCT_ATTRIBUTE prodAttr = ApplicationContext.Current.Products.GetProductAvailability(cart.ProdAttrID, out qtyList);

                Version = prodAttr.Version;

                ddlQuantity.DataSource = qtyList;
                ddlQuantity.DataBind();
                if (!qtyList.Contains(cart.Quantity))
                {
                    lblMessage.Text = Resources.Lang.InsufficientAvailabilityMessage;
                }
                if (qtyList.Count == 0)
                {
                    ddlQuantity.Enabled    = false;
                    lnkAddToBasket.Enabled = false;
                    loadProductAttributes();
                }
                //refreshing the size ddl
                loadProductAttributes();
                updPanelDDL.Update();
                return;
            }


            Version = null;
            Response.Redirect("/cart/mycart/");
        }
Пример #19
0
        /// <summary>
        /// Adds a new product to this session cart
        /// </summary>
        /// <param name="CustomerID"></param>
        /// <param name="CampaignID"></param>
        /// <param name="ProductId"></param>
        /// <param name="ProdAttrId"></param>
        /// <param name="Quantity"></param>
        public void AddProductToCart(int CustomerID, int CampaignID, int ProductId, int ProdAttrId, int Quantity, string BrandName)
        {
            if (CartID == null)
            {
                Guid g = Guid.NewGuid();
                UniqueIdGenerator unique = UniqueIdGenerator.GetInstance();
                string            cartId = unique.GetBase32UniqueId(g.ToByteArray(), 20).ToLower();
                CartID = cartId;
            }

            SHOPPING_CART cart = new SHOPPING_CART();

            cart.ID         = CartID;
            cart.FrontEnd   = false;
            cart.CampaignID = CampaignID;
            cart.CustomerID = CustomerID;
            cart.DateAdded  = DateTime.Now;
            cart.ProductID  = ProductId;
            cart.ProdAttrID = ProdAttrId;
            cart.Quantity   = Quantity;
            cart.BrandName  = BrandName;

            // the versions list of lists is created each time the product popup is shown, and destroyed each time it is closed
            if (Versions != null)
            {
                cart.ProductAttributeVersion = Versions.Where(x => x.Key == ProductId).FirstOrDefault().Value.Where(y => y.Key == ProdAttrId).FirstOrDefault().Value;
            }
            else
            {
                throw new ApplicationException("Session is compromised! Cannot proceed.");
            }

            if (CartSession == null)
            {
                CartSession = new List <SHOPPING_CART>();
            }

            List <SHOPPING_CART> carts = CartSession;
            SHOPPING_CART        sc;

            // already in the cart
            if (carts.Count > 0 && (sc = carts.Where(c => c.ID == cart.ID && c.ProdAttrID == cart.ProdAttrID).FirstOrDefault()) != null)
            {
                cart.Quantity += sc.Quantity;
                ApplicationContext.Current.Carts.Update(cart, sc.Quantity);

                // updating session with last quantity and last prod-attr version
                sc.Quantity = cart.Quantity;
                sc.ProductAttributeVersion = cart.ProductAttributeVersion;
                //sc = cart;
            }
            else
            {
                ApplicationContext.Current.Carts.Insert(cart);

                // already has the last version set from the context saving
                CartSession.Add(cart);
            }

            // refreshing session, optional
            //ApplicationContext.Current.Carts.GetShoppingCartItems(CartID);
            DataBind(CartSession);
        }
Пример #20
0
        public void GetInstanceTest()
        {
            var instance = UniqueIdGenerator.GetInstance();

            Assert.AreSame(instance, UniqueIdGenerator.GetInstance());
        }
Пример #21
0
 public virtual string Generate(ContentBase content)
 {
     return(UniqueIdGenerator.GetInstance().GetBase32UniqueId(16));
 }
Пример #22
0
 public static string Generate(int numDigits)
 {
     return(UniqueIdGenerator.GetInstance().GetBase32UniqueId(numDigits));
 }