static void Main(string[] args)
        {
            string[] paths = new string[] { @"af:\\MARC-PI2016\IntegratingPISystemAndR\MainElement|Inside Humidity",
                                            @"af:\\MARC-PI2016\IntegratingPISystemAndR\MainElement|Inside Temperature",
                                            @"af:\\MARC-PI2016\IntegratingPISystemAndR\MainElement|OutsideTemperature" };
            REngine           _engine        = REngine.GetInstance(null, true, null, null);
            SvgGraphicsDevice GraphicsDevice = new SvgGraphicsDevice(new SvgContextMapper(700, 700, SvgUnitType.Pixel, null));

            _engine.Initialize();
            _engine.Install(GraphicsDevice);

            RApplication app = new RApplication();

            app.GetPIData(paths, "1-Oct-2012", "1-Nov-2012", "1h");
            app.GenerateGraphic(_engine);
        }
Example #2
0
        public IHttpActionResult Execute(QueryData queryData)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();

            try
            {
                if ((queryData.Paths == null) || (queryData.Paths.Count() < 2))
                {
                    throw new Exception("There should be at least 2 attributes within the symbol.");
                }
                if (queryData.Paths.All(m => m.Substring(0, 2) == "af") == false)
                {
                    throw new Exception("PI Points are not accepted");
                }
                IEnumerable <string> plots = null;
                RApplication         app   = new RApplication();
                app.GetPIData(queryData.Paths, queryData.StartTime, queryData.EndTime, queryData.Interval);

                lock (_object)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (lastWidth != queryData.Width)
                    {
                        GraphicsDevice = new SvgGraphicsDevice(new SvgContextMapper(queryData.Width, queryData.Height, SvgUnitType.Pixel, null));
                        _engine.Install(GraphicsDevice);
                        lastWidth = queryData.Width;
                    }

                    app.GenerateGraphic(_engine);
                    plots = GraphicsDevice.GetImages().Select(RenderSvg);
                }
                return(Ok(plots));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message + "|\n" + ex.Source + "|\n" + ex.StackTrace));
            }
            finally
            {
                watch.Stop();
            }
        }