Example #1
0
        static void OnTemplateChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            // Get reference to self
            QueryEditorModel source = (QueryEditorModel)sender;

            // Add Handling Code
            string newValue = (string)args.NewValue;

            if (!String.IsNullOrEmpty(newValue))
            {
                List <string> parameteres = QueryBuilder.GetParameters(newValue);
                if (parameteres.Count > 0)
                {
                    source.Parameters.Clear();
                    foreach (var item in parameteres.Distinct())
                    {
                        if (source.ParameterResolvers != null && source.ParameterResolvers.ContainsKey(item))
                        {
                            source.Parameters.Add(ParameterResolver.GetParameter(item, source.ParameterResolvers[item]));
                        }
                        else
                        {
                            source.Parameters.Add(ParameterResolver.GetParameter(item, null));
                        }
                    }

                    source.QueryString = newValue;
                    source.State       = QueryModelState.Template;
                }
                else
                {
                    var fileContent = args.NewValue as string;
                    source.QueryString = fileContent;
                    source.Template    = null;
                    source.State       = QueryModelState.Opened;
                    source.HasChanges  = false;
                }
            }
        }