Esempio n. 1
0
        private object GetModelFromService(long layoutId)
        {
            AvrServiceAccessability access = AvrServiceAccessability.Check();

            if (!access.IsOk)
            {
                return(access.ErrorMessage);
            }
            AvrServicePivotResult pivotResult = ServiceClientHelper.GetAvrServicePivotResult(Session.SessionID, layoutId);

            if (!pivotResult.IsOk)
            {
                return(pivotResult.ErrorMessage);
            }

            pivotResult.Model.ViewHeader.AssignOwnerAndUniquePath();

            DataTable dt = pivotResult.Model.ViewData;

            AvrViewHelper.AddIDColumn(ref dt);

            AvrViewHelper.RemoveHASCadditions(pivotResult.Model.ViewHeader, ref dt);
            pivotResult.Model.ViewData = dt;

            return(pivotResult);
        }
Esempio n. 2
0
        private AvrPivotGridModel GetModelFromSession(long layoutId = -1)
        {
            if (layoutId <= 0)
            {
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
                layoutId = Convert.ToInt64(nameValueCollection["layoutId"]);
            }
            //var model = ModelStorage.Get(Session.SessionID, layoutId, StoragePrefix, false) as AvrPivotGridModel;
            var model = ObjectStorage.Using <AvrPivotGridModel, AvrPivotGridModel>(o => o, Session.SessionID, layoutId, StoragePrefix, false);

            if (model == null)
            {
                long queryId = 0L;
                try
                {
                    AvrServiceAccessability access = AvrServiceAccessability.Check();
                    if (!access.IsOk)
                    {
                        m_ErrorMessage = access.ErrorMessage;
                        return(null);
                    }

                    model = FillData(ref queryId, layoutId);
                }
                catch (Exception ex)
                {
                    m_ErrorMessage = ex.Message;
                    return(null);
                }
                ObjectStorage.Put(Session.SessionID, queryId, layoutId, StoragePrefix, model);
            }
            LayoutPivotGridHelper.ResetDisplayTextHandler();

            return(model);
        }
Esempio n. 3
0
 public void AvrServiceHelperCheckAvrServiceAccessTest()
 {
     using (var wrapper = new AvrServiceClientWrapper(m_HostKeeper.CurrentServiceHostURL))
     {
         AvrServiceAccessability access = AvrServiceAccessability.Check(wrapper);
         Assert.IsTrue(access.IsOk);
     }
 }
Esempio n. 4
0
        private string RefreshQueryData(long queryId)
        {
            AvrServiceAccessability access = AvrServiceAccessability.Check();

            if (!access.IsOk)
            {
                return(access.ErrorMessage);
            }
            ServiceClientHelper.AvrServiceClearQueryCache(queryId);
            ServiceClientHelper.RefreshQuery(queryId);
            return(string.Empty);
        }
Esempio n. 5
0
        public ActionResult GetGeoDB(long layoutId)
        {
            var    connectionCredentials = new bv.common.Configuration.ConnectionCredentials();
            string connection            = connectionCredentials.ConnectionString;

            AvrServiceAccessability access = AvrServiceAccessability.Check();

            if (!access.IsOk)
            {
                return(View("AvrServiceError", (object)access.ErrorMessage));
            }

            return(ObjectStorage.Using <AvrPivotViewModel, ActionResult>(viewModel =>
            {
                ViewBag.Title = string.Format(Translator.GetMessageString("webMapTitle"), viewModel.ViewHeader.LayoutName);

                // have we anything selected in combo admin unit?
                if (!string.IsNullOrEmpty(viewModel.ViewHeader.MapAdminUnitViewColumn))
                {
                    DataSet dataSet;
                    string error = ChartMapHelper.TryToPrepareMapData(viewModel, out dataSet);
                    if (error.Length > 0)
                    {
                        return View("AvrServiceError", (object)error);
                    }

                    string path = Path.Combine(Server.MapPath("~/App_Data/ExportQueryFiles"), DateTime.Now.Ticks.ToString());
                    System.IO.Directory.CreateDirectory(path); path = path + '\\';
                    string SrvPath = Server.MapPath("");
                    eidss.gis.common.MapUtils.ExportToFGDB(dataSet, connection, path);

                    string filename = "Export.fgdb.zip";
                    string filepath = path + filename;
                    byte[] filedata = System.IO.File.ReadAllBytes(filepath);

                    var cd = new System.Net.Mime.ContentDisposition
                    {
                        FileName = filename,
                        Inline = true,
                    };

                    Response.AppendHeader("Content-Disposition", cd.ToString());

                    return File(filedata, "application/force-download");
                }
                return View();
            }, Session.SessionID, layoutId, ViewLayoutController.StoragePrefix));
        }
Esempio n. 6
0
        public ActionResult ExportQuery(long queryId, int exportType)
        {
            AvrServiceAccessability access = AvrServiceAccessability.Check();
            var result = new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new
                {
                    result = access.IsOk ? "OK" : "ERROR",
                    url    = access.IsOk
                        ? Url.Action("ExportQueryRoutines", new { queryId, exportType })
                        : Url.Action("AvrServError", new { error = access.ErrorMessage }),
                }
            };

            return(result);
        }
Esempio n. 7
0
        private string RefreshPivotData()
        {
            AvrServiceAccessability access = AvrServiceAccessability.Check();

            if (!access.IsOk)
            {
                return(access.ErrorMessage);
            }
            AvrPivotGridModel model = GetModelFromSession();

            if (model != null)
            {
                ServiceClientHelper.AvrServiceClearQueryCache(model.PivotSettings.QueryId);
                RemovePivotViewObjects(model.PivotSettings.LayoutId);
            }
            return(string.Empty);
        }
Esempio n. 8
0
        public ActionResult Index(long layoutId)
        {
            var    connectionCredentials = new bv.common.Configuration.ConnectionCredentials();
            string connection            = connectionCredentials.ConnectionString;

            AvrServiceAccessability access = AvrServiceAccessability.Check();

            if (!access.IsOk)
            {
                return(View("AvrServiceError", (object)access.ErrorMessage));
            }

            return(ObjectStorage.Using <AvrPivotViewModel, ActionResult>(viewModel =>
            {
                ViewBag.Title = string.Format(Translator.GetMessageString("webMapTitle"), viewModel.ViewHeader.LayoutName);

                // have we anything selected in combo admin unit?
                if (!string.IsNullOrEmpty(viewModel.ViewHeader.MapAdminUnitViewColumn))
                {
                    DataSet dataSet;
                    string error = ChartMapHelper.TryToPrepareMapData(viewModel, out dataSet);
                    if (error.Length > 0)
                    {
                        return View("AvrServiceError", (object)error);
                    }

                    //TEST
                    for (int j = 0; j < dataSet.Tables[1].Rows.Count; j++)
                    {
                        string c_name = dataSet.Tables[1].Rows[j]["ColumnName"].ToString();
                        string c_new_name = dataSet.Tables[1].Rows[j]["ColumnDescription"].ToString();
                        c_new_name = c_new_name.TrimStart(); // Spaces in column name, comes outside
                        dataSet.Tables[0].Columns[c_name].ColumnName = c_new_name;
                    }

                    SharpMap.Rendering.Thematics.ITheme gradLayerTheme;
                    SharpMap.Rendering.Thematics.ITheme chartLayerTheme;
                    string gradLayerName, chartLayerName;
                    gis.GisInterface.GetAvrStyles(layoutId, out gradLayerName, out gradLayerTheme, out chartLayerName, out chartLayerTheme);

                    if (chartLayerTheme is GIS_V4.Rendering.BarChartTheme)
                    {
                        var chart_theme = (GIS_V4.Rendering.BarChartTheme)chartLayerTheme;
                        string chart_style = "{\"BarCharts\" : [";
                        for (int j = 0; j < chart_theme.BarChartItems.Count; j++)
                        {
                            var c_column = chart_theme.BarChartItems[j].ColumnName;
                            var c_color = HexConverter(chart_theme.BarChartItems[j].Color);
                            chart_style += '{' + string.Format("\"title\":\"{0}\", \"color\":\"{1}\"", c_column, c_color) + '}' + ", ";
                        }
                        chart_style += "]}";
                        chart_style = chart_style.Replace(", ]", "]");
                        ViewBag.chart_style = new HtmlString(chart_style);
                    }

                    if (gradLayerTheme is GIS_V4.Rendering.GradientTheme)
                    {
                        GIS_V4.Rendering.GradientTheme grad_theme = (GIS_V4.Rendering.GradientTheme)gradLayerTheme;
                        string min_value = grad_theme.Min.ToString();
                        string max_value = grad_theme.Max.ToString();

                        System.Drawing.SolidBrush min_brush = (System.Drawing.SolidBrush)((SharpMap.Styles.VectorStyle)grad_theme.MinStyle).Fill;
                        string min_r = min_brush.Color.R.ToString();
                        string min_g = min_brush.Color.G.ToString();
                        string min_b = min_brush.Color.B.ToString();

                        System.Drawing.SolidBrush max_brush = (System.Drawing.SolidBrush)((SharpMap.Styles.VectorStyle)grad_theme.MaxStyle).Fill;
                        string max_r = max_brush.Color.R.ToString();
                        string max_g = max_brush.Color.G.ToString();
                        string max_b = max_brush.Color.B.ToString();

                        ViewBag.grad_style = new HtmlString("{" + string.Format("\"type\":\"gradient\", \"min_value\":{0}, \"max_value\":{1}, \"min_color\":[{2}, {3}, {4}], \"max_color\":[{5}, {6}, {7}]", min_value, max_value, min_r, min_g, min_b, max_r, max_g, max_b) + "}");
                    }

                    if (gradLayerTheme is GIS_V4.Rendering.GraduatedTheme)
                    {
                        dataSet.Tables[0].Columns.Add("color");
                        dataSet.Tables[0].Columns.Add("symbol");


                        string grad_style = "{\"type\":\"graduated\", \"legend\" : [";
                        GIS_V4.Rendering.GraduatedTheme grad_theme = (GIS_V4.Rendering.GraduatedTheme)gradLayerTheme;
                        for (int i = 0; i < grad_theme.Rules.Count; i++)
                        {
                            string value_title = ((GIS_V4.Rendering.GraduatedTheme)gradLayerTheme).Rules[i].Title;
                            System.Drawing.SolidBrush value_brush = (System.Drawing.SolidBrush)((SharpMap.Styles.VectorStyle)grad_theme.Rules[i].Style).Fill;
                            var val_color = HexConverter(value_brush.Color);
                            var val_symbol = ((SharpMap.Styles.VectorStyle)grad_theme.Rules[i].Style).SymbolId;

                            grad_style += '{' + string.Format("\"title\":\"{0}\", \"color\":\"{1}\", \"symbol\":\"{2}\"", value_title, val_color, val_symbol) + '}' + ", ";

                            var dataView = dataSet.DefaultViewManager.CreateDataView(dataSet.Tables[0]);
                            dataView.RowFilter = grad_theme.Rules[i].Condition;
                            for (int j = 0; j < dataView.Count; j++)
                            {
                                dataView[j].Row["color"] = val_color;
                                dataView[j].Row["symbol"] = val_symbol;
                            }
                        }
                        grad_style += "]}";
                        grad_style = grad_style.Replace(", ]", "]");
                        ViewBag.grad_style = new HtmlString(grad_style);
                    }


                    // Space in column fix
                    for (int j = 0; j < dataSet.Tables[1].Rows.Count; j++)
                    {
                        string c_new_name = dataSet.Tables[1].Rows[j]["ColumnDescription"].ToString();
                        c_new_name = c_new_name.TrimStart(); // Spaces in column name, comes outside
                        dataSet.Tables[0].Columns[c_new_name].ColumnName = c_new_name.TrimStart();
                        dataSet.Tables[1].Rows[j]["ColumnDescription"] = c_new_name.TrimStart();
                    }

                    using (var sqlConnection = new SqlConnection(connection))
                    {
                        try
                        {
                            sqlConnection.Open();
                            var CountryID = EidssSiteContext.Instance.CountryID;
                            SharpMap.Geometries.Geometry feature = Extents.GetGeomById(sqlConnection, "gisWKBCountry", CountryID);
                            if (feature != null)
                            {
                                feature = GeometryTransform.TransformGeometry(feature, GIS_V4.Common.CoordinateSystems.SphericalMercatorCS, GIS_V4.Common.CoordinateSystems.WGS84);
                            }
                            SharpMap.Geometries.Point center_point = feature.GetBoundingBox().GetCentroid();
                            ViewBag.county_lon = center_point.X;
                            ViewBag.county_lat = center_point.Y;
                        }
                        catch (Exception)
                        {
                            ViewBag.county_lon = 0;
                            ViewBag.county_lat = 0;
                        }
                    }
                    //TEST

                    if (error.Length == 0)
                    {
                        var ds = new DataSet();
                        ds.Tables.Add(dataSet.Tables[1].Copy());
                        string json = GeoJSON.DataSetToJSON(ds);
                        string avr_json = GeoJSON.DataSetToJSON(ds);
                        ViewBag.avr_json = new HtmlString(avr_json);

                        string map_json = GetMapJson(dataSet.Tables[0]);
                        ViewBag.map_json = new HtmlString(map_json);
                        ViewBag.ColumnName = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[1].ToString());
                        ViewBag.ColumnDescription = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[1].ToString());
                        ViewBag.blnIsGradient = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[2].ToString());
                        ViewBag.gradLayerName = new HtmlString(gradLayerName);
                        ViewBag.chartLayerName = new HtmlString(chartLayerName);
                        ViewBag.blnIsChart = new HtmlString(dataSet.Tables[1].Rows[0].ItemArray[3].ToString());
                        ViewBag.map_localurl = Config.GetSetting("MapLocalUrl");
                        if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
                        {
                            ViewBag.left2right = 1;
                        }
                        else
                        {
                            ViewBag.left2right = 0;
                        }

                        return View("Index", dataSet);
                    }
                    return View("AvrServiceError", (object)error);
                }
                return View();
            }, Session.SessionID, layoutId, ViewLayoutController.StoragePrefix));
        }