Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                var curProcess = Process.GetCurrentProcess();
                var secondsOnStart = curProcess.TotalProcessorTime.TotalSeconds;
                var totalWatch = Stopwatch.StartNew();

                for (int i = 0; i < 20; i++)
                {
                    var client = new Client(Const.RPC_URI, Const.STREAMING_URI, "");
                    var recorder = new Recorder(client);
                    recorder.Start();

                    var loginWatch = Stopwatch.StartNew();
                    client.LogIn(Const.USERNAME, Const.PASSWORD);
                    loginWatch.Stop();

                    var accountInfoWatch = Stopwatch.StartNew();
                    var accountInfo = client.AccountInformation.GetClientAndTradingAccount();
                    accountInfoWatch.Stop();

                    var listSpreadMarketsWatch = Stopwatch.StartNew();
                    var resp = client.SpreadMarkets.ListSpreadMarkets("", "",
                        accountInfo.ClientAccountId, 100, false);
                    listSpreadMarketsWatch.Stop();

                    var logoutWatch = Stopwatch.StartNew();
                    client.LogOut();
                    logoutWatch.Stop();

                    var purgeHandle = client.ShutDown();
                    if (!purgeHandle.WaitOne(60000))
                        throw new ApplicationException();

                    var requests = recorder.GetRequests();
                    if (requests.Count != 4)
                        throw new ApplicationException();

                    AddResult(loginWatch, requests[0], "Login");
                    AddResult(accountInfoWatch, requests[1], "GetClientAndTradingAccount");
                    AddResult(listSpreadMarketsWatch, requests[2], "ListSpreadMarkets");
                    AddResult(logoutWatch, requests[3], "Logout");

                    recorder.Stop();
                    recorder.Dispose();
                    client.Dispose();
                }

                totalWatch.Stop();
                var secondsOnEnd = curProcess.TotalProcessorTime.TotalSeconds;
                Console.WriteLine("CPU time used, seconds: {0} total time: {1}", secondsOnEnd - secondsOnStart, totalWatch.Elapsed.TotalSeconds);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }

            Debugger.Break();
        }
Пример #2
0
        static void Main(string[] args)
        {

            var gate = new AutoResetEvent(false);
            Exception exception = null;
            
            var server = new CassiniDevServer();
            var path = new ContentLocator("WcfRestService1").LocateContent();
            server.StartServer(path);

            var client = new SampleClient(server.NormalizeUrl("").TrimEnd('/'));
            var recorder = new Recorder(client);
            recorder .Start();



            client.BeginListService1(ar =>
                                         {
                                             try
                                             {
                                                 List<SampleItem> result = client.EndListService1(ar);
                                                 Console.WriteLine(DateTime.Now + " " + result.Count);
                                             }
                                             catch (Exception ex)
                                             {

                                                 exception = ex;
                                             }
                                             finally
                                             {
                                                 gate.Set();
                                             }


                                         }, null);


            Wait(exception, gate);


            server.StopServer();
            server.Dispose();


            var recording = recorder.GetRequests();
            recorder.Dispose();

            var serializedRecording = client.Serializer.SerializeObject(recording);

            client.Dispose();

            File.WriteAllText("output.txt", serializedRecording);
        }
        public void DoWork()
        {
            var rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, "bogus_app_key");

            var recorder = new Recorder(rpcClient);
            recorder.Start();
            
            rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);


            var accounts = rpcClient.AccountInformation.GetClientAndTradingAccount();

            var response = rpcClient.CFDMarkets.ListCfdMarkets("USD", null, accounts.ClientAccountId, 500, false);

            var dto = new ListMarketInformationRequestDTO();
            dto.MarketIds = response.Markets.Select(m => m.MarketId).ToArray();
            var marketInformation = rpcClient.Market.ListMarketInformation(dto);
             rpcClient.LogOut();
            
            
            recorder.Stop();

            var json = rpcClient.Serializer.SerializeObject(recorder.GetRequests());
        }
Пример #4
0
        public void HowToUseRecorder()
        {
            var rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, AppKey);

            // start recording requests
            var recorder = new Recorder(rpcClient);
            recorder.Start();

            rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);





            // get some headlines
            var headlines = rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 100);

            // get a story id from one of the headlines
            var storyId = headlines.Headlines[0].StoryId;

            // get the body of the story
 
            var storyDetail = rpcClient.News.GetNewsDetail("dj", storyId.ToString());

            Assert.IsNotNullOrEmpty(storyDetail.NewsDetail.Story, "story was empty?");


            rpcClient.LogOut();
            recorder.Stop();

            List<RequestInfoBase> requests = recorder.GetRequests();
            // let's serialize the recorded requests to simulate typical usage because you typically would use pre-canned data
            // to run unit tests agains.
            var requestsSerialized = rpcClient.Serializer.SerializeObject(requests);

            rpcClient.Dispose();





            // now we will use our recorded (and serialized) request data to run the same requests through the client 
            // without actually sending any requests over the wire.


            TestRequestFactory factory = new TestRequestFactory();

            rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, AppKey, new Serializer(), factory);
            rpcClient.IncludeIndexInHeaders = true;

            requests = rpcClient.Serializer.DeserializeObject<List<RequestInfoBase>>(requestsSerialized);
            var finder = new TestWebRequestFinder { Reference = requests };

            // setup a callback on the test request factory so that we can populate the response using the recorded data

            factory.PrepareResponse = testRequest =>
                {

                    // look for a matching request in our recording using the uri and request body
                    var match = finder.FindMatchExact(testRequest);

                    if (match == null)
                    {
                        throw new Exception("no matching request found");
                    }
                    finder.PopulateRequest(testRequest, match);
                };

            // now that our request stack is set up, we can make the same calls with repeatable results


            rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword);

            // get some headlines
            headlines = rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 100);

            // get a story id from one of the headlines
            storyId = headlines.Headlines[0].StoryId;

            storyDetail = rpcClient.News.GetNewsDetail("dj", storyId.ToString());

            Assert.IsNotNullOrEmpty(storyDetail.NewsDetail.Story, "story was empty?");


            rpcClient.LogOut();
            rpcClient.Dispose();
        }