コード例 #1
0
        /// <summary>
        /// Adds or updates data for a FieldPath list in the cache.  If it already exists, it will query the data again.
        /// </summary>
        /// <param name="path"></param>
        public virtual void UpdateCache(dbqf.Criterion.IFieldPath path)
        {
            // if item exists in cache, clear and update
            // if item does not exist in cache, add it
            CacheData result;

            if (_listCache.ContainsKey(path))
            {
                result = _listCache[path];
            }
            else
            {
                result = new CacheData()
                {
                    Data = new BindingList <object>()
                };
                _listCache.Add(path, result);

                // return if the field has a pre-defined list of items
                if (path.Last.List.Count > 0)
                {
                    result.Data.Add(string.Empty);
                    foreach (var x in path.Last.List)
                    {
                        result.Data.Add(x);
                    }
                    return;
                }
            }

            if (DbService != null)
            {
                DbService.GetList(path, new CachedListCallback(ListCallback, path, result));
            }
        }
コード例 #2
0
ファイル: PresetAdapter.cs プロジェクト: zaharPonimash/dbqf
        protected override dbqf.Display.Preset.PresetPart <T> CreatePart(dbqf.Criterion.IFieldPath path)
        {
            var part = base.CreatePart(path);

            part.Parser = Parser.Create(part.SelectedPath, part.SelectedBuilder);
            return(part);
        }
コード例 #3
0
        /// <summary>
        /// Adds or updates data for a FieldPath list in the cache.  If it already exists, it will query the data again.
        /// </summary>
        /// <param name="path"></param>
        public virtual void UpdateCache(dbqf.Criterion.IFieldPath path)
        {
            // if item exists in cache, clear and update
            // if item does not exist in cache, add it
            CacheData result;

            if (_listCache.ContainsKey(path))
            {
                result = _listCache[path];
            }
            else
            {
                result = new CacheData()
                {
                    Data = new BindingList <object>()
                };
                _listCache.Add(path, result);

                // return if the field has a pre-defined list of items
                if (path.Last.List.Count > 0)
                {
                    result.Data.Add(string.Empty);
                    foreach (var x in path.Last.List)
                    {
                        result.Data.Add(x);
                    }
                    return;
                }
            }

            var gen = ResultFactory.CreateSqlListGenerator(Configuration).Path(path);

            if (Regex.IsMatch(path.Last.List.Source, @"^select.*[`'\[\s]id", RegexOptions.IgnoreCase))
            {
                gen.IdColumn("ID")
                .ValueColumn("Value");
            }

            // ensure we'll be able to generate a command
            try { gen.Validate(); }
            catch { return; }

            // kill any existing worker
            if (result.CurrentWorker != null)
            {
                result.CurrentWorker.CancelAsync();
            }

            var bgw = new BackgroundWorker();

            bgw.WorkerSupportsCancellation = true;
            bgw.DoWork += (s2, e2) =>
            {
                result.CurrentWorker = bgw;
                try
                {
                    e2.Result = ResultFactory.CreateSqlResults(Connection).GetList(gen);
                }
                catch (Exception te)
                {
                    e2.Result = te;
                }
            };
            bgw.RunWorkerCompleted += (s2, e2) =>
            {
                if (e2.Cancelled)
                {
                    return;
                }

                if (e2.Result is Exception)
                {
                    // what do we do?
                }
                else
                {
                    var list = result.Data;
                    list.RaiseListChangedEvents = false;
                    list.Clear();
                    list.Add(string.Empty);
                    foreach (var i in (IList <object>)e2.Result)
                    {
                        list.Add(i);
                    }
                    list.RaiseListChangedEvents = true;
                    list.ResetBindings();
                }

                if (bgw == result.CurrentWorker)
                {
                    result.CurrentWorker = null;
                }
            };
            bgw.RunWorkerAsync();
        }