Пример #1
0
 private static void IClient_Disconnected(object sender, string e)
 {
     ISLogger.Write("Lost connection to the Inputshare service... exiting");
     Exit();
 }
Пример #2
0
 static void OnInvalidArgs()
 {
     ISLogger.Write("SP started with invalid args");
     Thread.Sleep(20000);
     Console.ReadLine();
 }
Пример #3
0
        protected override void OnStart(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            string path = AppDomain.CurrentDomain.BaseDirectory;

            ISLogger.SetLogFileName(path + @"\logs\InputshareService.log");
            ISLogger.EnableConsole = false;
            ISLogger.EnableLogFile = true;


            ISLogger.Write("Current path = " + path);
            if (!Directory.Exists(path + "\\logs"))
            {
                try
                {
                    if (!Directory.Exists(path + "\\logs"))
                    {
                        Directory.CreateDirectory(path + "\\logs");
                    }

                    if (!Directory.Exists(path + "\\Downloads"))
                    {
                        Directory.CreateDirectory(path + "\\Downloads");
                    }
                }
                catch (Exception ex)
                {
                    ISLogger.Write($"Failed to create file folder: {ex.Message}");
                }
            }

            ISLogger.Write("Service->Service started");

            try
            {
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
            }
            catch (Exception ex)
            {
                ISLogger.Write($"Error setting realtime priority: {ex.Message}");
            }


            try
            {
                namedIpc                             = new NamedIpcServer();
                namedIpc.Ipc_Connect                += NamedIpc_Connect;
                namedIpc.RequestedState             += NamedIpc_RequestedState;
                namedIpc.Ipc_Disconnect             += NamedIpc_Disconnect;
                namedIpc.RequestedSetDownloadFolder += NamedIpc_RequestedSetDownloadFolder;
                namedIpc.RequestedDownloadFolder    += NamedIpc_RequestedDownloadFolder;
                ISLogger.Write("Service->Named IPC server started");
            }catch (Exception ex)
            {
                ISLogger.Write($"Service->Failed to create NamedIPC server: " + ex.Message);
            }

            if (!File.Exists(path + "\\inputsharesp.exe"))
            {
                ISLogger.Write("Service->Error: inputsharepSP not found! stopping service!");
                Stop();
                return;
            }

            CreatePipes();
            EnableSASHKey();

            cSocket = new ServerSocket();
            cSocket.FileReceivePath = path + "\\Downloads";
            spMon = new SpMonitor();
            spMon.StartMonitoring();
            spMon.SpStarted += SpMon_SpStarted;
            spMon.SpStopped += SpMon_SpStopped;

            launcher = new SpLauncher();

            if (!launcher.SpRunning)
            {
                ISLogger.Write("Service->SP not found... launching");

                try
                {
                    launcher.LaunchSp(ipcWrite.PipeHandleAsString, ipcRead.PipeHandleAsString);
                    ipcWrite.RemoveHandle();
                    ipcRead.RemoveHandle();
                }
                catch (Exception ex)
                {
                    if (ex is InvalidOperationException || ex is Win32Exception)
                    {
                        ISLogger.Write($"Failed to launch inputsharesp: {ex.Message}");
                    }
                }
            }

            cSocket.InputReceived         += CSocket_InputReceived;
            cSocket.ClipboardTextReceived += CSocket_ClipboardTextReceived;
            cSocket.MessageReceived       += CSocket_MessageReceived;
            cSocket.Connected             += CSocket_Connected;
            cSocket.Disconnected          += CSocket_Disconnected;
            cSocket.ConnectionFailed      += CSocket_ConnectionFailed;
            cSocket.ConnectionError       += CSocket_ConnectionError;

            ISLogger.Write("Service->Service started");

            //Read initial config
            string lastAddr    = ConfigManager.ReadConfig("LastAddress");
            string lastName    = ConfigManager.ReadConfig("LastName");
            string lastGuidStr = ConfigManager.ReadConfig("LastGuid");

            if (lastAddr == null || lastName == null || lastGuidStr == null)
            {
                return;
            }

            IPEndPoint.TryParse(lastAddr, out IPEndPoint lastEp);
            if (lastEp == null)
            {
                ISLogger.Write($"Service->Config file contained invalid address");
                return;
            }

            Guid.TryParse(lastGuidStr, out Guid lastGuid);
            if (lastGuid == null)
            {
                ISLogger.Write($"Service->Config file contained invalid guid");
                return;
            }

            if (lastName == "" && lastName.Length > 32)
            {
                ISLogger.Write($"Serivce->Config file contained invalid username");
                return;
            }

            lastServer             = lastEp;
            keepRetryingConnection = true;
            Ipc_Connect(lastEp, lastName, lastGuid);
        }
Пример #4
0
 public RemoveJobUpdater(InstanceInfoUpdater instanceInfoUpdater, ISLogger logger, IUnitOfWork unitOfWork, IConnectionManager connManager,
                         IInstanceDataCollector instanceDataCollector) :
     base(instanceInfoUpdater, logger, unitOfWork, connManager, instanceDataCollector)
 {
 }
Пример #5
0
        private void IsThreadHandleMouse(uint wParam, MSLLHOOKSTRUCT mouseStruct)
        {
            int code = (int)wParam;

            switch (code)
            {
            case WM_MOUSEMOVE:
            {
                short relX = (short)(mouseStruct.pt.X - mPos.X);
                short relY = (short)(mouseStruct.pt.Y - mPos.Y);

                //Mouse hooks can sometimes report a mouse move that isnt enough for the mouse to move a single pixel, we ignore these messages
                //Sometimes the hook reports movements that make no sense (eg 1000X 1000Y) we also want to ingore these.
                if ((relX == 0 && relY == 0) || relX > 100 || relY > 100 || relX < -100 || relY < -100)
                {
                    ISLogger.Write($"Invalid movement: {relX}:{relY}");
                    mouseData = new ISInputData(ISInputCode.IS_UNKNOWN, 0, 0);
                    return;
                }

                mouseData = new ISInputData(ISInputCode.IS_MOUSEMOVERELATIVE, relX, relY);
                break;
            }

            case WM_LMOUSEDOWN:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSELDOWN, 0, 0);
                break;
            }

            case WM_LMOUSEUP:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSELUP, 0, 0);
                break;
            }

            case WM_RMOUSEDOWN:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSERDOWN, 0, 0);
                break;
            }

            case WM_RMOUSEUP:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSERUP, 0, 0);
                break;
            }

            case WM_MBUTTONDOWN:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSEMDOWN, 0, 0);
                break;
            }

            case WM_MBUTTONUP:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSEMUP, 0, 0);
                break;
            }

            case WM_MOUSEWHEEL:
            {
                //TODO - implement X axis scrolling
                mouseData = new ISInputData(ISInputCode.IS_MOUSEYSCROLL, unchecked ((short)((long)mouseStruct.mouseData >> 16)), 0);
                break;
            }

            case WM_XBUTTONDOWN:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSEXDOWN, unchecked ((short)((long)mouseStruct.mouseData >> 16)), 0);
                break;
            }

            case WM_XBUTTONUP:
            {
                mouseData = new ISInputData(ISInputCode.IS_MOUSEXUP, unchecked ((short)((long)mouseStruct.mouseData >> 16)), 0);
                break;
            }

            default:
                ISLogger.Write("Unexpected windows mouse input code " + code.ToString("X"));
                mouseData = new ISInputData(ISInputCode.IS_UNKNOWN, 0, 0);
                return;
            }


            if (UserInputBlocked)
            {
                if (mouseData.Code != ISInputCode.IS_UNKNOWN)
                {
                    InputReceived?.Invoke(this, mouseData);
                }
                else
                {
                    ISLogger.Write($"Error: invalid mouse input data {mouseData.Code}:{mouseData.Param1}:{mouseData.Param2}");
                }
            }
        }
Пример #6
0
 private void Server_InputClientSwitched(object sender, EventArgs e)
 {
     ISLogger.Write("Current client: " + server.GetInputClient().ClientName);
 }
 private void File_ReadComplete(object sender, EventArgs e)
 {
     ClipboardVirtualFileData.FileAttributes file = sender as ClipboardVirtualFileData.FileAttributes;
     ISLogger.Write("Debug: Clipboard: {0} read complete", file.FileName);
 }
Пример #8
0
 static InputshareDataObject()
 {
     InputshareClipboardFormatId = RegisterClipboardFormatA("InputshareData");
     ISLogger.Write("Registered clipboard format 'InputshareData'. Format = " + InputshareClipboardFormatId);
 }
Пример #9
0
        public InputshareDataObject(ClipboardDataBase data, bool isDragDrop)
        {
            isDragDropData = isDragDrop;
            OperationGuid  = data.OperationId;

            supportedFormats.Add(new FORMATETC
            {
                cfFormat = (short)InputshareClipboardFormatId,
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                lindex   = -1,
                ptd      = IntPtr.Zero,
                tymed    = TYMED.TYMED_HGLOBAL
            });

            if (data is ClipboardTextData cbText)
            {
                supportedFormats.Add(new FORMATETC
                {
                    cfFormat = formatTextId,
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex   = -1,
                    ptd      = IntPtr.Zero,
                    tymed    = TYMED.TYMED_HGLOBAL
                });

                ISLogger.Write("Stored text = " + cbText.Text);
                storedText = cbText.Text;
            }
            else if (data is ClipboardVirtualFileData cbFiles)
            {
                storedFiles = cbFiles;

                supportedFormats.Add(new FORMATETC
                {
                    cfFormat = formatFileContentsId,
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex   = -1,
                    ptd      = IntPtr.Zero,
                    tymed    = TYMED.TYMED_ISTREAM
                });

                supportedFormats.Add(new FORMATETC
                {
                    cfFormat = formatFileDescriptorId,
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex   = -1,
                    ptd      = IntPtr.Zero,
                    tymed    = TYMED.TYMED_HGLOBAL
                });

                supportedFormats.Add(new FORMATETC
                {
                    cfFormat = (short)DataFormats.GetFormat("Preferred DropEffect").Id,
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex   = -1,
                    ptd      = IntPtr.Zero,
                    tymed    = TYMED.TYMED_HGLOBAL
                });
            }
            else if (data is ClipboardImageData cbImage)
            {
                using (MemoryStream ms = new MemoryStream(cbImage.ImageData))
                {
                    storedImage = (Bitmap)Image.FromStream(ms);
                }

                supportedFormats.Add(new FORMATETC
                {
                    cfFormat = formatBitmapId,
                    dwAspect = DVASPECT.DVASPECT_CONTENT,
                    lindex   = -1,
                    ptd      = IntPtr.Zero,
                    tymed    = TYMED.TYMED_GDI
                });
            }
        }
Пример #10
0
        public void Start(int port)
        {
            if (Running)
            {
                throw new InvalidOperationException("Server already running");
            }

            try
            {
                Process.GetCurrentProcess().PriorityClass = ServerBasePriority;
            }catch (Exception ex)
            {
                ISLogger.Write("Cannot set process priority to {0}: {1}", ServerBasePriority, ex.Message);
            }


            ConnectedClient.LocalHost = new ConnectedClient(true);
            ISLogger.Write("Starting server...");
            ServerPort = port;
            clientMan  = new ClientManager(ServerDefaultMaxClients);
            clientMan.AddClient(ConnectedClient.LocalHost);
            tcpListener = new ClientListener();
            tcpListener.ClientConnected += TcpListener_ClientConnected;


            tcpListener.Start(port);


            SetConsoleText("Current client: localhost");

            //We need to determine which OS is being used
            OSHelper.Os os = OSHelper.GetOsVersion();

            switch (os.System)
            {
            case OSHelper.Platform.Windows:
            {
                inputMan    = new WindowsInputManager();
                curMonitor  = new WindowsCursorMonitor();
                outManager  = new WindowsOutputManager();
                procMonitor = new WindowsProcessMonitor();
                break;
            }

            default:
                throw new NotImplementedException();
            }
            inputMan.Start();

            curMonitor.Start();
            curMonitor.EdgeHit += LocalHost_EdgeHit;

            procMonitor.StartMonitoring();
            procMonitor.ProcessEnteredFullscreen += ProcMonitor_ProcessEnteredFullscreen;
            procMonitor.ProcessExitedFullscreen  += ProcMonitor_ProcessExitedFullscreen;
            Running = true;

            inputMan.InputReceived         += InputMan_InputReceived;
            inputMan.ClientHotkeyPressed   += InputMan_ClientHotkeyPressed;
            inputMan.FunctionHotkeyPressed += InputMan_FunctionHotkeyPressed;
            inputMan.ClipboardTextCopied   += InputMan_ClipboardTextCopied;

            LoadHotkeySettings();
        }
Пример #11
0
        public override void Send(ISInputData input)
        {
            if (input.Code == ISInputCode.IS_MOUSEMOVERELATIVE)
            {
                XWarpPointer(xConnection.XDisplay, IntPtr.Zero, IntPtr.Zero, 0, 0, 0, 0, input.Param1, input.Param2);
            }
            else if (input.Code == ISInputCode.IS_MOUSELDOWN)
            {
                XTestFakeButtonEvent(xConnection.XDisplay, X11_LEFTBUTTON, true, 0);
            }
            else if (input.Code == ISInputCode.IS_MOUSELUP)
            {
                XTestFakeButtonEvent(xConnection.XDisplay, X11_LEFTBUTTON, false, 0);
            }
            else if (input.Code == ISInputCode.IS_MOUSERDOWN)
            {
                XTestFakeButtonEvent(xConnection.XDisplay, X11_RIGHTBUTTON, true, 0);
            }
            else if (input.Code == ISInputCode.IS_MOUSERUP)
            {
                XTestFakeButtonEvent(xConnection.XDisplay, X11_RIGHTBUTTON, false, 0);
            }
            else if (input.Code == ISInputCode.IS_MOUSEMDOWN)
            {
                XTestFakeButtonEvent(xConnection.XDisplay, X11_MIDDLEBUTTON, true, 0);
            }
            else if (input.Code == ISInputCode.IS_MOUSEMUP)
            {
                XTestFakeButtonEvent(xConnection.XDisplay, X11_MIDDLEBUTTON, false, 0);
            }
            else if (input.Code == ISInputCode.IS_MOUSEYSCROLL)
            {
                //Param1 contains the mouse direction, 120 = up; -120 = down
                if (input.Param1 > 0)
                {
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_SCROLLDOWN, true, 0);
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_SCROLLDOWN, false, 0);
                }
                else
                {
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_SCROLLUP, true, 0);
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_SCROLLUP, false, 0);
                }
            }
            else if (input.Code == ISInputCode.IS_MOUSEXSCROLL)
            {
                //todo
            }
            else if (input.Code == ISInputCode.IS_MOUSEXDOWN)
            {
                //first param is the ID of the button. 4 = forward, 5 = back
                if (input.Param1 == 4)
                {
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_XBUTTONFORWARD, true, 0);
                }
                else
                {
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_XBUTTONBACK, true, 0);
                }
            }
            else if (input.Code == ISInputCode.IS_MOUSEXUP)
            {
                if (input.Param1 == 4)
                {
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_XBUTTONFORWARD, false, 0);
                }
                else
                {
                    XTestFakeButtonEvent(xConnection.XDisplay, X11_XBUTTONBACK, false, 0);
                }
            }
            else if (input.Code == ISInputCode.IS_KEYDOWN || input.Code == ISInputCode.IS_KEYUP)
            {
                bool down = input.Code == ISInputCode.IS_KEYDOWN;

                try
                {
                    uint key = ConvertKey((WindowsVirtualKey)input.Param1);

                    if (input.Code == ISInputCode.IS_KEYDOWN && Settings.DEBUG_PRINTOUTPUTKEYS)
                    {
                        ISLogger.Write("DEBUG: KEY {0}", XKeysymToString(XKeycodeToKeysym(xConnection.XDisplay, (int)key, 0)));
                    }

                    if (key < 1)
                    {
                        throw new Exception("Could not translate key " + (WindowsVirtualKey)input.Param1);
                    }

                    XTestFakeKeyEvent(xConnection.XDisplay, key, down, 0);
                }
                catch (Exception ex)
                {
                    ISLogger.Write("Failed to send key {0}: {1}", (WindowsVirtualKey)input.Param1, ex.Message);
                }
            }

            XFlush(xConnection.XDisplay);
        }
Пример #12
0
 private void ProcMonitor_ProcessEnteredFullscreen(object sender, Process proc)
 {
     ISLogger.Write($"{proc.ProcessName} entered fullscreen");
 }
Пример #13
0
        public void SetClientEdge(ConnectedClientInfo clientA, BoundEdge sideof, ConnectedClientInfo clientB)
        {
            ConnectedClient a = null;

            if (clientA != null)
            {
                a = clientMan.GetClientFromGuid(clientA.ClientId);
            }

            ConnectedClient b = clientMan.GetClientFromGuid(clientB.ClientId);


            if (a == null)
            {
                switch (sideof)
                {
                case BoundEdge.Left:
                    if (b.LeftClient != null)
                    {
                        b.LeftClient.RightClient = null;
                    }
                    break;

                case BoundEdge.Right:
                    if (b.RightClient != null)
                    {
                        b.RightClient.LeftClient = null;
                    }
                    break;

                case BoundEdge.Bottom:
                    if (b.BelowClient != null)
                    {
                        b.BelowClient.AboveClient = null;
                    }
                    break;

                case BoundEdge.Top:
                    if (b.AboveClient != null)
                    {
                        b.AboveClient.BelowClient = null;
                    }
                    break;
                }
            }

            switch (sideof)
            {
            case BoundEdge.Bottom:
                b.BelowClient = a;
                if (a != null)
                {
                    a.AboveClient = b;
                }
                break;

            case BoundEdge.Right:
                b.RightClient = a;
                if (a != null)
                {
                    a.LeftClient = b;
                }
                break;

            case BoundEdge.Left:
                b.LeftClient = a;
                if (a != null)
                {
                    a.RightClient = b;
                }
                break;

            case BoundEdge.Top:
                b.AboveClient = a;
                if (a != null)
                {
                    a.BelowClient = b;
                }
                break;
            }


            if (a == null)
            {
                ISLogger.Write("Set None {0}of {1}", sideof, b.ClientName);
            }
            else
            {
                ISLogger.Write("Set {0} {1}of {2}", a.ClientName, sideof, b.ClientName);
            }
            DisplayConfigChanged(this, null);
        }
Пример #14
0
 public BaseJobSaver(ISLogger logger, ILocalStorage localDb, SQLTaskScheduler scheduler)
 {
     this.localDb   = localDb;
     this.logger    = logger;
     this.scheduler = scheduler;
 }
Пример #15
0
 public InstanceInfoUpdater(ISLogger logger)
 {
     this._logger = logger;
 }
Пример #16
0
 private void ClientInstance_Disconnected(object sender, EventArgs e)
 {
     ISLogger.Write("Disconnected");
 }
Пример #17
0
 void IStream.Stat(out System.Runtime.InteropServices.ComTypes.STATSTG streamStats, int grfStatFlag)
 {
     streamStats = new STATSTG();
     ISLogger.Write("STAT CALLED");
 }
Пример #18
0
 private void ClientInstance_Connected(object sender, System.Net.IPEndPoint e)
 {
     ISLogger.Write("Connected to server");
     ConfigFile.TryWriteProperty(ServiceConfigProperties.LastConnectedAddress, e.ToString());
 }
Пример #19
0
 public UsersController(IUnitOfWork uof, ISLogger log, IMapper mapp)
 {
     unitOfWork = uof;
     logger     = log;
     mapper     = mapp;
 }
Пример #20
0
 private void ClientInstance_ConnectionFailed(object sender, string error)
 {
     ISLogger.Write("Failed to connect: " + error);
 }
Пример #21
0
 public StatusJobSaver(ISLogger logger, ILocalStorage localDb, SQLTaskScheduler scheduler) : base(logger, localDb, scheduler)
 {
 }
Пример #22
0
 private void ClientInstance_ConnectionError(object sender, string error)
 {
     ISLogger.Write("Connection error: " + error);
 }
Пример #23
0
        private void IsThreadHandleKeyboard(uint wParam, KBDLLHOOKSTRUCT keyboardStruct)
        {
            int code = (int)wParam;

            switch (code)
            {
            case WM_SYSKEYDOWN:
            case WM_KEYDOWN:
            {
                if (keyboardStruct.scanCode == 0)
                {
                    ISLogger.Write("Cannot get scancode for virtual key {0}", keyboardStruct.vkCode);
                    return;
                }


                if (keyboardStruct.scanCode == (int)ScanCode.Control)
                {
                    currentModifiers |= Hotkey.Modifiers.Ctrl;
                }
                else if (keyboardStruct.scanCode == (int)ScanCode.Alt)
                {
                    currentModifiers |= Hotkey.Modifiers.Alt;
                }
                else if (keyboardStruct.scanCode == (int)ScanCode.LShift | keyboardStruct.scanCode == (int)ScanCode.RShift)
                {
                    currentModifiers |= Hotkey.Modifiers.Shift;
                }

                Hotkey[] list = hotkeyList.ToArray();

                for (int i = 0; i < list.Length; i++)
                {
                    if ((keyboardStruct.scanCode == (short)list[i].HkScan) && (currentModifiers == list[i].Mods))
                    {
                        if (list[i] is ClientHotkey)
                        {
                            ClientHotkey hk = list[i] as ClientHotkey;
                            ClientHotkeyPressed?.Invoke(this, hk);
                        }
                        else if (list[i] is FunctionHotkey)
                        {
                            FunctionHotkey hk = list[i] as FunctionHotkey;
                            FunctionHotkeyPressed?.Invoke(this, hk);
                        }
                    }
                }

                kbData = new ISInputData(ISInputCode.IS_KEYDOWN, (short)keyboardStruct.scanCode, 0);
                break;
            }

            case WM_SYSKEYUP:
            case WM_KEYUP:
            {
                if (keyboardStruct.scanCode == (int)ScanCode.Control)
                {
                    currentModifiers &= ~Hotkey.Modifiers.Ctrl;
                }
                else if (keyboardStruct.scanCode == (int)ScanCode.Alt)
                {
                    currentModifiers &= ~Hotkey.Modifiers.Alt;
                }
                else if (keyboardStruct.scanCode == (int)ScanCode.LShift | keyboardStruct.scanCode == (int)ScanCode.RShift)
                {
                    currentModifiers &= ~Hotkey.Modifiers.Shift;
                }
                kbData = new ISInputData(ISInputCode.IS_KEYUP, (short)keyboardStruct.scanCode, 0);
                break;
            }

            default:
            {
                ISLogger.Write("Unexpected windows keyboard input code " + code);
                return;
            }
            }


            if (UserInputBlocked)
            {
                InputReceived?.Invoke(this, kbData);
            }
        }
Пример #24
0
        void System.Runtime.InteropServices.ComTypes.IDataObject.GetData(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatetc, out System.Runtime.InteropServices.ComTypes.STGMEDIUM medium)
        {
            try
            {
                medium = new System.Runtime.InteropServices.ComTypes.STGMEDIUM();

                if (formatetc.cfFormat == (Int16)DataFormats.GetFormat(NativeMethods.CFSTR_FILECONTENTS).Id)
                {
                    m_lindex = formatetc.lindex;
                }

                if (GetTymedUseable(formatetc.tymed))
                {
                    if ((formatetc.tymed & TYMED.TYMED_ISTREAM) != TYMED.TYMED_NULL)
                    {
                        if (objectType != ClipboardDataType.File)
                        {
                            return;
                        }

                        try
                        {
                            //DropSuccess?.Invoke(this, null);
                            medium.tymed = TYMED.TYMED_ISTREAM;
                            IStream o = (IStream)GetData("FileContents", false);
                            medium.unionmember = Marshal.GetComInterfaceForObject(o, typeof(IStream));
                            return;
                        }
                        catch (Exception ex)
                        {
                            //ISLogger.Write("InputshareDataObject: Get FileContents failed: " + ex.Message);
                            return;
                        }
                    }
                    else if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != TYMED.TYMED_NULL)
                    {
                        medium.tymed       = TYMED.TYMED_HGLOBAL;
                        medium.unionmember = NativeMethods.GlobalAlloc(NativeMethods.GHND | NativeMethods.GMEM_DDESHARE, 1);
                        if (medium.unionmember == IntPtr.Zero)
                        {
                            throw new OutOfMemoryException();
                        }
                        try
                        {
                            ((System.Runtime.InteropServices.ComTypes.IDataObject) this).GetDataHere(ref formatetc, ref medium);
                            return;
                        }
                        catch
                        {
                            NativeMethods.GlobalFree(new HandleRef((STGMEDIUM)medium, medium.unionmember));
                            medium.unionmember = IntPtr.Zero;
                            return;
                        }
                    }
                    medium.tymed = formatetc.tymed;
                    ((System.Runtime.InteropServices.ComTypes.IDataObject) this).GetDataHere(ref formatetc, ref medium);
                }
                else
                {
                    Marshal.ThrowExceptionForHR(NativeMethods.DV_E_TYMED);
                }
            }catch (Exception ex)
            {
                medium = new STGMEDIUM();
                ISLogger.Write("InputshareDataObject: " + ex.Message);
            }
        }
Пример #25
0
        private void ReadCallback(IAsyncResult ar)
        {
            Stream recv = (Stream)ar.AsyncState;

            try
            {
                bytesIn = recv.EndRead(ar);

                //Make sure we read all 4 bytes
                do
                {
                    bytesIn += recv.Read(readBuffer, bytesIn, 4 - bytesIn);
                } while (bytesIn < 4);

                int header = BitConverter.ToInt32(readBuffer, 0);

                //TODO - implement a better way to deal with messages larger than buffer
                if (header + 4 > readBuffer.Length && header < 1024 * 1024 * 50) //max 50mb
                {
                    readBuffer = new byte[header + 4];
                }

                bytesIn = recv.Read(readBuffer, 4, header);

                //Keep reading bytes until full packet has been read
                while (bytesIn != header)
                {
                    bytesIn += recv.Read(readBuffer, bytesIn + 4, header - bytesIn);
                }

                byte[] packet = new byte[header];
                Buffer.BlockCopy(readBuffer, 4, packet, 0, header);

                try
                {
                    if (!useSerializer)
                    {
                        PreProcessMessage(packet);
                    }
                    else
                    {
                        PreProcessMessage(IpcMessageSerializer.DeSerialize(packet));
                    }
                }catch (Exception ex)
                {
                    ISLogger.Write("IpcBase: An error occurred while handling message: " + ex.Message);
                    ISLogger.Write(ex.StackTrace);
                    Thread.Sleep(2000);
                    Process.GetCurrentProcess().Kill();
                }

                //Reset buffer size if changed
                if (readBuffer.Length != 1024)
                {
                    readBuffer = new byte[1024];
                }

                recv.BeginRead(readBuffer, 0, 4, ReadCallback, recv);
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
        }
Пример #26
0
 private void SpMon_SpStarted(object sender, EventArgs e)
 {
     ISLogger.Write($"SP process started");
 }
Пример #27
0
 private void NamedIpc_RequestedDownloadFolder(object sender, EventArgs e)
 {
     ISLogger.Write($"NamedIpc->Requested download folder");
     namedIpc.SendDownloadFolderLocation(cSocket.FileReceivePath);
 }
Пример #28
0
 public InstanceStatusKeeper(ISLogger logger)
 {
     this.logger        = logger;
     instanceInfoHelper = new InstanceInfoHelper();
     localDbHelper      = new LocalDbHelper();
 }
Пример #29
0
 private void OnSASReceived()
 {
     ISLogger.Write("Sending SAS");
     SendSAS(false); //Sends alt+ctrl+del
 }
Пример #30
0
 public InstanceDataCollector(IConnectionManager connManager, IResourceManager resourceManager, ISLogger logger)
 {
     this.connManager     = connManager;
     command              = new SqlCommand();
     command.Connection   = connManager.Connection;
     this.logger          = logger;
     this.resourceManager = resourceManager;
 }