예제 #1
0
        public void Login(Action<LoginResult> endLogin, string server, int port, string userName, string password, Language language, string oldSessionId = null)
        {
            if (this._MessageClient == null)
            {
                this._MessageClient = new MessageClient();
            }

            EndpointAddress address = new EndpointAddress(string.Format("net.tcp://{0}:{1}/Service", server, port));
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None) { MaxReceivedMessageSize = Int32.MaxValue };
            DuplexChannelFactory<IClientService> factory = new DuplexChannelFactory<IClientService>(this._MessageClient, binding, address);
            this._ServiceProxy = factory.CreateChannel();
            this._ServiceProxy.BeginLogin(userName, password, oldSessionId, language, delegate(IAsyncResult ar)
            {
                LoginResult result = this._ServiceProxy.EndLogin(ar);
                if (result.Succeeded)
                {
                    this._SessionId = result.SessionId;
                    //this.GetAccessPermissions(this.EndGetPermissions);
                }
                endLogin(result);
            }, null);
        }
예제 #2
0
        public void Login(Action<LoginResult, string> endLogin, string server, int port, string userName, string password, Language language)
        {
            if (this._MessageClient == null)
            {
                this._MessageClient = new MessageClient();
            }

            this._Server = server;
            this._Port = port;
            this.CreateChannel();
            this._ServiceProxy.BeginLogin(userName, password, language, delegate(IAsyncResult ar)
            {
                try
                {
                    LoginResult result = this._ServiceProxy.EndLogin(ar);
                    this._User = result.User;
                    Principal.Instance.User = result.User;
                    if (result.Succeeded)
                    {
                        App.MainFrameWindow.StatusBar.ShowUserConnectionState(ConnectionState.Connected);
                        App.MainFrameWindow.StatusBar.ShowLoginUser(this._User.UserName);
                        this._IsLoggedIn = true;
                        ICommunicationObject communicationObject = this._ServiceProxy as ICommunicationObject;
                        communicationObject.Faulted += communicationObject_Faulted;
                        this._SessionId = result.SessionId;
                        if (this._User.IsAdmin)
                        {
                            Principal.Instance.UserPermission = new UserPermission();
                        }
                        else
                        {
                            this.GetAccessPermissions(this.EndGetPermissions);
                        }
                    }
                    endLogin(result, null);
                }
                catch (EndpointNotFoundException ex)
                {
                    endLogin(null, "Server not found: " + ex.Message);
                }
                catch (CommunicationException)
                {
                    endLogin(null, "Invalid user name or password.");
                }
                catch (Exception ex)
                {
                    endLogin(null, ex.Message);
                    Logger.TraceEvent(TraceEventType.Error, "Login failed: \r\n{0}", ex.Message);
                }
            }, null);
        }