コード例 #1
0
        /// <summary>
        /// Trả về byte[] chứa content, việc chuyển đổi về kiểu dữ liệu dùng được thì cần phải làm ở bước bên ngoài
        /// </summary>
        /// <param name="notificationid">ID  của Notification</param>
        /// <returns></returns>
        private static async Task <byte[]> GetNotificationContentAsync(long notificationid)
        {
            var ServerName = LocalSettings.LocalSettingsManager.ServerIP;
            var PortName   = LocalSettings.LocalSettingsManager.RNSClientPort;

            UWPTCPClient.UWPTCPClient client = new UWPTCPClient.UWPTCPClient(ServerName, PortName);

            if (await client.ConnectAsync())
            {
                UWPTCPClient.SendAndReceiveResult result = await client.SendAndRecieveAsync(
                    _FromClientPacketConverter.ObjectToBytes(
                        new SharedModels.NetworkPackets.FromClient.FromClientPacket(
                            SharedModels.NetworkPackets.FromClient.FromClientPacketType.GetNotificationContent,
                            new SharedModels.NetworkPackets.FromClient.GetNotificationContentPacketData(notificationid))));

                if (result.IsSuccess)
                {
                    return(_FromServerPacketConverter.BytesToObject(result.Data).Data);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Lỗi khi liên lạc vs server");
                    return(null);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Lỗi kết nối");
                return(null);
            }
        }
コード例 #2
0
        public static async void SendURI()
        {
            var ServerName = LocalSettings.LocalSettingsManager.ServerIP;
            var PortName   = LocalSettings.LocalSettingsManager.RNSClientPort;
            var DeviceID   = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation().Id.ToString();
            PushNotificationChannel chanel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

            System.Diagnostics.Debug.WriteLine(chanel.Uri);
            System.Diagnostics.Debug.WriteLine(DeviceID);
            if (chanel.Uri == null)
            {
                return;
            }
            UWPTCPClient.UWPTCPClient client = new UWPTCPClient.UWPTCPClient(ServerName, PortName);
            try
            {
                await client.ConnectAsync();
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("connect lỗi");
                return;
            }


            UWPTCPClient.SendAndReceiveResult Result = await client.SendAndRecieveAsync(_FromClientPacketConverter.ObjectToBytes(
                                                                                            new SharedModels.NetworkPackets.FromClient.FromClientPacket(
                                                                                                SharedModels.NetworkPackets.FromClient.FromClientPacketType.Register,
                                                                                                new SharedModels.NetworkPackets.FromClient.RegisterPacketData(DeviceID,
                                                                                                                                                              chanel.Uri, SharedModels.NetworkPackets.OperatingSystemIDTemplates.Windows10,
                                                                                                                                                              LocalSettings.LocalSettingsManager.UserName
                                                                                                                                                              ))));

            if (Result.IsSuccess)
            {
                if (_FromServerPacketConverter.BytesToObject(Result.Data).ResultType == SharedModels.NetworkPackets.FromServer.ServerResult.Success)
                {
                    System.Diagnostics.Debug.WriteLine("ok");
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("ko register được");
                }
            }
        }
コード例 #3
0
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            if (!await Client.ConnectAsync())
            {
                await new MessageDialog("Kết nối tới login server thất bại").ShowAsync();
                //return;
            }
            var result = await Client.SendAndRecieveAsync(
                _FromClientConverter.ObjectToBytes(
                    new ClientNetworkPacketSharedModels.FromClient.FromClientPacket
                    (
                        ClientNetworkPacketSharedModels.FromClient.FromClientPacketType.Login,
                        new ClientNetworkPacketSharedModels.FromClient.FCLoginPacketData(txt_UserName.Text, txt_Pasword.Text)
                    )));

            if (result.IsSuccess)
            {
                await new MessageDialog("Đăng nhập thành công").ShowAsync();
                var FromserverPacket = _FromLoginServerConverter.BytesToObject(result.Data);
                var PacketData       = FromserverPacket.Data as ClientNetworkPacketSharedModels.FromServer.FSLoginPacketData;
                ClientHelper.RegisterUserNameWithRNS(PacketData.OldID);
                System.Diagnostics.Debug.WriteLine("register done");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Đăng nhập thất bại");
            }

            PushNotificationChannel chanel = await Notification_Helper_Client.Normal_Task.getChanel();

            System.Diagnostics.Debug.WriteLine(chanel.Uri);
            System.Diagnostics.Debug.WriteLine(Notification_Helper_Client.Device.ID);
            if (chanel.Uri == null)
            {
                return;
            }
            chanel.PushNotificationReceived += Chanel_PushNotificationReceived;
            txt_URI.Text = chanel.Uri;
        }