Inheritance: BaseContent
Exemple #1
0
        private void LoadAllQueries(string sqlFolder)
        {
            if (sqlQueries.Any())
            {
                sqlQueries.ForEach(s =>
                {
                    var sqlQuery = s as SqlQuery;
                    if (sqlQuery != null)
                        DrawCircle(sqlQuery.InputParameters.FirstOrDefault(p => p.Type == SqlParameterTypes.RadiusInMeter));
                });
                return;
            }
            foreach (var parameter in Model.Model.Parameters)
            {
                switch (parameter.Name)
                {
                    case "SqlQueries":
                        var set = new XmlReaderSettings {ConformanceLevel = ConformanceLevel.Fragment};
                        var query = parameter.Value;
                        try
                        {
                            var xs = XDocument.Load(XmlReader.Create(new StringReader(query), set));

                            var c = xs.Root;
                            if (c != null)
                                foreach (var xcl in c.Elements())
                                {
                                    var sqlQuery = new SqlQuery();
                                    sqlQuery.FromXml(xcl, sqlFolder);
                                    sqlQueries.Add(sqlQuery);

                                    DrawCircleAndExecuteQuery(sqlQuery);
                                }
                        }
                        catch (SystemException e)
                        {
                            Logger.Log("SqlQueryModel", "Cannot load SQL query", e.Message, Logger.Level.Error, true);
                        }
                        break;
                    case "SymbolStyle":
                        var symbolString = parameter.Source == ModelParameterSource.direct
                            ? parameter.Value
                            : Poi.Labels.ContainsKey(parameter.Value)
                                ? Poi.Labels[parameter.Value] 
                                : Poi.Service.Settings.Labels.ContainsKey(parameter.Value)
                                    ? Poi.Service.Settings.Labels[parameter.Value]
                                    : SymbolStyle.Line.ToString();
                        Enum.TryParse(symbolString, true, out symbolStyle);
                        if (parameter.Source == ModelParameterSource.label && Poi.Labels.ContainsKey(parameter.Value))
                        {
                            var p = parameter;
                            Poi.LabelChanged += (sender, args) =>
                            {
                                if (!string.Equals(args.Label, p.Value)) return;
                                QueryLayer.Graphics.Remove(GetCircle());
                                foreach (var sqlQuery in sqlQueries.OfType<SqlQuery>())
                                    DrawCircle(sqlQuery.InputParameters.FirstOrDefault(p1 => p1.Type == SqlParameterTypes.RadiusInMeter));
                            };
                        }
                        break;
                    case "StrokeColor":
                        var colorString = parameter.Source == ModelParameterSource.direct
                            ? parameter.Value
                            : Poi.Labels.ContainsKey(parameter.Value)
                                ? Poi.Labels[parameter.Value]
                                : Poi.Service.Settings.Labels.ContainsKey(parameter.Value)
                                    ? Poi.Service.Settings.Labels[parameter.Value] 
                                    : "Red";
                        var color = ColorConverter.ConvertFromString(colorString);
                        if (color != null) strokeBrush = new SolidColorBrush((Color) color);
                        if (parameter.Source == ModelParameterSource.label && Poi.Labels.ContainsKey(parameter.Value))
                        {
                            var p = parameter;
                            Poi.LabelChanged += (sender, args) =>
                            {
                                if (!string.Equals(args.Label, p.Value)) return;
                                color = ColorConverter.ConvertFromString(Poi.Labels[p.Value]);
                                if (color != null) strokeBrush = new SolidColorBrush((Color) color);
                                foreach (var sqlQuery in sqlQueries.OfType<SqlQuery>())
                                    DrawCircle(sqlQuery.InputParameters.FirstOrDefault(p1 => p1.Type == SqlParameterTypes.RadiusInMeter));
                            };
                        }
                        break;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Draw the circle and, optionally, execute the query again.
        /// The query is executed when the changedLabel == string.Empty (forced), or when there is a label-based
        /// input parameter that has changed.
        /// </summary>
        /// <param name="sqlQuery"></param>
        /// <param name="changedLabel"></param>
        private void DrawCircleAndExecuteQuery(SqlQuery sqlQuery, string changedLabel = "")
        {
            DrawCircle(sqlQuery.InputParameters.FirstOrDefault(p => p.Type == SqlParameterTypes.RadiusInMeter));

            if (string.IsNullOrEmpty(changedLabel) || sqlQuery.InputParameters.Any(p => string.Equals(p.LabelName, changedLabel)))
            {
                sqlQuery.Execute(Poi.Service as PoiService, Poi, null, true);
            }
        }