Exemple #1
0
 internal static ResultData CreateResultData(ComputeWithInputDataResponse response)
 {
     return(new ResultData(response.ComputeWithInputDataResult.requestStartTime,
                           response.ComputeWithInputDataResult.requestEndTime,
                           response.ComputeWithInputDataResult.commonDataAccessStartTime,
                           response.ComputeWithInputDataResult.commonDataAccessStopTime,
                           TryParseTaskInstanceId(response.ComputeWithInputDataResult.CCP_TASKINSTANCEID),
                           response.ComputeWithInputDataResult.sendStart,
                           DateTime.Now));
 }
Exemple #2
0
        private static void InternalTestAsync(SessionBase session)
        {
            int faultCalls = 0;

            byte[] task_data = new byte[input_data_size];
            (new Random()).NextBytes(task_data);

            if (sleep_before_sending > 0)
            {
                Thread.Sleep(sleep_before_sending);
            }

            data.StartSendRequest = DateTime.Now;

            Binding binding;

            if (http)
            {
                binding = Utils.CreateHttpBinding();
            }
            else
            {
                binding = Utils.CreateNetTcpBinding();
            }

            int            counting = batchCount;
            AutoResetEvent evt      = new AutoResetEvent(false);

            data.SendStart = DateTime.Now;

            for (int i = 0; i < batchCount; i++)
            {
                int msg_count = req_count / batchCount;
                if (i == batchCount - 1)
                {
                    msg_count += req_count % batchCount;
                }

                string clientId = Environment.MachineName + "-" + i.ToString() + "-" + Process.GetCurrentProcess().Id.ToString();
                Thread t        = new Thread(new ThreadStart(() =>
                {
                    int AsyncResultCount            = msg_count;
                    AutoResetEvent AsyncResultsDone = new AutoResetEvent(false);

                    Log("Client {0}: Begin to send requests", clientId);
                    if (req_count == 0)
                    {
                        AsyncResultsDone.Set();
                    }

                    List <ResultData> results = new List <ResultData>();
                    Service1Client client     = new Service1Client(binding, session.EndpointReference);

                    for (int k = 0; k < msg_count; k++)
                    {
                        ResultData result = new ResultData();
                        ComputeWithInputDataRequest request = new ComputeWithInputDataRequest
                        {
                            millisec   = millisec_for_each_req,
                            input_data = task_data,
                            commonData_dataClientId = commonData_dataClientId,
                            responseSize            = output_data_size,
                        };
                        client.BeginComputeWithInputData(request,
                                                         (AsyncCallback) delegate(IAsyncResult r)
                        {
                            try
                            {
                                ResultData rtn = r.AsyncState as ResultData;
                                ComputeWithInputDataResponse response = client.EndComputeWithInputData(r);
                                rtn.TaskId = int.Parse(response.ComputeWithInputDataResult.CCP_TASKINSTANCEID);
                                rtn.Start  = response.ComputeWithInputDataResult.requestStartTime;
                                rtn.End    = response.ComputeWithInputDataResult.requestEndTime;

                                lock (results)
                                {
                                    results.Add(rtn);
                                }
                            }
                            catch (Exception e)
                            {
                                Log(e.ToString());
                                lock (results)
                                {
                                    results.Add(new ResultData(DateTime.Now,
                                                               DateTime.Now,
                                                               -1,
                                                               DateTime.Now, DateTime.Now));
                                }
                                Interlocked.Increment(ref faultCalls);
                            }

                            if (Interlocked.Decrement(ref AsyncResultCount) <= 0)
                            {
                                AsyncResultsDone.Set();
                            }
                        },
                                                         result);
                    }


                    AsyncResultsDone.WaitOne();

                    Log("Client {0}: All requests returned.", clientId);

                    if (DateTime.Now > data.RetrieveEnd)
                    {
                        data.RetrieveEnd = DateTime.Now;
                    }

                    client.Close();

                    lock (data)
                    {
                        data.ResultCollection.AddRange(results);
                    }



                    if (Interlocked.Decrement(ref counting) <= 0)
                    {
                        evt.Set();
                    }
                }));

                t.Start();
            }

            evt.WaitOne();

            data.FaultCount = faultCalls;
        }