Click here to Skip to main content
15,895,798 members
Articles / Programming Languages / C# 4.0

Cache System in Silverlight 5 RIA Application - Part 1 - Data Load

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
4 Nov 2012CPOL2 min read 10.2K   78   8  
An effective way to implement a caching system in Silverlight (MVVM) RIA
//------------------------------------------------------------------------------
// <auto-generated>
//     Il codice è stato generato da uno strumento.
//     Versione runtime:4.0.30319.17929
//
//     Le modifiche apportate a questo file possono provocare un comportamento non corretto e andranno perse se
//     il codice viene rigenerato.
// </auto-generated>
//------------------------------------------------------------------------------

// 
// This code was auto-generated by Microsoft.Silverlight.ServiceReference, version 5.0.61118.0
// 
namespace SilverlightClient.LoginService {
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="LoginService.ILogin")]
    public interface ILogin {
        
        [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/ILogin/UserLogin", ReplyAction="http://tempuri.org/ILogin/UserLoginResponse")]
        System.IAsyncResult BeginUserLogin(string username, string password, System.AsyncCallback callback, object asyncState);
        
        PortableLibrary.UserContext EndUserLogin(System.IAsyncResult result);
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface ILoginChannel : SilverlightClient.LoginService.ILogin, System.ServiceModel.IClientChannel {
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class UserLoginCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
        
        private object[] results;
        
        public UserLoginCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
                base(exception, cancelled, userState) {
            this.results = results;
        }
        
        public PortableLibrary.UserContext Result {
            get {
                base.RaiseExceptionIfNecessary();
                return ((PortableLibrary.UserContext)(this.results[0]));
            }
        }
    }
    
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class LoginClient : System.ServiceModel.ClientBase<SilverlightClient.LoginService.ILogin>, SilverlightClient.LoginService.ILogin {
        
        private BeginOperationDelegate onBeginUserLoginDelegate;
        
        private EndOperationDelegate onEndUserLoginDelegate;
        
        private System.Threading.SendOrPostCallback onUserLoginCompletedDelegate;
        
        private BeginOperationDelegate onBeginOpenDelegate;
        
        private EndOperationDelegate onEndOpenDelegate;
        
        private System.Threading.SendOrPostCallback onOpenCompletedDelegate;
        
        private BeginOperationDelegate onBeginCloseDelegate;
        
        private EndOperationDelegate onEndCloseDelegate;
        
        private System.Threading.SendOrPostCallback onCloseCompletedDelegate;
        
        public LoginClient() {
        }
        
        public LoginClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }
        
        public LoginClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public LoginClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }
        
        public LoginClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }
        
        public System.Net.CookieContainer CookieContainer {
            get {
                System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
                if ((httpCookieContainerManager != null)) {
                    return httpCookieContainerManager.CookieContainer;
                }
                else {
                    return null;
                }
            }
            set {
                System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
                if ((httpCookieContainerManager != null)) {
                    httpCookieContainerManager.CookieContainer = value;
                }
                else {
                    throw new System.InvalidOperationException("Impossibile impostare CookieContainer. Verificare che il binding contenga un elem" +
                            "ento HttpCookieContainerBindingElement.");
                }
            }
        }
        
        public event System.EventHandler<UserLoginCompletedEventArgs> UserLoginCompleted;
        
        public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> OpenCompleted;
        
        public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> CloseCompleted;
        
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        System.IAsyncResult SilverlightClient.LoginService.ILogin.BeginUserLogin(string username, string password, System.AsyncCallback callback, object asyncState) {
            return base.Channel.BeginUserLogin(username, password, callback, asyncState);
        }
        
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        PortableLibrary.UserContext SilverlightClient.LoginService.ILogin.EndUserLogin(System.IAsyncResult result) {
            return base.Channel.EndUserLogin(result);
        }
        
        private System.IAsyncResult OnBeginUserLogin(object[] inValues, System.AsyncCallback callback, object asyncState) {
            string username = ((string)(inValues[0]));
            string password = ((string)(inValues[1]));
            return ((SilverlightClient.LoginService.ILogin)(this)).BeginUserLogin(username, password, callback, asyncState);
        }
        
        private object[] OnEndUserLogin(System.IAsyncResult result) {
            PortableLibrary.UserContext retVal = ((SilverlightClient.LoginService.ILogin)(this)).EndUserLogin(result);
            return new object[] {
                    retVal};
        }
        
        private void OnUserLoginCompleted(object state) {
            if ((this.UserLoginCompleted != null)) {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.UserLoginCompleted(this, new UserLoginCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }
        
        public void UserLoginAsync(string username, string password) {
            this.UserLoginAsync(username, password, null);
        }
        
        public void UserLoginAsync(string username, string password, object userState) {
            if ((this.onBeginUserLoginDelegate == null)) {
                this.onBeginUserLoginDelegate = new BeginOperationDelegate(this.OnBeginUserLogin);
            }
            if ((this.onEndUserLoginDelegate == null)) {
                this.onEndUserLoginDelegate = new EndOperationDelegate(this.OnEndUserLogin);
            }
            if ((this.onUserLoginCompletedDelegate == null)) {
                this.onUserLoginCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnUserLoginCompleted);
            }
            base.InvokeAsync(this.onBeginUserLoginDelegate, new object[] {
                        username,
                        password}, this.onEndUserLoginDelegate, this.onUserLoginCompletedDelegate, userState);
        }
        
        private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState) {
            return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
        }
        
        private object[] OnEndOpen(System.IAsyncResult result) {
            ((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result);
            return null;
        }
        
        private void OnOpenCompleted(object state) {
            if ((this.OpenCompleted != null)) {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
            }
        }
        
        public void OpenAsync() {
            this.OpenAsync(null);
        }
        
        public void OpenAsync(object userState) {
            if ((this.onBeginOpenDelegate == null)) {
                this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen);
            }
            if ((this.onEndOpenDelegate == null)) {
                this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen);
            }
            if ((this.onOpenCompletedDelegate == null)) {
                this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted);
            }
            base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
        }
        
        private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState) {
            return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
        }
        
        private object[] OnEndClose(System.IAsyncResult result) {
            ((System.ServiceModel.ICommunicationObject)(this)).EndClose(result);
            return null;
        }
        
        private void OnCloseCompleted(object state) {
            if ((this.CloseCompleted != null)) {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
            }
        }
        
        public void CloseAsync() {
            this.CloseAsync(null);
        }
        
        public void CloseAsync(object userState) {
            if ((this.onBeginCloseDelegate == null)) {
                this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose);
            }
            if ((this.onEndCloseDelegate == null)) {
                this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose);
            }
            if ((this.onCloseCompletedDelegate == null)) {
                this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted);
            }
            base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
        }
        
        protected override SilverlightClient.LoginService.ILogin CreateChannel() {
            return new LoginClientChannel(this);
        }
        
        private class LoginClientChannel : ChannelBase<SilverlightClient.LoginService.ILogin>, SilverlightClient.LoginService.ILogin {
            
            public LoginClientChannel(System.ServiceModel.ClientBase<SilverlightClient.LoginService.ILogin> client) : 
                    base(client) {
            }
            
            public System.IAsyncResult BeginUserLogin(string username, string password, System.AsyncCallback callback, object asyncState) {
                object[] _args = new object[2];
                _args[0] = username;
                _args[1] = password;
                System.IAsyncResult _result = base.BeginInvoke("UserLogin", _args, callback, asyncState);
                return _result;
            }
            
            public PortableLibrary.UserContext EndUserLogin(System.IAsyncResult result) {
                object[] _args = new object[0];
                PortableLibrary.UserContext _result = ((PortableLibrary.UserContext)(base.EndInvoke("UserLogin", _args, result)));
                return _result;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions