private void btnLogin_Click(object sender, EventArgs e)
        {
            _endpoint = new EndpointAddress(string.Format("net.tcp://{0}:{1}/DataServer_Service", txtHost.Text, numPort.Value));
            _context  = new InstanceContext(this);
            _client   = new WCFServiceClient(_context, _binding, _endpoint);

            try
            {
                txtLog.AppendText("Connecting..." + Environment.NewLine);
                var loginRequest = new LoginRequest {
                    Login = txtLogin.Text, Password = txtPassword.Text
                };
                _client.Login(loginRequest);
                txtLog.AppendText("Connected" + Environment.NewLine);
                _client.MessageIn(new DataFeedListRequest());
                EnabledControls(true);
                ScrollToEnd();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //_client.MessageIn(HistoryRequest
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            WCFServiceClient proxy = new WCFServiceClient("BasicHttpBinding_IWCFService");

            Console.WriteLine("Test call service using HTTP--------------------.");

            //实例化数据契约对象,设置信息
            UserDataContract user = new UserDataContract();

            user.UserName  = "******";
            user.UserEmail = "WCF Client: [email protected] ";
            user.Mobile    = "WCF Client:1666666666";

            proxy.AddNewUser(user);

            string           name  = "WCF Client: Frank Xu";
            UserDataContract user1 = proxy.GetUserByName(name);

            if (user1 != null)
            {
                Console.WriteLine(user1.UserName);
                Console.WriteLine(user1.UserEmail);
                Console.WriteLine(user1.Mobile);
            }

            //Debuging
            Console.WriteLine("Press any key to continue");
            Console.Read();
        }
 private void Initialize()
 {
     Logger.Info("Connector Initialize");
     _callbackObject = new CallbackObject(this);
     _context        = new InstanceContext(_callbackObject);
     _client         = new WCFServiceClient(_context, _binding, _endpoint);
 }
        private void DeInitialize()
        {
            Logger.Info("Connector Deinitialize");
            StopHeartBeat();

            try
            {
                if (_client != null)
                {
                    if (_client.State != CommunicationState.Faulted)
                    {
                        _client.Close();
                    }
                    else
                    {
                        _client.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("DeInitialize", ex);
            }
            _client = null;

            try
            {
                if (_context != null)
                {
                    if (_context.State != CommunicationState.Faulted)
                    {
                        try
                        {
                            _context.Close(TimeSpan.FromSeconds(5));
                        }
                        catch (TimeoutException ex)
                        {
                            Logger.Error("DeInitialize connector", ex);
                        }
                    }
                    else
                    {
                        _context.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("DeInitialize", ex);
            }
            _context = null;

            if (_callbackObject != null)
            {
                _callbackObject.Dispose();
            }

            _callbackObject = null;
        }
Exemplo n.º 5
0
Arquivo: Program.cs Projeto: zlgan/WCF
        static void Main(string[] args)
        {
            WCFServiceClient svc = new WCFServiceClient();

            Console.WriteLine(svc.GetData(666));

            Console.ReadKey();
        }
Exemplo n.º 6
0
        public ShopWindows(string Login, string Password)
        {
            this.Title = "Maets";
            string data1  = Environment.CurrentDirectory + "\\Content\\maets.cur";
            var    cursor = new System.Windows.Input.Cursor(data1);

            this.Cursor = cursor;
            this.Title  = "Maets";
            client      = new WCFServiceClient(new System.ServiceModel.InstanceContext(new CallbackClass(this)), "NetTcpBinding_IWCFService");

            client.Connect(Login, Password);
            profile = client.ActiveProfile(Login, Password);
            if (profile != null)
            {
                products  = client.GetProductTable().ToList();
                profilesq = client.GetAllUsers().ToList();
                InitializeComponent();
                Loaded += Window_Loaded;
                Onlyforadmin.Visibility = Visibility.Hidden;
                if (profile.AccessRight >= 3)
                {
                    productsmoderation = client.GetModerationProduct(profile.ID).ToList();
                    for (int i = 0; i < productsmoderation.Count; i++)
                    {
                        Moderationproduct.Items.Add(productsmoderation[i]);

                        // listuser.Items.Add(i);
                    }
                    Onlyforadmin.Visibility = Visibility.Visible;
                    //if(profile.AccessRight==4)
                    //{
                    //    listuser.ItemsSource = products;
                    //    for(idxg=1;idxg<5;idxg++)
                    //    {
                    //      // listrigth;
                    //    }
                    //}



                    if (profile.AccessRight >= 2)
                    {
                        AddGame.Visibility = Visibility.Visible;
                    }
                }
                foreach (Service.Product p in profile.Games.ToList())
                {
                    mylibrary.Items.Add(p);
                }
            }

            else
            {
                throw new Exception("Ошибка подключения");
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            WCFServiceClient serviceProxy = new WCFServiceClient("BasicHttpBinding_IWCFService");

            //WCF主要的目标是面向服务,平台无关,使用DataTable,DataSet来传递数据,客户端必须知道ADO.Net关于此类的定义信息,
            //这显然违背了面向服务编程的原则
            Console.WriteLine("from DataTable---");
            DataTable table = serviceProxy.GetDataByTable();

            if (table != null)
            {
                foreach (DataRow row in table.Rows)
                {
                    Console.WriteLine(row["func_name"].ToString());
                }
            }

            Console.WriteLine("from DataSet---");
            DataTable dt = serviceProxy.GetDataByDataSet().Tables[0];

            if (dt != null)
            {
                foreach (DataRow row in table.Rows)
                {
                    Console.WriteLine(row["func_name"].ToString());
                }
            }


            Console.WriteLine("from Collection---");
            //注意这里,服务端使用的List<User>,在客户端被封装成了对应类型的数组
            //WCF为集合类提供了专属的封装机制,客户端范序列化成与之对应类型的数组
            //开发时,推荐使用集合来传递数据
            Func[] funcList = serviceProxy.GetDataByCollection();
            if (funcList.Length > 0)
            {
                foreach (Func f in funcList)
                {
                    Console.WriteLine(f.Name);
                }
            }

            Console.Read();
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            /*
             * WCF规定客户端不能直接与服务交互,必须通过代理,代理公开的操作与服务一样,代理同时增加了对一些对服务管理的方法
             *
             * 服务寄宿的目的就是开启一个进程,为WCF服务提供一个运行的环境。
             */

            //创建服务代理对象(在添加对服务的引用时,自动生成)
            using (WCFServiceClient proxy = new WCFServiceClient())
            {
                //通过代理调用SayHello服务
                Console.WriteLine(proxy.SayHello("startcaft"));
                //通过代理调用SayHelloToUser服务,传递对象
                User user = new User();
                user.FirstName = "kai";
                user.LastName  = "Pi";
                Console.WriteLine(proxy.SayHelloToUser(user));

                Console.Read();
            }
        }
 public void Start()
 {
     _endpoint = new EndpointAddress(string.Format("net.tcp://{0}:{1}/DataServer_Service", dataserverip, dataserverport));
     _context  = new InstanceContext(this);
     _client   = new WCFServiceClient(_context, _binding, _endpoint);
     try
     {
         Console.WriteLine("Connecting to DataServer");
         Logger.Info("Connecting to DataServer");
         var loginRequest = new LoginRequest {
             Login = username, Password = password
         };
         _client.Login(loginRequest);
         Console.WriteLine("Connected to DataServer");
         Logger.Info("Connected to DataServer");
         _client.MessageIn(new DataFeedListRequest());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 10
0
 private void btnRegister_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (tbLogin.Text == "")
         {
             throw new Exception("Поле логин не может быть пустым");
         }
         if (tbMail.Text == "")
         {
             throw new Exception("Поле почта не может быть пустым");
         }
         if (tbPassword.Password == "")
         {
             throw new Exception("Поле пароль не может быть пустым");
         }
         if (tbPassword.Password != tbPassword2.Password)
         {
             throw new Exception("Пароли не совпадают");
         }
         WCFServiceClient client  = new WCFServiceClient(new System.ServiceModel.InstanceContext(new CallbackClass()), "NetTcpBinding_IWCFService");
         Service.Profile  profile = new Service.Profile();
         profile.Login = tbLogin.Text;
         profile.Mail  = tbMail.Text;
         string hashpassword = dp.HashPassword(tbPassword.Password);
         profile.AccessRight = 1;
         profile.Telephone   = tbTelephone.Text;
         profile.Name        = tbName.Text;
         MailConfirmation q = new MailConfirmation(profile, hashpassword);
         q.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 11
0
        void queueDownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            this.Width = Application.Current.Host.Content.ActualWidth;
            this.Height = Application.Current.Host.Content.ActualHeight;

            ImageButton faceList = new ImageButton() {
                TotalWidth = 162,
                TotalHeight = 27,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/18.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(42),
                TextStyle = Application.Current.Resources["TextStyle5"] as Style,
                TextHasEffect = false,
                TextBrush = new SolidColorBrush(Colors.Black),
            };
            this.Children.Add(faceList);
            Canvas.SetLeft(faceList, 15);
            Canvas.SetTop(faceList, 85);

            for (int i = 0; i < roleMax; i++) {
                roleList[i] = new ImageButton() {
                    Tag = "",
                    TotalWidth = 168,
                    TotalHeight = 54,
                    Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/4.png", UriType.Web), Stretch = Stretch.None },
                    TextStyle = Application.Current.Resources["TextStyle6"] as Style,
                    TextHasEffect = true,
                    TextEffectColor = Colors.Red,
                    TextBrush = new SolidColorBrush(Colors.White),
                    TextHoverBrush = new SolidColorBrush(Colors.Yellow),
                };
                this.Children.Add(roleList[i]);
                Canvas.SetLeft(roleList[i], 10);
                Canvas.SetTop(roleList[i], 120 + 56 * i);
                Canvas.SetZIndex(roleList[i], 3);
                roleList[0].Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/20.png", UriType.Web) };
                roleList[i].Click += (s1, e1) => {
                    ImageButton obj = s1 as ImageButton;
                    if (obj.Tag.ToString().Equals("")) { return; }
                    for (int j = 0; j <= roleList.GetUpperBound(0); j++) {
                        roleList[j].TextBrush = new SolidColorBrush(Colors.White);
                        roleList[j].Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/4.png", UriType.Web), };
                    }
                    obj.TextBrush = new SolidColorBrush(Color.FromArgb(255, 172, 255, 140));
                    obj.Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/20.png", UriType.Web), };

                    LoginManager.RoleName = obj.Tag.ToString();
                    ChangeRole(roles.Single(X => X.RoleName == LoginManager.RoleName));
                };
            }
            roleList[0].TextBrush = new SolidColorBrush(Color.FromArgb(255, 172, 255, 140));

            aura = new AnimationBase() { Code = 71, Loop = true, IsHitTestVisible = false, Position =new Point(258,380)  };
            this.Children.Add(aura);
            aura.HeartStart();

            this.Children.Add(roleModel);
            Canvas.SetLeft(roleModel, 220);
            Canvas.SetTop(roleModel, 100);

            Image roleData = new Image() { Source = GlobalMethod.GetImage("UI/19.png", UriType.Web), };
            this.Children.Add(roleData);
            Canvas.SetLeft(roleData, 582);
            Canvas.SetTop(roleData, 40);

            this.Children.Add(avatar);
            Canvas.SetLeft(avatar, 654);
            Canvas.SetTop(avatar, 70);

            TextBlock text0 = new TextBlock() { Text = GetLanguagePackContent(43), Style = Application.Current.Resources["TextStyle7"] as Style };
            TextBlock text1 = new TextBlock() { Text = GetLanguagePackContent(44), Style = Application.Current.Resources["TextStyle7"] as Style };
            TextBlock text2 = new TextBlock() { Text = GetLanguagePackContent(45), Style = Application.Current.Resources["TextStyle7"] as Style };
            TextBlock text3 = new TextBlock() { Text = GetLanguagePackContent(46), Style = Application.Current.Resources["TextStyle7"] as Style };
            TextBlock text4 = new TextBlock() { Text = GetLanguagePackContent(47), Style = Application.Current.Resources["TextStyle7"] as Style };
            TextBlock text5 = new TextBlock() { Text = GetLanguagePackContent(48), Style = Application.Current.Resources["TextStyle7"] as Style };
            TextBlock text6 = new TextBlock() { Text = GetLanguagePackContent(49), Style = Application.Current.Resources["TextStyle7"] as Style };
            this.Children.Add(text0); Canvas.SetLeft(text0, 680); Canvas.SetTop(text0, 158);
            this.Children.Add(text1); Canvas.SetLeft(text1, 645); Canvas.SetTop(text1, 192);
            this.Children.Add(text2); Canvas.SetLeft(text2, 714); Canvas.SetTop(text2, 192);
            this.Children.Add(text3); Canvas.SetLeft(text3, 680); Canvas.SetTop(text3, 226);
            this.Children.Add(text4); Canvas.SetLeft(text4, 680); Canvas.SetTop(text4, 258);
            this.Children.Add(text5); Canvas.SetLeft(text5, 670); Canvas.SetTop(text5, 292);
            this.Children.Add(text6); Canvas.SetLeft(text6, 658); Canvas.SetTop(text6, 326);

            Grid grid0 = new Grid() { Width = 130 }; this.Children.Add(grid0); Canvas.SetLeft(grid0, 626); Canvas.SetTop(grid0, 173);
            Grid grid1 = new Grid() { Width = 60 }; this.Children.Add(grid1); Canvas.SetLeft(grid1, 626); Canvas.SetTop(grid1, 207);
            Grid grid2 = new Grid() { Width = 60 }; this.Children.Add(grid2); Canvas.SetLeft(grid2, 694); Canvas.SetTop(grid2, 207);
            Grid grid3 = new Grid() { Width = 130 }; this.Children.Add(grid3); Canvas.SetLeft(grid3, 626); Canvas.SetTop(grid3, 241);
            Grid grid4 = new Grid() { Width = 130 }; this.Children.Add(grid4); Canvas.SetLeft(grid4, 626); Canvas.SetTop(grid4, 273);
            Grid grid5 = new Grid() { Width = 130 }; this.Children.Add(grid5); Canvas.SetLeft(grid5, 626); Canvas.SetTop(grid5, 307);
            Grid grid6 = new Grid() { Width = 130 }; this.Children.Add(grid6); Canvas.SetLeft(grid6, 626); Canvas.SetTop(grid6, 341);
            roleName = new TextBlock() { Style = Application.Current.Resources["TextStyle8"] as Style };
            occupation = new TextBlock() { Style = Application.Current.Resources["TextStyle8"] as Style };
            level = new TextBlock() { Style = Application.Current.Resources["TextStyle8"] as Style };
            experience = new TextBlock() { Style = Application.Current.Resources["TextStyle8"] as Style };
            map = new TextBlock() { Style = Application.Current.Resources["TextStyle8"] as Style };
            time = new TextBlock() { Style = Application.Current.Resources["TextStyle8"] as Style };
            ip = new TextBlock() { Style = Application.Current.Resources["TextStyle8"] as Style };
            grid0.Children.Add(roleName);
            grid1.Children.Add(occupation);
            grid2.Children.Add(level);
            grid3.Children.Add(experience);
            grid4.Children.Add(map);
            grid5.Children.Add(time);
            grid6.Children.Add(ip);

            ImageButton startGame = new ImageButton() {
                TotalWidth = 80,
                TotalHeight = 25,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/3.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(50),
                TextStyle = Application.Current.Resources["TextStyle1"] as Style,
                TextHasEffect = true,
                TextEffectColor = Colors.Black,
                TextBrush = new SolidColorBrush(Color.FromArgb(255, 48, 83, 96)),
                TextHoverBrush = new SolidColorBrush(Colors.White),
            };
            startGame.Click += (s1, e1) => {
                Dispose(this,null);
                if (GameStart != null) { GameStart(this, e1); }
            };
            ImageButton cannel = new ImageButton() {
                TotalWidth = 80,
                TotalHeight = 25,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/3.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(51),
                TextStyle = Application.Current.Resources["TextStyle1"] as Style,
                TextHasEffect = true,
                TextEffectColor = Colors.Black,
                TextBrush = new SolidColorBrush(Color.FromArgb(255, 48, 83, 96)),
                TextHoverBrush = new SolidColorBrush(Colors.White),
            };
            cannel.Click += (s1, e1) => {
                Dispose(this, null);
                if (Cannel != null) { Cannel(this, e1); }
            };
            ImageButton newRole = new ImageButton() {
                TotalWidth = 80,
                TotalHeight = 25,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/3.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(52),
                TextStyle = Application.Current.Resources["TextStyle1"] as Style,
                TextHasEffect = true,
                TextEffectColor = Colors.Black,
                TextBrush = new SolidColorBrush(Color.FromArgb(255, 48, 83, 96)),
                TextHoverBrush = new SolidColorBrush(Colors.White),
            };
            newRole.Click += (s1, e1) => {
                LoginManager.loading.Show();
                WCFServiceClient wcf1 = new WCFServiceClient();
                wcf1.GetUserRoleNumAsync(LoginManager.UserName);
                wcf1.GetUserRoleNumCompleted += (s2, e2) => {
                    if (e2.Result == 6) {
                        LoginManager.loginTip.Show(GetLanguagePackContent(53), LoginTipMode.TipOnly);
                        LoginManager.loading.Hide();
                    } else {
                        Dispose(this, null);
                        if (CreateRole != null) { CreateRole(this, e1); }
                    }
                    wcf1.CloseAsync();
                };
            };
            delRole = new ImageButton() {
                TotalWidth = 80,
                TotalHeight = 25,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/3.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(54),
                TextStyle = Application.Current.Resources["TextStyle1"] as Style,
                TextHasEffect = true,
                TextEffectColor = Colors.Black,
                TextBrush = new SolidColorBrush(Color.FromArgb(255, 48, 83, 96)),
                TextHoverBrush = new SolidColorBrush(Colors.White),
            };
            delRole.Click += (s1, e1) => {
                if (roles.Count() == 0) { return; }
                LoginManager.loginTip.Show(GetLanguagePackContent(59), LoginTipMode.ConfirmOrCannel);
                LoginManager.loginTip.OK += new MouseButtonEventHandler(dialog_OK);
            };
            this.Children.Add(startGame); Canvas.SetLeft(startGame, 650); Canvas.SetTop(startGame, 380);
            this.Children.Add(cannel); Canvas.SetLeft(cannel, 650); Canvas.SetTop(cannel, 415);
            this.Children.Add(newRole); Canvas.SetLeft(newRole, 650); Canvas.SetTop(newRole, 450);
            this.Children.Add(delRole); Canvas.SetLeft(delRole, 650); Canvas.SetTop(delRole, 485);

            base.OnResourceReady(this, e);
            LoadRoles(LoginManager.UserName);
        }
Exemplo n.º 12
0
 /// <summary>
 /// 加载该用户所有角色
 /// </summary>
 void LoadRoles(string userName)
 {
     LoginManager.loading.Show();
     WCFServiceClient wcfServiceClient = new WCFServiceClient();
     wcfServiceClient.GetRoleByUserNameAsync(userName);
     wcfServiceClient.GetRoleByUserNameCompleted += (s1, e1) => {
         int count = 0;
         roles.Clear();
         foreach (Role role in e1.Result) {
             roles.Add(role);
             roleList[count].Text = string.Format("{0}\r{1} {2} {3}", role.RoleName, ProfessionName((Professions)role.Occupation), role.RoleLevel, GetLanguagePackContent(55));
             roleList[count].Tag = role.RoleName;
             if (count == 0) {
                 LoginManager.RoleName = role.RoleName;
                 ChangeRole(role);
             }
             count++;
         }
         for (int i = count; i < roleMax; i++) {
             roleList[i].Text = "";
             roleList[count].Tag = "";
         }
         wcfServiceClient.CloseAsync();
         LoginManager.loading.Hide();
     };
 }
Exemplo n.º 13
0
 //删除角色
 void dialog_OK(object s, MouseButtonEventArgs e)
 {
     LoginManager.loginTip.OK -= dialog_OK;
     LoginManager.loading.Show();
     WCFServiceClient wcf2 = new WCFServiceClient();
     wcf2.DeleteRoleAsync(LoginManager.RoleName);
     wcf2.DeleteRoleCompleted += (s2, e2) => {
         if (e2.Result == 1) {
             LoginManager.loginTip.Show(string.Format("{0} {1}", LoginManager.RoleName, GetLanguagePackContent(41)), LoginTipMode.TipOnly);
             for (int i = 0; i <= roleList.GetUpperBound(0); i++) {
                 roleList[i].TextBrush = new SolidColorBrush(Colors.White);
                 roleList[i].Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/4.png", UriType.Web), };
             }
             roleList[0].TextBrush = new SolidColorBrush(Color.FromArgb(255, 172, 255, 140));
             roleList[0].Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/20.png", UriType.Web), };
             roleModel.Content = null;
             avatar.Source = null;
             roleName.Text = "";
             occupation.Text = "";
             level.Text = "";
             experience.Text = "";
             map.Text = "";
             time.Text = "";
             ip.Text = "";
             LoadRoles(LoginManager.UserName);
         } else {
             LoginManager.loginTip.Show(GetLanguagePackContent(60), LoginTipMode.TipOnly);
         }
         wcf2.CloseAsync();
         LoginManager.loading.Hide();
     };
 }
Exemplo n.º 14
0
        void queueDownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            this.Width = 910;
            this.Height = 590;

            ImageButton faceList = new ImageButton() {
                TotalWidth = 162,
                TotalHeight = 27,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/18.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(25),
                TextStyle = Application.Current.Resources["TextStyle5"] as Style,
                TextHasEffect = false,
                TextBrush = new SolidColorBrush(Colors.Black),
            };
            this.Children.Add(faceList);
            Canvas.SetLeft(faceList, 0);
            Canvas.SetTop(faceList, 85);

            avatarSelector = new AnimationBase() { Code = 70, Loop = true, Z = 10, IsHitTestVisible = false };
            this.Children.Add(avatarSelector);
            avatarSelector.HeartStart();

            for (int i = 0; i <= avatar.GetUpperBound(0); i++) {
                avatar[i] = new ImageButton() {
                    Code = i,
                    TotalWidth = 74,
                    TotalHeight = 74,
                    BodyHasEffect = true,
                    BodyEffectColor = Colors.Blue,
                };
                this.Children.Add(avatar[i]);
                Canvas.SetLeft(avatar[i], 40);
                Canvas.SetTop(avatar[i], 130 + i * 85);
                Canvas.SetZIndex(avatar[i], 3);
                avatar[i].MouseLeftButtonDown += (s1, e1) => {
                    ImageButton obj =s1 as ImageButton;
                    faceCode = obj.Code;
                    avatarSelector.Visibility = Visibility.Visible;
                    avatarSelector.IsVisible = true;
                    avatarSelector.Position = obj.Position;
                };
            }
            ShowSexFace(Sex.male);
            avatarSelector.Position = avatar[0].Position;

            light = new AnimationBase { Code = 72, Loop = true, Z = 4, IsHitTestVisible = false };
            this.Children.Add(light);
            light.HeartStart();
            light.Position = new Point(190, 75);

            this.Children.Add(maleModel);
            Canvas.SetLeft(maleModel, 80);
            Canvas.SetTop(maleModel, 120);
            maleModel.MouseLeftButtonDown += (s1, e1) => {
                //waiting.Show(); Canvas.SetLeft(waiting, -400); Canvas.SetTop(waiting, 100);
                ShowSexFace(Sex.male);
                ShowRoleModel(profession, Sex.male);
                light.Position = new Point(190, 75);
            };
            this.Children.Add(femaleModel);
            Canvas.SetLeft(femaleModel, 270);
            Canvas.SetTop(femaleModel, 120);
            ShowRoleModel(profession, Sex.male);
            femaleModel.MouseLeftButtonDown += (s1, e1) => {
                //waiting.Show(); Canvas.SetLeft(waiting, -200); Canvas.SetTop(waiting, 100);
                ShowSexFace(Sex.female);
                ShowRoleModel(profession, Sex.female);
                light.Position = new Point(385, 75);
            };

            for (int i = 0; i <= professionSelector.GetUpperBound(0); i++) {
                professionSelector[i] = new ImageButton() {
                    Tag = i,
                    TotalWidth = 153,
                    TotalHeight = 32,
                    Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/5.png", UriType.Web), Stretch = Stretch.None },
                    TextStyle = Application.Current.Resources["TextStyle3"] as Style,
                    TextHasEffect = true,
                    TextEffectColor = Colors.Red,
                    TextBrush = new SolidColorBrush(Colors.White),
                    TextHoverBrush = new SolidColorBrush(Colors.Yellow),
                    Z  = 3,
                };
                this.Children.Add(professionSelector[i]);
                professionSelector[i].Position = new Point(600, 70 + 50 * i);
                professionSelector[0].Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/9.png", UriType.Web) };
                professionSelector[i].Click += (s1, e1) => {
                    for (int j = 0; j <= professionSelector.GetUpperBound(0); j++) {
                        professionSelector[j].Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/5.png", UriType.Web) };
                    }
                    ImageButton obj = s1 as ImageButton;
                    obj.Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/9.png", UriType.Web) };
                    ShowRoleModel((Professions)obj.Tag, sex);
                };
            }
            professionSelector[0].Text = GetLanguagePackContent(28);
            professionSelector[1].Text = GetLanguagePackContent(27);
            professionSelector[2].Text = GetLanguagePackContent(26);
            professionSelector[3].Text = GetLanguagePackContent(29);

            Image descriptionHead = new Image() { Source = GlobalMethod.GetImage("UI/6.png", UriType.Web) };
            Grid descriptionBody = new Grid() {
                Width = 221,
                Height = 220,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/7.png", UriType.Web) }
            };
            descriptionBody.Children.Add(description);
            Image descriptionFoot = new Image() { Source = GlobalMethod.GetImage("UI/8.png", UriType.Web) };
            this.Children.Add(descriptionHead);
            this.Children.Add(descriptionFoot);
            this.Children.Add(descriptionBody);
            Canvas.SetLeft(descriptionHead, 570);
            Canvas.SetTop(descriptionHead, 280);
            Canvas.SetLeft(descriptionBody, 570);
            Canvas.SetTop(descriptionBody, 285);
            Canvas.SetLeft(descriptionFoot, 570);
            Canvas.SetTop(descriptionFoot, 455);

            TextBlock text0 = new TextBlock() { Text = GetLanguagePackContent(30), Foreground = new SolidColorBrush(Colors.White), FontSize = 18, FontWeight = FontWeights.SemiBold };
            this.Children.Add(text0);
            Canvas.SetLeft(text0, 200);
            Canvas.SetTop(text0, 545);
            TextBox roleName = new TextBox() { Width = 240, Background = new SolidColorBrush(Color.FromArgb(255, 57, 57, 57)), Style = Application.Current.Resources["TextStyle2"] as Style };
            this.Children.Add(roleName);
            Canvas.SetLeft(roleName, 285);
            Canvas.SetTop(roleName, 548);

            ImageButton createRole = new ImageButton() {
                TotalWidth = 80,
                TotalHeight = 25,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/3.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(31),
                TextStyle = Application.Current.Resources["TextStyle1"] as Style,
                TextHasEffect = true,
                TextEffectColor = Colors.Black,
                TextBrush = new SolidColorBrush(Color.FromArgb(255, 48, 83, 96)),
                TextHoverBrush = new SolidColorBrush(Colors.White),
            };
            this.Children.Add(createRole);
            Canvas.SetLeft(createRole, 550);
            Canvas.SetTop(createRole, 547);
            //创建角色
            createRole.MouseLeftButtonDown += (s1, e1) => {
                if (roleName.Text.Trim().Equals("") || roleName.Text.Trim().Length > 20) { LoginManager.loginTip.Show(GetLanguagePackContent(40), LoginTipMode.TipOnly); return; }
                LoginManager.loading.Show();
                WCFServiceClient wcfServiceClient = new WCFServiceClient();
                wcfServiceClient.CheckRoleExistAsync(roleName.Text.Trim());
                wcfServiceClient.CheckRoleExistCompleted += (s2, e2) => {
                    if (e2.Result == 0) {
                        wcfServiceClient.InsertRoleAsync(LoginManager.UserName, roleName.Text.Trim(), (byte)faceCode, (byte)sex, (byte)profession, 1, 0, 1, Application.Current.Host.InitParams["ClientIP"], "");
                        wcfServiceClient.InsertRoleCompleted += (s3, e3) => {
                            LoginManager.loading.Hide();
                            if (e3.Result != 0) {
                                LoginManager.loginTip.Show(string.Format("{0} {1}", roleName.Text.Trim(), GetLanguagePackContent(58)), LoginTipMode.TipOnly);
                                MouseButtonEventHandler handler = null;
                                LoginManager.loginTip.OK += handler = delegate {
                                    LoginManager.loginTip.OK -= handler;
                                    Dispose(this, null);
                                    if (RoleCreated != null) { RoleCreated(this, null); }
                                };
                                e1.Handled = true;
                            } else {
                                LoginManager.loginTip.Show(GetLanguagePackContent(38), LoginTipMode.TipOnly);
                            }
                        };
                    } else {
                        LoginManager.loading.Hide();
                        LoginManager.loginTip.Show(GetLanguagePackContent(39), LoginTipMode.TipOnly);
                    }
                    wcfServiceClient.CloseAsync();
                };
            };
            ImageButton cannel = new ImageButton() {
                TotalWidth = 80,
                TotalHeight = 25,
                Background = new ImageBrush() { ImageSource = GlobalMethod.GetImage("UI/3.png", UriType.Web), Stretch = Stretch.None },
                Text = GetLanguagePackContent(51),
                TextStyle = Application.Current.Resources["TextStyle1"] as Style,
                TextHasEffect = true,
                TextEffectColor = Colors.Black,
                TextBrush = new SolidColorBrush(Color.FromArgb(255, 48, 83, 96)),
                TextHoverBrush = new SolidColorBrush(Colors.White),
            };
            this.Children.Add(cannel);
            Canvas.SetLeft(cannel, 650);
            Canvas.SetTop(cannel, 547);
            cannel.Click += (s1, e1) => {
                Dispose(this, null);
                if (Cannel != null) {  Cannel(this, e1); }
            };
            base.OnResourceReady(this, e);
        }
Exemplo n.º 15
0
 //成功登陆后如果用户还未创建过任何角色则进入角色创建界面,否则进入角色选择界面
 void EnterRoleManager(object sender, MouseButtonEventArgs e)
 {
     this.Children.Remove(sender as WindowBase);
     WCFServiceClient wcfServiceClient = new WCFServiceClient();
     wcfServiceClient.GetUserRoleNumAsync(UserName);
     wcfServiceClient.GetUserRoleNumCompleted += (wcfs, wcfe) => {
         if (wcfe.Result == 0) {
             ShowCreateRole();
         } else {
             ShowSelectRole();
         }
         wcfServiceClient.CloseAsync();
     };
 }