⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statemanager.cs

📁 ajax patterns 这是关于ajax设计模式方面的原代码
💻 CS
字号:
/*
    Copyright 2006 Christian Gross http://www.devspace.com
    From the book Ajax Patterns and Best Practices

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Web;
using System.Collections.Generic;
using Devspace.Commons.Tracer;
using System.Collections;

namespace Devspace.Ajax.StateNavigation {
    public class State {
        public State() { }
        public State( string stateIdentifier) {
            _stateIdentifier = stateIdentifier;
        }
        public State( String stateIdentifier, String buffer) {
            _buffer = buffer;
            _stateIdentifier = stateIdentifier;
        }
        
        private string _URL;
        public virtual string URL {
            get {
                return _URL;
            }
            set {
                _URL = value;
            }
        }
        
        private string _windowName;
        public virtual string WindowName {
            get {
                return _windowName;
            }
            set {
                _windowName = value;
            }
        }
        
        private string _buffer;
        public virtual string Buffer {
            get {
                return _buffer;
            }
            set {
                _buffer = value;
            }
        }
        
        private string _stateIdentifier;
        public virtual string StateIdentifier {
            get {
                return _stateIdentifier;
            }
            set {
                _stateIdentifier = value;
            }
        }
        public override string ToString() {
            return "URL (" + _URL + ") WindowName (" + _windowName + ") StateIdentifier (" + _stateIdentifier + ") Buffer (" + _buffer + ")";
        }
    }
    
    public class StateManager {
        private ArrayList _stateArray = new ArrayList();
        public StateManager() { }
        public State GetState(String stateIdentifier) {
            GenerateOutput.Write( "StateManager.GetState", "Retrieve state identifier (" + stateIdentifier + ")");
            foreach( State state in _stateArray) {
                if( state.StateIdentifier == stateIdentifier) {
                    GenerateOutput.Write( "StateManager.GetState", "returning state (" + state.ToString() + ")");
                    return state;
                }
            }
            GenerateOutput.Write( "StateManager.GetState", "Nothing could be found, creating new state");
            State newState;
            if( stateIdentifier == "none") {
                newState = new State( Convert.ToString( _stateArray.Count + 10));
            }
            else {
                newState = new State( stateIdentifier);
            }
            _stateArray.Add( newState);
            GenerateOutput.Write( "StateManager.GetState", "returning state (" + newState.ToString() + ")");
            return newState;
        }
        
        public State CopyState(String stateIdentifier) {
            GenerateOutput.Write( "StateManager.CopyState", "Copy state identifier (" + stateIdentifier + ")");
            State state = GetState(stateIdentifier);
            State copiedState = new State( Convert.ToString( _stateArray.Count + 10), state.Buffer);
            _stateArray.Add( copiedState);
            return copiedState;
        }
        
        public void SetState(State state) {
            _stateArray.Add(state);
        }
        
        public void SetState(String hashcode, String buffer) {
            State state = GetState(hashcode);
            state.Buffer = buffer;
        }
        
        public State GetEmptyState() {
            State state = new State();
            state.StateIdentifier = Convert.ToString( _stateArray.Count + 10);
            _stateArray.Add( state);
            return state;
        }
        
        public State GetEmptyState(String url, String windowName) {
            throw new Exception ("Ooops should not be calling GetEmptyState");
        }
        public State CopyState(String stateIdentifier, String url, String windowName) {
            throw new Exception ("Ooops should not be calling CopyState");
            
        }
        public State[] GetStateWindowName(String windowName) {
            throw new Exception ("Ooops should not be calling GetStateWindowName");
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -