コード例 #1
0
        public void ErrorService(ErrorReportTemplate errorReportTemplate)
        {
            if (errorReportTemplate != null)
            {
                switch (errorReportTemplate.ErrorType)
                {
                case ErrorType.Other:
                    this.NotifyUserByRowState(RowStateResourcesName.l_undefError, errorReportTemplate.Error.Message);
                    break;

                case ErrorType.UnCorrectServerResponse:
                    this.NotifyUserByRowState(RowStateResourcesName.l_uncorServerResponse);
                    break;

                case ErrorType.WrongLoginOrPassword:
                    this.NotifyUserByRowState(RowStateResourcesName.l_wrngLogOrPass);
                    break;

                case ErrorType.UserAlreadyRegistr:
                    this.NotifyUserByRowState(RowStateResourcesName.l_userAlrReg);
                    break;

                case ErrorType.NoConnectionWithServer:
                    this.NotifyUserByRowState(RowStateResourcesName.l_noConWithServer);
                    break;
                }
            }
            else
            {
                this.NotifyUserByRowState(RowStateResourcesName.l_uncorServerResponse);
            }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: Katran88/Katran_project
        static private void ErrorService(ErrorReportTemplate error)
        {
            switch (error.ErrorType)
            {
            case ErrorType.Other:
                MessageBox.Show(error.Error.Message);
                break;

            case ErrorType.WrongLoginOrPassword:
                MessageBox.Show("Wrong login or password");
                break;

            case ErrorType.UserAlreadyRegistr:
                MessageBox.Show("Login is already busy");
                break;
            }
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: Katran88/Katran_project
        public static RRTemplate ServerRequest(RRTemplate request)
        {
            try
            {
                client = new TcpClient();
                client.Connect(serverIP, serverPort);
                clientStream = client.GetStream();

                BinaryFormatter formatter = new BinaryFormatter();
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    formatter.Serialize(memoryStream, request);

                    clientStream.Write(memoryStream.GetBuffer(), 0, memoryStream.GetBuffer().Length);

                    switch (request.RRType) //если попадает в default, то будет ответ, если нет, то нет
                    {
                    case RRType.RefreshContacts:
                    case RRType.SearchOutContacts:
                    case RRType.UserDisconected:
                    case RRType.AddContact:
                    case RRType.RemoveContact:
                    case RRType.SendMessage:
                    case RRType.AddContactTarget:
                    case RRType.RemoveContactTarget:
                    case RRType.RefreshContactStatus:
                    case RRType.RefreshMessageState:
                    case RRType.CreateConv:
                    case RRType.RemoveConv:
                        clientStream.Close();
                        client.Close();
                        return(null);

                        break;

                    default:
                        memoryStream.Flush();
                        memoryStream.Position = 0;

                        do
                        {
                            byte[] buffer = new byte[256];
                            int    bytes;

                            bytes = clientStream.Read(buffer, 0, buffer.Length);
                            memoryStream.Write(buffer, 0, bytes);

                            buffer = new byte[256];
                        }while (clientStream.DataAvailable);

                        memoryStream.Position = 0;
                        RRTemplate serverResponse = formatter.Deserialize(memoryStream) as RRTemplate;

                        if (serverResponse != null)
                        {
                            switch (serverResponse.RRType)
                            {
                            case RRType.Authorization:
                            case RRType.RefreshUserData:
                                RegistrationTemplate reg = serverResponse.RRObject as RegistrationTemplate;         //RegistrationTemplate служит как шаблон для преднастройки приложения
                                if (reg != null)
                                {
                                    CreateAuthToken(reg);
                                    return(serverResponse);
                                }
                                break;

                            case RRType.DownloadFile:
                                DownloadFileTemplate dfileT = serverResponse.RRObject as DownloadFileTemplate;
                                if (dfileT != null)
                                {
                                    return(serverResponse);
                                }
                                break;

                            case RRType.AdminSearch:
                                AdminSearchTemplate admST = serverResponse.RRObject as AdminSearchTemplate;
                                if (admST != null)
                                {
                                    return(serverResponse);
                                }
                                break;

                            case RRType.BlockUnblockUser:
                                BlockUnblockUserTemplate blunblUT = serverResponse.RRObject as BlockUnblockUserTemplate;
                                if (blunblUT != null)
                                {
                                    return(serverResponse);
                                }
                                break;

                            case RRType.Error:
                                ErrorReportTemplate error = serverResponse.RRObject as ErrorReportTemplate;
                                if (error != null)
                                {
                                    return(new RRTemplate(RRType.Error, error));
                                }
                                break;

                            default:
                                return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.Other, new Exception("Unknown problem"))));

                                break;
                            }
                        }
                        else
                        {
                            return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.UnCorrectServerResponse, new Exception("Uncorrect server response"))));
                        }
                        break;
                    }
                }
                return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.Other, new Exception("Unknown problem"))));
            }
            catch (SocketException ex)
            {
                return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.NoConnectionWithServer, ex)));
            }
            catch (Exception ex)
            {
                return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.Other, ex)));
            }
        }