예제 #1
0
        private void StartVnc(string userId, VncEntry data)
        {
            int result = vncClientImpl.StartClient(data.IpAddress, data.Port);

            // save to user list
            int userDBid = ConnectedClientHelper.GetInstance().GetClientInfo(userId).DbUserId;

            Server.LaunchedVncHelper.GetInstance().AddLaunchedApp(userDBid, result, data.Identifier);
        }
예제 #2
0
        public override void ExecuteCommand(string userId, string command)
        {
            ClientWndCmd data = deserialize.Deserialize <ClientWndCmd>(command);

            if (data == null)
            {
                return;
            }

            switch (data.CommandType)
            {
            case ClientWndCmd.CommandId.EMinimize:
                NativeMethods.ShowWindow(new IntPtr(data.Id), Constant.SW_SHOWMINIMIZED);
                break;

            case ClientWndCmd.CommandId.EMaximize:
                NativeMethods.ShowWindow(new IntPtr(data.Id), Constant.SW_SHOWMAXIMIZED);
                NativeMethods.SetForegroundWindow(new IntPtr(data.Id));
                break;

            case ClientWndCmd.CommandId.ERelocation:
                NativeMethods.SetWindowPos(new IntPtr(data.Id), Constant.HWND_TOP, data.PositionX, data.PositionY, 0, 0, (Int32)(Constant.SWP_NOSIZE | Constant.SWP_ASYNCWINDOWPOS));
                break;

            case ClientWndCmd.CommandId.EResize:
                NativeMethods.SetWindowPos(new IntPtr(data.Id), Constant.HWND_TOP, 0, 0, data.Width, data.Height, (Int32)(Constant.SWP_NOMOVE | Constant.SWP_ASYNCWINDOWPOS));
                break;

            case ClientWndCmd.CommandId.ERestore:
                NativeMethods.ShowWindow(new IntPtr(data.Id), Constant.SW_SHOWNORMAL);
                NativeMethods.SendMessage(new IntPtr(data.Id), Constant.WM_USER + 1002, IntPtr.Zero, IntPtr.Zero);          // cater Ultra VNC custom restore message - from spy++
                break;

            case ClientWndCmd.CommandId.EClose:
                NativeMethods.PostMessage(new IntPtr(data.Id), Constant.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);

                // remove from user's trigger list
                int userDBid = ConnectedClientHelper.GetInstance().GetClientInfo(userId).DbUserId;
                Server.LaunchedWndHelper.GetInstance().RemoveLaunchedApp(userDBid, data.Id);
                Server.LaunchedSourcesHelper.GetInstance().RemoveLaunchedApp(userDBid, data.Id);
                Server.LaunchedVncHelper.GetInstance().RemoveLaunchedApp(userDBid, data.Id);

                break;

            case ClientWndCmd.CommandId.ESetForeground:
                NativeMethods.SetWindowPos(new IntPtr(data.Id), Constant.HWND_TOPMOST, 0, 0, 0, 0, (Int32)(Constant.SWP_NOMOVE | Constant.SWP_NOSIZE | Constant.SWP_SHOWWINDOW));
                NativeMethods.SetWindowPos(new IntPtr(data.Id), Constant.HWND_NOTOPMOST, 0, 0, 0, 0, (Int32)(Constant.SWP_NOMOVE | Constant.SWP_NOSIZE | Constant.SWP_SHOWWINDOW));
                break;

            default:
                break;
            }
        }
예제 #3
0
        public override void ExecuteCommand(string userId, string command)
        {
            ClientInputCommand visionData = deserialize.Deserialize <ClientInputCommand>(command);

            if (visionData == null)
            {
                return;
            }

            int result   = ServerVisionHelper.getInstance().LaunchVisionWindow(visionData.Attribute.InputId);
            int userDBid = ConnectedClientHelper.GetInstance().GetClientInfo(userId).DbUserId;

            Server.LaunchedSourcesHelper.GetInstance().AddLaunchedApp(userDBid, result, visionData.Attribute.InputId);
        }
예제 #4
0
        public void ClientCredentialReceived(Server.Model.ClientInfoModel model, int desktopRow, int desktopCol)
        {
            ManualResetEvent resetEvt;

            if (connectionEvtDictionary.TryGetValue(model.SocketUserId, out resetEvt))
            {
                resetEvt.Set();
                connectionEvtDictionary.Remove(model.SocketUserId);

                // Reply to user
                sendLoginReply(model, desktopRow, desktopCol);

                // add the user to list
                ConnectedClientHelper.GetInstance().AddClient(model.SocketUserId, model);
            }
        }
예제 #5
0
        public override void ExecuteCommand(string userId, string command)
        {
            ClientApplicationCmd clientAppData = deserialize.Deserialize <ClientApplicationCmd>(command);

            if (clientAppData == null)
            {
                return;
            }

            ApplicationData appData = Server.ServerDbHelper.GetInstance().GetAllApplications().First(AppData
                                                                                                     => AppData.id == clientAppData.ApplicationEntry.Identifier);

            if (appData == null)
            {
                Trace.WriteLine("unable to find matched application id: " + clientAppData.ApplicationEntry.Identifier);
                return;
            }

            int result = LaunchApplication(appData);
            //Server.ConnectedClientHelper.GetInstance().AddLaunchedApp(userId, result, appData.id);
            int userDBid = ConnectedClientHelper.GetInstance().GetClientInfo(userId).DbUserId;

            Server.LaunchedWndHelper.GetInstance().AddLaunchedApp(userDBid, result, appData.id);
        }
예제 #6
0
        public override void ExecuteCommand(string userId, string command)
        {
            ClientPresetsCmd presetData = deserialize.Deserialize <ClientPresetsCmd>(command);

            if (presetData == null)
            {
                return;
            }

            bool broadcastChanges = false;

            switch (presetData.ControlType)
            {
            case ClientPresetsCmd.EControlType.Add:
                AddPreset(userId, clientId, presetData);
                broadcastChanges = true;
                break;

            case ClientPresetsCmd.EControlType.Delete:
                RemovePreset(presetData);
                broadcastChanges = true;
                break;

            case ClientPresetsCmd.EControlType.Launch:
                LaunchPreset(userId, clientId, presetData);
                break;

            case ClientPresetsCmd.EControlType.Modify:
                ModifyPreset(clientId, presetData);
                break;

            default:
                break;
            }

            if (broadcastChanges)
            {
                // TODO: broadcast changes to user who login using the owner's account
                // get user's preset list
                ServerPresetsStatus serverPresetStatus = new ServerPresetsStatus();
                serverPresetStatus.UserPresetList = new List <PresetsEntry>();
                foreach (PresetData data in Server.ServerDbHelper.GetInstance().GetPresetByUserId(clientId))
                {
                    List <ApplicationEntry> presetAppEntries = new List <ApplicationEntry>();
                    foreach (ApplicationData appData in data.AppDataList)
                    {
                        presetAppEntries.Add(new ApplicationEntry()
                        {
                            Identifier = appData.id,
                            Name       = appData.name
                        });
                    }

                    List <VncEntry> presetVncEntries = new List <VncEntry>();
                    foreach (RemoteVncData vncData in data.VncDataList)
                    {
                        presetVncEntries.Add(new VncEntry()
                        {
                            Identifier  = vncData.id,
                            DisplayName = vncData.name,
                            IpAddress   = vncData.remoteIp,
                            Port        = vncData.remotePort,
                        });
                    }

                    List <InputAttributes> presetInputEntries = new List <InputAttributes>();
                    foreach (VisionData inputData in data.InputDataList)
                    {
                        presetInputEntries.Add(
                            ServerVisionHelper.getInstance().GetAllVisionInputsAttributes().First(InputAttributes
                                                                                                  => InputAttributes.InputId == inputData.id));
                    }

                    serverPresetStatus.UserPresetList.Add(new PresetsEntry()
                    {
                        Identifier      = data.Id,
                        Name            = data.Name,
                        ApplicationList = presetAppEntries,
                        VncList         = presetVncEntries,
                        InputList       = presetInputEntries,
                    });
                }

                // should get all connected client with same login
                List <string> connectedClientSocketList;
                if (ConnectedClientHelper.GetInstance().GetConnectedUsersGroupByDB().TryGetValue(clientId, out connectedClientSocketList))
                {
                    server.GetConnectionMgr().SendData(
                        (int)CommandConst.MainCommandServer.UserPriviledge,
                        (int)CommandConst.SubCommandServer.PresetList,
                        serverPresetStatus,
                        connectedClientSocketList);
                }
                else
                {
                    // Should not happen, just in case
                    Trace.WriteLine("ERROR: cannot get connected user socket list by user db id: " + clientId);
                    server.GetConnectionMgr().SendData(
                        (int)CommandConst.MainCommandServer.UserPriviledge,
                        (int)CommandConst.SubCommandServer.PresetList,
                        serverPresetStatus,
                        new List <string>()
                    {
                        userId
                    });
                }
            }
        }
예제 #7
0
        void runningWndsMgr_EvtApplicationWndChanged(List <WindowsAppMgr.WndAttributes> wndAttributes)
        {
            if (Server.ConnectedClientHelper.GetInstance().GetClientsCount() == 0)
            {
                return;
            }

            List <WndPos> windowList    = new List <WndPos>();
            int           zOrderCounter = 0;

            foreach (Windows.WindowsAppMgr.WndAttributes attribute in wndAttributes)
            {
                WndPos wndPos = new WndPos
                {
                    id        = attribute.id,
                    name      = attribute.name,
                    posX      = attribute.posX,
                    posY      = attribute.posY,
                    width     = attribute.width,
                    height    = attribute.height,
                    style     = attribute.style,
                    ZOrder    = zOrderCounter,
                    ProcessId = attribute.processId,
                };

                windowList.Add(wndPos);

                zOrderCounter++;
            }

            try
            {
                ServerWindowsPos windowsPos = new ServerWindowsPos();
                windowsPos.WindowsAttributes = windowList;

                // send to whole group of users login using same login id
                connectionMgr.SendData((int)CommandConst.MainCommandServer.WindowsInfo,
                                       (int)CommandConst.SubCommandServer.WindowsList,
                                       windowsPos,
                                       ConnectedClientHelper.GetInstance().GetAllClientsSocketId());
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
            }

            /*
             * // filter application launched by different login id
             * Dictionary<int, List<String>> userMap = ConnectedClientHelper.GetInstance().GetConnectedUsersGroupByDB();
             * foreach(KeyValuePair<int, List<String>> userData in userMap)
             * {
             *  ServerWindowsPos windowsPos = new ServerWindowsPos();
             *  windowsPos.WindowsAttributes = new List<WndPos>();
             *
             *  // get the launched application by user based on user's db index
             *  Dictionary<int, int> launchedApp = LaunchedWndHelper.GetInstance().GetLaunchedApps(userData.Key);
             *  foreach (KeyValuePair<int, int> launchedData in launchedApp)
             *  {
             *      var eligibleAppWnd = windowList.FindAll(t => t.id == launchedData.Key);
             *      windowsPos.WindowsAttributes.AddRange(eligibleAppWnd);
             *  }
             *
             *  Dictionary<int, int> launchedSources = LaunchedSourcesHelper.GetInstance().GetLaunchedApps(userData.Key);
             *  foreach (KeyValuePair<int, int> launchedData in launchedSources)
             *  {
             *      var eligibleSourceWnd = windowList.FindAll(t => t.id == launchedData.Key);
             *      windowsPos.WindowsAttributes.AddRange(eligibleSourceWnd);
             *  }
             *
             *  Dictionary<int, int> launchedVnc = LaunchedVncHelper.GetInstance().GetLaunchedApps(userData.Key);
             *  foreach (KeyValuePair<int, int> launchedData in launchedVnc)
             *  {
             *      var eligibleVncWnd = windowList.FindAll(t => t.id == launchedData.Key);
             *      windowsPos.WindowsAttributes.AddRange(eligibleVncWnd);
             *  }
             *
             *  try
             *  {
             *      // send to whole group of users login using same login id
             *      connectionMgr.SendData((int)CommandConst.MainCommandServer.WindowsInfo,
             *          (int)CommandConst.SubCommandServer.WindowsList,
             *          windowsPos,
             *          userData.Value);
             *  }
             *  catch (Exception e)
             *  {
             *      Trace.WriteLine(e);
             *  }
             * }
             * */
        }
예제 #8
0
 public Server.Model.ClientInfoModel GetClientInfo(string userId)
 {
     return(ConnectedClientHelper.GetInstance().GetClientInfo(userId));
 }