コード例 #1
0
        private void receviedDisconnect(IPEndPoint recevied, String[] splits)
        {
            User user = new User(recevied.Address, "No Information", "Others");

            if (!UserList.Add(user))
            {
                user = UserList.Get(recevied.Address);
            }

            window.Dispatcher.Invoke((Action)(() =>
            {
                window.RemoveUserFromTree(user);
            }));
            if (UserList.xml[recevied.Address].UnreadMessages > 0)
            {
                window.Dispatcher.Invoke((Action)(() =>
                {
                    window.AddUserToOffile(user);
                }));
            }
            else
            {
                UserList.Remove(recevied.Address);
            }
        }
コード例 #2
0
        public void RequestRemote(IPAddress host)
        {
            //    videoConf = new VideoConf(udp, host);

            //            videoConf.Show();

            remoteWin = new Window();
            remoteWin.BorderThickness = new Thickness(0, 0, 0, 0);
            //remoteWin.AllowsTransparency = true;
            remoteWin.Topmost             = true;
            remoteWin.HorizontalAlignment = HorizontalAlignment.Center;
            remoteWin.VerticalAlignment   = VerticalAlignment.Center;
            remoteWin.Width = 250; remoteWin.Height = 250;


            remoteWin.Title = "Remote Request From" + host.ToString();
            remoteWin.Show();
            VideoPreview vp = new VideoPreview(VideoPreview.Mode.Request, host, true);

            vp.Height = 250; vp.Width = 250;
            vp.Nick   = UserList.Get(host).nick;
            vp.window = this;
            remoteWin.SizeToContent = SizeToContent.WidthAndHeight;
            remoteWin.Content       = vp;
        }
コード例 #3
0
        public SentMessage(IPAddress ip, string message, string time, XMLClient client, int index)
        {
            try
            {
                InitializeComponent();
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(message));
                if (!UserList.Get(ip).IsMobile)
                {
                    Message.Document = Conversation.TransformImages((FlowDocument)XamlReader.Load(ms), ip, index);
                }
                else
                {
                    string[] splits = message.Split(new String[] { UDP.Breaker }, StringSplitOptions.RemoveEmptyEntries);
                    if (splits.Length > 1)
                    {
                        Paragraph para = new Paragraph();
                        para.Inlines.Add(new Run(splits[0] + "\n"));
                        Paragraph para2 = new Paragraph();
                        para.Inlines.Add(new Run(splits[1]));

                        Message.Document.Blocks.Add(para);
                        Message.Document.Blocks.Add(para2);
                    }
                }
                //  Message.Text = message;
                Time.Text      = time;
                this.xmlClient = client;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error " + e.Message);
            }
        }
コード例 #4
0
ファイル: XMLClient.cs プロジェクト: ashokkoduru/onLanChat2
        public XMLClient(IPAddress user)
        {
            this.ip = user;
            User _user = UserList.Get(user);

            this.nick      = _user.nick;
            this.groupName = _user.groupName;

            path   = AppDomain.CurrentDomain.BaseDirectory + "\\" + user.ToString().Replace('.', '\\') + "\\Message.xml";
            xmlDoc = new XmlDocument();

            if (!System.IO.File.Exists(path))
            {
                XmlWriter xmlWriter = XmlWriter.Create(path);
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("Messages");
                xmlWriter.WriteStartElement("Count");
                xmlWriter.WriteCData("0");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteStartElement("Unread");
                xmlWriter.WriteCData("0");
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();
                xmlWriter.Close();
            }

            xmlDoc.Load(path);
        }
コード例 #5
0
        public Sharing(IPAddress ip)
        {
            InitializeComponent();
            this.Background = MainWindow.brushColor;
            listFiles       = new List <string>();
            this.ip         = ip;

            this.Title = UserList.Get(ip).nick + " Sharing";
        }
コード例 #6
0
        private void receviedConnect(IPEndPoint recevied, String[] splits)
        {
            if (MainWindow.hostIPS.Contains(recevied.Address))
            {
                MainWindow.hostIP = recevied.Address;
            }

            if (System.IO.File.Exists("UserSettings.xml") == true)
            {
                settings.Load(AppDomain.CurrentDomain.BaseDirectory + "\\UserSettings.xml");
                nickname  = settings.SelectSingleNode("UserProfile/General/NickName").InnerText;
                groupname = settings.SelectSingleNode("UserProfile/General/GroupName").InnerText;
            }
            SendMessageTo(RConnect + nickname + UDP.Breaker + groupname, recevied.Address);

            //  SendMessageTo(RConnect + Environment.MachineName + Breaker + Environment.MachineName+Breaker+recevied.Address, recevied.Address);
#if UDPConnection
            System.Diagnostics.Debug.WriteLine("-----Sending:" + RConnect + "------");
#endif

#if !Fake
            User user = new User(recevied.Address, splits[0], splits[1]);
#endif
#if Fake
            User[] list = new User[25];

            for (int i = 0; i < 25; i++)
            {
                list[i] = new User(IPAddress.Parse("127.0.0." + i), "FakeUser" + i, "FakeGroup" + i / 5);
                User user = list[i];
#endif
 #if !Fake
            if (UserList.Add(user) | UserList.Get(recevied.Address).IsOffline)
            {
                window.Dispatcher.Invoke((Action)(() =>
                {
                    //this.window.AddToUserList(user.CreateView(),splits[1]);
                    window.AddUserToTree(user);
                    UserList.Get(recevied.Address).IsOffline = false;
                }));
            }
#endif

#if Fake
            if (UserList.Add(user))
            {
                window.Dispatcher.Invoke((Action)(() => { window.AddUserToTree(user); }));
            }
        }
#endif
        }
コード例 #7
0
 public void MakeUserPreview(IPAddress ip, VideoPreview.Mode mode)
 {
     vp.Add(ip, new VideoPreview(mode, ip)
     {
         Nick = UserList.Get(ip).nick, myip = ip
     });
     vp[ip].window = mParent;
     vp[ip].udp    = udp;
     vp[ip].HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
     vp[ip].VerticalAlignment   = VerticalAlignment.Stretch;
     vp[ip].hostIP       = host;
     vp[ip].SizeChanged += VideoConf_SizeChanged;
     _stack.Children.Add(vp[ip]);
     _stack.SizeChanged += _stack_SizeChanged;
 }
コード例 #8
0
        private void receviedRConnect(IPEndPoint recevied, String[] splits)
        {
            User user = new User(recevied.Address, splits[0], splits[1]);

            if (splits.Length == 3)
            {
                user.hostIP = IPAddress.Parse(splits[2]);
            }

            if (UserList.Add(user) | UserList.Get(recevied.Address).IsOffline)
            {
                window.Dispatcher.Invoke((Action)(() =>
                {
                    window.AddUserToTree(user);
                    UserList.Get(recevied.Address).IsOffline = false;
                }));
            }
        }
コード例 #9
0
        public void CreateAudioConf(IPAddress host)
        {
            waiting = new Window();
            waiting.BorderThickness     = new Thickness(0, 0, 0, 0);
            waiting.AllowsTransparency  = true;
            waiting.Topmost             = true;
            waiting.HorizontalAlignment = HorizontalAlignment.Center;
            waiting.VerticalAlignment   = VerticalAlignment.Center;

            AudioPreview vp = new AudioPreview(AudioPreview.Mode.Request, host);

            vp.Nick             = UserList.Get(host).nick;
            vp.window           = this;
            waiting.Content     = vp;
            waiting.Width       = 250; waiting.Height = 250;
            waiting.WindowStyle = WindowStyle.None;
            vp.udp = udp;
            waiting.Show();
        }
コード例 #10
0
        private void receviedMessage(IPEndPoint recevied, String[] splits)
        {
            if (splits.Length > 0 && splits[0].Contains(Breaker))
            {
                // MessageBox.Show("Message from ..." + UserList.Get(recevied.Address).nick + splits[0]);
                window.Dispatcher.BeginInvoke((Action)(() =>
                {
                    (window.groupLists[UserList.Get(recevied.Address).groupName].Header as System.Windows.Controls.Grid).Background =
                        new ImageBrush(new BitmapImage(new Uri(
                                                           "pack://application:,,,/Images/rectangle_mediumblue_154x48.png",
                                                           UriKind.Absolute)))
                    {
                    };
                    System.Diagnostics.Debug.WriteLine(window.groupLists[UserList.Get(recevied.Address).groupName]);
                }));

                String cate = splits[0].Substring(splits[0].IndexOf(Breaker) + 3, splits[0].Length - splits[0].IndexOf(Breaker) - Breaker.Length);
                settings.Load(AppDomain.CurrentDomain.BaseDirectory + "\\UserSettings.xml");
                XmlNode node = settings.SelectSingleNode("UserProfile/BlockedList/Block_Others");

                if (cate == "Others" && node.InnerText == "Yes")
                {
                    return;
                }
                node = settings.SelectSingleNode("UserProfile/BlockedList/Block_Games");

                if (cate == "Games" && node.InnerText == "Yes")
                {
                    return;
                }
                node = settings.SelectSingleNode("UserProfile/BlockedList/Block_Study");

                if (cate == "Study" && node.InnerText == "Yes")
                {
                    return;
                }


                UserList.xml[recevied.Address].addMessage(DateTime.Now, splits[0].Substring(0, splits[0].IndexOf(Breaker)), cate);



                try
                {
                    window.nicon.ShowBalloonTip(5, "Message Received From", UserList.Get(recevied.Address).nick, System.Windows.Forms.ToolTipIcon.Info);

                    UserList.conversation[recevied.Address].Dispatcher.BeginInvoke((Action)(() =>
                    {
                        UserList.conversation[recevied.Address].Redraw();
                    }));
                }
                catch (Exception e)
                {
                }


                UserView uv = UserList.Get(recevied.Address).userView;
                uv.Dispatcher.BeginInvoke((Action)(() =>
                {
                    uv.openChat.Content = UserList.xml[recevied.Address].UnreadMessages;
                }));
            }
        }
コード例 #11
0
        public void recevingThread()
        {
            recevingClient.Client.ReceiveBufferSize = 1024 * 1024;

            while (true)
            {
                byte[]     data;
                IPEndPoint recevied = new IPEndPoint(IPAddress.Any, port);

                data = recevingClient.Receive(ref recevied);


                string stringData = Encoding.ASCII.GetString(data);

                //settings.Load(AppDomain.CurrentDomain.BaseDirectory + "\\UserSettings.xml");
                System.Diagnostics.Debug.WriteLine("UDP||-----Recevied " + stringData + " from " + recevied.Address + " ----");
                if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\UserSettings.xml"))
                {
                    settings.Load(AppDomain.CurrentDomain.BaseDirectory + "\\UserSettings.xml");
                    int asdf = 0;
                    foreach (XmlNode user in settings.SelectNodes("UserProfile/BlockedList/Users/Blockeduser"))
                    {
                        if (user.InnerText.Equals(recevied.Address.ToString()))
                        {
                            asdf = 100;
                            break;
                        }
                    }
                    if (asdf == 100)
                    {
                        continue;
                    }
                }



                #region Connection
                if (stringData.StartsWith(Connect))
                {
                    string[] splits = stringData.Split(new String[] { Connect, Breaker }, StringSplitOptions.RemoveEmptyEntries);
                    if (splits.Length != 2)
                    {
#if UDPConnection
                        System.Diagnostics.Debug.WriteLine("-----" + recevied.Address + "Does  not Contain PC/Nick Name----");
#endif
                        continue;
                    }

                    receviedConnect(recevied, splits);
                }
                else if (stringData.StartsWith(RConnect))
                {
                    string[] splits = stringData.Split(new String[] { RConnect, Breaker }, StringSplitOptions.RemoveEmptyEntries);
                    if (splits.Length < 2)
                    {
#if UDPConnection
                        System.Diagnostics.Debug.WriteLine("-----" + recevied.Address + "Does  not Contain PC/Nick Name/Group Name----");
#endif
                        continue;
                    }
                    receviedRConnect(recevied, splits);
                }

                else if (stringData.StartsWith(Disconnect))
                {
                    string[] splits = stringData.Split(new String[] { Disconnect }, StringSplitOptions.RemoveEmptyEntries);
                    receviedDisconnect(recevied, splits);
                }
                #endregion

                #region VideoCall Connection

                else if (stringData.StartsWith(Videocall))
                {
                    window.Dispatcher.Invoke((Action)(() => { window.CreateVideoConf(recevied.Address); }));
                }
                else if (stringData.StartsWith(RVideocall))
                {
                    if (window.videoConf != null)
                    {
                        receviedRVoiceCall(recevied);
                    }
                }
                else if (stringData.StartsWith(AddMember))
                {
                    string[] splits = stringData.Split(new String[] { AddMember }, StringSplitOptions.RemoveEmptyEntries);
                    if (splits.Length > 0)
                    {
                        if (window.videoConf == null)
                        {
                            window.Dispatcher.Invoke((Action)(() => { window.CreateVideoConf(recevied.Address); }));
                        }
                        window.videoConf.Dispatcher.Invoke((Action)(() =>
                        {
                            window.videoConf.AddUser(IPAddress.Parse(splits[0]));
                            window.videoConf.MakeUserPreview(IPAddress.Parse(splits[0]), VideoPreview.Mode.InCall);
                        }));
                    }
                }
                else if (stringData.StartsWith(RemoveMember))
                {
                    window.videoConf.Dispatcher.Invoke((Action)(() =>
                    {
                        window.videoConf.requestedUsers.Remove(recevied.Address);
                        window.videoConf._stack.Children.Remove(window.videoConf.vp[recevied.Address]);
                        window.videoConf.statusLabel.Content = UserList.Get(recevied.Address).nick + " can't Join :(";
                        if (window.videoConf.Users.Count == window.videoConf.requestedUsers.Count)
                        {
                            window.videoConf.statusLabel.Content = "Room Created Successfully With (" + window.videoConf.requestedUsers.Count + ")Members ...:D";
                        }
                    }));
                }
                else if (stringData.StartsWith(ExitCall))
                {
                    if (window.waiting != null)
                    {
                        window.waiting.Dispatcher.Invoke((Action)(() =>
                        {
                            window.waiting.Close();
                        }));
                    }
                    if (window.videoConf != null)
                    {
                        window.videoConf.Dispatcher.Invoke((Action)(() =>
                        {
                            window.videoConf.Close();
                        }));
                    }
                }

                #endregion

                #region AudioCall Connection

                else if (stringData.StartsWith(Audiocall))
                {
                    window.Dispatcher.Invoke((Action)(() => { window.CreateAudioConf(recevied.Address); }));
                }
                else if (stringData.StartsWith(RAudiocall))
                {
                    if (window.audioConf != null)
                    {
                        receviedRAudioCall(recevied);
                    }
                }
                else if (stringData.StartsWith(AddMemberA))
                {
                    string[] splits = stringData.Split(new String[] { AddMemberA }, StringSplitOptions.RemoveEmptyEntries);
                    if (splits.Length > 0)
                    {
                        if (window.audioConf == null)
                        {
                            window.Dispatcher.Invoke((Action)(() => { window.CreateAudioConf(recevied.Address); }));
                        }
                        window.audioConf.Dispatcher.Invoke((Action)(() =>
                        {
                            window.audioConf.AddUser(IPAddress.Parse(splits[0]));
                            window.audioConf.MakeUserPreview(IPAddress.Parse(splits[0]), AudioPreview.Mode.InCall);
                        }));
                    }
                }
                else if (stringData.StartsWith(RemoveMemberA))
                {
                    window.audioConf.Dispatcher.Invoke((Action)(() =>
                    {
                        window.audioConf.requestedUsers.Remove(recevied.Address);
                        window.audioConf._stack.Children.Remove(window.audioConf.vp[recevied.Address]);
                        window.audioConf.statusLabel.Content = UserList.Get(recevied.Address).nick + " can't Join :(";
                        if (window.audioConf.Users.Count == window.audioConf.requestedUsers.Count)
                        {
                            window.audioConf.statusLabel.Content = "Room Created Successfully With (" + window.audioConf.requestedUsers.Count + ")Members ...:D";
                        }
                    }));
                }
                else if (stringData.StartsWith(ExitCallA))
                {
                    if (window.waiting != null)
                    {
                        window.waiting.Dispatcher.Invoke((Action)(() =>
                        {
                            window.waiting.Close();
                        }));
                    }
                    if (window.audioConf != null)
                    {
                        window.audioConf.Dispatcher.Invoke((Action)(() =>
                        {
                            window.audioConf.Close();
                        }));
                    }
                }

                #endregion
                #region Remote
                else if (stringData.StartsWith(Remote))
                {
                    window.Dispatcher.Invoke((Action)(() =>
                    {
                        window.RequestRemote(recevied.Address);
                    }));
                }
                else if (stringData.StartsWith(RRemote))
                {
                    window.remote.Dispatcher.Invoke((Action)(() =>
                    {
                        //  window.remote.Screen._Mode = VideoPreview.Mode.InCall;
                    }));
                }
                else if (stringData.StartsWith(Mouse))
                {
                    if (window.remote != null)
                    {
                        window.remote.change = true;
                        string[] splits = stringData.Split(new String[] { Mouse, Breaker }, StringSplitOptions.RemoveEmptyEntries);
                        if (splits.Length == 3)
                        {
                            SEN_project_v2.Remote.MouseFlag = Convert.ToInt32(splits[0]);

                            SEN_project_v2.Remote.mousePos.X = Convert.ToInt32(splits[1]);
                            SEN_project_v2.Remote.mousePos.Y = Convert.ToInt32(splits[2]);
                        }
                        else
                        {
                        }
                    }
                }
                else if (stringData.StartsWith(Keyboard))
                {
                    if (window.remote != null)
                    {
                        string[] splits = stringData.Split(new String[] { Keyboard, Breaker }, StringSplitOptions.RemoveEmptyEntries);
                        if (splits.Length == 2)
                        {
                            Remote.KeyStatus ks = new Remote.KeyStatus();
                            ks.code = (SEN_project_v2.Remote.Keys)Convert.ToByte(splits[0]);
                            ks.Flag = Convert.ToByte(splits[1]);
                            window.remote.waiting.Add(ks);
                        }
                        else
                        {
                        }
                    }
                }
                else if (stringData.StartsWith(EndRemote))
                {
                    //   window.remote.StopSending();

                    if (window.remote != null)
                    {
                        window.remote.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            window.remote.StopSending();

                            window.Remote.Content = "Remote";
                            window.remote.Close();
                        }));
                    }
                    if (window.remoteWin != null)
                    {
                        window.remoteWin.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            window.remoteWin.Close();
                        }));
                    }
                }
                else if (stringData.StartsWith(RemoteDecline))
                {
                    if (window.remote != null)
                    {
                        window.remote.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            //window.remote.StopSending();

                            //  window.Remote.Content = "Remote";
                            window.remote.Close();
                        }));
                    }
                }

                #endregion

                #region Message
                else if (stringData.StartsWith(Message))
                {
                    String[] splits = stringData.Split(new String[] { Message }, StringSplitOptions.RemoveEmptyEntries);

                    receviedMessage(recevied, splits);
                }
                else if (stringData.StartsWith(RMessage))
                {
                    window.nicon.ShowBalloonTip(5, "Message was opened", UserList.Get(recevied.Address).nick, System.Windows.Forms.ToolTipIcon.Info);
                }
                #endregion

                else if (stringData.StartsWith(MConnect))
                {
                    string[] spilts = stringData.Split(new String[] { MConnect }, StringSplitOptions.RemoveEmptyEntries);
                    SendMessageTo(RMConnect, recevied.Address);
                    window.Dispatcher.BeginInvoke((Action)(() => {
                        User user = new User(recevied.Address, spilts[0]);
                        user.IsMobile = true;
                        if (UserList.Add(user))
                        {
                            window.AddUserToMobileTree(user);
                        }
                    }));
                }
                else if (stringData.StartsWith(MMessage))
                {
                    string[] splits = stringData.Split(new String[] { MMessage }, StringSplitOptions.RemoveEmptyEntries);
                    if (splits.Length > 0)
                    {
                        try
                        {
                            window.nicon.ShowBalloonTip(5, "Moblie Message Received In", UserList.Get(recevied.Address).nick, System.Windows.Forms.ToolTipIcon.Info);

                            UserList.conversation[recevied.Address].Dispatcher.BeginInvoke((Action)(() =>
                            {
                                UserList.conversation[recevied.Address].Redraw();
                            }));
                        }
                        catch (Exception e)
                        {
                        }

                        UserList.xml[recevied.Address].addMessage(DateTime.Now, splits[0], "Mobile");
                        UserView uv = UserList.Get(recevied.Address).userView;
                        uv.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            uv.openChat.Content = UserList.xml[recevied.Address].UnreadMessages;
                        }));
                    }
                }

                else if (stringData.StartsWith(MobileMouse))
                {
                    /*      string[] splits = stringData.Split(new String[] { MobileMouse,Breaker }, StringSplitOptions.RemoveEmptyEntries);
                     * //          if(splits.Length>1)
                     *    SEN_project_v2.Remote.User32.SetCursorPos((int)Double.Parse(splits[0]),(int) Double.Parse(splits[1]));*/
                }
                else if (stringData.StartsWith(Sharing))
                {
                    string path = AppDomain.CurrentDomain.BaseDirectory + "\\Sharing.xml";
                    MainWindow.tcp.SendFile(path, recevied.Address, 2);
                }
                else if (stringData.StartsWith(SendFile))
                {
                    string[] splits = stringData.Split(new String[] { SendFile }, StringSplitOptions.RemoveEmptyEntries);
                    MainWindow.tcp.SendFile(splits[0], recevied.Address, 0);
                }
                else if (stringData.StartsWith(SendDir))
                {
                    string[] splits = stringData.Split(new String[] { SendDir, Breaker }, StringSplitOptions.RemoveEmptyEntries);

                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.RestoreDirectory = true;
                    bool?result = saveFileDialog.ShowDialog();
                    saveFileDialog.Title = splits[0];

                    if (result.Value == true)
                    {
                        System.IO.File.Delete(saveFileDialog.FileName);
                        System.IO.Directory.CreateDirectory(saveFileDialog.FileName);

                        SendMessageTo(RSendDir + saveFileDialog.FileName + Breaker + splits[0], recevied.Address);
                    }
                }
                else if (stringData.StartsWith(RSendDir))
                {
                    string[] splits             = stringData.Split(new String[] { RSendDir, Breaker }, StringSplitOptions.RemoveEmptyEntries);
                    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(splits[1]);
                    if (dir.Exists)
                    {
                        foreach (var file in dir.GetFiles())
                        {
                            MainWindow.tcp.SendFileToFolder(file.FullName, splits[0], recevied.Address, 3);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invaild Dir");
                    }
                }
                else if (stringData.StartsWith(UpdatePic))

                {
                    string picpath = AppDomain.CurrentDomain.BaseDirectory + "\\Pic.png";
                    if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\UserSettings.xml"))
                    {
                        if (settings.SelectSingleNode("UserProfile/Appearance/ProfilepicPath").InnerText != "")
                        {
                            System.IO.File.Delete(picpath);
                            System.IO.File.Copy(settings.SelectSingleNode("UserProfile/Appearance/ProfilepicPath").InnerText, picpath);
                            // picpath = settings.SelectSingleNode("UserProfile/Appearance/ProfilepicPath").InnerText;
                        }
                        else
                        {
                            PngBitmapEncoder encoder = new PngBitmapEncoder();
                            BitmapImage      image   = new BitmapImage(new Uri("pack://application:,,,/Images/user-icon.png", UriKind.Absolute)).Clone();
                            encoder.Frames.Add(BitmapFrame.Create(image));
                            using (System.IO.FileStream stream = System.IO.File.Create(picpath))
                            {
                                encoder.Save(stream);
                                stream.Flush();
                                stream.Close();
                            }
                        }
                    }

                    MainWindow.tcp.SendFile(picpath, recevied.Address, 2);
                }
            }
        }
コード例 #12
0
        public void tcpReceving_proc(TcpClient Client)
        {
            TcpClient tcpRecevingClient = Client;
            IPAddress ip = ((IPEndPoint)tcpRecevingClient.Client.RemoteEndPoint).Address;

            NetworkStream readStream = tcpRecevingClient.GetStream();

            var filesCount = new Byte[4];

            readStream.Read(filesCount, 0, 4);
            for (int i = 0; i < BitConverter.ToInt32(filesCount, 0); i++)
            {
                Int64 bytesReceived = 0;


                string filename = "";
                int    count;
                var    buffer = new byte[1024 * 8];
                byte   isDir  = (byte)readStream.ReadByte();

                int   Flag          = 0;
                Int64 numberOfBytes = 0;

                readStream.Read(buffer, 0, 8);
                numberOfBytes = BitConverter.ToInt64(buffer, 0);

                readStream.Read(buffer, 0, 4);
                int stringLength = BitConverter.ToInt32(buffer, 0);
                readStream.Read(buffer, 0, stringLength);
                filename = Encoding.ASCII.GetString(buffer, 0, stringLength);
                string Path = "";
                if (isDir == 0xD)
                {
                    readStream.Read(buffer, 0, 4);
                    int pathLength = BitConverter.ToInt32(buffer, 0);
                    readStream.Read(buffer, 0, pathLength);
                    Path = Encoding.ASCII.GetString(buffer, 0, pathLength);
                }
                readStream.Read(buffer, 0, 4);
                Flag = BitConverter.ToInt32(buffer, 0);

                //         System.Diagnostics.Debug.WriteLine(numberOfBytes);
                String      FileName = filename;
                ProgressBar progress = null;
                UserView    view     = null;
                if (Flag != 2)
                {
                    view = UserList.Get(ip).userView;
                    view.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        view.AddProgressBar(readStream, filename);
                    }));

                    //Thread.Sleep(1000);
                    {
                        int temp = 0;
                        while (!view.ProgressBars.ContainsKey(readStream) && temp++ < 10)
                        {
                            Thread.Sleep(100);
                        }
                    }



                    progress = UserList.Get(ip).userView.ProgressBars[readStream];
                }
                if (Flag == 0)
                {
                    progress.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        progress.Value = 0;
                        progress.Visibility = System.Windows.Visibility.Visible;
                        progress.Maximum = numberOfBytes / (1024 * 8);
                    }));
                    System.Windows.Forms.SaveFileDialog saveFile = new System.Windows.Forms.SaveFileDialog();
                    saveFile.RestoreDirectory = true;
                    saveFile.Filter           = "(" + filename.Split('.').Last() + ") Files|*." + filename.Split('.').Last() + "";
                    saveFile.Title            = filename;
                    saveFile.FileName         = filename;
                    if (saveFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        FileName = saveFile.FileName;
                    }
                    else
                    {
                        readStream.Close();
                        progress.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            progress.Visibility = System.Windows.Visibility.Hidden;
                            view.RemoveProgressBar(readStream);
                        }));
                        break;
                    }
                }
                else if (Flag == 1)
                {
                    FileName = AppDomain.CurrentDomain.BaseDirectory + ip.ToString().Replace('.', '\\') + "\\" + (UserList.xml[ip].CountMessages - 1) + "." +
                               string.Join(".", filename.Split('.').Skip(1).ToArray());
                }
                else if (Flag == 2)
                {
                    FileName = AppDomain.CurrentDomain.BaseDirectory + ip.ToString().Replace('.', '\\') + "\\" + filename;
                }
                else if (Flag == 3)
                {
                    progress.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        progress.Value = 0;
                        progress.Visibility = System.Windows.Visibility.Visible;
                        progress.Maximum = numberOfBytes / (1024 * 8);
                    }));
                    if (isDir == 0xD)
                    {
                        FileName = Path + "\\" + filename;
                    }
                }
                try
                {
                    using (FileStream fileIO = File.Open(FileName, FileMode.Create))
                    // FileStream fileIO = File.Create(FileName);
                    {
                        int l = buffer.Length;
                        while (bytesReceived < numberOfBytes && (count = readStream.Read(buffer, 0, l)) > 0)
                        {
                            fileIO.Write(buffer, 0, count);
                            //progress.Dispatcher.BeginInvoke((Action)(() =>
                            //{
                            //    progress.Value++;
                            //    progress.UpdateLayout();
                            //}));

                            if (Flag != 2)
                            {
                                progress.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render,
                                                                new DispatcherOperationCallback(delegate { progress.Value++; return(null); }), null);
                            }
                            //       progress.Dispatcher.Invoke((()=> {progress.Value++; progress.UpdateLayout()}));
                            bytesReceived += count;
                            if ((numberOfBytes - bytesReceived) < buffer.Length)
                            {
                                l = (int)(numberOfBytes - bytesReceived);
                            }
                        }
                        fileIO.Flush();
                        fileIO.Close();
                        //  fileIO.EndWrite(asyncResult);
                    }
                    if (Flag != 2)
                    {
                        progress.Dispatcher.BeginInvoke((Action)(() =>
                        {
                            progress.Visibility = System.Windows.Visibility.Hidden;
                            view.RemoveProgressBar(readStream);
                        }));
                    }
                }catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message);
                    if (progress != null)
                    {
                        progress.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render,
                                                        new DispatcherOperationCallback(delegate { progress.Visibility = System.Windows.Visibility.Hidden; return(null); }), null);
                    }
                }
            }

            readStream.Close();
            Clients.Remove(Client);
            Client.Close();


            //  Clients.Remove(ip);
            //  Threads.Remove(ip);
        }
コード例 #13
0
        private void openChat_Click(object sender, RoutedEventArgs e)
        {
            if (!UserList.Get(u_ip).IsMobile)
            {
                if (UserList.xml[u_ip].UnreadMessages > 0)
                {
                    MainWindow.udp.SendMessageTo(UDP.RMessage, u_ip);
                }

                TreeViewItem tvi = ((Parent as ListView).Parent as TreeViewItem);



                if (tvi.Background != MainWindow.restoreImage)
                {
                    int temp = 0;
                    foreach (var ip in UserList.UserOfGroup[UserList.GroupList[u_ip]])
                    {
                        if (UserList.xml[ip].UnreadMessages != 0)
                        {
                            temp++;
                            break;
                        }
                    }
                    if (temp == 0)
                    {
                        (tvi.Header as Grid).Background = MainWindow.restoreImage;
                    }
                }
            }

            Window       w      = new Window();
            Conversation conver = new Conversation(u_ip)
            {
                udp = MainWindow.udp
            };

            if (UserList.conversation.ContainsKey(u_ip))
            {
                UserList.conversation.Remove(u_ip);
            }
            UserList.conversation.Add(u_ip, conver);
            w.Closing += (a, b) => {
                UserList.conversation.Remove(u_ip);
            };
            conver.udp = MainWindow.udp;
            //w.WindowStyle = WindowStyle.None;
            //w.AllowsTransparency = true;

            w.Content = conver;
            //w.Background = System.Windows.Media.Brushes.Transparent;
            conver.Nick.Content = u_nick + " (" + u_ip.ToString() + ") "; conver.Group.Content = UserList.GroupList[u_ip];
            //w.BorderThickness = new Thickness(25);
            w.SizeToContent = SizeToContent.WidthAndHeight;
            w.Title         = "Conversation";
            w.Show();
            w.MinWidth  = 600;
            w.MinHeight = 500;
            w.MaxWidth  = 700;
            w.MaxHeight = 700;



            this.openChat.Content = UserList.xml[u_ip].UnreadMessages;

            UserList.xml[u_ip].UnreadMessages = 0;
        }