public StateItem Add(string key, object value)
 {
     if (string.IsNullOrEmpty(key))
     {
         throw ExceptionUtil.ParameterNullOrEmpty("key");
     }
     StateItem item = this.bag[key] as StateItem;
     if (item == null)
     {
         if ((value != null) || this.marked)
         {
             item = new StateItem(value);
             this.bag.Add(key, item);
         }
     }
     else if ((value == null) && !this.marked)
     {
         this.bag.Remove(key);
     }
     else
     {
         item.Value = value;
     }
     if ((item != null) && this.marked)
     {
         item.IsDirty = true;
     }
     return item;
 }
Example #2
0
        public StateItem Add(string key, object value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw ExceptionUtil.ParameterNullOrEmpty("key");
            }
            StateItem item = this.bag[key] as StateItem;

            if (item == null)
            {
                if ((value != null) || this.marked)
                {
                    item = new StateItem(value);
                    this.bag.Add(key, item);
                }
            }
            else if ((value == null) && !this.marked)
            {
                this.bag.Remove(key);
            }
            else
            {
                item.Value = value;
            }
            if ((item != null) && this.marked)
            {
                item.IsDirty = true;
            }
            return(item);
        }
Example #3
0
        /*
         * Return object containing state that has been modified since "mark".
         * Returns null if there is no modified state.
         */
        /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.SaveViewState"]/*' />
        /// <devdoc>
        ///    <para>Returns an object that contains all state changes for items stored in the
        ///    <see langword='StateBag'/> object.</para>
        /// </devdoc>
        internal object SaveViewState()
        {
            ArrayList changedKeys   = null;
            ArrayList changedValues = null;

            if (bag.Count != 0)
            {
                IDictionaryEnumerator e = bag.GetEnumerator();
                while (e.MoveNext())
                {
                    StateItem item = (StateItem)(e.Value);
                    if (item.IsDirty)
                    {
                        if (changedKeys == null)
                        {
                            changedKeys   = new ArrayList(5);
                            changedValues = new ArrayList(5);
                        }

                        changedKeys.Add(e.Key);
                        changedValues.Add(item.Value);
                    }
                }

                if (changedKeys != null)
                {
                    return(new Pair(changedKeys, changedValues));
                }
            }

            return(null);
        }
Example #4
0
        /*
         * Add a new StateItem or update an existing StateItem in the bag.
         */
        /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.Add"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public StateItem Add(string key, object value)
        {
            if (key == null || key.Length == 0)
            {
                throw new ArgumentException(HttpRuntime.FormatResourceString(SR.Key_Cannot_Be_Null));
            }

            StateItem item = bag[key] as StateItem;

            if (item == null)
            {
                if (value != null || marked)
                {
                    item = new StateItem(value);
                    bag.Add(key, item);
                }
            }
            else
            {
                if (value == null && !marked)
                {
                    bag.Remove(key);
                }
                else
                {
                    item.Value = value;
                }
            }
            if (item != null && marked)
            {
                item.IsDirty = true;
            }
            return(item);
        }
Example #5
0
        /*
         * Return object containing state that has been modified since "mark".
         * Returns null if there is no modified state.
         */

        /// <devdoc>
        ///    <para>Returns an object that contains all state changes for items stored in the
        ///    <see langword='StateBag'/> object.</para>
        /// </devdoc>
        internal object SaveViewState()
        {
            ArrayList data = null;

            //

            if (bag.Count != 0)
            {
                IDictionaryEnumerator e = bag.GetEnumerator();
                while (e.MoveNext())
                {
                    StateItem item = (StateItem)(e.Value);
                    if (item.IsDirty)
                    {
                        if (data == null)
                        {
                            data = new ArrayList();
                        }
#if OBJECTSTATEFORMATTER
                        data.Add(new IndexedString((string)e.Key));
#else
                        data.Add(e.Key);
#endif
                        data.Add(item.Value);
                    }
                }
            }

            return(data);
        }
Example #6
0
 public void SetDirty(bool dirty)
 {
     foreach (DictionaryEntry de in ht)
     {
         StateItem si = (StateItem)de.Value;
         si.IsDirty = dirty;
     }
 }
Example #7
0
        public void SetItemDirty(string key, bool dirty)
        {
            StateItem si = (StateItem)ht [key];

            if (si != null)
            {
                si.IsDirty = dirty;
            }
        }
Example #8
0
        /*
         * Internal method for setting dirty flag on a state item.
         * Used internallly to prevent state management of certain properties.
         */
        /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.SetItemDirty"]/*' />
        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        public void SetItemDirty(string key, bool dirty)
        {
            StateItem item = bag[key] as StateItem;

            if (item != null)
            {
                item.IsDirty = dirty;
            }
        }
Example #9
0
        /*
         * Return the dirty flag of the state item.
         * Returns false if there is not an item for given key.
         */
        /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.IsItemDirty"]/*' />
        /// <devdoc>
        /// <para>Checks an item stored in the <see langword='StateBag'/> to see if it has been
        ///    modified.</para>
        /// </devdoc>
        public bool IsItemDirty(string key)
        {
            StateItem item = bag[key] as StateItem;

            if (item != null)
            {
                return(item.IsDirty);
            }

            return(false);
        }
Example #10
0
        public StateItem Add(string key, object value)
        {
            StateItem si = ht [key] as StateItem;

            if (si == null)
            {
                ht [key] = si = new StateItem(value);
            }
            si.Value    = value;
            si.IsDirty |= track;

            return(si);
        }
Example #11
0
        /*
         * Get or set value of a StateItem.
         * A set will automatically add a new StateItem for a
         * key which is not already in the bag.  A set to null
         * will remove the item if set before mark, otherwise
         * a null set will be saved to allow tracking of state
         * removed after mark.
         */
        /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.this"]/*' />
        /// <devdoc>
        ///    <para> Indicates the value of an item stored in the
        ///    <see langword='StateBag'/>
        ///    object. Setting this property with a key not already stored in the StateBag will
        ///    add an item to the bag. If you set this property to <see langword='null'/> before
        ///    the TrackState method is called on an item will remove it from the bag. Otherwise,
        ///    when you set this property to <see langword='null'/>
        ///    the key will be saved to allow tracking of the item's state.</para>
        /// </devdoc>
        public object this[string key] {
            get {
                if (key == null || key.Length == 0)
                {
                    throw new ArgumentException(HttpRuntime.FormatResourceString(SR.Key_Cannot_Be_Null));
                }

                StateItem item = bag[key] as StateItem;
                if (item != null)
                {
                    return(item.Value);
                }
                return(null);
            }
            set {
                Add(key, value);
            }
        }
Example #12
0
        /*
         * Get or set value of a StateItem.
         * A set will automatically add a new StateItem for a
         * key which is not already in the bag.  A set to null
         * will remove the item if set before mark, otherwise
         * a null set will be saved to allow tracking of state
         * removed after mark.
         */

        /// <devdoc>
        ///    <para> Indicates the value of an item stored in the
        ///    <see langword='StateBag'/>
        ///    object. Setting this property with a key not already stored in the StateBag will
        ///    add an item to the bag. If you set this property to <see langword='null'/> before
        ///    the TrackState method is called on an item will remove it from the bag. Otherwise,
        ///    when you set this property to <see langword='null'/>
        ///    the key will be saved to allow tracking of the item's state.</para>
        /// </devdoc>
        public object this[string key] {
            get {
                if (String.IsNullOrEmpty(key))
                {
                    throw ExceptionUtil.ParameterNullOrEmpty("key");
                }

                StateItem item = bag[key] as StateItem;
                if (item != null)
                {
                    return(item.Value);
                }
                return(null);
            }
            set {
                Add(key, value);
            }
        }
Example #13
0
        internal object SaveViewState()
        {
            Hashtable h = null;

            foreach (DictionaryEntry de in ht)
            {
                StateItem si = (StateItem)de.Value;
                if (si.IsDirty)
                {
                    if (h == null)
                    {
                        h = new Hashtable();
                    }
                    h.Add(de.Key, si.Value);
                }
            }

            return(h);
        }
Example #14
0
 public void AddAttributes(HtmlTextWriter writer)
 {
     if (this._bag.Count > 0)
     {
         IDictionaryEnumerator enumerator = this._bag.GetEnumerator();
         while (enumerator.MoveNext())
         {
             StateItem item = enumerator.Value as StateItem;
             if (item != null)
             {
                 string str = item.Value as string;
                 string key = enumerator.Key as string;
                 if ((key != null) && (str != null))
                 {
                     writer.AddAttribute(key, str, true);
                 }
             }
         }
     }
 }
Example #15
0
        public object this [string key] {
            get {
                StateItem i = ht [key] as StateItem;
                if (i != null)
                {
                    return(i.Value);
                }
                return(null);
            }

            set {
                if (value == null && !IsTrackingViewState)
                {
                    Remove(key);
                }
                else
                {
                    Add(key, value);
                }
            }
        }
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void AddAttributes(HtmlTextWriter writer)
        {
            if (_bag.Count > 0)
            {
                IDictionaryEnumerator e = _bag.GetEnumerator();

                while (e.MoveNext())
                {
                    StateItem item = e.Value as StateItem;
                    if (item != null)
                    {
                        string value = item.Value as string;
                        string key   = e.Key as string;
                        if (key != null && value != null)
                        {
                            writer.AddAttribute(key, value, true /*fEncode*/);
                        }
                    }
                }
            }
        }
Example #17
0
        internal object SaveViewState()
        {
            ArrayList list = null;

            if (this.bag.Count != 0)
            {
                IDictionaryEnumerator enumerator = this.bag.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    StateItem item = (StateItem)enumerator.Value;
                    if (item.IsDirty)
                    {
                        if (list == null)
                        {
                            list = new ArrayList();
                        }
                        list.Add(new IndexedString((string)enumerator.Key));
                        list.Add(item.Value);
                    }
                }
            }
            return(list);
        }
Example #18
0
        /*
         * Add a new StateItem or update an existing StateItem in the bag.
         */

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public StateItem Add(string key,object value) {

            if (String.IsNullOrEmpty(key))
                throw ExceptionUtil.ParameterNullOrEmpty("key");
              
            StateItem item = bag[key] as StateItem;

            if (item == null) {
                if (value != null || marked) {
                    item = new StateItem(value);
                    bag.Add(key,item);
                }
            }
            else {
                if (value == null && !marked) {
                    bag.Remove(key);
                }
                else {
                    item.Value = value;
                }
            }
            if (item != null && marked) {
                item.IsDirty = true;
            }
            return item;
        }
Example #19
0
		public StateItem Add (string key, object value)
		{
			if (key == null || key.Length == 0)
				throw new ArgumentException (HttpRuntime.FormatResourceString ("Key_Cannot_Be_Null"));

			StateItem val = bag [key] as StateItem; //don't throw exception when null
			if(val == null) {
				if(value != null || marked) {
					val = new StateItem (value);
					bag.Add (key, val);
				}
			}
			else if (value == null && !marked)
				bag.Remove (key);
			else
				val.Value = value;

			if (val != null && marked) {
				val.IsDirty = true;
			}

			return val;
		}
Example #20
0
		public void FixtureSetup ()
		{
			item = new StateBag ().Add ("key", "value");
		}
Example #21
0
        public bool IsItemDirty(string key)
        {
            StateItem si = ht [key] as StateItem;

            return(si != null && si.IsDirty);
        }
Example #22
0
        public bool IsItemDirty(string key)
        {
            StateItem item = this.bag[key] as StateItem;

            return((item != null) && item.IsDirty);
        }
Example #23
0
    public string ToString(string preserve, string removeList, System.Web.UI.StateBag viewState)
    {
        HttpRequest       Request = HttpContext.Current.Request;
        HttpServerUtility Server  = HttpContext.Current.Server;

        string[] List;

        if (removeList == "")
        {
            List = new string[1];
        }
        else
        {
            List = removeList.Split(new Char[] { ';' });
        }

        if (preserve == "All" || preserve == "GET")
        {
            if (viewState != null)
            {
                int      length = viewState.Count;
                string[] keys   = new string[length];
                System.Web.UI.StateItem[] values = new System.Web.UI.StateItem[length];
                viewState.Keys.CopyTo(keys, 0);
                viewState.Values.CopyTo(values, 0);
                string cvalue = "";
                for (int i = 0; i < length; i++)
                {
                    if (values[i].Value != null)
                    {
                        cvalue = values[i].Value.ToString();
                    }
                    else
                    {
                        cvalue = "";
                    }
                    string ckey = "";
                    if (keys[i].EndsWith("SortField") && cvalue != "Default")
                    {
                        ckey = keys[i].Replace("SortField", "Order");
                    }
                    if (keys[i].EndsWith("SortDir"))
                    {
                        ckey = keys[i].Replace("SortDir", "Dir");
                    }
                    if (keys[i].EndsWith("PageNumber") && cvalue != "1")
                    {
                        ckey = keys[i].Replace("PageNumber", "Page");
                    }
                    if (ckey != "" && Array.IndexOf(List, ckey) < 0)
                    {
                        if (this[ckey] == null)
                        {
                            Add(ckey, cvalue);
                        }
                        else
                        {
                            this[ckey] = cvalue;
                        }
                    }
                }
            }
            for (int i = 0; i < Request.QueryString.Count; i++)
            {
                if (Array.IndexOf(List, Request.QueryString.AllKeys[i]) < 0 && BaseGet(Request.QueryString.AllKeys[i]) == null)
                {
                    foreach (string val in Request.QueryString.GetValues(i))
                    {
                        Add(Request.QueryString.AllKeys[i], Server.UrlEncode(val));
                    }
                }
            }
        }
        if (preserve == "All" || preserve == "POST")
        {
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Array.IndexOf(List, Request.Form.AllKeys[i]) < 0 &&
                    Request.Form.AllKeys[i] != "__EVENTTARGET" &&
                    Request.Form.AllKeys[i] != "__EVENTARGUMENT" &&
                    Request.Form.AllKeys[i] != "__VIEWSTATE" &&
                    BaseGet(Request.Form.AllKeys[i]) == null)
                {
                    foreach (string val in Request.Form.GetValues(i))
                    {
                        Add(Request.Form.AllKeys[i], Server.UrlEncode(val));
                    }
                }
            }
        }

        return(ToString(""));
    }
		public StateItem Add (string key, object value)
		{
			StateItem si = ht [key] as StateItem;
			if (si == null)
				ht [key] = si = new StateItem (value);
			si.Value = value;
			si.IsDirty |= track;
			
			return si;
		}