Ejemplo n.º 1
0
        static void PerformScheduledTasks(string key, Object value, CacheItemRemovedReason reason)
        {
            try
            {
                MerchantTribe.Commerce.RequestContext context = new MerchantTribe.Commerce.RequestContext();
                MerchantTribeApplication app = MerchantTribe.Commerce.MerchantTribeApplication.InstantiateForDataBase(context);

                List <long> storeIds = app.ScheduleServices.QueuedTasks.ListStoresWithTasksToRun();
                if (storeIds != null)
                {
                    List <MerchantTribe.Commerce.Accounts.StoreDomainSnapshot> stores = app.AccountServices.Stores.FindDomainSnapshotsByIds(storeIds);
                    if (stores != null)
                    {
                        System.Threading.Tasks.Parallel.ForEach(stores, CallTasksOnStore);
                        //foreach (MerchantTribe.Commerce.Accounts.StoreDomainSnapshot snap in stores)
                        //{
                        //    string storekey = System.Configuration.ConfigurationManager.AppSettings["storekey"];
                        //    string rootUrl = snap.RootUrl();
                        //    string destination = rootUrl + "scheduledtasks/" + storekey;
                        //    MerchantTribe.Commerce.Utilities.WebForms.SendRequestByPost(destination, string.Empty);
                        //}
                    }
                }
            }
            catch
            {
                // suppress error and schedule next run
            }

            ScheduleTaskTrigger();
        }
Ejemplo n.º 2
0
        static void PerformScheduledTasks(string key, Object value, CacheItemRemovedReason reason)
        {
            try
            {
                MerchantTribe.Commerce.RequestContext context = new MerchantTribe.Commerce.RequestContext();
                MerchantTribeApplication app = MerchantTribe.Commerce.MerchantTribeApplication.InstantiateForDataBase(context);

                List<long> storeIds = app.ScheduleServices.QueuedTasks.ListStoresWithTasksToRun();
                if (storeIds != null)
                {
                    List<MerchantTribe.Commerce.Accounts.StoreDomainSnapshot> stores = app.AccountServices.Stores.FindDomainSnapshotsByIds(storeIds);
                    if (stores != null)
                    {
                        System.Threading.Tasks.Parallel.ForEach(stores, CallTasksOnStore);
                        //foreach (MerchantTribe.Commerce.Accounts.StoreDomainSnapshot snap in stores)
                        //{
                        //    string storekey = System.Configuration.ConfigurationManager.AppSettings["storekey"];
                        //    string rootUrl = snap.RootUrl();
                        //    string destination = rootUrl + "scheduledtasks/" + storekey;
                        //    MerchantTribe.Commerce.Utilities.WebForms.SendRequestByPost(destination, string.Empty);
                        //}
                    }
                }

            }
            catch
            {
                // suppress error and schedule next run
            }

            ScheduleTaskTrigger();
        }
        public void CanAddSampleProductsToStore()
        {
            RequestContext c = new RequestContext();
            MerchantTribeApplication target = MerchantTribeApplication.InstantiateForMemory(c);
            target.AddSampleProductsToStore();

            int totalCount = target.CatalogServices.Products.CountOfAll();
            Assert.AreEqual(6, totalCount, "Six Products should have been created.");
            List<Catalog.CategorySnapshot> cats = target.CatalogServices.Categories.FindAll();
            Assert.IsNotNull(cats);
            Assert.AreEqual(4, cats.Count, "Four categories should have been created!");            
        }
        public void CanCreateAnAddressAndAssignBvin()
        {
            RequestContext c = new RequestContext();
            c.CurrentStore.Id = 12;
            AddressRepository target = AddressRepository.InstantiateForMemory(c);

            Address item = new Address();
            item.City = "Richmond";

            bool expected = true;
            bool actual;
            actual = target.Create(item);

            Assert.AreEqual(expected, actual);
            Assert.AreNotEqual(string.Empty, item.Bvin, "Bvin should not be empty after create.");            
        }
Ejemplo n.º 5
0
        public void Setup()
        {
            WebAppSettings.SetUnitTestPhysicalPath(@"C:\git\MerchantTribe\App\MerchantTribeStore");
                        
            context = ContextHelper.GetFakeRequestContext("", "http://demo.localhost.dev/", "");            
            app = MerchantTribeApplication.InstantiateForMemory(context);

            viewBag = new DynamicViewDataDictionary(() => new System.Web.Mvc.ViewDataDictionary());
            //viewBag.RootUrlSecure = app.StoreUrl(true, false);
            //viewBag.RootUrl = app.StoreUrl(false, true);
            //viewBag.StoreClosed = app.CurrentStore.Settings.StoreClosed;
            //viewBag.StoreName = app.CurrentStore.Settings.FriendlyName;            
            //viewBag.StoreUniqueId = app.CurrentStore.StoreUniqueId(app);            
            viewBag.CustomerIp = "0.0.0.0";            
            //viewBag.CustomerId = app.CurrentCustomerId ?? string.Empty;
            //viewBag.HideAnalytics = app.CurrentStore.Settings.Analytics.DisableMerchantTribeAnalytics;     

            tagProvider = new TagProvider();
        }
Ejemplo n.º 6
0
 public static bool StoreLogEvent(long storeId, string source, string message, EventLogSeverity severity)
 {
     bool ret = false;
     Metrics.EventLogEntry e = new Metrics.EventLogEntry(source, message, severity, storeId);
     e.StoreId = storeId;
     try
     {
         RequestContext context = new RequestContext();
         context.CurrentStore = new Accounts.Store() { Id = storeId };
         Metrics.EventLogRepository repository = new Metrics.EventLogRepository(context);
         ret = repository.Create(e);
         repository.Roll();
     }
     catch(Exception ex)
     {
         LogEvent(ex);
         return false;
     }
     return true;
 }
Ejemplo n.º 7
0
        public void CanCreateShippingMethod()
        {
            RequestContext c = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);
            c.CurrentStore = new Accounts.Store();
            c.CurrentStore.Id = 230;

            Shipping.ShippingMethod target = new Shipping.ShippingMethod();
            target.Adjustment = 1.23m;
            target.AdjustmentType = Shipping.ShippingMethodAdjustmentType.Percentage;
            target.Bvin = string.Empty;
            //target.CustomProperties.Add("bvsoftware", "mykey", "myvalue");
            target.Name = "Test Name";
            target.Settings.AddOrUpdate("MySetting", "MySetVal");
            target.ShippingProviderId = "123456";
            target.ZoneId = -101;

            Assert.IsTrue(app.OrderServices.ShippingMethods.Create(target));
            Assert.AreNotEqual(string.Empty, target.Bvin, "Bvin should not be empty");
        }
 public MerchantTribeApplication(RequestContext c, bool isForMemoryOnly)
 {
     this.CurrentRequestContext = c;
     this._IsForMemoryOnly = isForMemoryOnly;
 }
 public MerchantTribeApplication(RequestContext c)
 {
     this._IsForMemoryOnly = false;
     this.CurrentRequestContext = c;
 }
 public static MerchantTribeApplication InstantiateForDataBase(RequestContext c)
 {
     return new MerchantTribeApplication(c, false);
 }
Ejemplo n.º 11
0
        public void CanFindStoreAddressIfOneDoesntExist()
        {
            RequestContext c = new RequestContext();
            c.CurrentStore.Id = 100;            
            AddressRepository target = AddressRepository.InstantiateForMemory(c);

            int countBefore = target.CountOfAll();
            Assert.AreEqual(0, countBefore, "No Addresses should exist before the request for store address");

            // Target Store Address Should Not Exist            
            Address actual;
            actual = target.FindStoreContactAddress();

            // Make sure we received an address
            Assert.IsNotNull(actual, "Actual address should not be null");
            Assert.AreNotEqual(string.Empty, actual.Bvin, "Bvin should be a valid value");

            // Make sure it was saved in the database
            int countAfter = target.CountOfAll();
            Assert.AreEqual(1, countAfter, "Request for store address should have created one if missing.");

            // Make sure we can update it
            actual.City = "My New City";
            Assert.IsTrue(target.Update(actual), "Update should be true");

            Address actual2 = target.FindStoreContactAddress();
            Assert.IsNotNull(actual2, "Second request should return an address");
            Assert.AreEqual(actual.Bvin, actual2.Bvin, "Both request should return the same address");
            Assert.AreEqual("My New City", actual2.City, "City should have been updated.");
            
        }
Ejemplo n.º 12
0
 public void Setup()
 {
     context = new RequestContext();
     app = new MerchantTribeApplication(context);
     tagProvider = new TagProvider();
 }
Ejemplo n.º 13
0
        public void CanAddOptionsToProductInCorrectOrder()
        {
            RequestContext c = new RequestContext();
            c.CurrentStore = new Accounts.Store();
            c.CurrentStore.Id = 342;

            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            Product p = new Product();
            p.Sku = "TESTABC";
            p.ProductName = "Test Product ABC";


            Option opt = new Option();
            opt.SetProcessor(OptionTypes.CheckBoxes);
            opt.Name = "Test Option A";
            opt.Items.Add(new OptionItem() { Name = "Item A" });
            opt.Items.Add(new OptionItem() { Name = "Item B" });

            Option opt2 = new Option();
            opt.SetProcessor(OptionTypes.DropDownList);
            opt.Items.Add(new OptionItem() { Name = "Choice One" });
            opt.Items.Add(new OptionItem() { Name = "Choice Two" });

            Option opt3 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 3";

            Option opt4 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 4";

            Option opt5 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 5";

            Option opt6 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 6";

            Option opt7 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 7";


            // Add the option
            p.Options.Add(opt);
            p.Options.Add(opt2);
            p.Options.Add(opt3);
            p.Options.Add(opt4);
            p.Options.Add(opt5);
            p.Options.Add(opt6);
            p.Options.Add(opt7);            

            Assert.IsTrue(app.CatalogServices.Products.Create(p));

            Product actual = app.CatalogServices.Products.Find(p.Bvin);
            Assert.IsNotNull(actual, "Actual product should not be null");

            Assert.AreEqual(7, actual.Options.Count, "There should be one option on the product");
            
            Assert.AreEqual(opt.Name, actual.Options[0].Name, "Option name didn't match");
            Assert.AreEqual(opt2.Name, actual.Options[1].Name, "Option2 name didn't match");
            Assert.AreEqual(opt3.Name, actual.Options[2].Name, "Option3 name didn't match");
            Assert.AreEqual(opt4.Name, actual.Options[3].Name, "Option4 name didn't match");
            Assert.AreEqual(opt5.Name, actual.Options[4].Name, "Option5 name didn't match");
            Assert.AreEqual(opt6.Name, actual.Options[5].Name, "Option6 name didn't match");
            Assert.AreEqual(opt7.Name, actual.Options[6].Name, "Option7 name didn't match");                        
        }
Ejemplo n.º 14
0
        public void CanAddOptionsToProductWithItemsInCorrectOrder()
        {
            RequestContext c = new RequestContext();
            c.CurrentStore = new Accounts.Store();
            c.CurrentStore.Id = 342;

            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            Product p = new Product();
            p.Sku = "TESTABC";
            p.ProductName = "Test Product ABC";

            Option opt = new Option();
            opt.SetProcessor(OptionTypes.CheckBoxes);
            opt.Name = "Test Option";
            opt.Items.Add(new OptionItem() { Name = "Item A" });
            opt.Items.Add(new OptionItem() { Name = "Item B" });
            opt.Items.Add(new OptionItem() { Name = "Alphabet City" });
            
            // Add the option
            p.Options.Add(opt);

            Assert.IsTrue(app.CatalogServices.Products.Create(p));

            Product actual = app.CatalogServices.Products.Find(p.Bvin);
            Assert.IsNotNull(actual, "Actual product should not be null");
            
            Assert.AreEqual(1, actual.Options.Count, "There should be one option on the product");
            Assert.AreEqual(opt.Name, actual.Options[0].Name, "Option name didn't match");
            Assert.AreEqual(opt.OptionType, actual.Options[0].OptionType, "Option type was incorrect");
            
            Assert.AreEqual(3, actual.Options[0].Items.Count, "Item count on option should be 3");

            Assert.AreEqual(1, actual.Options[0].Items[0].SortOrder, "First sort order should be zero");
            Assert.AreEqual("Item A", actual.Options[0].Items[0].Name, "First Name Didn't Match");

            Assert.AreEqual(2, actual.Options[0].Items[1].SortOrder, "Second sort order should be zero");
            Assert.AreEqual("Item B", actual.Options[0].Items[1].Name, "Second Name Didn't Match");

            Assert.AreEqual(3, actual.Options[0].Items[2].SortOrder, "Third sort order should be zero");
            Assert.AreEqual("Alphabet City", actual.Options[0].Items[2].Name, "Third Name Didn't Match");
        }
Ejemplo n.º 15
0
        //public static RequestContext GetCurrentRequestContext()
        //{
        //    RequestContext alternateContext = new RequestContext();
        //    alternateContext.CurrentStore.Id = -1;

        //    try
        //    {
        //        // Try to pull from HttpContext.Items first in case
        //        // we already created this in an MVC controller
        //        if (System.Web.HttpContext.Current.Items != null)
        //        {
        //            object maybe = System.Web.HttpContext.Current.Items["mtapp"];
        //            if (maybe != null)
        //            {
        //                return ((MerchantTribeApplication)maybe).CurrentRequestContext;
        //            }
        //        }
        //        if (System.Web.HttpContext.Current != null)
        //        {
        //            if (System.Web.HttpContext.Current.Handler != null)
        //            {
        //                if (System.Web.HttpContext.Current.Handler is IMultiStorePage)
        //                {
        //                    return ((IMultiStorePage)System.Web.HttpContext.Current.Handler).MTApp.CurrentRequestContext;
        //                }
        //            }
        //        }                
        //    }
        //    catch
        //    {

        //    }
            
        //    return alternateContext;
        //}

        public static bool ForceCurrentRequestContext(RequestContext contextToSet)
        {
            try
            {
                if (System.Web.HttpContext.Current != null)
                {
                    if (System.Web.HttpContext.Current.Handler != null)
                    {
                        if (System.Web.HttpContext.Current.Handler is IMultiStorePage)
                        {
                            ((IMultiStorePage)System.Web.HttpContext.Current.Handler).MTApp.CurrentRequestContext = contextToSet;
                        }
                    }
                }
            }
            catch
            {

            }

            return false;
        }
Ejemplo n.º 16
0
        public void CanRetrieveShippingMethod()
        {
            RequestContext c = new RequestContext();
            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);
            c.CurrentStore = new Accounts.Store();
            c.CurrentStore.Id = 230;

            Shipping.ShippingMethod target = new Shipping.ShippingMethod();
            target.Adjustment = 1.23m;
            target.AdjustmentType = Shipping.ShippingMethodAdjustmentType.Percentage;
            target.Bvin = string.Empty;
            //target.CustomProperties.Add("bvsoftware", "mykey", "myvalue");
            target.Name = "Test Name";
            target.Settings.AddOrUpdate("MySetting", "MySetVal");
            target.ShippingProviderId = "123456";
            target.ZoneId = -101;

            app.OrderServices.ShippingMethods.Create(target);
            Assert.AreNotEqual(string.Empty, target.Bvin, "Bvin should not be empty");

            Shipping.ShippingMethod actual = app.OrderServices.ShippingMethods.Find(target.Bvin);
            Assert.IsNotNull(actual, "Actual should not be null");

            Assert.AreEqual(actual.Adjustment,target.Adjustment);
            Assert.AreEqual(actual.AdjustmentType,target.AdjustmentType);
            Assert.AreEqual(actual.Bvin,target.Bvin);
            //Assert.AreEqual(actual.CustomProperties[0].Key, target.CustomProperties[0].Key);
            Assert.AreEqual(actual.Name,target.Name);
            Assert.AreEqual(actual.Settings["MySetting"], target.Settings["MySetting"]);
            Assert.AreEqual(actual.ShippingProviderId,target.ShippingProviderId);
            Assert.AreEqual(actual.ZoneId,target.ZoneId);

        }
 public static MerchantTribeApplication InstantiateForMemory(RequestContext c)
 {
     return new MerchantTribeApplication(c, true);
 }