public static void reload_thmb_scr(byte[] _buffer, GlobalTypes.ClientInfo item)
 {
     try
     {
         Ref_Bitmap = buf_to_bitmap(_buffer).GetHbitmap();
         if (item.Image != null)
         {
             XPorter.Bus.Main_Handle.Dispatcher.Invoke(new MethodInvoker(delegate
             {
                 try
                 {
                     BitmapSource bmpsrc;
                     bmpsrc = Imaging.CreateBitmapSourceFromHBitmap(
                         Ref_Bitmap,
                         IntPtr.Zero,
                         Int32Rect.Empty,
                         BitmapSizeOptions.FromEmptyOptions()
                         );
                     item.Image.Source   = bmpsrc;
                     item.LastConnection = System.DateTime.Now;
                 }
                 catch (Exception ex) { }
             }));
         }
     }
     catch (Exception ex) { }
     finally
     {
         if (Ref_Bitmap != IntPtr.Zero)
         {
             MainWindow.DeleteObject(Ref_Bitmap);
             Ref_Bitmap = IntPtr.Zero;
         }
     }
 }
        ////try to get picture from one to one mode
        //public static void try_get_screen(GlobalTypes.ClientInfo item, GlobalTypes.ServiceMessageStruct msg)
        //{
        //    UdpClient client = null;
        //    if ((msg.Flag > 0) && (msg.Flag < 11))
        //    {
        //        client = new UdpClient(5012);
        //        IPEndPoint rem_pnt = new IPEndPoint(item.HostInfo.Addr, 5012);
        //        client.Client.ReceiveTimeout = 1000;
        //        client.Client.SendTimeout = 1000;
        //        for (int i = 0; i < 10; i++)
        //        {
        //            if (thr_One_To_One == null)
        //            {
        //                send_to<GlobalTypes.ServiceMessageStruct>(client, rem_pnt, msg);
        //                rem_pnt = null;
        //                byte[] buffer = client.Receive(ref rem_pnt);
        //                if (buffer != null)
        //                {
        //                    System.Windows.Forms.MessageBox.Show("TYeah");
        //                    thr_One_To_One = new Thread(one_to_one);
        //                    thr_One_To_One.SetApartmentState(ApartmentState.STA);
        //                    thr_One_To_One.Start();
        //                    break;
        //                }
        //            }
        //        }

        //        if (thr_One_To_One == null)
        //        {
        //            System.Windows.Forms.MessageBox.Show("Disable unicast connect");
        //        }
        //    }
        //}

        //function which get some data from UDP
        public static void get_query(Object Args)
        {
            UdpClient client = null;

            try
            {
                Object[] args = (Object[])Args;
                GlobalTypes.ClientInfo           item = (GlobalTypes.ClientInfo)args[0];
                GlobalTypes.ServiceMessageStruct msg  = (GlobalTypes.ServiceMessageStruct)args[1];
                switch (Encoding.UTF8.GetString(msg.Msg))
                {
                case "GET":
                    switch (msg.Flag)
                    {
                    case 0:
                        try_get_thumb(item, msg);
                        break;

                    default:
                        //try_get_screen(item, msg);
                        break;
                    }
                    break;
                }
            }
            catch (SocketException ex) { }
            catch (Exception ex1) { }
            finally
            {
                if (client != null)
                {
                    client.Close();
                }
            }
        }
 public static void paint_thmb_scr(GlobalTypes.ClientInfo item)
 {
     XPorter.Bus.Main_Handle.Dispatcher.Invoke(new MethodInvoker(delegate
     {
         lock (MainWindow.Client_Catalog)
         {
             System.Windows.Controls.Image tmp = new System.Windows.Controls.Image();
             tmp.MouseLeftButtonUp            += unicast;
             tmp.Stretch             = Stretch.Fill;
             tmp.Margin              = new Thickness(12, 15, 12, 0);
             tmp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
             tmp.Width  = 170;
             tmp.Height = 100;
             item.Image = tmp;
             DockPanel pic_container = new DockPanel();
             TextBlock name          = new TextBlock();
             name.FontSize           = 12;
             name.FontFamily         = new System.Windows.Media.FontFamily("Arial");
             name.MaxWidth           = 170;
             name.TextTrimming       = TextTrimming.CharacterEllipsis;
             name.Text = item.HostInfo.HostName;
             name.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
             pic_container.Children.Add(tmp);
             pic_container.Children.Add(name);
             name.Foreground = System.Windows.Media.Brushes.White;
             tmp.SetValue(DockPanel.DockProperty, Dock.Top);
             name.SetValue(DockPanel.DockProperty, Dock.Bottom);
             tmp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
             XPorter.Bus.Main_Handle.Scr_Cont.Children.Add(pic_container);
             //В другой модуль Create context menu
             System.Windows.Controls.ContextMenu menu = ReinCorpDesign.sources.UserContextMenu.get_contx_menu(item);
             item.Image.ContextMenu = menu;
         }
     }));
 }
        public void one_to_one(Object Arg)
        {
            try
            {
                GlobalTypes.ClientInfo tmp = Arg as GlobalTypes.ClientInfo;
                Client = new UdpClient(tmp.HostInfo.ScreenPort);                                                                 //port for exchange picture in onetoone mode
                Client.Client.ReceiveTimeout = 3000;

                while (Visible)
                {
                    GlobalTypes.ScreenPart recent_struct = RCScreenClient.receive_from <GlobalTypes.ScreenPart>(Client);

                    //if(thr_One_To_One.ThreadState!=ThreadState.AbortRequested)
                    if (recent_struct.Buffer != null)
                    {
                        Bitmap bmp = RCScreenClient.buf_to_bitmap(recent_struct.Buffer);
                        Screen_Box.BeginInvoke(new MethodInvoker(delegate()                          //paint received picture
                        {
                            show_pic(
                                bmp,
                                recent_struct.Point.X,
                                recent_struct.Point.Y
                                );
                        }));
                    }
                }
                Client.Client.Shutdown(SocketShutdown.Both);
                Client.Close();
            }
            catch (Exception ex) { }
        }
Exemple #5
0
        public static void cnt_cycle(object sender)
        {
            try
            {
                int thr_number = (int)sender;

                for (int i = 0;
                     (i <= ((Ip_Range_List.Count - (thr_number + 1)) / GlobalTypes.Settings.ThreadCount) &&
                      (!Abort_Thread)); i++)
                {
                    int       index             = i * GlobalTypes.Settings.ThreadCount + thr_number;                                //pop address for current thread
                    TcpClient sys_cmd_client    = get_tcp(Ip_Range_List[index], GlobalTypes.Settings.TCPPort);
                    GlobalTypes.ClientInfo item = find_item_in_cli_ctlg(Ip_Range_List[index]);
                    if (sys_cmd_client != null)
                    {
                        sys_msg_analyzer(sys_cmd_client, item, new GlobalTypes.SysMessageStruct("SCR", 0));
                        sys_cmd_client.Close();
                    }
                    else
                    {
                        if (item != null)
                        {
                            XPorter.Bus.Main_Handle.Dispatcher.BeginInvoke(
                                new MethodInvoker(delegate
                            {
                                if ((DockPanel)item.Image.Parent != null)
                                {
                                    XPorter.Bus.Main_Handle.Scr_Cont.Children.Remove((DockPanel)item.Image.Parent);
                                    lock (MainWindow.Client_Catalog)
                                    {
                                        MainWindow.Client_Catalog.Remove(item);
                                    }
                                    //Написать Мягкое обновление элементов TreeViewItems
                                    //lock (XPorter.Bus.MDI.Main_Handle.TreeUngroup)
                                    //{
                                    //    foreach(var it in XPorter.Bus.MDI.Main_Handle.TreeUngroup.Items)
                                    //    {
                                    //        if (((TreeViewItem)it).Header == item.HostInfo.Addr.ToString())
                                    //            XPorter.Bus.MDI.Main_Handle.TreeUngroup.Items.Remove(it);
                                    //    }
                                    //}
                                }
                            }));
                        }
                    }
                }
                Threads_Done++;
            }
            catch (SocketException ex) { /*MessageBox.Show(ex.ToString());*/ }
            catch (Exception ex) { /*MessageBox.Show(ex.ToString()); */ }
        }
Exemple #6
0
 private static void cnt_elem_refr(GlobalTypes.HostInfo host_inf,
                                   GlobalTypes.SysMessageStruct msg,
                                   GlobalTypes.ClientInfo item,
                                   bool flag)
 {
     if ((Encoding.UTF8.GetString(msg.Msg) == "SYN") && (msg.Flag == 2))
     {
         if (!flag)
         {
             item = new GlobalTypes.ClientInfo(host_inf);
             lock (MainWindow.Client_Catalog)
             {
                 MainWindow.Client_Catalog.Add(item);
             }
             RCScreenClient.paint_thmb_scr(item);
         }
         else
         {
             lock (MainWindow.Client_Catalog)
             {
                 item.HostInfo       = host_inf;
                 item.LastConnection = DateTime.Now;
             }
         }
         lock (XPorter.Bus.Main_Handle.TreeUngroup)
         {
             XPorter.Bus.Main_Handle.TreeUngroup.Dispatcher.BeginInvoke(new MethodInvoker(delegate()
             {
                 System.Windows.Controls.ContextMenu item_menu = ReinCorpDesign.sources.UserContextMenu.get_contx_menu(item);
                 if (XPorter.Bus.Main_Handle.TreeUngroup.IsExpanded == false)
                 {
                     XPorter.Bus.Main_Handle.TreeUngroup.IsExpanded = true;
                 }
                 TreeViewItem tr_item = new TreeViewItem();
                 tr_item.ContextMenu  = item_menu;
                 tr_item.Header       = item.HostInfo.Addr.ToString();
                 tr_item.Tag          = "3";
                 XPorter.Bus.Main_Handle.TreeUngroup.Items.Add(tr_item);
             }));
         }
         Thread   thr_tmp = new Thread(RCScreenClient.get_query);
         Object[] args    = new Object[2];
         args[0]      = item;
         args[1]      = new GlobalTypes.ServiceMessageStruct("GET", 0);
         thr_tmp.Name = "get_query";
         thr_tmp.SetApartmentState(ApartmentState.STA);
         //thr_tmp.Start(args);
     }
 }
        private static void unicast(object sender, RoutedEventArgs e)
        {
            GlobalTypes.ClientInfo tmp = null;

            if (VisualEffectsAndComponents.Connector.Cntr == null)
            {
                foreach (var _tmp in MainWindow.Client_Catalog)
                {
                    if (_tmp.Image == (System.Windows.Controls.Image)sender)
                    {
                        tmp = _tmp;
                    }
                }
                Thread thr_tmp = new Thread(start_one_to_one);
                thr_tmp.Start(tmp);
            }
        }
        //get small picture into thumb
        public static void try_get_thumb(GlobalTypes.ClientInfo item, GlobalTypes.ServiceMessageStruct msg)
        {
            UdpClient client = null;

            client = new UdpClient();
            lock (MainWindow.Client_Catalog)
            {
                IPEndPoint rem_pnt = new IPEndPoint(item.HostInfo.Addr, 5011);
                send_to <GlobalTypes.ServiceMessageStruct>(client, rem_pnt, msg);
                rem_pnt = null;
                client.Client.ReceiveTimeout = 1000;
                byte[] buffer = client.Receive(ref rem_pnt);
                if (buffer != null)
                {
                    reload_thmb_scr(buffer, item);
                }
            }
        }
Exemple #9
0
        //analyze msg for futher action
        public static void sys_msg_analyzer(TcpClient tcp_client, GlobalTypes.ClientInfo item, GlobalTypes.SysMessageStruct main_msg)
        {
            try {
                NetworkStream net_stream = tcp_client.GetStream();
                send_to <GlobalTypes.SysMessageStruct>(net_stream, main_msg);
                switch (Encoding.UTF8.GetString(main_msg.Msg))
                {
                    #region Screen
                case "SCR": {
                    switch (main_msg.Flag)
                    {
                    case 0: {
                        tcp_client.Client.ReceiveTimeout = 5000;
                        GlobalTypes.SysMessageStruct host_inf = receive_from <GlobalTypes.SysMessageStruct>(net_stream);
                        GlobalTypes.SysMessageStruct msg      = receive_from <GlobalTypes.SysMessageStruct>(net_stream);
                        if ((host_inf != null) && (msg != null))
                        {
                            cnt_elem_refr(new GlobalTypes.HostInfo(
                                              ((IPEndPoint)tcp_client.Client.RemoteEndPoint).Address,
                                              host_inf.Info), msg, item, item != null);
                        }
                        else
                        {
                            MessageBox.Show("Не удалось установить соединение");                 //Дописать в лог
                        }
                    } break;

                    case 11: {
                    }
                    break;

                    default: {
                        if ((main_msg.Flag > 0) && (main_msg.Flag < 11))
                        {
                        }
                    } break;
                    }
                } break;
                    #endregion
                }
            }
            catch (Exception ex) { MessageBox.Show("Lost Connection"); }
        }
Exemple #10
0
        public scrfrm(FrameworkElement placementTarget, TabItem item, GlobalTypes.ClientInfo tmp)
        {
            InitializeComponent();
            var color = ((SolidColorBrush)XPorter.Bus.Main_Handle.MainTab.Background).Color;

            this.BackColor    = System.Drawing.Color.FromArgb(color.R, color.G, color.B);
            this.FormClosing += delegate
            {
                MainWindow.thr_killer(thr_One_To_One);
                RCHOOKLIB.HookMng.Mouse    -= mouse_hook_proc;
                RCHOOKLIB.HookMng.Keyboard -= keyboard_hook_proc;
            };

            //---------------------here was delegate -----------------------------//
            Placement_Target = placementTarget;
            Item             = item;
            Tmp   = tmp;
            owner = Window.GetWindow(placementTarget);
            owner.LocationChanged             += delegate { on_size_and_location_changing(); };
            Placement_Target.SizeChanged      += delegate { on_size_and_location_changing(); };
            Placement_Target.IsVisibleChanged += visible_changing;


            XPorter.Bus.Main_Handle.StateChanged += delegate
            {
                if (thr_One_To_One.ThreadState != ThreadState.Running)
                {
                    on_size_and_location_changing();
                    thr_One_To_One = new Thread(one_to_one);
                    thr_One_To_One.Start(Tmp);
                    this.Visible = true;
                }
            };
            if (item.IsVisible)
            {
                Show(new Wpf32Window(owner));
            }
        }
        //function which performs in thread
        //public static void one_to_one(Object Arg)
        //{
        //    UdpClient client = new UdpClient(5012);                                                                 //port for exchange picture in onetoone mode
        //    client.Client.ReceiveTimeout = 10000;

        //    while (true)
        //    {
        //        GlobalTypes.ScreenPart recent_struct = receive_from<GlobalTypes.ScreenPart>(client);
        //        if (recent_struct.Buffer != null)
        //        {
        //            Bitmap bmp = buf_to_bitmap(recent_struct.Buffer);
        //            XPorter.Bus.Main_Handle.Dispatcher.Invoke(new MethodInvoker(delegate()                          //paint received picture
        //                {
        //                    XPorter.Bus.Main_Handle.show_pic(
        //                        bmp,
        //                        recent_struct.Point.X,
        //                        recent_struct.Point.Y
        //                        );
        //                }));
        //        }
        //    }
        //}

        public static void start_one_to_one(object Args)
        {
            GlobalTypes.ClientInfo tmp = Args as GlobalTypes.ClientInfo;
            if ((!RCConnectLibrary.Threads_Already_Started) && (tmp != null))
            {
                RCConnectLibrary.send_to_all_sys_msg(new GlobalTypes.SysMessageStruct("SCR", 11));

                tmp.HostInfo.ScreenPort = RCConnectLibrary.port_dealer(tmp.HostInfo.Addr, new GlobalTypes.SysMessageStruct
                                                                           ("PRT", 0), 8268); //TCP port + 1
                RCConnectLibrary.Opened_Ports.Add(tmp.HostInfo.ScreenPort);
                //Выполнить проверку если порты принялись нулевые....если так то сервер выеживается
                if (tmp.HostInfo.ScreenPort != 0)
                {
                    XPorter.Bus.Main_Handle.Dispatcher.Invoke(new MethodInvoker(delegate()
                    {
                        var tab       = XPorter.Bus.Main_Handle.uni_tab_creator(null, true);
                        tab.Unloaded += delegate
                        {
                            TcpClient client = RCConnectLibrary.get_tcp(tmp.HostInfo.Addr, GlobalTypes.Settings.TCPPort);
                            if (client != null)
                            {
                                RCConnectLibrary.sys_msg_analyzer(
                                    client,
                                    null,
                                    new GlobalTypes.SysMessageStruct("SCR", 11)
                                    );
                                client.Close();
                            }
                            //MainWindow.thr_killer(RCScreenClient.thr_One_To_One);
                        };

                        tab.Loaded += delegate
                        {
                            Grid target_grid = new Grid();
                            tab.Content      = target_grid;
                            tab.Header       = (GlobalTypes.Settings.TabHeader == "IP") ?
                                               tmp.HostInfo.Addr.ToString() : tmp.HostInfo.HostName;
                            scrfrm _win = new scrfrm(target_grid, tab, tmp);
                            ((FrameworkElement)tab.Template.FindName("Cross", tab)).MouseLeftButtonDown += delegate(
                                object ss,
                                MouseButtonEventArgs ee
                                )
                            {
                                _win.Close();
                                XPorter.Bus.Main_Handle.MainTab.Items.Remove(tab);
                            };


                            Bitmap bmp = new Bitmap(800, 600);
                            using (var gr = Graphics.FromImage(bmp)) {
                                gr.Clear(System.Drawing.Color.Black);
                            }
                            _win.Screen_Box.Image = bmp;
                        };
                        //_Win.GotFocus += delegate
                        //{
                        //    XPorter.Bus.MDI.curentAddress = tmp.HostInfo.Addr;
                        //    IPEndPoint point = new IPEndPoint(XPorter.Bus.MDI.curentAddress, 5002);
                        //    keyboardClient = new TcpClient();
                        //    keyboardClient.Connect(point);
                        //    RCHLib.RCHookManager.Keyboard += KeyboardControl;
                        //};
                        //_Win.LostFocus += delegate
                        //{
                        //   // keyboardClient.Close();
                        //    XPorter.Bus.MDI.curentAddress = null;
                        //    RCHLib.RCHookManager.Keyboard -= KeyboardControl;
                        //};


                        //IntPtr refBitmap = bmp.GetHbitmap();
                        //BitmapSource bmpsrc;
                        //bmpsrc = Imaging.CreateBitmapSourceFromHBitmap(
                        //refBitmap,
                        //IntPtr.Zero,
                        //Int32Rect.Empty,
                        //BitmapSizeOptions.FromEmptyOptions()
                        //);
                        //MainWindow.ScreenBox.Source = bmpsrc;
                        //TAB_item.Content=MainWindow.ScreenBox;
                        //Grid.SetRowSpan(MainWindow.ScreenBox, 2);
                        //MainWindow.DeleteObject(refBitmap);
                    }));
                    MainWindow.thr_killer(RCScreenClient.thr_Get_Img_From_UDP);
                    TcpClient _client = RCConnectLibrary.get_tcp(tmp.HostInfo.Addr, GlobalTypes.Settings.TCPPort);
                    RCConnectLibrary.sys_msg_analyzer(_client, tmp, new GlobalTypes.SysMessageStruct("SCR", 10));
                    //Object[] args = new Object[2];
                    //args[0] = tmp;
                    //args[1] = new GlobalTypes.ServiceMessageStruct("GET", 3);
                    //RCScreenClient.get_query(args);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Lost Connection!");
                }
            }
        }