コード例 #1
0
        public void Run(string accessKey)
        {
            Console.WriteLine("EngineExample Running");
            var engineClient = new EngineClient(accessKey);

            if (!engineClient.IsAlive())
            {
                Console.WriteLine("Engine is not running");
                return;
            }

            try
            {
                var result = engineClient.Get("1", 10, new[] { "1" });
                foreach (var res in result.ItemScores)
                {
                    Console.WriteLine("Sync:" + res.Item + " " + res.Score);
                }
                var asyncResult = engineClient.GetAsync("1", 10, new[] { "1" }).Result;
                foreach (var res in asyncResult.ItemScores)
                {
                    Console.WriteLine("Async:" + res.Item + " " + res.Score);
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #2
0
        public void Run(string accessKey)
        {
            Console.WriteLine("EngineExample Running");
            var engineClient = new EngineClient(accessKey);
            if (!engineClient.IsAlive())
            {
                Console.WriteLine("Engine is not running");
                return;
            }

            try
            {
                var result = engineClient.Get("1", 10, new[] { "1" });
                foreach (var res in result.ItemScores)
                {
                    Console.WriteLine("Sync:" + res.Item + " " + res.Score);
                }
                var asyncResult = engineClient.GetAsync("1", 10, new[] { "1" }).Result;
                foreach (var res in asyncResult.ItemScores)
                {
                    Console.WriteLine("Async:" + res.Item + " " + res.Score);
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

        }
コード例 #3
0
ファイル: Program.cs プロジェクト: antoine510/MouseDeamon
        static void Main(string[] args)
        {
            Toolbox.RegisterLogCallback(ErrorCallback, LogMask.ERROR);
            Toolbox.SetDefinitionLoadCallback(File.ReadAllText);
            Toolbox.SetResourceLoadCallback(File.ReadAllBytes);
            Comet.InitModule();
            Nebula.InitModule();
            Engine.InitModule("SBG/MouseDeamon");

            while (!Engine.IsLocalRunning())
            {
                Console.WriteLine("Waiting for local engine...");
                System.Threading.Thread.Sleep(1000);
            }

            try {
                Satellite.GetSelf();
            } catch (StarburstException) {
                Satellite.Deploy();
            }
            Component mouseComp = new Component("SBG/MouseClient");

            Topic.CometReceiver mousePositionTopic = new Topic.CometReceiver("mousePosition", Topic.CometReceiver.StorageType.STREAM);
            Topic.CometReceiver mouseEventTopic    = new Topic.CometReceiver("mouseEvent", Topic.CometReceiver.StorageType.QUEUE);

            Satellite self    = Satellite.GetSelf();
            string    address = EngineClient.Get(self.EngineClientID).Address;

            Session se = null;

            while (!Session.TryFind(out se))
            {
                System.Threading.Thread.Sleep(1000);
            }
            Engine.JoinSession(se);
            while (mouseComp.Action != ComponentAction.START)
            {
                System.Threading.Thread.Sleep(100);
            }
            mouseComp.ReportState(ComponentState.STARTED);

            CMouseInput mi = new CMouseInput {
                dwFlags = CMouseInput.FLAG_ABSOLUTE
            };

            var  inputPtr     = Marshal.AllocHGlobal(Marshal.SizeOf <CInput>());
            bool inputChanged = false;

            while (mouseComp.Action != ComponentAction.STOP)
            {
                Comet c = mousePositionTopic.GetComet();                    // Range: -1 to 1
                if (c != null)
                {
                    if ((mi.dx != WinRange(c["X"].AsFloat()) || mi.dy != WinRange(c["Y"].AsFloat())) && c["Client"].AsString() == address)
                    {
                        mi.dx        = WinRange(c["X"].AsFloat());                    // Range: 0 to 65536
                        mi.dy        = WinRange(c["Y"].AsFloat());
                        mi.dwFlags  |= CMouseInput.FLAG_MOUSEMOVED;
                        inputChanged = true;
                    }

                    c.Dispose();
                }

                c = mouseEventTopic.GetComet();
                if (c != null)
                {
                    if (c["Client"].AsString() == address)
                    {
                        mi.dwFlags  |= c["LeftDown"].AsBool() ? CMouseInput.FLAG_LEFTDOWN : 0;
                        mi.dwFlags  |= c["LeftUp"].AsBool() ? CMouseInput.FLAG_LEFTUP : 0;
                        mi.dwFlags  |= c["RightDown"].AsBool() ? CMouseInput.FLAG_RIGHTDOWN : 0;
                        mi.dwFlags  |= c["RightUp"].AsBool() ? CMouseInput.FLAG_RIGHTUP : 0;
                        inputChanged = true;
                    }

                    c.Dispose();
                }

                if (inputChanged)
                {
                    Marshal.StructureToPtr(mi.AsCInput(), inputPtr, true);
                    if (SendInput(1, inputPtr, Marshal.SizeOf <CInput>()) < 1)
                    {
                        throw new Exception("Couldn't send input : error " + GetLastError());
                    }
                    mi.dwFlags   = CMouseInput.FLAG_ABSOLUTE;                    // reseting flags
                    inputChanged = false;
                }

                System.Threading.Thread.Sleep(20);
            }
            mouseComp.ReportState(ComponentState.STOPPED);
        }