Example #1
0
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            var msg = $"Service is recall at {DateTime.Now}";

            _server.PushMessage(new ServerCommand {
                Action = ServerAction.Info, Data = msg
            });
        }
Example #2
0
        public void UniverseUpdateAfter()
        {
            if (_serverMainLoop == null && ServerContext.VillageDirector != null && ServerContext.VillageDirector.HasDirectorFacade())
            {
                _serverMainLoop = (ServerMainLoop)typeof(DirectorUniverseFacade)
                                  .GetField("_serverMainLoop",
                                            BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                  ?.GetValue(ServerContext.VillageDirector.UniverseFacade);

                _pipeServer.PushMessage(new PipeClass {
                    Current = KeyEnum.Intergrated
                });
            }
        }
 private void OnAttachDebuggerMessageReceived(NamedPipeConnection <AttachDebuggerMessage, AttachDebuggerMessage> connection,
                                              AttachDebuggerMessage message)
 {
     try
     {
         message.DebuggerAttachedSuccessfully = _debuggerAttacher.AttachDebugger(message.ProcessId);
         if (!message.DebuggerAttachedSuccessfully)
         {
             message.ErrorMessage = $"Could not attach debugger to process {message.ProcessId} for unknown reasons";
         }
     }
     catch (Exception e)
     {
         message.DebuggerAttachedSuccessfully = false;
         message.ErrorMessage = $"Could not attach debugger to process {message.ProcessId} because of exception on server side:{Environment.NewLine}{e}";
     }
     finally
     {
         try
         {
             _server.PushMessage(message);
         }
         catch (Exception e)
         {
             _logger.LogError($"Exception on server side while sending debugging response message:{Environment.NewLine}{e}");
         }
     }
 }
 public void SendMessageToClient(int messageType, string content)
 {
     pipeServer.PushMessage(new PipeMessage()
     {
         messageType = messageType, content = content
     });
 }
Example #5
0
 private void SendPipeMessage(PacketID packetId, bool isIdle = false, string data = "", string data2 = "", PacketID requestId = PacketID.None, NamedPipeConnection <IdleMessage, IdleMessage> connection = null)
 {
     try
     {
         if (connection == null)
         {
             server.PushMessage(new IdleMessage
             {
                 packetId  = (int)packetId,
                 isIdle    = isIdle,
                 requestId = (int)requestId,
                 data      = data,
                 data2     = data2
             });
         }
         else
         {
             connection.PushMessage(new IdleMessage
             {
                 packetId  = (int)packetId,
                 isIdle    = isIdle,
                 requestId = (int)requestId,
                 data      = data,
                 data2     = data2
             });
         }
     }
     catch (Exception ex)
     {
         Utilities.Log("SendPipeMessage: " + ex.Message);
     }
 }
Example #6
0
 private void ProcessErrorAndResponse(ErrorInfo.ErrorCode errorCode, MessageContainer message)
 {
     if (ClientConnected)
     {
         var response = new MsgResponse {
             ErrorCode = errorCode, Message = message.Message
         };
         _server.PushMessage(new MessageContainer(response));
     }
     if (errorCode != ErrorInfo.ErrorCode.NoErrors)
     {
         for (int i = 0; i < 5; i++)
         {
             var err = _outputManagement.SetAllOff();
             if (err == ErrorInfo.ErrorCode.NoErrors)
             {
                 break;
             }
             System.Threading.Thread.Sleep(200);
         }
         Logger.Log("ProcessErrorAndResponse: " + errorCode.ToString());
         System.Threading.Thread.Sleep(2000);
         Environment.Exit(1);
     }
 }
Example #7
0
 public void Run()
 {
     while (true)
     {
         try
         {
             if (_connection != null && _connection.Answers.Count > 0)
             {
                 _server.PushMessage(_connection.Answers.Dequeue());
             }
         }
         catch (Exception e)
         {
             OnError(e);
         }
     }
 }
Example #8
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBoxMessage.Text))
            {
                return;
            }
            if (listBoxClients.SelectedItem == null)
            {
                _server.PushMessage(textBoxMessage.Text);
            }
            else
            {
                var clientName = listBoxClients.SelectedItem.ToString();
                _server.PushMessage(textBoxMessage.Text, clientName);
            }

            textBoxMessage.Text = "";
        }
Example #9
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBoxMessage.Text))
            {
                return;
            }

            _server.PushMessage(textBoxMessage.Text);
            textBoxMessage.Text = "";
        }
Example #10
0
        public bool SendCommandToUI(BeSafePipeCommand command)
        {
            try
            {
                _serverPipe.PushMessage(command);
                return(true);
            }
            catch (Exception ex)
            {
                ex.Log();
            }

            return(false);
        }
Example #11
0
 private void PushMessage(BaseMessage msg)
 {
     if (m_waitingForAuth)
     {
         // We'll only allow auth messages through until authentication has
         // been confirmed.
         if (msg.GetType() == typeof(AuthenticationMessage))
         {
             m_server.PushMessage(msg);
         }
         else if (msg.GetType() == typeof(RelaxedPolicyMessage))
         {
             m_server.PushMessage(msg);
         }
         else if (msg.GetType() == typeof(NotifyBlockActionMessage))
         {
             m_server.PushMessage(msg);
         }
     }
     else
     {
         m_server.PushMessage(msg);
     }
 }
Example #12
0
        private void test2()
        {
            _server = new NamedPipeServer <String>("DataTablePipe");
            _server.ClientMessage   += ServerOnClientMessage;
            _server.ClientConnected += ServerOnClientConnected;
            _server.Error           += ServerError;
            _server.Start();

            _client = new NamedPipeClient <String>("DataTablePipe");
            _client.ServerMessage += ClientOnServerMessage;
            _client.Start();
            _client.WaitForConnection();

            _client.PushMessage("Dog");
            _server.PushMessage("Cat");
        }
Example #13
0
 private void SendPipeMessage(PacketID packetId, bool isIdle = false, string data = "", PacketID requestId = PacketID.None)
 {
     try
     {
         server.PushMessage(new IdleMessage
         {
             packetId  = (int)packetId,
             isIdle    = isIdle,
             requestId = (int)requestId,
             data      = data
         });
     }
     catch (Exception ex)
     {
         Utilities.Log("SendPipeMessage: " + ex.Message);
     }
 }
Example #14
0
        public void NamedPipeTest()
        {
            string a = "abc";
            string b = "123";

            // serwer wysyla do klienta "abc"
            // klient weryfikuje, ze otrzymal "abc"
            // klient odsyla do serwera "123"
            // serwer weryfikuje, ze otrzymal "123"

            var pipeServer = new NamedPipeServer <PipeMessage>("testtesttest");

            pipeServer.ClientMessage += delegate(NamedPipeConnection <PipeMessage, PipeMessage> conn, PipeMessage message)
            {
                Assert.AreEqual(b, message.content);
            };

            pipeServer.Start();

            var pipeClient = new NamedPipeClient <PipeMessage>("testtesttest");

            pipeClient.ServerMessage += delegate(NamedPipeConnection <PipeMessage, PipeMessage> conn, PipeMessage message)
            {
                Assert.AreEqual(a, message.content);

                pipeClient.PushMessage(new PipeMessage()
                {
                    messageType = 0, content = b
                });
            };

            pipeClient.Start();

            pipeServer.PushMessage(new PipeMessage()
            {
                messageType = 0, content = a
            });
        }
Example #15
0
 public void Send(XmlDocument xml)
 {
     server.PushMessage(xml.OuterXml);
 }
Example #16
0
 public override void PushMessage(Message message)
 {
     server.PushMessage(message);
 }
Example #17
0
        private static void OnMouseMove(InputEventArgs e)
        {
            if (_isMoving)
            {
                return;
            }
            try
            {
                _isMoving = true;
                var app = SAPHook.Instance.app;
                if (app != null && app.Children != null)
                {
                    for (int x = 0; x < app.Children.Count; x++)
                    {
                        var con = app.Children.ElementAt(x) as GuiConnection;
                        if (con.Sessions.Count == 0)
                        {
                            continue;
                        }

                        for (int j = 0; j < con.Sessions.Count; j++)
                        {
                            var session    = con.Children.ElementAt(j) as GuiSession;
                            var SystemName = session.Info.SystemName.ToLower();
                            // var ele = session as GuiComponent;
                            GuiCollection keys = null;
                            try
                            {
                                if (System.Threading.Monitor.TryEnter(_lock, 1))
                                {
                                    try
                                    {
                                        var _y = session.ActiveWindow.Top;
                                        var _x = session.ActiveWindow.Left;
                                        var w  = session.ActiveWindow.Width;
                                        var h  = session.ActiveWindow.Height;
                                        if (e.X < _x || e.Y < _y)
                                        {
                                            return;
                                        }
                                        if (e.X > (_x + w) || e.Y > (_y + h))
                                        {
                                            return;
                                        }
                                        keys = session.FindByPosition(e.X, e.Y);
                                    }
                                    finally
                                    {
                                        System.Threading.Monitor.Exit(_lock);
                                    }
                                }
                                else
                                {
                                    return;
                                }
                            }
                            catch (System.Runtime.InteropServices.COMException ex)
                            {
                                // OnMouseMove(e);
                            }
                            catch (Exception ex)
                            {
                                log(ex.Message);
                            }
                            if (keys == null)
                            {
                                return;
                            }
                            var _keys = new List <string>();
                            foreach (string key in keys)
                            {
                                _keys.Add(key);
                            }

                            SAPEventElement[] elements = new SAPEventElement[] { };

                            log("**************************");
                            var          children = new List <SAPEventElement>();
                            GuiComponent last     = null;
                            foreach (string key in keys)
                            {
                                log(key.ToString());
                                if (string.IsNullOrEmpty(key))
                                {
                                    continue;
                                }
                                if (!key.Contains("?"))
                                {
                                    var ele = session.FindById(key);
                                    if (ele == null)
                                    {
                                        continue;
                                    }
                                    last = ele as GuiComponent;
                                    // last = ele as GuiVComponent;
                                    // if(last != null) last.Visualize(true);
                                    var _msg = new SAPEventElement(ele, SystemName, "", false);
                                    children.Add(_msg);
                                }
                            }
                            if (last != null)
                            {
                                foreach (string key in keys)
                                {
                                    if (string.IsNullOrEmpty(key))
                                    {
                                        continue;
                                    }
                                    if (key.Contains("?"))
                                    {
                                        if (LastElement == null)
                                        {
                                            continue;
                                        }
                                        var _key = key.Substring(0, key.IndexOf("?"));
                                        log(_key);
                                        var msg = new SAPEventElement(session, last, session.Info.SystemName, false, _key, "", false, false, 1, false);
                                        if (msg != null)
                                        {
                                            children.Add(msg);
                                            LastElement = msg;
                                        }
                                    }
                                }
                            }
                            LastElement = children.LastOrDefault();
                            if (LastElement != null)
                            {
                                SAPEvent message = new SAPEvent("mousemove");
                                message.Set(LastElement);
                                if (log_send_message)
                                {
                                    form.AddText("[send] " + message.action + " " + LastElement.ToString() + " " + LastElement.Rectangle.ToString());
                                }
                                pipe.PushMessage(message);
                            }
                        }
                    }
                }


                // elements = children.ToArray();

                //if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //{
                //    try
                //    {
                //        if (isMoving) return;
                //        isMoving = true;
                //    }
                //    finally
                //    {
                //        System.Threading.Monitor.Exit(_lock);
                //    }
                //}
                //try
                //{
                //    if (SAPHook.Instance.Connections.Count() == 0 || SAPHook.Instance.UIElements.Count() == 0)
                //    {
                //        if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //        {
                //            try
                //            {
                //                isMoving = false;
                //            }
                //            finally
                //            {
                //                System.Threading.Monitor.Exit(_lock);
                //            }
                //        }
                //        return;
                //    }
                //    var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y));
                //    if (Element != null)
                //    {
                //        var ProcessId = Element.Current.ProcessId;
                //        if (ProcessId < 1)
                //        {
                //            if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //            {
                //                try
                //                {
                //                    isMoving = false;
                //                }
                //                finally
                //                {
                //                    System.Threading.Monitor.Exit(_lock);
                //                }
                //            }
                //            return;
                //        }
                //        if (SAPProcessId > 0 && SAPProcessId != ProcessId)
                //        {
                //            if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //            {
                //                try
                //                {
                //                    isMoving = false;
                //                }
                //                finally
                //                {
                //                    System.Threading.Monitor.Exit(_lock);
                //                }
                //            }
                //            return;
                //        }
                //        if (SAPProcessId != ProcessId)
                //        {
                //            using (var p = System.Diagnostics.Process.GetProcessById(ProcessId))
                //            {
                //                if (p.ProcessName.ToLower() == "saplogon") SAPProcessId = p.Id;
                //                if (p.ProcessName.ToLower() != "saplogon")
                //                {
                //                    if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //                    {
                //                        try
                //                        {
                //                            isMoving = false;
                //                        }
                //                        finally
                //                        {
                //                            System.Threading.Monitor.Exit(_lock);
                //                        }
                //                    }
                //                    return;
                //                }
                //            }
                //        }
                //        if (SAPHook.Instance.Connections.Count() == 0) SAPHook.Instance.RefreshSessions();
                //        if (SAPHook.Instance.UIElements.Count() == 0) SAPHook.Instance.RefreshUIElements(true);
                //        SAPEventElement[] elements = new SAPEventElement[] { };
                //        if (System.Threading.Monitor.TryEnter(SAPHook.Instance.UIElements, 10000))
                //        {
                //            try
                //            {
                //                elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                //            }
                //            finally
                //            {
                //                System.Threading.Monitor.Exit(SAPHook.Instance.UIElements);
                //            }
                //        }
                //        if (elements.Count() > 0)
                //        {
                //            //Program.log("[mousemove] " + e.X + " " + e.Y);
                //            //foreach(var ele in elements)
                //            //{
                //            //    Program.log("[element] " + ele.ToString());
                //            //}
                //            var found = elements.OrderBy(x => x.IdPathCell.Length).Last();
                //            if (found.Items != null && found.Items.Length > 0)
                //            {
                //                elements = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                //                if (elements != null && elements.Length > 0) found = elements.OrderBy(x => x.IdPathCell.Length).Last();

                //            }
                //            //Program.log("[element] " + found.ToString() + " " + found.Rectangle.ToString());

                //            if (found.Items != null && found.Items.Length > 0)
                //            {
                //                var found2 = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                //                if (found2.Length > 0)
                //                {
                //                    found = found2.First();
                //                }
                //            }

                //            if (LastElement != null && (found.Id == LastElement.Id && found.Path == LastElement.Path && found.Cell == LastElement.Cell))
                //            {
                //                // form.AddText("[SKIP] mousemove " + LastElement.ToString());
                //                if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //                {
                //                    try
                //                    {
                //                        isMoving = false;
                //                    }
                //                    finally
                //                    {
                //                        System.Threading.Monitor.Exit(_lock);
                //                    }
                //                }
                //                return;
                //            }
                //            LastElement = found;
                //            SAPEvent message = new SAPEvent("mousemove");
                //            message.Set(LastElement);
                //            if (log_send_message) form.AddText("[send] " + message.action + " " + LastElement.ToString() + " " + LastElement.Rectangle.ToString());
                //            pipe.PushMessage(message);
                //        }
                //        else
                //        {
                //            // log("Mouseover " + e.X + "," + e.Y + " not found in UI List");
                //        }
                //    }
                //}
                //catch (Exception)
                //{
                //}
                //if (System.Threading.Monitor.TryEnter(_lock, 10000))
                //{
                //    try
                //    {
                //        isMoving = false;
                //    }
                //    finally
                //    {
                //        System.Threading.Monitor.Exit(_lock);
                //    }
                //}
            }
            finally
            {
                _isMoving = false;
            }
        }
Example #18
0
 public void MemoryLoop()
 {
     //Console.Clear();
     if (GetSignature("WORLD", out var worldSig))
     {
         SigWorldData data = (SigWorldData)worldSig.GetData(ffxivProcess);
         if (worldData == null || !data.Equals(worldData))
         {
             dataPipe.PushMessage(CreatePipeData(data));
             Console.WriteLine("World: " + data.world);
             worldData = data;
         }
     }
     if (GetSignature("PERFSTATUS", out var perfSig))
     {
         SigPerfData data = (SigPerfData)perfSig.GetData(ffxivProcess);
         if (data != null)
         {
             if (perfData == null || !data.Equals(perfData))
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 Console.WriteLine("Performance change " + data.IsUp());
                 perfData = data;
             }
         }
     }
     if (GetSignature("CHARID", out var charidSig))
     {
         SigCharIdData data = (SigCharIdData)charidSig.GetData(ffxivProcess);
         if (data != null)
         {
             if (charIdData == null || !data.Equals(charIdData))
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 Console.WriteLine("New charid: " + data.id);
                 charIdData = data;
             }
         }
     }
     if (GetSignature("CHARMAP", out var charSig))
     {
         SigActorsData data = (SigActorsData)charSig.GetData(ffxivProcess);
         if (data != null)
         {
             if (data.currentActors.Values.Count > 0)
             {
                 ActorData me = data.currentActors.First().Value;
                 //Console.WriteLine(string.Format("YOU: {0} {1}", me.name, me.id));
             }
             if (data.addedActors.Count > 0 || data.removedActors.Count > 0)
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 string added = String.Join("+", data.addedActors.Select(t => t.Value.name).ToArray());
                 Console.WriteLine(string.Format("Players: {0} new, {1} removed: {2}", data.addedActors.Count, data.removedActors.Count, added));
             }
             if (false)
             {
                 string added   = String.Join(",", data.addedActors.Select(t => t.Value.name).ToArray());
                 string current = String.Join(",", data.currentActors.Select(t => t.Value.name).ToArray());
                 string removed = String.Join(",", data.removedActors.Select(t => t.Value.name).ToArray());
                 Console.WriteLine(string.Format("--- {0} players", data.currentActors.Count()));
                 Console.WriteLine(string.Format("ADDED: {0}", added));
                 Console.WriteLine(string.Format("REMOVED: {0}", removed));
                 Console.WriteLine(string.Format("CURRENT: {0}", current));
             }
         }
     }
     if (GetSignature("CHATLOG", out var chatlogSig))
     {
         SigChatLogData data = (SigChatLogData)chatlogSig.GetData(ffxivProcess);
         if (data != null)
         {
             foreach (ChatLogItem msg in data.chatMessages)
             {
                 Console.WriteLine(msg.Line);
             }
             if (data.chatMessages.Count > 0)
             {
                 dataPipe.PushMessage(CreatePipeData(data));
                 Console.WriteLine(string.Format("Chatlog: {0} new", data.chatMessages.Count));
             }
         }
     }
 }
Example #19
0
        public void StartProcess(
            ProcessStartInfo processInfo,
            object cancellationToken,
            string logger,
            Action postProcess,
            TimeSpan timeOut)
        {
            Process process = null;

            try
            {
                if (processInfo == null)
                {
                    throw new ArgumentNullException($"{nameof(processInfo)} was null");
                }
                var processName = "<unidentified>";
                var processId   = "<N/A>";
                var sw          = new Stopwatch();
                var token       = (CancellationToken)cancellationToken;
                process = new Process {
                    StartInfo = processInfo
                };
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.EnableRaisingEvents = true;
                process.Exited += (sender,
                                   args) =>
                {
                    sw.Stop();
                    $"'{processName}' with id '{processId}' has exited. Time elapsed (ms) = {sw.ElapsedMilliseconds.ToString("F")}".Info(logger);
                };
                process.Disposed += (sender,
                                     args) =>
                {
                    $"'{processName}' with id '{processId}' has been disposed (event)".Info(logger);
                };
                process.ErrorDataReceived += (sender,
                                              args) =>
                {
                    if (!string.IsNullOrEmpty(args.Data))
                    {
                        $"Error data received on '{processName}' with id '{processId}' : {args.Data}".Info(logger);
                    }
                };
                process.OutputDataReceived += (sender,
                                               args) =>
                {
                    if (!string.IsNullOrEmpty(args.Data))
                    {
                        $"Output data received on '{processName}' with id '{processId}': {args.Data}".Info(logger);
                    }
                };
                lock (_processListLockingObject)
                {
                    _processes.Add(process);
                }
                sw.Start();
                if (!process.Start() && process.HasExited)
                {
                    $"Process has exited immediately after start".Info();
                }
                else
                {
                    processName = process.ProcessName;
                    processId   = process.Id.ToString();
                    $"Starting process '{processName}' with id '{processId}' using file '{process.StartInfo.FileName}' and arguments '{process.StartInfo.Arguments ?? "<none>"} in working dir {process.StartInfo.WorkingDirectory}".Info();
                }
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
                _pipeServer?.PushMessage(new ProcessDescriptor()
                {
                    ProcessId = process.Id
                });
                postProcess?.Invoke();
                var startTime = DateTime.UtcNow;
                while (!token.IsCancellationRequested)
                {
                    if (process.HasExited)
                    {
                        break;
                    }
                    if ((DateTime.UtcNow - startTime) > timeOut)
                    {
                        $"Killing process {process.Id} because its runtime exceeded timeout {timeOut.TotalSeconds}s".Info();
                        throw new TimeoutException("Process timed out");
                    }
                    token.WaitHandle.WaitOne(TimeSpan.FromMilliseconds(1000));
                }
            }
            catch (Exception e)
            {
                e.Error(logger);
            }
            finally
            {
                if (process != null && !process.HasExited)
                {
                    process.Kill();
                    process.Dispose();
                    if (!process.WaitForExit(60000))
                    {
                        throw new InvalidOperationException($"Could not terminate '{process.ProcessName}' process");
                    }
                }
            }
        }
Example #20
0
        private static void OnMouseMove(InputEventArgs e)
        {
            lock (_lock)
            {
                if (isMoving)
                {
                    return;
                }
                isMoving = true;
            }
            try
            {
                if (SAPHook.Instance.Connections.Count() == 0 || SAPHook.Instance.UIElements.Count() == 0)
                {
                    lock (_lock)
                    {
                        isMoving = false;
                    }
                    return;
                }
                var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y));
                if (Element != null)
                {
                    var ProcessId = Element.Current.ProcessId;
                    if (ProcessId < 1)
                    {
                        lock (_lock)
                        {
                            isMoving = false;
                        }
                        return;
                    }
                    if (SAPProcessId > 0 && SAPProcessId != ProcessId)
                    {
                        lock (_lock)
                        {
                            isMoving = false;
                        }
                        return;
                    }
                    if (SAPProcessId != ProcessId)
                    {
                        var p = System.Diagnostics.Process.GetProcessById(ProcessId);
                        if (p.ProcessName.ToLower() == "saplogon")
                        {
                            SAPProcessId = p.Id;
                        }
                        if (p.ProcessName.ToLower() != "saplogon")
                        {
                            lock (_lock)
                            {
                                isMoving = false;
                            }
                            return;
                        }
                    }
                    if (SAPHook.Instance.Connections.Count() == 0)
                    {
                        SAPHook.Instance.RefreshSessions();
                    }
                    if (SAPHook.Instance.UIElements.Count() == 0)
                    {
                        SAPHook.Instance.RefreshUIElements(true);
                    }
                    SAPEventElement[] elements = new SAPEventElement[] { };
                    lock (SAPHook.Instance.UIElements)
                    {
                        elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                    }
                    if (elements.Count() > 0)
                    {
                        //Program.log("[mousemove] " + e.X + " " + e.Y);
                        //foreach(var ele in elements)
                        //{
                        //    Program.log("[element] " + ele.ToString());
                        //}
                        var found = elements.OrderBy(x => x.IdPathCell.Length).Last();
                        if (found.Items != null && found.Items.Length > 0)
                        {
                            elements = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                            if (elements != null && elements.Length > 0)
                            {
                                found = elements.OrderBy(x => x.IdPathCell.Length).Last();
                            }
                        }
                        //Program.log("[element] " + found.ToString() + " " + found.Rectangle.ToString());

                        if (found.Items != null && found.Items.Length > 0)
                        {
                            var found2 = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
                            if (found2.Length > 0)
                            {
                                found = found2.First();
                            }
                        }

                        if (LastElement != null && (found.Id == LastElement.Id && found.Path == LastElement.Path && found.Cell == LastElement.Cell))
                        {
                            // form.AddText("[SKIP] mousemove " + LastElement.ToString());
                            lock (_lock)
                            {
                                isMoving = false;
                            }
                            return;
                        }
                        LastElement = found;
                        SAPEvent message = new SAPEvent("mousemove");
                        message.Set(LastElement);
                        form.AddText("[send] " + message.action + " " + LastElement.ToString() + " " + LastElement.Rectangle.ToString());
                        pipe.PushMessage(message);
                    }
                    else
                    {
                        log("Mouseover " + e.X + "," + e.Y + " not found in UI List");
                    }
                }
            }
            catch (Exception)
            {
            }
            lock (_lock)
            {
                isMoving = false;
            }
        }
Example #21
0
 public override void OnDataUpdate(object data)
 {
     base.OnDataUpdate(data);
     dataPipe.PushMessage(CreatePipeData(data));
 }
Example #22
0
 public void BroadcastTemperature(float t)
 {
     _Server.PushMessage(string.Format(TemperatureFormat, t));
 }
Example #23
0
 public static void SendPipeCommand(string cmd)
 {
     Console.WriteLine("Sending pipe command: " + cmd);
     server.PushMessage(cmd);
 }
Example #24
0
 private static void OnMouseMove(InputEventArgs e)
 {
     System.Diagnostics.Trace.WriteLine("OnMouseMove: " + isMoving);
     if (isMoving)
     {
         return;
     }
     isMoving = true;
     try
     {
         if (SAPHook.Instance.Connections.Count() == 0)
         {
             return;
         }
         if (SAPHook.Instance.UIElements.Count() == 0)
         {
             return;
         }
         var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y));
         if (Element != null)
         {
             var ProcessId = Element.Current.ProcessId;
             if (ProcessId < 1)
             {
                 return;
             }
             if (SAPProcessId > 0 && SAPProcessId != ProcessId)
             {
                 return;
             }
             if (SAPProcessId != ProcessId)
             {
                 var p = System.Diagnostics.Process.GetProcessById(ProcessId);
                 if (p.ProcessName.ToLower() == "saplogon")
                 {
                     SAPProcessId = p.Id;
                 }
                 if (p.ProcessName.ToLower() != "saplogon")
                 {
                     return;
                 }
             }
             LastElement = Element;
             if (SAPHook.Instance.Connections.Count() == 0)
             {
                 SAPHook.Instance.RefreshSessions();
             }
             if (SAPHook.Instance.UIElements.Count() == 0)
             {
                 SAPHook.Instance.RefreshUIElements();
             }
             SAPEventElement[] elements = new SAPEventElement[] { };
             lock (SAPHook.Instance.UIElements)
             {
                 elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray();
             }
             if (elements.Count() > 0)
             {
                 var      last    = elements.OrderBy(x => x.Id.Length).Last();
                 SAPEvent message = new SAPEvent("mousemove");
                 message.Set(last);
                 form.AddText("[send] " + message.action + " " + last.Id);
                 pipe.PushMessage(message);
             }
             else
             {
                 log("Mouseover " + e.X + "," + e.Y + " not found in UI List");
             }
         }
     }
     catch (Exception)
     {
     }
     isMoving = false;
 }
Example #25
0
 private void OnClientMessage(NamedPipeConnection <string, string> connection, string message)
 {
     //_server object has the PUBLISHING feature
     _server.PushMessage($"<<PUBLISH MESSAGE!!! Client {connection.Id} says: {message}>>");
 }