コード例 #1
0
        public void Get_returns_same_object_for_same_id()
        {
            // arrange
            LookupCache <AccessLevel>   target;
            Dictionary <string, object> props;
            AccessLevel expected;
            AccessLevel actual;

            target = new LookupCache <AccessLevel>(null);

            props = new Dictionary <string, object>
            {
                {
                    "id", 90
                },
                {
                    "name", "alpha"
                },
                {
                    "label", "beta"
                }
            };

            expected = target.Get(props);

            // act
            actual = target.Get(expected.Id);

            // assert
            Assert.AreSame(expected, actual);
        }
コード例 #2
0
        private void lookUpEdit_Reg_EditValueChanged(object sender, EventArgs e)
        {
            #region Change rayon list

            if (lookUpEdit_Reg.EditValue != null)
            {
                var rayons = LookupCache.Get(LookupTables.Rayon);

                rayons.RowFilter = string.Format("idfsRegion = {0} OR idfsRegion = {1}", lookUpEdit_Reg.EditValue, -101);

                lookUpEdit_Ryn.SuspendLayout();
                lookUpEdit_Ryn.Properties.Columns.Clear();
                lookUpEdit_Ryn.Properties.Columns.Add(new LookUpColumnInfo("strRayonName", "", 200, FormatType.None, "",
                                                                           true, HorzAlignment.Near));
                lookUpEdit_Ryn.Properties.PopupWidth = lookUpEdit_Ryn.Width;

                lookUpEdit_Ryn.Properties.DataSource = rayons;

                lookUpEdit_Ryn.Properties.DisplayMember = "strRayonName";
                lookUpEdit_Ryn.Properties.ValueMember   = "idfsRayon";

                lookUpEdit_Ryn.EditValue = null;

                lookUpEdit_Ryn.ResumeLayout();
            }
            else
            {
                lookUpEdit_Ryn.EditValue = null;
            }

            #endregion
        }
コード例 #3
0
        /// <summary>
        /// Gets the lookup table for the property from a lookup cache using <see cref="TableType"/>.
        /// </summary>
        /// <param name="cachedOnly">True to return only the cached lookup table, False to try to load it, if it's not cached.</param>
        /// <param name="row">Data row for which to get the lookup table, or null if the property is not in a data list object.</param>
        /// <returns>The lookup table to be used for the property.</returns>
        protected virtual LookupTable GetLookupTable(bool cachedOnly = false, DataRow row = null)
        {
            LookupCache cache = row?.GetLookupCache(this) ?? LocalCacheLoader?.LocalCache ??
                                LookupCache.Get(parent?.ServiceProvider ?? DI.DefaultServiceProvider, CacheType);

            return(cache?.GetLookupTable(TableType, cachedOnly));
        }
コード例 #4
0
        public void Get_returns_existing_item_from_id()
        {
            // arrange
            LookupCache <AccessLevel> target;
            AccessLevel expected;
            AccessLevel actual;
            Dictionary <int, AccessLevel> dict;

            target = new LookupCache <AccessLevel>(null);

            dict = (Dictionary <int, AccessLevel>)target.GetType().GetField("_cache", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(target);

            expected = new AccessLevel
            {
                Id    = 90,
                Name  = "alpha",
                Label = "beta"
            };

            dict.Add(expected.Id, expected);

            // act
            actual = target.Get(expected.Id);

            // assert
            Assert.AreSame(expected, actual);
        }
コード例 #5
0
        /// <summary>
        /// Gets the lookup table for the property from a lookup cache using <see cref="TableType"/>, and loads it asynchronously as needed.
        /// </summary>
        /// <param name="row">Data row for which to get the lookup table, or null if the property is not in a data list object.</param>
        /// <param name="token">Cancellation token.</param>
        /// <returns>The lookup table to be used for the property.</returns>
        protected async virtual Task <LookupTable> GetLookupTableAsync(DataRow row = null, CancellationToken token = default)
        {
            LookupCache cache = row?.GetLookupCache(this) ?? LocalCacheLoader?.LocalCache ??
                                LookupCache.Get(parent?.ServiceProvider ?? DI.DefaultServiceProvider, CacheType);

            return(await cache?.GetLookupTableAsync(TableType, token));
        }
コード例 #6
0
        public static DataView GetAggregateFunctionsView()
        {
            DataView dataView = LookupCache.Get(LookupTables.AggregateFunction.ToString());

            dataView.RowFilter = "blnPivotGridFunction=1";
            return(dataView);
        }
コード例 #7
0
 public LookupTableController(IServiceProvider serviceProvider)
 {
     if (serviceProvider == null)
     {
         throw new ArgumentNullException("serviceProvider");
     }
     globalCache = LookupCache.Get(serviceProvider, LookupCache.Global);
 }
コード例 #8
0
 public LookupTableController(IServiceProvider serviceProvider, ResourceManager resourceManager)
 {
     if (serviceProvider == null)
     {
         throw new ArgumentNullException(nameof(serviceProvider));
     }
     globalCache = LookupCache.Get(serviceProvider, LookupCache.Global);
     resMgr      = resourceManager ?? Messages.ResourceManager;
 }
コード例 #9
0
        public static long GetFirstlayoutId()
        {
            DataView layoutLookup = LookupCache.Get(LookupTables.Layout);

            layoutLookup.Sort = "idflLayout";
            return(layoutLookup.Count > 0
                ? (long)layoutLookup[0]["idflLayout"]
                : -1);
        }
コード例 #10
0
        /// <summary>
        /// Gets the lookup table for the property. The default implementation uses the <see cref="EnumType"/>
        /// to find the lookup table in the lookup cache specified by the <see cref="CacheType"/>.
        /// </summary>
        /// <returns>The lookup table to be used for the property.</returns>
        protected virtual LookupTable GetLookupTable()
        {
            if (LocalLookupTable != null)
            {
                return(LocalLookupTable);
            }
            LookupCache cache = LookupCache.Get(parent != null ? parent.ServiceProvider : DI.DefaultServiceProvider, CacheType);

            LookupCache.LookupTableReady onReady = null;
            return(cache == null ? null : cache.GetLookupTable(EnumType, onReady));
        }
コード例 #11
0
        /// <summary>
        /// Validates the specified list of values using the current <see cref="ValidationContext"/>.
        /// </summary>
        /// <param name="values">The list of values to validate.</param>
        /// <param name="validationContext">The validation context to use.</param>
        /// <returns><see cref="ValidationResult.Success"/> if all the values in the list are valid,
        /// and a <see cref="ValidationResult"/> with the localized error otherwise.</returns>
        protected ValidationResult IsValidList(ICollection values, ValidationContext validationContext)
        {
            if (ValidationType == LookupValidationType.None)
            {
                return(ValidationResult.Success);
            }

            IServiceProvider svcProvider = (validationContext?.GetService(typeof(ResourceManager)) != null) ? validationContext : DI.DefaultServiceProvider;
            ResourceManager  rm          = (ResourceManager)svcProvider?.GetService(typeof(ResourceManager)) ?? Messages.ResourceManager;
            LookupCache      cache       = LookupCache.Get(svcProvider, CacheType);
            LookupTable      table       = cache?.GetLookupTable(LookupTable);

            if (table == null)
            {
                throw new InvalidOperationException(
                          string.Format(rm.GetString(Messages.Validation_InvalidLookupTable), validationContext.DisplayName, LookupTable));
            }
            string[]      memberNames   = validationContext.MemberName != null ? new string[] { validationContext.MemberName } : null;
            List <string> invalidValues = new List <string>();

            foreach (object val in values)
            {
                string strVal = val?.ToString();
                if (val is bool)
                {
                    strVal = strVal.ToLower();
                }
                if (string.IsNullOrEmpty(strVal))
                {
                    continue;
                }
                Header h = table.LookupById(strVal);
                if (h == null || ValidationType == LookupValidationType.ActiveItem && !h.IsActive)
                {
                    invalidValues.Add("'" + strVal + "'");
                }
            }
            if (invalidValues.Count == 0)
            {
                return(ValidationResult.Success);
            }
            string errMsg = invalidValues.Count > 1 ? Messages.Validation_LookupValues : Messages.Validation_LookupValue;

            return(new ValidationResult(string.Format(rm.GetString(errMsg), validationContext.DisplayName, LookupTable, string.Join(", ", invalidValues)), memberNames));
        }
コード例 #12
0
        public void MissedValuesLookupTests()
        {
            using (DbManagerProxy manager = DbManagerFactory.Factory.Create())
            {
                DbManager command = manager.SetCommand(
                    @"select 
		sf.idfsSearchField, 
		br.strDefault,
		sf.strSearchFieldAlias,
		sf.strLookupTable,
		sf.strLookupAttribute
		  
from	tasSearchField sf
inner join trtBaseReference br
	on sf.idfsSearchFieldType = br.idfsBaseReference
	and br.idfsReferenceType = 19000081
	and sf.blnAllowMissedReferenceValues = 1
	and  sf.idfsSearchFieldType <> 10081002"
                    );

                DataTable searchFields = command.ExecuteDataTable();
                Assert.AreEqual(0, searchFields.Select("strLookupTable is NULL").Length, "Not all search fields have strLookupTable");
                Assert.AreEqual(0, searchFields.Select("strLookupAttribute is NULL").Length, "Not all search fields have strLookupAttribute");
                foreach (DataRow row in searchFields.Rows)
                {
                    object tableNameObj  = row["strLookupTable"];
                    object columnNameObj = row["strLookupAttribute"];
                    if (tableNameObj != DBNull.Value && columnNameObj != DBNull.Value)
                    {
                        string   tableName  = tableNameObj.ToString();
                        string   columnName = columnNameObj.ToString();
                        DataView lookup     = LookupCache.Get(tableName);
                        Assert.IsNotNull(lookup, string.Format("Could not load lookup '{0}'", tableName));

                        //if (!lookup.Table.Columns.Contains(columnName) && columnName == "strRegionExtendedName")
                        //{
                        //    columnName = "strExtendedRegionName";
                        //}
                        Assert.IsTrue(lookup.Table.Columns.Contains(columnName),
                                      string.Format("Could not find attribute '{0}' in lookup '{1}'", columnName, tableName));
                    }
                }
            }
        }
コード例 #13
0
        public void VirtualPivotGetModelTest()
        {
            DataView layoutLookup = LookupCache.Get(LookupTables.Layout);

            if (layoutLookup.Count > 0)
            {
                var layoutId = (long)layoutLookup.Table.Rows[0]["idflLayout"];

                for (int i = 0; i < 3; i++)
                {
                    using (new StopwathTransaction("++ VirtualPivot with View++ " + i))
                    {
                        AvrPivotViewModel model = VirtualPivot.CreateAvrPivotViewModel(layoutId, "en", StructureMapContainerInit());

                        Assert.IsNotNull(model);
                    }
                }
            }
        }
コード例 #14
0
 public void EIDSS_LookupCacheHelperPrimaryKeyTest()
 {
     EIDSS_LookupCacheHelper.Init();
     foreach (var val in Enum.GetNames(typeof(LookupTables)))
     {
         //for(int i = 0;i<100;i++)
         {
             var view = LookupCache.Get(val);
             //if (view == null)
             //{
             //    Thread.Sleep(100);
             //    continue;
             //}
             if (view != null)
             {
                 Dbg.Debug("{0} records in table {1}", view.Count, val);
                 view.Table.DataSet.EnforceConstraints = false;
                 view.Table.DataSet.EnforceConstraints = true;
             }
             //break;
         }
     }
 }
コード例 #15
0
        public void Get_constructs_object_from_properties_dictionary()
        {
            // arrange
            LookupCache <AccessLevel>   target;
            Dictionary <string, object> props;
            AccessLevel expected;
            AccessLevel actual;

            target = new LookupCache <AccessLevel>(null);

            props = new Dictionary <string, object>
            {
                {
                    "id", 90
                },
                {
                    "name", "alpha"
                },
                {
                    "label", "beta"
                }
            };

            expected = new AccessLevel
            {
                Id    = 90,
                Name  = "alpha",
                Label = "beta"
            };

            // act
            actual = target.Get(props);

            // assert
            Assert.AreEqual(expected, actual);
        }
コード例 #16
0
        private void AdminUnitMaskForm_Load(object sender, EventArgs e)
        {
            #region Fill Countriy list

            var countries = LookupCache.Get(LookupTables.Country);

            countries.RowFilter = string.Format("strCountryName <> '{0}'", "");

            lookUpEdit_Cnt.SuspendLayout();
            lookUpEdit_Cnt.Properties.Columns.Clear();
            lookUpEdit_Cnt.Properties.Columns.Add(new LookUpColumnInfo("strCountryName", "", 200, FormatType.None, "",
                                                                       true, HorzAlignment.Near));
            lookUpEdit_Cnt.Properties.PopupWidth = lookUpEdit_Cnt.Width;

            lookUpEdit_Cnt.Properties.DataSource = countries;

            lookUpEdit_Cnt.Properties.DisplayMember = "strCountryName";
            lookUpEdit_Cnt.Properties.ValueMember   = "idfsCountry";

            lookUpEdit_Cnt.EditValue = IdfsCountry ?? model.Core.EidssSiteContext.Instance.CountryID;
            lookUpEdit_Cnt.ResumeLayout();

            #endregion
        }
コード例 #17
0
        public void LookupAggregateTest()
        {
            DataView view = LookupCache.Get(LookupTables.AggregateFunction.ToString());

            Assert.IsTrue(view.Count >= 6);
        }