public SaveResponse Update(TranslationUpdateRequest request)
        {
            if (request.Translations == null)
            {
                throw new ArgumentNullException("translations");
            }

            var translations = List(new TranslationListRequest
            {
                SourceLanguageID = request.TargetLanguageID,
            }).Entities.ToDictionary(x => x.Key, x => x.CustomText);

            foreach (var item in request.Translations)
            {
                translations[item.Key] = item.Value;
            }

            var result = new SortedDictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (var pair in translations)
            {
                if (!pair.Value.IsEmptyOrNull())
                {
                    result.Add(pair.Key, pair.Value);
                }
            }

            string json = JSON.StringifyIndented(result, indentation: 2);

            var textsFilePath = GetUserTextsFilePath(request.TargetLanguageID);

            Directory.CreateDirectory(Path.GetDirectoryName(textsFilePath));
            File.WriteAllText(textsFilePath, json);

            Dependency.Resolve <IDependencyRegistrar>().RegisterInstance <ILocalTextRegistry>(new LocalTextRegistry());
            CommonInitialization.InitializeLocalTexts();
            TwoLevelCache.ExpireGroupItems(UserRow.Fields.GenerationKey);
            DynamicScriptManager.Reset();

            return(new SaveResponse());
        }
Ejemplo n.º 2
0
 public ActionResult Index()
 {
     var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
         OrderRow.Fields.GenerationKey, () =>
         {
             var model = new DashboardPageModel();
             var o = OrderRow.Fields;
             using (var connection = SqlConnections.NewFor<OrderRow>())
             {
                 model.OpenOrders = connection.Count<OrderRow>(o.ShippingState == (int)OrderShippingState.NotShipped);
                 var closedOrders = connection.Count<OrderRow>(o.ShippingState == (int)OrderShippingState.Shipped);
                 var totalOrders = model.OpenOrders + closedOrders;
                 model.ClosedOrderPercent = (int)Math.Round(totalOrders == 0 ? 100 :
                     ((double)closedOrders / (double)totalOrders * 100));
                 model.CustomerCount = connection.Count<CustomerRow>();
                 model.ProductCount = connection.Count<ProductRow>();
             }
             return model;
         });
     return View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel);
 }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              OsnovnoSredstvoRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = OsnovnoSredstvoRow.Fields;
                using (var connection = SqlConnections.NewFor <OsnovnoSredstvoRow>())
                {
                    model.OpenOrders         = connection.Count <OsnovnoSredstvoRow>(o.OsnovnoId == OsnovnoSredstvoRow.Fields.OsnovnoId);
                    var closedOrders         = connection.Count <AktivacijaSredstvaRow>(o.OsnovnoId == AktivacijaSredstvaRow.Fields.OsnovnoId);
                    var totalOrders          = model.OpenOrders + closedOrders;
                    model.ClosedOrderPercent = (int)Math.Round(totalOrders == 0 ? 100 :
                                                               ((double)closedOrders / (double)totalOrders * 100));
                    model.CustomerCount = connection.Count <PartneriRow>();
                    model.ProductCount  = connection.Count <AktivacijaSredstvaRow>();
                }
                return(model);
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              BuildingRow.Fields.GenerationKey, () =>
            {
                var model      = new DashboardPageModel();
                var connection = SqlConnections.NewByKey("Default");

                #region Zoning
                model.TotalBuildings  = connection.Count <BuildingRow>();
                model.TotalApartments = connection.Count <ApartmentRow>();
                #endregion

                #region Parameter
                model.ParametersList = connection.List <ParameterRow>();
                #endregion

                #region Meter
                model.MetersList  = connection.List <MeterRow>();
                model.TotalMeters = connection.Count <MeterRow>();
                #endregion

                #region EMSDevice
                model.TotalEMSDevices = connection.Count <EmsDeviceRow>();
                #endregion

                #region Charts
                model.BarLstModel = new List <SimpleReportViewModel>();
                model.BarLstModel = Bar();

                model.PieLstModel = new List <SimpleReportViewModel>();
                model.PieLstModel = Pie();
                #endregion

                return(model);
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
        public ActionResult Index()
        {
            /*
             * var cahcedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5), OrderRow.Fields.GenerationKey, () =>
             * {
             *  var model = new DashboardPageModel();
             *  var o = OrderRow.Fields;
             *  using (var connection = SqlConnections.NewFor<OrderRow>())
             *  {
             *      model.OpenOrders = connection.Count<OrderRow>(o.ShippingState == (int)OrderShippingState.NotShipped);
             *      var closedOrders = connection.Count<OrderRow>(o.ShippingState == (int)OrderShippingState.Shipped);
             *      var totalOrders = model.OpenOrders + closedOrders;
             *      model.ClosedOrderPercent = (int).Math.Round(totalOrder == 0 ? 100 : ((double)closedOrders / (double)totalOrders * 100);
             *      model.CustomerCount = connection.Count<CustomerRow>();
             *      model.ProductCount = connection.Count<ProductRow>();
             *  }
             *  return model;
             * });
             */
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromSeconds(1), OrdersRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = OrdersRow.Fields;
                var p     = ProductsRow.Fields;
                using (var connection = SqlConnections.NewByKey("Default"))
                {
                    model.OrderCount           = connection.Count <OrdersRow>(o.DatetimeOrder == DateTime.Today);
                    model.CustomerCount        = connection.Count <CustomersRow>();
                    model.ProductCount         = connection.Count <ProductsRow>();
                    model.RunsOutProductCount  = connection.Count <ProductsRow>(p.StockQuantityProduct < 20);
                    model.LowStockProductCount = connection.Count <ProductsRow>(p.StockQuantityProduct >= 20 && p.StockQuantityProduct <= 50);
                }
                return(model);
            });

            //return View(MVC.Views.Common.Dashboard.DashboardIndex, new DashboardPageModel());
            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Ejemplo n.º 6
0
            public void Get_WithLocalCachedItem_Null_Distributed_NotNull()
            {
                var memoryCache = new MemoryCache(new Microsoft.Extensions.Options.OptionsWrapper <MemoryCacheOptions>(
                                                      new MemoryCacheOptions()));

                memoryCache.Set("UserByName_admin$Generation$", (ulong)641427502);
                memoryCache.Set("UserGenerationKey", (ulong)641427502);
                memoryCache.Set <UserDefinition>("UserByName_admin", null);
                var distributedCache = new MemoryDistributedCache(
                    new Microsoft.Extensions.Options.OptionsWrapper <MemoryDistributedCacheOptions>(
                        new MemoryDistributedCacheOptions()));

                distributedCache.Set("UserByName_admin$Generation$", BitConverter.GetBytes((ulong)641427502));
                distributedCache.SetAutoJson("UserByName_admin", new UserDefinition {
                    Username = "******", UserId = 1
                });
                distributedCache.Set("UserGenerationKey", BitConverter.GetBytes((ulong)641427502));
                var cache     = new TwoLevelCache(memoryCache, distributedCache);
                var loadCount = 0;
                var user      = GetUserByName(cache, "admin", ref loadCount);

                Assert.Equal("admin", user?.Username);
                Assert.Equal(0, loadCount);
            }
Ejemplo n.º 7
0
        public ScriptUserDefinition GetUserData()
        {
            var result = new ScriptUserDefinition();
            var user   = Authorization.UserDefinition as UserDefinition;

            if (user == null)
            {
                result.Permissions = new Dictionary <string, bool>();
                return(result);
            }

            result.Username    = user.Username;
            result.DisplayName = user.DisplayName;
            result.IsAdmin     = user.Username == "admin";
            result.UserRoles   = user.UserRoles;
            result.Ktp         = user.Ktp;
            result.UserRoles   = user.UserRoles;

            //using (var connection = SqlConnections.NewFor<UserRoleRow>())
            //{
            //    UserRoleListRequest request = new UserRoleListRequest();
            //    request.UserID = user.UserId;
            //    List<int> userRoleList = new UserRoleRepository().List(connection, request).Entities;
            //    List<string> arrRole = new List<string>();
            //    foreach (var roleId in userRoleList)
            //    {
            //        RetrieveRequest roleRequest = new RetrieveRequest();
            //        roleRequest.EntityId = roleId;
            //        var roleName = new RoleRepository().GetRoleName(connection, roleId);
            //        arrRole.Add(roleName);
            //    }
            //    user.UserRoles = string.Join(",", arrRole.ToArray());
            //    result.Roles = user.UserRoles;
            //}

            result.Permissions = TwoLevelCache.GetLocalStoreOnly("ScriptUserPermissions:" + user.Id, TimeSpan.Zero,
                                                                 UserPermissionRow.Fields.GenerationKey, () =>
            {
                var permissions = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

                if (permissionsUsedFromScript == null)
                {
                    permissionsUsedFromScript = new UserPermissionRepository().ListPermissionKeys().Entities
                                                .Where(permissionKey =>
                    {
                        // this sends permission information for all permission keys to client side.
                        // if you don't need all of them to be available from script, filter them here.
                        // this is recommended for security / performance reasons...
                        return(true);
                    }).ToArray();
                }

                foreach (var permissionKey in permissionsUsedFromScript)
                {
                    if (Authorization.HasPermission(permissionKey))
                    {
                        permissions[permissionKey] = true;
                    }
                }

                return(permissions);
            });

            return(result);
        }
Ejemplo n.º 8
0
 public NavigationModel()
 {
     Items = TwoLevelCache.GetLocalStoreOnly("LeftNavigationModel:NavigationItems:" + (Authorization.UserId ?? "-1"), TimeSpan.Zero,
                                             UserPermissionRow.Fields.GenerationKey, () =>
                                             NavigationHelper.GetNavigationItems(System.Web.VirtualPathUtility.ToAbsolute));
 }
Ejemplo n.º 9
0
 public void Update()
 {
     TwoLevelCache.ChangeGlobalGeneration(this.generationKey);
 }
Ejemplo n.º 10
0
 public void Update()
 {
     TwoLevelCache.ExpireGroupItems(this.groupKey);
 }
Ejemplo n.º 11
0
        public void TestTwoLevelCache()
        {
            var hundredBytes = new byte[100];
            ICache primary = new MemoryCache(500, new LruCacheEvictionPolicy(), 400, 300);
            ICache secondary = new MemoryCache(1000, new LruCacheEvictionPolicy(), 900, 700);
            ICache cache = new TwoLevelCache(primary, secondary);

            for (int i = 0; i < 9; i++)
            {
                cache.Insert("Entry " + i, hundredBytes, CachePriority.Normal);
                Thread.Sleep(20);
            }

            for(int i = 0; i < 9; i++)
            {
                Assert.IsTrue(secondary.ContainsKey("Entry " + i), "Expected secondary cache to contain Entry {0} after initialization");
                if (i < 5) Assert.IsFalse(primary.ContainsKey("Entry " + i), "Expected primary cache to NOT contain Entry {0} after initialization", i);
                else Assert.IsTrue(primary.ContainsKey("Entry " + i), "Expected primary cache to contain Entry {0} after initialization", i);
            }

            cache.Insert("Entry 10", hundredBytes, CachePriority.Normal);
            Assert.IsFalse(cache.ContainsKey("Entry 0"));
            Assert.IsFalse(cache.ContainsKey("Entry 1"));
            Assert.IsTrue(cache.ContainsKey("Entry 2"));
            Assert.IsTrue(cache.ContainsKey("Entry 10"));
            Assert.IsTrue(primary.ContainsKey("Entry 10"));
            Assert.IsTrue(secondary.ContainsKey("Entry 10"));
        }