Пример #1
0
        public async Task<JsonResult> GetData(long wellboreId, DateTime startTime, DateTime? endTime, List<Parameter> parameters)
        {
            Response.BufferOutput = false;

            //IRealtimeConnection testConnection;
            var pipeConnection = new PipeConnection();
            var limitPoints = new List<decimal>();

            using (var store = new Store())
            {
                StringBuilder queryBuilder = new StringBuilder();
                parameters.ForEach(x => store.FillParameter(x));
                parameters.ForEach(x => queryBuilder.Append(",").Append(x.Code));
                limitPoints = store.GetLimitPoints(wellboreId, startTime, parameters, queryBuilder);

                var data = store.GetData(parameters, new Wellbore { Id = wellboreId }, startTime, (DateTime)endTime);
                var processedData = DataProcess.ProcessNewData(data, parameters, limitPoints);

                limitPoints = processedData.Last().Take(processedData.Last().Count - 1).ToList();

                Response.Write(processedData);
                Response.Flush();
            }

            if (endTime == null)
                return Json(new { success = true });

            pipeConnection.ConfigureConnection(wellboreId, parameters, limitPoints);

            pipeConnection.PipeClient =
                       new NamedPipeClientStream(".", "PipeConnection",
                           PipeDirection.InOut, PipeOptions.Asynchronous);
            pipeConnection.PipeClient.Connect();

            while (true)
            {
                var newData = await pipeConnection.GetNewData();
                if (newData == null) break;

                var processedRealTimeData = DataProcess.ProcessNewData(newData, parameters, limitPoints);
                limitPoints = processedRealTimeData.Last().Take(processedData.Last().Count - 1).ToList();

                Response.Write(DataProcess.ProcessNewData(newData, parameters, limitPoints));
                Response.Flush();
            }
            
            Response.End();
            pipeConnection.PipeClient.Close();
            return Json(new { success = true }, JsonRequestBehavior.AllowGet);
        }