Beispiel #1
0
        /// <summary>
        /// Replaces existing query parameter(s) or appends to the end. If value is a collection type (array, IEnumerable, etc.),
        /// multiple parameters are added, i.e. x=1&amp;x=2. If any of the same name already exist, they are overwritten one by one
        /// (preserving order) and any remaining are appended to the end. If fewer values are specified than already exist,
        /// remaining existing values are removed.
        /// </summary>
        /// <param name="name">Name of the parameter.</param>
        /// <param name="value">Value of the parameter. If it's a collection, multiple parameters of the same name are added/replaced.</param>
        /// <param name="isEncoded">If true, assume value(s) already URL-encoded.</param>
        /// <param name="nullValueHandling">Describes how to handle null values.</param>
        public void AddOrReplace(string name, object value, bool isEncoded = false, NullValueHandling nullValueHandling = NullValueHandling.Remove)
        {
            if (!Contains(name))
            {
                Add(name, value, isEncoded, nullValueHandling);
            }

            // This covers some complex edge cases involving multiple values of the same name.
            // example: x has values at positions 2 and 4 in the query string, then we set x to
            // an array of 4 values. We want to replace the values at positions 2 and 4 with the
            // first 2 values of the new array, then append the remaining 2 values to the end.
            //var parameters = this.Where(p => p.Name == name).ToArray();
            var values = new Queue <object>(SplitCollection(value));

            var old = _values.ToArray();

            _values.Clear();

            foreach (var item in old)
            {
                if (item.Name != name)
                {
                    _values.Add(item);
                    continue;
                }

                if (!values.Any())
                {
                    continue;                     // remove, effectively
                }
                var val = values.Dequeue();
                if (val == null && nullValueHandling == NullValueHandling.Ignore)
                {
                    _values.Add(item);
                }
                else if (val == null && nullValueHandling == NullValueHandling.Remove)
                {
                    continue;
                }
                else
                {
                    Add(name, val, isEncoded, nullValueHandling);
                }
            }

            // add the rest to the end
            while (values.Any())
            {
                Add(name, values.Dequeue(), isEncoded, nullValueHandling);
            }
        }
Beispiel #2
0
        public static void Reload(Transaction trans, params string[] fields)
        {
            lock (Singleton)
            {
                if (_buf == null)
                {
                    _buf = new NameValueList();
                }

                Command cmd = new Command(string.Format("select * from {0}", EnsuredTableName));
                if (fields.Length > 0)
                {
                    Builder.AppendWhere(
                        cmd,
                        new Compare(KeyFieldName, fields as object[]).ToWhere(),
                        KeyFieldName, DbProvider.Adapter
                        );
                }
                else
                {
                    _buf.Clear();
                }

                NameValueList _old_buf = _buf;
                _buf = new NameValueList();
                (Singleton as DbConfiguration <T>).Initialize();
                foreach (var i in _buf)
                {
                    if (!_old_buf.ContainsKey(i.Name))
                    {
                        _old_buf.Add(i);
                    }
                }
                _buf = _old_buf;

                NameValueList[] res = cmd.Execute(trans);
                foreach (var nv in res)
                {
                    try
                    {
                        _buf.Add(
                            nv.Get <string>(KeyFieldName),
                            Burst.Utils.DeserializeAs(
                                nv.Get <object>(ValueFieldName),
                                Type.GetType(nv.Get <string>(TypeFieldName)),
                                SerializeType
                                )
                            );
                    }
                    catch { }
                }
            }
        }
        private void _forest_ForestGrowComplete(object sender, EventArgs e)
        {
            Progress            = 100;
            IsBtnGenerateEnable = true;
            IsBtnResolveEnable  = true;

            App.Current.Dispatcher.Invoke(() => { NameValueList.Clear(); });
            IItemNumerical item  = _forest.CreateItem();
            var            names = _forest.GetFeatureNames();

            foreach (var name in names)
            {
                if (name == ResolutionFeatureName)
                {
                    continue;
                }
                App.Current.Dispatcher.Invoke(() =>
                {
                    NameValueList.Add(new NameValue {
                        Name = name, Value = 0
                    });
                });
            }
        }