示例#1
0
        static void Main(string[] args)
        {
            CommServer server = new CommServer();

            server.ReadData();
            server.ProcessData();
            Console.ReadKey();
        }
示例#2
0
    public static void Main()
    {
        CommServer s = new CommServer();

        //s.callEvent += ParseRequest();
        s.Start();



        Console.WriteLine("\nHit enter to continue...");
        Console.Read();
    }
示例#3
0
        public static void Shutdown()
        {
            Logger.Log(LogEntryType.Info, "Shutting down beRemote Kernel and corresponding systems", LoggerContext);

            TrayIcon.TrayIconInstance.Hide();
            try
            {
                if (InterCommServer.Running)
                {
                    InterCommServer.Stop();
                    InterCommServer = null;
                }
            }
            catch { }
        }
示例#4
0
            public WorkerProcess(ClipboardAccess clipboard, WmiSession wmisession, IExceptionHandler exceptionhandler, IWorkerProcessHandler wphandler, IntPtr consoletoken)
            {
                this.clipboard        = clipboard;
                this.wmisession       = wmisession;
                this.exceptionhandler = exceptionhandler;
                this.wphandler        = wphandler;

                workerlock = new object();
                try
                {
                    comms = new CommServer(this);
                }
                catch (Exception e)
                {
                    wmisession.Log("Comms server failed to start:" + e.ToString());
                    throw;
                }
                try
                {
                    AddToXDIgnoreApplicationList();
                    string path     = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Citrix\\XenTools", "Install_Dir", "");
                    string fullpath = string.Format("{0}\\" + Branding.Instance.getString("FILENAME_dpriv"), path);
                    string cmdline  = string.Format(Branding.Instance.getString("FILENAME_dpriv") + " {0}", comms.secret);
                    this.worker            = new SafeWaitHandle(Win32Impl.CreateUserProcess(consoletoken, fullpath, cmdline), true);
                    workerWaiter           = new ProcessWaitHandle(this.worker);
                    registeredWorkerWaiter = ThreadPool.RegisterWaitForSingleObject(workerWaiter, handleWorker, null, Timeout.Infinite, true);
                    this.workerrunning     = true;
                    wmisession.Log("Worker Process spawned");
                }
                catch (Exception e)
                {
                    wmisession.Log("Worker process spawn exception : " + e.ToString());
                    comms.CloseMessagePipes();

                    throw;
                }
            }
示例#5
0
        private static void InitiateCore(Boolean databaseOnly)
        {
            // Set the failed handler in order to catch also AlreadyRunning exceptions
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            OnKernelFailed += Kernel_OnKernelFailed;
            // At first we need to check if other beremote instances are running, if so we do some stuff...
            //var exists = ExistsMultipleBeremoteInstances();
            //if (exists)
            //{
            //    var client = new CommClient();
            //    client.ShowNotification("beRemote is already running. Trying to focus it now...");
            //    client.FocusMainWindow();

            //    throw new ApplicationAlreadyRunningException();
            //}

            // Starting the logging facility
            InitiateLogger();

            // Starting the inter communication wcf service for communication accross multiple beremote instances (cli support only)
            try
            {
                InterCommServer = new CommServer(KernelInstanceGuid);
                InterCommServer.Start();
            }
            catch (System.ServiceModel.AddressAlreadyInUseException ex)
            {
                var client = new CommClient();
                client.ShowNotification("beRemote is already running. Trying to focus it now...");
                client.FocusMainWindow();

                //TriggerNewConnection();

                var exc = new ApplicationAlreadyRunningException();

                OnKernelFailed(null, new KernelFailedEventArgs(exc));

                return;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString(), 0);
            }


            try
            {
                //TODO: Remove this after update releases. Only for compatiblity purposes while old versions are in use
                var databasePath    = System.Environment.ExpandEnvironmentVariables(Helper.GetApplicationConfiguration().GetValue("database", "dbpath"));
                var newDbPath       = new FileInfo(databasePath);
                var compatOldDbPath = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "\\" + newDbPath.Name);

                if (compatOldDbPath.Exists && false == newDbPath.Exists)
                {
                    Logger.Warning("Database was present in executable folder. Copying it over to config file target.");

                    compatOldDbPath.CopyTo(newDbPath.FullName);
                }

                // possible override of database
                if (ParsedOptions != null)
                {
                    if (ParsedOptions.ContainsParameter("db-interface"))
                    {
                        var option = ParsedOptions.GetParameter("db-interface");

                        var localConfig = Helper.GetApplicationConfiguration();

                        Logger.Info("Overriding default database interface");

                        localConfig.SetValue("database", "dbinterface", option.Value, true);
                    }

                    if (ParsedOptions.ContainsParameter("db-path"))
                    {
                        var option = ParsedOptions.GetParameter("db-path");

                        var localConfig = Helper.GetApplicationConfiguration();

                        Logger.Info("Overriding default database path, now using: " + option.Value);

                        localConfig.SetValue("database", "dbpath", option.Value, true);
                    }
                }

                StorageCore.Core.InitDatabaseGuid(false);
            }
            catch { }

            // Deleting tmp folder
            try
            {
                var tmp = new DirectoryInfo(Environment.ExpandEnvironmentVariables("%appdata%\\beRemote\\tmp"));

                if (tmp.Exists)
                {
                    tmp.Delete(true);
                }
            }
            catch (Exception ex)
            {
                new beRemoteException(beRemoteExInfoPackage.MajorInformationPackage,
                                      "Problem removing tmp folder of previous instances.", ex);
            }


            if (true == databaseOnly)
            {
                Logger.Log(LogEntryType.Warning, "Kernel initiation is skipped due to database only flag!");

                if (OnKernelReady != null)
                {
                    OnKernelReady(new StackTrace(), new KernelReadyEventArgs());
                }

                return;
            }
            else
            {
                Logger.Log(LogEntryType.Debug, "Initiating beRemote ProtocolSystem thread", LoggerContext);

                AllPluginSystemCaller();


                Logger.Log(LogEntryType.Debug, "... all beRemote System threads are running!", LoggerContext);

                if (OnKernelReady != null)
                {
                    OnKernelReady(new StackTrace(), new KernelReadyEventArgs());
                }
            }
        }
示例#6
0
 // SERVER only
 public void ListenForClients(int port)
 {
     commServer = new CommServer(port);
     InitializeMultiplayer();
     commServer.Start();
 }
示例#7
0
        static void Main()
        {
            CommServer server = new CommServer();

            server.Listen(8888);
            server.OnConnect += delegate()
            {
                Console.WriteLine("An agent connects.");
            };
            server.OnReceive += delegate()
            {
                byte[] data;
                IMsg   msg;
                if (server.TryTake(out msg))
                {
                    MessageToServer mm = msg.Content as MessageToServer;
                    Console.WriteLine($"Receive a message from {mm.PlayerID}");
                    Console.WriteLine($"Message type::{mm.MessageType}");
                    if (mm.MessageType == MessageType.Send)
                    {
                        Console.WriteLine(mm.Message);
                    }
                }
                else
                {
                    Console.WriteLine("fail to dequeue");
                }
            };
            Console.WriteLine("============================");
            Console.ReadLine();

            {
                MessageToOneClient m = new MessageToOneClient();
                m.PlayerID    = 0;
                m.TeamID      = 0;
                m.MessageType = MessageType.ValidPlayer;
                m.Guid        = 888;
                server.SendMessage(m);
                Console.WriteLine("已发送Validplayer");
            }

            Console.ReadLine();
            server.SendMessage(TestMessage(0, MessageType.StartGame));
            Console.WriteLine("已发送StartGame");
            Console.ReadLine();
            for (int i = 0; i < 100; i++)
            {
                server.SendMessage(TestMessage(i, MessageType.Gaming));
                Thread.Sleep(50);
            }
            Console.WriteLine("Gaming");
            Console.ReadLine();
            for (int i = 0; i < 100; i++)
            {
                server.SendMessage(TestMessage(i + 100, MessageType.Gaming));
                Thread.Sleep(50);
            }
            MessageToOneClient m2OC = new MessageToOneClient();

            m2OC.Guid        = 12345;
            m2OC.PlayerID    = 0;
            m2OC.TeamID      = 0;
            m2OC.MessageType = MessageType.Send;
            m2OC.Message     = "Hello world!";
            server.SendMessage(m2OC);
            Console.WriteLine("Msg sent");
            for (int i = 0; i < 100; i++)
            {
                server.SendMessage(TestMessage(i + 200, MessageType.Gaming));
                Thread.Sleep(50);
            }
            server.SendMessage(TestMessage(666, MessageType.EndGame));
            Console.WriteLine("GameOver");
            Console.ReadLine();
            server.Dispose();
            server.Stop();
        }
示例#8
0
    public static void Main(String[] args)
    {
        string     command;
        CommServer server = new CommServer("192.168.7.1", 9009, 9008, 9007);

        server.OnBytesReceived += RespondToIncoming;

        // TEST FOR SENGIND A FILE TO BBB
        // the next three lines require a temp.txt file to be
        // present in the local directory
        // string path = Directory.GetCurrentDirectory();
        // path = path + "/temp.txt";
        // server.sendFile(path);

        // 1 <= deviceID <= 4
        int deviceID = 1;
        // server.turnPower(true, 1);

        // TEST FOR RECIEVE BYTES
        // byte[] things = server.receiveBytes(deviceID);
        // for(int i = 0; i < things.Length; i++) {
        // Console.WriteLine(things[i].ToString("X"));
        // }

        // TEST FOR SEND BYTES
        // Note that the actual function you would use would
        // be server.sendBytes(int id, byte[] data)
        // where id is the emm'd device id and data
        // is the data to be sent to the emm'd device
        // Console.WriteLine()
        // Console.WriteLine("TESTING SEND BYTES...");
        // server.testSendBytes(deviceID);
        // Console.WriteLine("SEND BYTES TESTING COMPLETE");

        // TEST GETVID()
        // Console.WriteLine("Getting VID...");
        // Console.WriteLine(server.getVID(deviceID));

        // TEST GETPID()
        // Console.WriteLine("Getting PID");
        // Console.WriteLine(server.getPID(deviceID));
        // System.Threading.Thread.Sleep(2000);
        // server.turnPower(false, 1);

        bool run = true;

        while (run)
        {
            command = Console.ReadLine();
            if (command == "off")
            {
                run = !run;
            }
            else if (command == "send")
            {
                command = Console.ReadLine();
                server.sendData(command);
            }
            else if (command == "test")
            {
                server.testSendBytes(deviceID);
            }
            else if (command == "chat")
            {
                server.sendData("RELAY:");
            }
            else if (command == "POWER")
            {
                server.turnPower(true, 0);
            }
        }

        server.disconnect();
    }